[Thread Prev][Thread Next][Index]

Re: Reading Fortran data files



Oh, tough questions....

The basic problem is that ForTran is so very good at creating whatever output you want. I think however that both can be solved, one easily and one with a little trickery.

For WeiQiang:
With direct access output you are missing the 4 bytes that are at the beginning and end of each record in a typical ForTran data file (this is the record length - not needed in direct access when all records are SUPPOSED to be the same length), that is why the /format=unformatted won't work for you. Try instead:
set data/format=stream/columns=3240/var=map1 data.dat

For Aiguo:
Yours is a little tougher because (if I remember correctly) what you have in each record would be:
4 bytes of record length (9720*4=38880)
12960 bytes of map1
12960 bytes of map2
12960 bytes of map3
4 bytes of record length (9720*4=38880)
There isn't a super clean way to read these (again, if I remember correctly). The only thing I can think to try is to "fool" ferret and access map1-3 (or amp, pha, and avg) as a single variable with depth. Try something like (CHANGES IN CAPITALS):
def axis/x=180W:180E/npoint=72/unit="degrees_east" lon
def axis/y=90S:90N/npoint=45/unit="degrees_north" lat
DEF AXIS/Z=1:3:1 NVAR ! CHANGE
def axis/t=1:5:1 time
def grid/x=lon/y=lat/Z=NVAR/t=time g5x4
! CHANGE
file/format=unformatted/var=MAPS/col=9720/grid=g5x4 data.dat
! CHANGE
!
LET AMP=MAPS[Z=1] ! CHANGE
LET PHA=MAPS[Z=2] ! CHANGE
LET AVG=MAPS[Z=3] ! CHANGE
set var/bad=-99999. amp
set var/bad=-99999. pha

Good Luck to you both! Mark

On Thursday, July 19, 2001, at 10:32 PM, weiq wrote:

Hello,
Another similiar question in the following:
parameter(mi=72,mj=45,msea=5)
real map1(mi,mj)

open(1,form='unformatted',file='data.dat',access='direct',recl=mi*mj)

do is=1,msea
write(1,rel=is) map1
enddo

How can read this data.dat using ferret? I try it sometimes, but i failed.
By the way, I can read the above data.dat using Matlab, using fread(fp1,[72,45],'float32'). But I must using ferret to read it for graphic output.


---------------------------------------------
Wang WeiQiang
LED, South China Sea Institute of Oceanology
Chinese Academy of Sciences
164 West Xingang Rd., Guangzhou 510301
P. R. China
--------------------------------------------


----- Original Message -----
From: "Aiguo Dai" <adai@ucar.edu>
To: <ferret_users@ferret.wrc.noaa.gov>
Sent: Friday, July 20, 2001 2:08 AM
Subject: Reading Fortran data files


Try this again:
Hello,

I was trying to read Fortran 77 files similar to the following one:

parameter(mi=72,mj=45,msea=5)
real map1(mi,mj),map2(mi,mj),map3(mi,mj)

open(1,form='unformatted',file='data.dat')

do is=1,msea
write(1)map1,map2,map3
enddo

using Ferret scripts:

def axis/x=180W:180E/npoint=72/unit="degrees_east" lon
def axis/y=90S:90N/npoint=45/unit="degrees_north" lat
def axis/t=1:5:1 time
def grid/x=lon/y=lat/t=time g5x4
file/format=unformatted/var=amp,pha,avg/col=9720/grid=g5x4 data.dat
!
set var/bad=-99999. amp
set var/bad=-99999. pha

However, the maps for amp[l=1], ..., amp[l=5], and pha are incorrect.

Any suggestions would be appreciated for reading this types of data
files (also for cases with only map1 and map2 written). Thanks lot.

-Aiguo Dai, NCAR, Boulder, CO


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement