[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Byte to Real conversion



Michael A. Wirth wrote:
> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?

An easy way is to use a structure. For example, let's say the header
format is:
Bytes  0:9 are junk
Bytes 10:11 are a signed 16 bit integer
Bytes 12:15 are a 32 bit float
Bytes 16:14335 are junk

To read the header:

header = { junk1 : bytarr( 10 ), $    ; array of 10 bytes
           word1 : 0, $               ; short integer
           word2 : 0L, $              ; long integer
           junk2 : bytarr( 14320 ) }  ; array of 14320 bytes
openr, lun, 'mri.dat', /free_lun
readu, lun, header
free_lun, lun
help, header.word1, header.word2

Cheers,
Liam.

---
Liam E. Gumley
http://cimss.ssec.wisc.edu/~gumley