[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Byte to Real conversion
- To: "Michael A. Wirth" <s9601460(at)131.170.8.11>
- Subject: Re: Byte to Real conversion
- From: Liam Gumley <Liam.Gumley(at)ssec.wisc.edu>
- Date: Fri, 19 Feb 1999 08:50:17 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: Space Science and Engineering Center, University of Wisconsin-Madison
- References: <36CCB875.BA77B780@131.170.8.11>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:13676
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