Hi Juan,
Thanks for the reply. When I remove the try/except, I get the same
error as I got with Scott's code:
Traceback (most recent call last):
File "C:\Hanlie\data\GsMAP\2005-01\test.py", line 19, in <module>
binvalues.read(if1, num_lon * num_lat)
TypeError: arg1 must be open file
Brent's code works, so I'm going to go with that.
On Jul 29, 1:55 pm, Juan F Paulini <[email protected]> wrote:
> Hi Hanlie,
>
> If you remove the try/except, do you get some exception?
>
> 2011/7/29, Scott Sinclair <[email protected]>:
>
> > On 29 July 2011 12:45, Hanlie Pretorius <[email protected]> wrote:
> >> I need to read and process hundreds of GSMaP binary files that are in the
> >> .gz archive format.
>
> >> [output]
> >> done with f1
> >> Text to test gzip module.
> >> done with f2
> >> [/output]
>
> >> This seems to indicate that something is wrong with f1 (the GSMaP
> >> file), but I can unzip the file manually and read it with a python
> >> script (code and output pasted after signature). I have hundreds of
> >> GSMAP files that have unique archived file names, but they all unzip
> >> to the same binary file, so I have to process the archived files in
> >> the python script.
>
> > Doesn't it work if you modify part of your pasted script as below?
>
> > # read binary file and store its data in an array
> > fp = 'C:\\out.00'
> > tmpfile = open(fp, 'rb')
>
> > Change to (untested):
>
> > # read binary file and store its data in an array
> > f1 = 'GSMaP_MVK+.20050101.00.0.1deg.hourly.v484.gz'
> > tmpfile = gzip.open(f1)
>
> > You could also simplify your code by using np.fromfile(tmpfile) to
> > read the binary data.
>
> > Cheers,
> > Scott