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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'skip:u 30': 0.07; 'subject:file': 0.07; 'f.close()': 0.09; 'forcing': 0.09; 'subject:using': 0.09; 'throws': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '(data': 0.16; 'cc:name:python list': 0.16; 'numpy': 0.16; 'subject:writing': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'error': 0.23; 'cc:2**0': 0.24; 'skip:v 30': 0.26; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'allows': 0.31; 'file': 0.32; 'advice': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'skip:f 40': 0.36; 'skip:j 20': 0.36; 'issue': 0.38; 'read': 0.60; 'experts': 0.60; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'skip:w 30': 0.69; 'trial': 0.83; 'here)': 0.84; 'oscar': 0.84; '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:from:date:message-id:subject:to :cc:content-type; bh=gmZ2HUQjGDia7WLEk2l1mhwo8ieMcZaUQ/D5iZgYLLU=; b=TdiC6q7cnJv7FL3C/16+/Or/qmp9NqIvUuleBfs+ebFPjgLtE1o3ELL5DtijBjfa1P HJpGWCNeJfTN+61ccnMSVPofGexGIuMVURxOlgWBY241w+xuOMZyMlr5HGOqXtrBtp0r ywWzGOqzY1kLVE88n2QyTYw5z0Jwex8j2YEfe8ei6Q/kuIHx+f60mrraRy0snUBSy8xy L5hCU1xrYx0Tqpabjvn+3V/o1tX48R3zW0jnv7kyq+esqtWhIVfFV6Ry8lXqr1C0JXaB OR0rUqwQ1xVTyNUEZfE2gO/fWhxkkzncb7amSpZ9orgp7wRk9HKyK90UQXIm0VGByO3K wbbA==
X-Received by 10.220.97.145 with SMTP id l17mr321344vcn.35.1384438756288; Thu, 14 Nov 2013 06:19:16 -0800 (PST)
MIME-Version 1.0
In-Reply-To <ac6f6659-0053-482c-b587-454066a4a515@googlegroups.com>
References <ac6f6659-0053-482c-b587-454066a4a515@googlegroups.com>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Thu, 14 Nov 2013 14:18:56 +0000
Subject Re: writing fortran equivalent binary file using python
To Sudheer Joseph <sjo.india@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2595.1384438765.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384438765 news.xs4all.nl 15923 [2001:888:2000:d::a6]:43430
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59436

Show key headers only | 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