Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59436

Re: writing fortran equivalent binary file using python

References <ac6f6659-0053-482c-b587-454066a4a515@googlegroups.com>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date 2013-11-14 14:18 +0000
Subject Re: writing fortran equivalent binary file using python
Newsgroups comp.lang.python
Message-ID <mailman.2595.1384438765.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 14 November 2013 00:53, Sudheer Joseph <sjo.india@gmail.com> wrote:
> My trial code with Python (data is read from file here)
>
> from netCDF4 import Dataset as nc
> import numpy as np
> XFIN=0.0,YFIN=-90.0,NREC=1461,DXIN=0.5;DYIN=0.5
> TITLE="NCMRWF 6HOURLY FORCING MKS"
> nf=nc('ncmrwf_uv.nc')
> ncv=nf.variables.keys()
> IWI=len(nf.variables[ncv[0]])
> JWI=len(nf.variables[ncv[1]])
> WDAY=nf.varlables[ncv[2]][0:NREC]
> U=nf.variables[ncv[3]][0:NREC,:,:]
> V=nf.variables[ncv[4]][0:NREC,:,:]
> bf=open('ncmrwf_uv.bin',"wb")
> f.write(TITLE)
> f.write(IWI,JWI,XFIN,YFIN,DXIN,DYIN,NREC,WDAY)
> for i in np.arange(0,NREC):
>     f.write(U[i,:,:],V[i,:,:])
> f.close()
>
> But the issue is that f.write do not allow multiple values( it allows one by one so throws an error with above code ) on same write statement like in the fortran code. experts may please advice if there a solution for this?

Can you just call write twice? e.g.:

f.write(U[i,:,:])
f.write(V[i,:,:])


Oscar

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

writing fortran equivalent binary file using python Sudheer Joseph <sjo.india@gmail.com> - 2013-11-13 16:53 -0800
  Re: writing fortran equivalent binary file using python David Froger <david.froger@inria.fr> - 2013-11-14 07:57 +0100
  Re: writing fortran equivalent binary file using python Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-11-14 14:18 +0000
  Re: writing fortran equivalent binary file using python Sudheer Joseph <sjo.india@gmail.com> - 2013-11-14 20:05 +0530
  Re: writing fortran equivalent binary file using python Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-14 15:46 +0100

csiph-web