[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading fortran stream file



Hi Imran & Dan,
We can write both the variable to a single
binary file and read it properly using the same jnl file
provided the two variables are written as two 'records'.

About "recl" (ie record length) : For a gridded data it
should be "xpoints*ypoints*4". Each variable,level & time
will increment the "rec" (ie, record) by 1. So in Imrans's example recl should not be 16 but 8*5*4 as noted by Dan.

I didn't explore the binary file writing for multiple
variables with multiple time/levels. But it seems Ferret
needs the binary file without mixing variables...but
in appended form (all the values for one variable, then
the next variable ..like that). You can try it out.

In order to write myvar1 and myvar2 to a single binary
file, please proceed as follows (you can use the same jnl
file for reading it in Ferret)

------------------------------------------------------------------
REAL myvar1(8,5),myvar2(8,5)

open (unit=20, file="test.dat", access="direct", recl=8*5*4)

do i = 1, 8
do j=1, 5
myvar1(i,j)= Real(i) + Real(j) * 10.0
myvar2(i,j)=-(Real(i) + Real(j) * 10.0)
enddo
enddo

write (20,rec=1) ((myvar1(i,j), i=1,8),j=1,5)
write (20,rec=2) ((myvar2(i,j), i=1,8),j=1,5)

end
------------------------------------------------------------------
Regards,

Jaison

On Thu, 6 Jul 2006, Yu, Hao-Cheng wrote:

Hi Imran,

Usually I output stream file like this (following your code)

real myvar1(8,5),myvar2(8,5)
open(20,file='test1.dat', access='direct',recl=8*5*4)
open(21,file='test2.dat', access='direct',recl=8*5*4)
........
write(20,rec=1) myvar1
write(21,rec=1) myvar2

In ferret script

file/var=myvar1/form=stream/type=r4/grid=g8x5 test1.dat
file/var=myvar2/form=stream/type=r4/grid=g8x5 test2.dat
save/file=test.cdf  myvar1[d=1],myvar2[d=2]

If you use -byteswapio option (PGI fortran) to compile  fortran file,  you
have to add "swap" qualifer.
Like

file/var=myvar1/form=stream/type=r4/swap/grid=g8x5 test1.dat

Hope this help you

Regards, dan

2006/7/6, IMRAN NADEEM <qphoton@gmail.com>:

Hi ferret users,

I wrote a stream file of two variable with these fortran commands:

Real*4 myvar1(8,5); Real*4 myvar2(8,5)


open (unit=20, file="test.dat", access="direct", recl=16)
... ... ... ....


myvar1(i,j)= Real(i) + Real(j) * 10.0
myvar2(i,j)=-(Real(i) + Real(j) * 10.0)

... ... ... ....
do 120 j=1, 5


write (20,rec=j), (myvar1(i,j),myvar2(i,j), i=1,8)
120 continue

end


myvar1(i,j) and myvar2(i,j) have same values but with opposite signs.I read the
output file with the ferret commands:

define axis/x=1:8:1 x8

define axis/y=1:5:1 y5

define grid/x=x8/y=y5 g8x5
file/var=myvar1,myvar2/grid=g8x5/format=stream test.dat
show data
list myvar1
list myvar2

I expect to see all positive values in myvar1 and all negative in myvar2. But what I get is



yes? list myvar1
VARIABLE : MYVAR1
FILENAME : test.dat
SUBSET : 8 by 5 points (X-Y)
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8


1 / 1: 11.00 -11.00 12.00 -12.00 13.00 -13.00 14.00 -14.00
2 / 2: 15.00 -15.00 16.00 -16.00 17.00 -17.00 18.00 -18.00
3 / 3: 21.00 -21.00 22.00 -22.00 23.00 -23.00 24.00 -24.00
4 / 4:

25.00 -25.00 26.00 -26.00 27.00 -27.00 28.00 -28.00
5 / 5: 31.00 -31.00 32.00 -32.00 33.00 -33.00 34.00 -34.00
yes? list myvar2
VARIABLE : MYVAR2
FILENAME : test.dat

SUBSET : 8 by 5 points (X-Y)

1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 / 1: 35.00 -35.00 36.00 -36.00
37.00 -37.00 38.00 -38.00
2 / 2: 41.00
-41.00 42.00 -42.00 43.00 -43.00 44.00 -44.00
3 / 3: 45.00 -45.00 46.00 -46.00 47.00 -47.00 48.00 -48.00
4 / 4: 51.00 -51.00 52.00 -52.00 53.00 -53.00
54.00 -54.00
5 / 5: 55.00 -55.00 56.00
-56.00 57.00 -57.00 58.00 -58.00


What is wrong? (test.dat is attached)

Nadeem
*********************************************************************************


--
Imran Nadeem
PhD Student
Institute of Meteorology
Department of Water, Atmosphere and Environment
Uni. of Natural Resources and Applied Life Sciences (BOKU)

Peter-Jordan Strasse 82
1190 Vienna, Austria

Mobile: +43 699 1194 3044
Tel.: +43 1 47654 5614
Fax: +43 1 47654 5610





[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement