long to float [message #24615] |
Thu, 05 April 2001 09:54  |
Dominik[1]
Messages: 46 Registered: April 2001
|
Member |
|
|
By furtune I came a liitle bit closer to the solution of my Problem, but
still coulndt solve it. But perhaps can somebody explain me this:
I tried it two ways:
first in a file:
pro test
out = -1.07615e+8
byteorder, out, /VAXTOF
end
which delivers me out = 14.2375
second way using the command line:
out = -1.07615e+8
byteorder, out, /VAXTOF
and in the variable watch now is out = 10.8 which is correct!
Also with -3.69732e+019, which should be 6588.0, but will be calculated in
the pro file to 6556, which is wrong
Funny?!?!?
Does somebody know a solution?
Thanks
Dominik
|
|
|
Re: long to float [message #24619 is a reply to message #24615] |
Thu, 05 April 2001 10:49  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Dominik wrote:
>
> Hello,
>
> I have a small problem (i hope)
>
> I read a number (is = -536852787) out of a file. But this number is not a
> long, it shoul be a float. It should be sb =6588.00. I am not sure if the
> first Number is a big endian, but the second is in little endian.
> so, after I multiply the start number with -1 and make byteorder, the same
> hexadecimal number is in the memory. It is FF1F33B9, but he shows
> e -14732359
> Is there a good way to see the stuff in memory as a float and not as a
> long??
>
> thanks for helping
> Dominik
>
> Example code
> pro test
>
> f = -536852787
> help, f
> print, Format='(Z)', f
> f = -1 * f
> help, f
> print, Format='(Z)', f
> byteorder, f
> help, f
> print, Format='(Z)', f
> end
I would tackle the problem on the step before: you mention you read
the number from a file. So (if it is a binary file) you should make
use of the swap_endian keyword if you read files produced on other
platforms. Then you can directly read in your float numbers with no
need of conversion.
BTW: You should always "declare" the variable type when you read stuff
from file, e.g.
time=0.D
value=0.
index=0L
readu,lun,time,value,index
Martin
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|