Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '"the': 0.07; 'skip:u 30': 0.07; 'subject:file': 0.07; 'f.close()': 0.09; 'forcing': 0.09; 'measure': 0.09; 'subject:using': 0.09; 'throws': 0.09; 'cc:addr:python-list': 0.11; 'martin': 0.11; 'python': 0.11; '(data': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'jr.': 0.16; 'numpy': 0.16; 'scientist': 0.16; 'skip:* 80': 0.16; 'subject:writing': 0.16; 'web-': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'thu,': 0.19; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'error': 0.23; 'skip:\xa0 20': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'skip:v 30': 0.26; 'header:In-Reply-To:1': 0.27; 'india.': 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'stands': 0.31; 'allows': 0.31; 'file': 0.32; 'alone': 0.33; 'ourselves': 0.33; 'skip:b 30': 0.33; 'skip:t 40': 0.33; '"the': 0.34; 'advice': 0.35; 'india': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'dies': 0.36; 'earth': 0.36; 'skip:f 40': 0.36; 'skip:j 20': 0.36; 'done': 0.36; 'skip:o 20': 0.38; 'thank': 0.38; 'nov': 0.38; 'issue': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'indian': 0.39; '8bit%:6': 0.40; 'read': 0.60; 'experts': 0.60; 'skip:o 30': 0.61; 'challenge': 0.61; 'e-mail:': 0.61; 'national': 0.62; 'times': 0.62; 'information': 0.63; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'services': 0.66; 'moments': 0.68; 'skip:w 30': 0.69; '500': 0.70; '8bit%:100': 0.72; 'dr.': 0.77; 'trial': 0.83; 'here)': 0.84; 'ocean': 0.84; 'oscar': 0.84; 'pines': 0.84; 'sciences,': 0.84; 'albert': 0.91; 'convenience,': 0.91; 'ministry': 0.91; 'ultimate': 0.93; 'comfort': 0.96; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MGrUfJb/Z22waBRwaWAr/J4rGIVDZufHuSFvfCgFk0M=; b=v3uf4rwetWsomMAT/V5kZV9RXxDzob05AlYLMzpBGyi1MoXu3NXR4Z4OL0P+e5qYa1 qyQP9oIFcnqTVyb6U7KJSz4Kd9lK2FsSZPH0rlEFSCsbKk1ZCLiubevCW//V6fqKmba1 s5Owqkyl5OPbu1Y+rhCF6Qw/Onx7IvPeVpt0vjCtt4G/MAs+KxlbkLMMKZfvkYuX0c8G FlzN2W2dMs0K4QjhwIvUWwYHNcTTHUnlIunm5jFA/9z4fV3I9CyV/VKM/TskOHj0cMAl 75c4IZKaNEo0TZx/GC091h1nOcUxa5BLrlcIHmAfntUlrDmvr5IcDy5xbTpBU/eC1rkl Wxig== MIME-Version: 1.0 X-Received: by 10.68.135.100 with SMTP id pr4mr1809653pbb.62.1384439743724; Thu, 14 Nov 2013 06:35:43 -0800 (PST) In-Reply-To: References: Date: Thu, 14 Nov 2013 20:05:43 +0530 Subject: Re: writing fortran equivalent binary file using python From: Sudheer Joseph To: Oscar Benjamin Content-Type: multipart/alternative; boundary=047d7b10ce272346ff04eb23ff49 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 166 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384439747 news.xs4all.nl 15882 [2001:888:2000:d::a6]:48358 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59442 --047d7b10ce272346ff04eb23ff49 Content-Type: text/plain; charset=ISO-8859-1 Thank you, But it wont allow to write it in unformatted way so that the fortran code can read with open(11,file="input.bin") read(11) IWI,JWI,XFIN,YFIN,DXIN,DYIN,NREC,WDAY with best regards, sudheer On Thu, Nov 14, 2013 at 7:48 PM, Oscar Benjamin wrote: > On 14 November 2013 00:53, Sudheer Joseph 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 > -- with best regards Sudheer ********************************************************************************** Dr. Sudheer Joseph Scientist INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS) MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA "OCEAN VALLEY" PRAGATHI NAGAR (BO) OPP.JNTU, NIZAMPET SO Andhra Pradesh, India. PIN- 500 090. TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile) Tel:+91-40-23886047(O),Fax:+91-40-23892910(O) E-mail: sudheer.joseph@yahoo.com; sjo@incois.gov.in. Web- http://oppamthadathil.tripod.com --------------* --------------- "The ultimate measure of a man is not where he stands in moments of comfort and convenience, but where he stands at times of challenge and controversy." Martin Luther King, Jr. "What we have done for ourselves alone dies with us. What we have done for others and the world remains and is immortal." - Albert Pines --047d7b10ce272346ff04eb23ff49 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you,
=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 But it wont allow= to write it in unformatted way so that the fortran code can read

with

open(11,file=3D"input.bin")
read(11) IWI,JWI,XFIN,YFIN,DXIN,DYIN,NREC,WDAY

with best= regards,
sudheer


On Thu, Nov 14, 2013 at 7:48 PM, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote:
On 14 November 2013 00:53, Sudheer Joseph &l= t;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=3D0.0,YFIN=3D-90.0,NREC=3D1461,DXIN=3D0.5;DYIN=3D0.5
> TITLE=3D"NCMRWF 6HOURLY FORCING MKS"
> nf=3Dnc('ncmrwf_= uv.nc')
> ncv=3Dnf.variables.keys()
> IWI=3Dlen(nf.variables[ncv[0]])
> JWI=3Dlen(nf.variables[ncv[1]])
> WDAY=3Dnf.varlables[ncv[2]][0:NREC]
> U=3Dnf.variables[ncv[3]][0:NREC,:,:]
> V=3Dnf.variables[ncv[4]][0:NREC,:,:]
> bf=3Dopen('ncmrwf_uv.bin',"wb")
> f.write(TITLE)
> f.write(IWI,JWI,XFIN,YFIN,DXIN,DYIN,NREC,WDAY)
> for i in np.arange(0,NREC):
> =A0 =A0 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 lik= e in the fortran code. experts may please advice if there a solution for th= is?

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

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


Oscar



--
with best= regards

Sudheer

********************************************= **************************************
Dr. Sudheer Joseph =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
Scientist =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0=A0
INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS)MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA
"OCEAN VALLEY&quo= t; PRAGATHI NAGAR (BO)
OPP.JNTU, NIZAMPET SO
Andhra Pradesh, India. PIN- 500 090.
TEl:+91-40= -23044600(R),Tel:+91-9440832534(Mobile)
Tel:+91-40-23886047(O),Fax:+91-4= 0-23892910(O)
E-mail: sudheer.joseph@yahoo.com; =A0sjo@incois.gov.in.
Web- http://= oppamthadathil.tripod.com
=A0 =A0 =A0 =A0 =A0 =A0--------------* ---= ------------
"The ultimate measure of a man is
not where he stan= ds in moments of
comfort and convenience, but where
he stands at times of challenge andcontroversy."
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Mar= tin Luther King, Jr.
"What we have done for ourselves alone dies wi= th us.
What we have done for others and the world remains and is immorta= l."
- Albert Pines
--047d7b10ce272346ff04eb23ff49--