comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: floats from strings... duh!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: floats from strings... duh! [message #4360 is a reply to message #4357] Fri, 26 May 1995 00:00 Go to previous message
zowie is currently offline  zowie
Messages: 9
Registered: March 1994
Junior Member
Pete Clinch (pjclinch@dux.dundee.ac.uk) wrote:

: I'm sure I'm missing something obvious... want to do the equivalent of a
: C sscanf or atof on a string I've got in a PV~Wave program that has a
: floating point number in string form.

: Rather than write my own function to convert "1.234" to 1.234, is there a
: way in the system to do it easily?

Yeah -- just cast it. If you don't bother, IDL will usually cast it for
you, ie 'A = 5 + "3.14"' will set A to 8.14. This is (IMAO) the Wrong
Thing, because IDL will cast strings to numbers in contexts where you
don't want it, ie

mydata = indgen(30)
plotno = 5
plot,mydata,title="Plot number "+plotno

will screw up by attempting to cast "Plot number " to an integer, and generate
an error message. You have to say

plot,mydata,title="Plot number "+string(plotno)

which won't look right because the title will be "Plot number 5"
instead of "Plot number 5", so you need to tack another bag on that:

plot,mydata,title="Plot number "+strtrim(string(plotno),2)

which is a lot of verbiage for text formatting that you could do more
elegantly on an Apple ][ in 1978.

All this is a long winded way of saying not to worry, IDL will convert
your strings for you whether you want it to or not!

--
Craig DeForest "My research group launched a rocket into space, and all I
got was this lousy T-shirt"
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Help for non-RSI libraries under IDL 4.0
Next Topic: Shading a band of ranges in pvwave

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 23:20:15 PDT 2025

Total time taken to generate the page: 0.64278 seconds