Reading binary files

Dan Stromberg drsalists at gmail.com
Mon Aug 31 05:27:55 CEST 2009


David Robinow wrote:
>>> This works for a simple binary file, but the actual file I'm trying to
>>> read is give throwing an error that the file cannot be found. Here is the
>>> name of the my file:
>>> 2009.08.02_06.52.00_WA-1_0001_00_0662_0.jstars
>>>
>>> Should python have trouble reading this file name or extension?
>>>       
>> I'm having trouble with the filename:
>> 2009.08.02_06.52.00_WA-1_0001_00_0662_0.jstars
>>
>> It throws an error with that file name, When I change it to something like
>> sample.txt it runs, but the data is still garbled. Is there any reason why I
>> can't use the above file name? If I'm using 'rb' to read the binary file why
>> is it still garbled?
>>     
>  I don't think it's garbled. It's a binary file. What do you expect?
>
> It's been over ten years since I've worked with any JSTARS stuff so I
> can't give you any details but you almost certainly have some sort of
> imagery. The military has a lot of bizarre formats and whoever sent
> you the data should have included a data sheet describing the format
> (or a pointer to such).  Ideally, you'll also get a pointer to code to
> read the thing, but sometimes you just have to bite the bullet and
> write a program to process the file.
>    (If all else fails, look at a dump of the first 512 bytes or so;
> often the image size is included at the beginning; maybe in ASCII, 16
> bit ints, 32 bit ints, floating point -- who knows)
> There've been times when I had to just display the thing at 512 or
> 1024 bytes (or ints) per row and try to surmise the info from that.
> So, look for the file description.
> ...
> Googling a bit:   I see there's a package at
>    http://www.mbari.org/data/mbsystem/index.html
> which purports to handle some JSTARS stuff. I've no idea if that will help you.
>   
If you don't find anything preexisting for reading JSTARS format, this 
might help:

http://stromberg.dnsalias.org/~strombrg/converting-binary.html




More information about the Python-list mailing list