inversed Real [message #10921] |
Wed, 04 February 1998 00:00 |
Hans-Martin Latuske
Messages: 1 Registered: February 1998
|
Junior Member |
|
|
Hello,
I have to read REAL numbers (6 byte) from a data field using IDL. My
problem: In this field the order of the bytes of each real number is
inverted, which means lowest byte first.
here is my solution which is working, but in my opinion to long
************************************
pro d
filename=DIALOG_Pickfile(/READ,FILTER='*.img',PATH='./')
;read header
openr, 1, filename
hed=bytarr(4048)
readu, 1, hed
close, 1
;copy height scale factor
rn = hed(3291:3296)
;get exponent
ex = double(rn(0) - 129)
ex = 2.0^ex
;get mantissa
k =5
val=0.0
for i=1,39 do begin
b=ishft(128,-(i mod 8))
c=rn(k) and b
if c gt 0 then begin
val = val + 0.5^i
endif
if (((i+1) mod 8) eq 0) then k=k-1
endfor
;get sign
v=1.0
c = rn(0) and 128
if c > 0 then v=-1.0
; put everything together -> Heightscalefactor
r = v * ex * (1.0 + val)
if rn(5) eq 0 then r = 0.0
******************************************************
Is there somebody who nows a more sufficiant way to read this REAL
number?
Thanks
--
Hans-Martin Latuske
Institut fuer Experimentelle Physik
Otto-von-Guericke Universitaet Magdeburg
39102 Magdeburg
|
|
|