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

Home » Public Forums » archive » Re: Casting floating point number into e-notation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Casting floating point number into e-notation [message #4551] Fri, 09 June 1995 00:00
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
cavanaug@uars1.acd.ucar.edu (Charles Cavanaugh) writes:


> Please, please, please somebody tell me what I'm doing wrong with
> my attempt to cast a floating point value into e-notation (using
> our old buddy IDL) :

> IDL> a = 3.567
> IDL> print, size(a)
> 0 4 1
> IDL> print, a
> 3.56700
> IDL> b = strtrim (a, 2)
> IDL> print, size(b)
> 0 7 1
> IDL> print, b
> 3.56700
> IDL> print, format = '(e11.4)', a
> 3.5670e+00
> IDL> print, format = '(e11.4)', b
> 3.5670e+00
> IDL> c = 0.0
> IDL> reads, format = '(e11.4)', a, c
> IDL> print, size(c)
> 0 4 1
> IDL> print, c
> 3.56700
> IDL> reads, format = '(e11.4)', b, c
> IDL> print, size(c)
> 0 4 1
> IDL> print, c
> 3.56700
> IDL> c = ''
> IDL> reads, format = '(e11.4)', a, c
> IDL> print, size(c)
> 0 7 1
> IDL> print, c
> 3.5670000
> IDL> reads, format = '(e11.4)', b, c
> IDL> print, size(c)
> 0 7 1
> IDL> print, c
> 3.5670000


> The print command works as expected when given a format, but when reads is
> used, the variable "c", afraid of being labelled as an e-type by his f-type
> friends, refuses, with all his strength, to be cast into e-notation. Why?
>

What I can't figure out is why you're using READS to cast something as a string
variable. I expect what's happening is the following:

1. READS uses the FORMAT specification to determine how to read the
string and convert it into one or more numerical values.

2. If the input parameter isn't a string, then IDL first makes it a
string and then reads it back out as a number again. This is
polite of it, but leads to confusion. It does not use the FORMAT
specification when converting it into the string, because the
FORMAT is for reading, not writing.

3. After reading the parameter according to the format specification,
it recasts the output into the correct data type. If necessary, it
recasts it into a string, but again it doesn't use the format
specification to do that, because that's not what it's for.

To see why it doesn't use the FORMAT expression to format the output, consider
the following statements.

IDL> A = ''
IDL> B = 0
IDL> READS, 'XY=345' , A, B, FORMAT='(A2,1X,I3)'

If it needed to recast the B value back into a string for some reason, it
wouldn't be able to use the FORMAT statement to do that because it wouldn't be
valid.

Bill Thompson
Re: Casting floating point number into e-notation [message #4554 is a reply to message #4551] Fri, 09 June 1995 00:00 Go to previous message
Tim Hammond is currently offline  Tim Hammond
Messages: 1
Registered: June 1995
Junior Member
cavanaug@uars1.acd.ucar.edu (Charles Cavanaugh) wrote:
>
> Please, please, please somebody tell me what I'm doing wrong with
> my attempt to cast a floating point value into e-notation (using
> our old buddy IDL) :
>


I'm not sure if this is exactly what you were asking, but to read a float
value into a string in exponential form you can simply use:

IDL> a=3.567
IDL> b=strtrim(string(a,format='(e11.4)'),2)
IDL> print,b
3.5670e+00
IDL> help,b
B STRING = '3.5670e+00'

If you actually want to force the numbers themselves to appear in this
format whatever their value then I'm afraid I can't help, sorry...

All the best,

Tim Hammond.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Widget convulsions.
Next Topic: Re: No more plot_io, plot_oi, plot_oo calls in IDL version 4.0?????

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

Current Time: Wed Oct 08 18:14:12 PDT 2025

Total time taken to generate the page: 0.00674 seconds