[Thread Prev][Thread Next][Index]

Re: Fortran Binary File Read



Hi David,

You do, indeed, have a somewhat messy file to describe to Ferret ... but Ferret
can read it.

In the Ferret Users guide you will find a section in Chapter 2

	6 TRICKS TO READING BINARY AND ASCII FILES

with the basic strategy of approaching each variable as a separate soft link.
The sections preceeding that explain FORTRAN unformatted record structure.
You'll find further information in the writeups on STREAM format under SET DATA
in the commands reference section of the UG (see
http://tmap.pmel.noaa.gov/home/ferret/ug/v44/partII.html#_2_18)

You'll want to set the /SKIP= parameter to the number of 4-byte words preceding
the start of the actual data for a given variable. For your first variable,
eta, the command will look something like this (untested):

I will use `nx`, `ny`, and `nk` to represent those values in Ferret

 let nx = ???
 let ny = ???
 let nk = ???

 define axis/x=1:`nx`:1 xax
 define axis/y=1:`ny`:1 yax
 define grid/x=xax/y=yax g2D

 file/skip=`1+3+1+1`/var=eta/grod=g2D/columns=`nx*ny`/format=stream myfile.unf

 set variable/title="ETA title"/units="whatever" eta
 save/file=myfile.cdf eta

The `1+3+1+1` skip value corresponds to
	1 word FORTRAN record length starting first record
	3 words, nx, ny, nk values stored in first record
	1 word FORTRAN record length ending   first  record
	1 word FORTRAN record length starting second record

For your second variable, "ub", you'll need to add nx*ny+2 to the SKIP value.

Hope this helps -- steve

=======================================================

On Sep 5,  1:18pm, David Oxilia wrote:
> Subject: Fortran Binary File Read
> Hello,
>
> 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
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
>-- End of excerpt from David Oxilia




-- 

		|  NOAA/PMEL               |  ph. (206) 526-6080  
Steve Hankin	|  7600 Sand Point Way NE  |  FAX (206) 526-6744
		|  Seattle, WA 98115-0070  |  hankin@pmel.noaa.gov


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement