[SciPy-user] Reading Binary Files

WolfgangZ wollez@gmx....
Thu Mar 8 12:32:29 CST 2007


Lorenzo Isella schrieb:
> 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


are you sure that fortran saves binary files? Have you  checked the 
files with a text editor?



More information about the SciPy-user mailing list