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


Groups > comp.lang.python > #59442

Re: writing fortran equivalent binary file using python

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 <sjo.india@gmail.com>
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; '&quot;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&gt;': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'error': 0.23; 'skip:\xa0 20': 0.24; 'cc:2**0': 0.24; '&gt;': 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 <CAHVvXxRDngZwAS1sh-w+GZ3bWL1wstciR7w9nkGQjPRkZnZh-w@mail.gmail.com>
References <ac6f6659-0053-482c-b587-454066a4a515@googlegroups.com> <CAHVvXxRDngZwAS1sh-w+GZ3bWL1wstciR7w9nkGQjPRkZnZh-w@mail.gmail.com>
Date Thu, 14 Nov 2013 20:05:43 +0530
Subject Re: writing fortran equivalent binary file using python
From Sudheer Joseph <sjo.india@gmail.com>
To Oscar Benjamin <oscar.j.benjamin@gmail.com>
Content-Type multipart/alternative; boundary=047d7b10ce272346ff04eb23ff49
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.2601.1384439747.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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
<oscar.j.benjamin@gmail.com>wrote:

> 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
>



-- 
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

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