[SciPy-user] Reading Binary Files

John Hassler hasslerjc@comcast....
Thu Mar 8 14:28:11 CST 2007


I realize that I was so eager to answer your question that I neglected 
to try to solve your problem.  If you have the source (and if this isn't 
legacy data files), just recompile with more usable I/O formats.  We 
used to use unformatted I/O back in the day when a BIG computer might 
have several tens of K (as in K) of memory, and the high speed I/O was 
mag. tape.  We'd dump to tape to get some free memory, backspace, and 
read it back in when we needed it.  "Unformatted" I/O was intended to be 
used by programs made by the same compiler on the same computer, and not 
for any external use.
john

Lorenzo Isella wrote:
> Dear All,
> I hope this is not too off-topic. I have been given an old but
> reliable fortran code for fluid dynamic simulations. It saves a a lot
> of data using 3D arrays (q1,q2,q3,pr) as a binary file.
> I cut and paste the part of the fortran code saving the data into a binary file:
> (in the following iav=1 and iwrq2=1).
>
>
> if(iav.eq.1) then
>       namfil='field'//ipfi//'.dat'
>       pnamfil='field'//ipfi//'.dat'
>       open(13,file=namfil,form='unformatted')
>                    else
>
>       pnamfil=filcnw
>       print*, "filcnw is", filcnw
>       open(13,file=filcnw,form='unformatted')
>                    endif
>       print*, "iav is", iav
>
>       write(6,*) pnamfil,'written at t=',
>      1          time, ' prma mi=',prma,prmi
>       nfil=13
>       rewind(nfil)
>       write(nfil) n1,n2,n3
>       write(nfil) ros,alx3d,ren,time
>       if(iwrq2.eq.1) then
> c
> c    large memory occupancy
> c
>        print*,"I am saving the extended results"
>       write(nfil) (((q1(i,j,k),i=1,n1),j=1,n2),k=1,n3),
>      1            (((q2(i,j,k),i=1,n1),j=1,n2),k=1,n3),
>      1            (((q3(i,j,k),i=1,n1),j=1,n2),k=1,n3),
>      1            (((pr(i,j,k),i=1,n1),j=1,n2),k=1,n3)
>                      else
> c
> c    reduced memory occupancy
> c    the pressure is not necessary for restarting files
> c    even for post processing can be saved but then
> c    the advancement of a time step should be performed
> c
>       write(nfil) (((q1(i,j,k),i=1,n1),j=1,n2),k=1,n3),
>      1            (((q3(i,j,k),i=1,n1),j=1,n2),k=1,n3),
>      1            (((pr(i,j,k),i=1,n1),j=1,n2),k=1,n3)
>                      endif
>       write(nfil) ntime,ntt,nav
>       close(nfil)
>
>
>
> The results is for instance file field0010.dat, which I try reading in
> Python by using pylab and the statement:
>
> s = file( './field0010.dat','rb' ).read( )
>
> newarr = fromstring(s ,Float)
>
> but the content of newarr seems absolutely wrong (number of the order
> of 1e+309 which are not produced or saved in the simulations...).
> Am I doing something wrong?
>
> Kind Regards
>
> Lorenzo
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
>   


More information about the SciPy-user mailing list