Re: Reading binary data whose source code not given [message #2081 is a reply to message #2080] |
Wed, 18 May 1994 09:33  |
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
|
|
|