[MITgcm-support] open source software for creating binary files from NetCDF

Oliver Jahn jahn at mit.edu
Wed Apr 22 09:52:36 EDT 2015


Hi Jonny,

if you want to read the files into MITgcm, you have to make sure they
are big-endian, e.g.,

a.astype('>f8').tofile('foo')

or replace '>f8' by '>f4' if you use readBinaryPrec=32.

For reading, you can use

a = np.fromfile('foo', '>f8').reshape((3, 3))

(for a 3x3 array).  If the files are MITgcm output and you have meta
files, you can also use rdmds from the MITgcmutils package in
MITgcm/utils/python which will set shape and precision automatically.

Oliver


On 2015-04-22 09:40, Jonny Williams wrote:
> It seems that something along these lines in Python may be able to do
> the trick...
> 
>>>> import numpy as np
>>>> a = np.array([1, 2, 3], dtype='float64')
>>>> a.tofile('foo')
> 
> Jonny
> 
> 
> On 22 April 2015 at 14:43, Jonny Williams <Jonny.Williams at bristol.ac.uk
> <mailto:Jonny.Williams at bristol.ac.uk>> wrote:
> 
>     Hi everyone
> 
>     Just a quick question if I may.
> 
>     I've successfully used the readbin.m and writebin.m MATLAB scripts
>     bundled with the MITgcm code base to make binary files from NetCDF
>     files and vice versa.
> 
>     Is there an open source way of doing this using, say, CDO or R, etc?
> 
>     Thanks!
> 
>     Jonny
> 
>     -- 
>     Dr Jonny Williams
>     School of Geographical Sciences
>     Cabot Institute
>     University of Bristol
>     BS8 1SS
> 
>     +44 (0)117 3318352 <tel:%2B44%20%280%29117%203318352>
>     jonny.williams at bristol.ac.uk <mailto:jonny.williams at bristol.ac.uk>
>     http://www.bristol.ac.uk/geography/people/jonny-h-williams
>     <http://bit.ly/jonnywilliams>
> 
> 
> 
> 
> -- 
> Dr Jonny Williams
> School of Geographical Sciences
> Cabot Institute
> University of Bristol
> BS8 1SS
> 
> +44 (0)117 3318352
> jonny.williams at bristol.ac.uk <mailto:jonny.williams at bristol.ac.uk>
> http://www.bristol.ac.uk/geography/people/jonny-h-williams
> <http://bit.ly/jonnywilliams>
> 
> 
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support
> 



More information about the MITgcm-support mailing list