[Thread Prev][Thread Next][Index]

Re: Fortran Binary File Read




One problem is that ferret will only make one read statement for each dataset.
You have 11 write statements there; with this setup you can only read one of
those quantities in at a time (subsequent "file/format=unf" statements will
replace earlier reads). If you want to have more than one of these quantities
to work with together, the only solution I know of is to change your write
command to something like:

	write(10) nx,ny,nk,eta			! I assume these are numbers
	write(10) ub,vb,up,vp,us,vs,dp,q,qx,qy	! and these are arrays

Now you can read this in as follows:

define axis/x=...
define axis/y=...
define axis/z=...
define grid/x=.../y=.../z=... gridname
file/format=unf/var="ub,vb,up,vp,us,vs,dp,q,qx,qy"/skip=1/col=`num_x*num_y*num_z*10`/g=gridname filename

Note the calculation of the number of columns in backquotes. This gives the
total number of values to be read on a single line, where num_x,num_y,num_z
describe the array size. All arrays must be the same size/shape here.

It is also possible to write the axis information in your fortran code, read
that from the fortran output, define the axes based on that, then in a second
read get the data. In this case it does not matter that the first read (of axis
information) is replaced since the axes have already been defined. Here's an
example:

! read and define the x-axis
file/unf/var=xlon filename	! xlon is a list of x-coordinates, 1 per record
define axis/from_data/x/name=xax_name/unit=lon xlon
! read and define the y-axis
file/unf/var=ylat filename	! ylat is a list of y-coordinates, 1 per record
define axis/from_data/y/name=yax_name/unit=lat ylat
! define the grid based on the above axes
define grid/x=xax_name/y=yax_name gridname
! read the data
file/format=unf/g=gridname/var=..../col=... filename

See "define axis/from_data" in the users manual.

The really best way of dealing with this is to write netcdf from your fortran
code. This is discussed in the users guide.

Billy K

--------------------------------------------------------------------------------
> I'd like to read a set of fortran binary files into ferret. I've tried it
> a couple of different ways according to the documentation (User guide v4.4
> p24) but ferret quits with a core dump.
> 
> The size of each binary file is 59435348 bytes and they are written with
> a fortran subroutine which looks like:
> 
> !
> ! generate file name from time t
> !
>       s = t
>       if(s.ge.10**6) s = 10**6-1
>       do i=5,0,-1
>         p = s/10**i
>         s = s - p*10**i
>         num((6-i):(6-i)) = digit(p)
>       enddo
>       fil = 'out'//num
>       if(sda) then
>          ff = 'physical'
>       else
>          ff = 'unformatted'
>       endif
> !
> ! open file and write it
> !
>       open(unit=10,status='unknown',file=fil,form=ff)
>       write(10) nx,ny,nk
>       
>       write(10) eta
>       write(10) ub
>       write(10) vb
>       write(10) up
>       write(10) vp
>       write(10) us
>       write(10) vs
>       write(10) dp
>       write(10) q
>       write(10) qx
>       write(10) qy
> 
>       close(10)
> 
> The variables are arrays of dimension (nx,ny) or (nx,ny,nk) and they
> are written unformatted. Any help would be appreciated.
> 
> thanks,
> 
> David.
> 
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> David Oxilia                          Tel: (541) 737-2368
> COAS-Oregon State University          Fax: (541) 737-2064
> Ocean Admin. Bldg. 104                
> Corvallis, OR 97331-5503              Email: oxilia@hejira.oce.orst.edu
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> 


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement