Re: floats from strings... duh! [message #4355] |
Sat, 27 May 1995 00:00 |
phil
Messages: 15 Registered: April 1995
|
Junior Member |
|
|
In article <3q568j$5bd@nntp.Stanford.EDU> zowie@banneker.stanford.edu (Craig DeForest) writes:
> 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)
>
you could also just use the strcompress function. ie:
plot,mydata,title="Plot number"+strcompress(plotno)
There is also no need for the trailing space in the "Plot number"
string since string compress prepends a space.
Hope this helps.
--
/*********************************************************** ****************/
Phil Williams
Postdoctoral Researcher "One man gathers what
MRI Facility another man spills..."
The Ohio State University -The Grateful Dead
email: phil@peace.med.ohio-state.edu
URL: http://justice.med.ohio-state.edu:1525
/*********************************************************** ****************/
|
|
|
Re: floats from strings... duh! [message #4356 is a reply to message #4355] |
Sat, 27 May 1995 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <3q4tku$iqu@dux.dundee.ac.uk>, pjclinch@dux.dundee.ac.uk (Pete Clinch) writes:
>
> 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?
>
Use the float() function. It can handle string input.
print, float('1.234')
1.23400
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|
Re: floats from strings... duh! [message #4357 is a reply to message #4355] |
Fri, 26 May 1995 00:00  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
afl@cdc.noaa.gov (Andy Loughe) writes:
> In article <3q4tku$iqu@dux.dundee.ac.uk>, pjclinch@dux.dundee.ac.uk (Pete
> Clinch) writes:
> |>
> |> 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?
> |>
> |> Thanks.
> |>
> |> Pete.
> |> --
> |> Peter Clinch Dundee Teaching Hospitals NHS Trust
> |> voice: 44 1382 660111 x 3637 snail: Directorate of Medical Physics
> |> fax: 44 1382 640177 Ninewells Hospital
> |> email: p.j.clinch@dundee.ac.uk Dundee DD1 9SY Scotland UK
> Again, I may be missing the boat here, but is this what you want?
> IDL> a = '1.234'
> IDL> b = float(a)
> IDL> help, b
> B FLOAT = 1.23400
In IDL, there's also a routine called READS, which works like READ or READF,
except that the input is a string instead of the keyboard or a file. Thus, one
could do things like
READS, '1.23 4.56 7.89', X, Y, Z
and can even use FORMAT statements. I don't know if this also exists in
PV-Wave or not.
Bill Thompson
|
|
|
Re: floats from strings... duh! [message #4359 is a reply to message #4357] |
Fri, 26 May 1995 00:00  |
afl
Messages: 51 Registered: December 1994
|
Member |
|
|
In article <3q4tku$iqu@dux.dundee.ac.uk>, pjclinch@dux.dundee.ac.uk (Pete
Clinch) writes:
|>
|> 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?
|>
|> Thanks.
|>
|> Pete.
|> --
|> Peter Clinch Dundee Teaching Hospitals NHS Trust
|> voice: 44 1382 660111 x 3637 snail: Directorate of Medical Physics
|> fax: 44 1382 640177 Ninewells Hospital
|> email: p.j.clinch@dundee.ac.uk Dundee DD1 9SY Scotland UK
Again, I may be missing the boat here, but is this what you want?
IDL> a = '1.234'
IDL> b = float(a)
IDL> help, b
B FLOAT = 1.23400
--
Andrew F. Loughe email: afl@cdc.noaa.gov
University of Colorado, CIRES voice: (303) 492-0707
Campus Box 449 fax: (303) 497-7013
Boulder, CO 80309-0449 USA
|
|
|
Re: floats from strings... duh! [message #4360 is a reply to message #4357] |
Fri, 26 May 1995 00:00  |
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"
|
|
|