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

Home » Public Forums » archive » Re: Reading binary data whose source code not given
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
Re: Reading binary data whose source code not given [message #2080] Wed, 18 May 1994 09:59
rlefevre is currently offline  rlefevre
Messages: 4
Registered: April 1994
Junior Member
In article <2rd8ft$hn2@mojo.eng.umd.edu> madabhus@eng.umd.edu (Rajiv Madabhushi) writes:

> I have a binary file with a 400 by 400 array. All I know about the
> elements of that array is that they are written as 16-bit 2's complement
> data. The file was created on a pc. I am no sure about what language
> the software that creates this file is written in (and cannot
> find out :-( ).

> None of the above attempts proved successful. (I compared the image plot
> with that from an ascii version of the file. The two plots are completely
> different. The binary data is read in ok - without any keywords - but none
> of the data points are read in correctly.)

> So my question is: is there any way to read such data? I would be willing
> (and I also tried, but unsuccessfully) to read the data element by element.

Yes, I think.
I read data from Unix F77 on my IDL for the PC. I have to use the function
byteorder and keyword /lswap. For example,

readu,unit,isize,data,isize & byteorder, data, /lswap

where isize is the size byte used by f77 unformatted write and data is the
data.

Hope this helps.
----------
Randy J. Lefevre
Return e-mail to rlefevre@tamu.edu
Re: Reading binary data whose source code not given [message #2081 is a reply to message #2080] Wed, 18 May 1994 09:33 Go to previous message
8015 is currently offline  8015
Messages: 52
Registered: November 1993
Member
In article <2rd8ft$hn2@mojo.eng.umd.edu>,
Rajiv Madabhushi <madabhus@eng.umd.edu> wrote:
>
> I have a binary file with a 400 by 400 array. All I know about the
> elements of that array is that they are written as 16-bit 2's complement
> data. The file was created on a pc. I am no sure about what language
> the software that creates this file is written in (and cannot
> find out :-( ).
>
> I am using IDL version 3.0 on a Sun SPARC 10 workstation. I have tried

Going from the PC to a Sun SPARC you will need to swap the byte order
of the file. You can do this within IDL using the byteorder command
(byteorder, data, /options), or from the Unix command line using the dd
command (dd if=infile of=outfile conv=swab). Correct me if I'm wrong,
but I don't think the 2's complement info comes into play. The
following ought to allow you to get the data to a point where it is
useable.

openr, lun, 'pc_file', /get_lun ; open the file for reading
fvar = fstat(lun) ; optional - in case all your data is not 400x400
arr_size = fix(sqrt(fvar.size)) ; optional - get array size from file size
data = intarr(arr_size, arr_size) ; allocate an array to hold the data
readu, lun, data ; read the file into an array
byteorder, data ; change the byte order of the array
...

Hope that works, or at least gives you a starting point.

Mike Schienle Hughes Santa Barbara Research Center
mgs@sbjse0.sbrc.hac.com 75 Coromar Drive, M/S B28/87
Voice: (805)562-7466 Fax: (805)562-7881 Goleta, CA 93117
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Reading binary data whose source code not given
Next Topic: GIF reader/writer for IDL

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

Current Time: Wed Oct 08 11:42:41 PDT 2025

Total time taken to generate the page: 0.00564 seconds