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

Home » Public Forums » archive » reading binary file with READ_BINARY
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
reading binary file with READ_BINARY [message #86190] Thu, 17 October 2013 05:00 Go to next message
mishooax is currently offline  mishooax
Messages: 1
Registered: October 2013
Junior Member
Folks,

I am trying to read a binary file in IDL containing a simple 2D array of 360x180 values. For reference, the binary file can be found here:

http://transcom.project.asu.edu/download/transcom03/smoothma p.fix.2.bin

Here is what the readme for this .bin says:

The file 'smoothmap.fix.2.bin' contains a single real, binary
array dimensioned 360 x 180. The array contains the numbers 1
through 22, denoting each of the 22 basis functions in the
TransCom 3 experiment. This file was written on an SGI Origin
2000 hosting UNIX.

And my code:

GET_LUN, fstart
OPENR, fstart, FFilename

mask_data = READ_BINARY(fstart, DATA_DIMS=[360,180], DATA_TYPE=4) ; float data


Now mask_data contains only junk values:
print, mask_data[0:100] gives
-2.24089e-038 0.000000 0.000000 0.000000 ....

Why would that be?

Also, I've noticed the .bin file size is 259208 bytes, aka 8 bytes more than the space required to store a 360x180 float array. I've been looking at this for an hour now and I'm stumped. Played around with endian-ness settings but that did not help.

How can I read in this file correctly?

Thank you!
Re: reading binary file with READ_BINARY [message #86199 is a reply to message #86190] Thu, 17 October 2013 06:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
mishooax@gmail.com writes:

> I am trying to read a binary file in IDL containing a simple 2D array of 360x180 values. For reference, the binary file can be found here:
>
> http://transcom.project.asu.edu/download/transcom03/smoothma p.fix.2.bin
>
> Here is what the readme for this .bin says:
>
> The file 'smoothmap.fix.2.bin' contains a single real, binary
> array dimensioned 360 x 180. The array contains the numbers 1
> through 22, denoting each of the 22 basis functions in the
> TransCom 3 experiment. This file was written on an SGI Origin
> 2000 hosting UNIX.
>
> How can I read in this file correctly?

I would read it like this.

file = 'smoothmap.fix.2.bin
OpenR, lun, file, /Get, /Swap_If_Little_Endian
data = FltArr(260, 180)
ReadU, lun, data
Free_Lun, lun

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: reading binary file with READ_BINARY [message #89891 is a reply to message #86190] Wed, 17 December 2014 14:32 Go to previous message
zzhaoch is currently offline  zzhaoch
Messages: 1
Registered: December 2014
Junior Member
Hi,

You can read in the follow way,

Data = read_binary('smoothmap.fix.2.bin',DATA_TYPE=4,ENDIAN='big');
Data = Data[1:64800]
Data = reform(Data,[360,180])

Best,
Zhao


On Thursday, October 17, 2013 8:00:10 AM UTC-4, mish...@gmail.com wrote:
> Folks,
>
> I am trying to read a binary file in IDL containing a simple 2D array of 360x180 values. For reference, the binary file can be found here:
>
> http://transcom.project.asu.edu/download/transcom03/smoothma p.fix.2.bin
>
> Here is what the readme for this .bin says:
>
> The file 'smoothmap.fix.2.bin' contains a single real, binary
> array dimensioned 360 x 180. The array contains the numbers 1
> through 22, denoting each of the 22 basis functions in the
> TransCom 3 experiment. This file was written on an SGI Origin
> 2000 hosting UNIX.
>
> And my code:
>
> GET_LUN, fstart
> OPENR, fstart, FFilename
>
> mask_data = READ_BINARY(fstart, DATA_DIMS=[360,180], DATA_TYPE=4) ; float data
>
>
> Now mask_data contains only junk values:
> print, mask_data[0:100] gives
> -2.24089e-038 0.000000 0.000000 0.000000 ....
>
> Why would that be?
>
> Also, I've noticed the .bin file size is 259208 bytes, aka 8 bytes more than the space required to store a 360x180 float array. I've been looking at this for an hour now and I'm stumped. Played around with endian-ness settings but that did not help.
>
> How can I read in this file correctly?
>
> Thank you!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Synchronizing xrange of cgZPlot with another plot
Next Topic: quirk End of file encountered before end of program

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

Current Time: Wed Oct 08 13:37:04 PDT 2025

Total time taken to generate the page: 0.00609 seconds