Pradeep Jha gmail.com> writes:
>
>
>
> Hello,
>
> I am trying to read a fortran unformatted binary file with
> FortranFile as follows but I get an error.
> -
> >>> from FortranFile import FortranFile
> >>> f = FortranFile("vor_465.float",endian="<")
> >
Neil Martinsen-Burrell wartburg.edu> writes:
>
> On 2009-05-29 10:12 , David Froger wrote:
> > I think the FortranFile class is not intended to read arrays written
> > with the syntax 'write(11) array1, array2, array3' (correct me if I'm
> > wrong). This is the use in the laboratory where I
>
> You're half wrong. FortranFile can read arrays written as above, but it
> sees them as a single real array. So, with the attached Fortran program::
>
> In [1]: from fortranfile import FortranFile
>
> In [2]: f = FortranFile('uxuyp.bin', endian='<') # Original bug was
> incorrect byte order
>
On 2009-05-29 10:12 , David Froger wrote:
I think the FortranFile class is not intended to read arrays written
with the syntax 'write(11) array1, array2, array3' (correct me if I'm
wrong). This is the use in the laboratory where I'm currently
completing a phd.
You're half wrong. FortranFile
I think the FortranFile class is not intended to read arrays written with
the syntax 'write(11) array1, array2, array3' (correct me if I'm wrong).
This is the use in the laboratory where I'm currently completing a phd.
I'm going to dive into struc, FotranFile etc.. to propose something
convenient
Sorry, I still don't understand how to use FortranFile ...
The fortran code
program writeArray
implicit none
integer,parameter:: nx=2,ny=5
real(4),dimension(nx,ny):: ux,uy,p
integer :: i,j
do i = 1,nx
do j = 1,ny
ux(i,j) = 100. + j+(i-1.)*10.
uy(i,j) = 200. + j+
On 2009-05-28 12:11 , David Froger wrote:
> Thank you very much :-)
Things should be cleared up now on the wiki as well. Peace,
-Neil
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Thank you very much :-)
2009/5/28 Neil Martinsen-Burrell
> On 2009-05-28 09:32 , David Froger wrote:
>
>> Hy Neil Martinsen-Burrell,
>>
>> I'm trying the FortranFile class,
>> http://www.scipy.org/Cookbook/FortranIO/FortranFile
>>
>> It looks like there are some bug in the last revision (7):
>>
On 2009-05-28 09:32 , David Froger wrote:
Hy Neil Martinsen-Burrell,
I'm trying the FortranFile class,
http://www.scipy.org/Cookbook/FortranIO/FortranFile
It looks like there are some bug in the last revision (7):
* There are errors cause by lines 60,61,63 in
* There are indentation e
Hy Neil Martinsen-Burrell,
I'm trying the FortranFile class,
http://www.scipy.org/Cookbook/FortranIO/FortranFile
It looks like there are some bug in the last revision (7):
* There are errors cause by lines 60,61,63 in
* There are indentation errors on lines 97 and 113.
___
the last line was missing :
return arrays
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thanks a lot Fransesc and Neil, yours messages really help me.
I'll look at these solutions attentively.
Here is what I write recently, but I begin to understand it's effectively
not portable...
def fread(fileObject,*arrayAttributs):
""" Reading in a binary (=unformatted) Fortran file
L
A Friday 30 January 2009, David Froger escrigué:
> ok for f2py!
>
> > Otherwise, you will have to figure out how your Fortran program
> > writes the file. I.e. what padding, metainformation, etc. that are
> > used. If you switch Fortran compiler, or even compiler version from
> > the same vendor, y
David Froger gmail.com> writes:
> Hy,My question is about reading Fortran binary file (oh no this question
> again...)
I've posted this before, but I finally got it cleaned up for the Cookbook.
For this purpose I use a subclass of file that has methods for reading
unformatted Fortran data. Se
The only time I've done this, I used numpy.fromfile exactly as follows.
The file had a header followed by a number of records (one float
followed by 128 complex numbers), requiring separate calls of
numpy.fromfile to read each part. The only strange part about this was
that the Fortran code was
ok for f2py!
> Otherwise, you will have to figure out how your Fortran program writes the
>file. I.e. what padding, metainformation, etc. that are used. If you
>switch Fortran compiler, or even compiler version from the same vendor,
>you must start over again.
In my experience, I never had this k
> Careful -- the last time I read a Fortran-=written binary file, I found
> that the various structures (is that what you call them in Fortran?)
> were padded with I think 4 bytes.
That is precisely why I suggested using f2py. If you let Fortran read the
file (be careful to the same compiler!), i
David Froger wrote:
> import numpy as np
>
> nx,ny = 2,5
>
> fourBytes = np.fromfile('uxuyp.bin', count=1, dtype=np.float32)
> ux = np.fromfile('uxuyp.bin', count=nx*ny,
> dtype=np.float32).reshape((nx,ny), order='F')
>
> print ux
> #===
>
> I get :
>
Thank Sturla and Christopher,
yes, with the Fortran code :
!=
program makeArray
implicit none
integer,parameter:: nx=2,ny=5
real(4),dimension(nx,ny):: ux,uy,p
integer :: i,j
open(11,file='uxuyp.bin',form='unformatted')
do i = 1,nx
do j = 1,ny
ux(i,j)
> If you want to be completely safe, read the file in Fortran, then send
> it as an array to Python (use f2py). Aside from that, assuming your
> compiler only writes the raw bytes in Fortran order to the file:
Careful -- the last time I read a Fortran-=written binary file, I found
that the vari
On 1/30/2009 5:27 PM, Sturla Molden wrote:
> On 1/30/2009 5:23 PM, Sturla Molden wrote:
>
>> ux = np.fromfile(nx*ny, dtype=np.float32).view((nx,ny), order='F')
>
> oops.. this should be
>
> ux = np.fromfile(file, count=nx*ny, dtype=np.float32).view((nx,ny),
>order='F')
fu*k
ux = n
On 1/30/2009 5:23 PM, Sturla Molden wrote:
> ux = np.fromfile(nx*ny, dtype=np.float32).view((nx,ny), order='F')
oops.. this should be
ux = np.fromfile(file, count=nx*ny, dtype=np.float32).view((nx,ny),
order='F')
S.M.
___
Numpy-discussion
On 1/30/2009 5:03 PM, David Froger wrote:
> I think it will be a good idea to put the Fortran writting-arrays code
> and the Python reading-array script in the cookbook and maybe a page to
> help people comming from Fortran to start with Python ?
If you want to be completely safe, read the file
Hy,
My question is about reading Fortran binary file (oh no this question
again...)
Until now, I was using the unpack module like that :
def lread(f,fourBeginning,fourEnd,*tuple):
from struct import unpack
"""Reading a Fortran binary file in litte-endian"""
if fourBeginning: f.seek(4
24 matches
Mail list logo