Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
I need to read a Fortran binary file with python, named merg_2015041312_4km-pixel.Z
(from here), that is compressed; the structure of uncompressed file is defined here. The definition says that
Each file contains 2 records: the 1st for the "on the hour" images (":00") and the 2nd for the "on the half hour" images (":30").
and
Each record is a 9896 x 3298 Fortran array of IR brightness temperatures that have been scaled to fit into 1-byte by subtracting "75" from each datum.
GrADS .ctl file description:
DSET merg_1999042012_4km-pixel
OPTIONS yrev little_endian template
UNDEF 330
TITLE globally merged IR data
XDEF 9896 LINEAR 0.0182 0.036378335
YDEF 3298 LINEAR -59.982 0.036383683
ZDEF 01 LEVELS 1
TDEF 99999 LINEAR 12z04Apr1999 30mn
VARS 1
ch4 1 -1,40,1,-1 IR BT (add '75' to this value)
ENDVARS
and I tried to write some python code:
>>> import struct
>>> file = open("merg_2015041312_4km-pixel", 'rb')
>>> data = struct.unpack('>h', file.read())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: unpack requires a string argument of length 2
Unfortunately, I'm not used to binary files...
How can I obtain the second record (half hourly) from this file?