problem with writing out binary file by calling fortran within NCL

From: Rui Mei <meir02ster_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 06 2012 - 11:31:12 MDT

Dear all,

To simplify the problem, here are the two simple cases that I have tested.

Case 1:

in the .f (F77 not F90) file which is called within NCL

       integer *4 a1, a2, a3
       real*4 a4
       OPEN ( FILE = 'test.txt' ,
     & UNIT = 1 ,
     & FORM = 'UNFORMATTED' ,
     & ACCESS = 'SEQUENTIAL' )

       WRITE(1) a1, a4, a2, a3 ! write these four variables into a
binary file named test.txt
       WRITE(*,*) a1, a4, a2, a3 ! output it to screen
       CLOSE(1)

After I execute the ncl file (which calls the above fortran and outputs
test.txt), here is the output to screen:
 5 0.000000 78 0 (these are true values of the 4
variables above).

But when I read the binary file test.txt either with NCL or fortran, it
gives me this:

in NCL:
0 5 0 78 ( here are the two associated
lines: data=fbinrecread("./test.txt",0,4,"integer"), print(data) )

in Fortran:
 0 7.0064923E-45 0 78 (the lines are almost the same
as the above fortran lines except that I replace "write" with "read" )

Note that in the above NCL lines (those read test.txt), I forced the a4 to
be integer, which might be causing some problem in NCL read, but in fortran
this should not be the concern, so I do not understand (I use the same
compiler gfortran ).

Case 2 is the same as Case 1 except that a4 is changed to integer, here is
the output from NCL and Fortran

in NCL: 0 5 0 78
in Fortran: 0 5 0 78

So here are my two questions:
1) In above cases when I use NCL and fortran to read the binary file, it
seems to miss the fourth value and fill the first value with 0 no matter I
am reading data of single data type or multiple data types.

2) if I have data of multiple data types to read per each record (such as
in CASE1), it seems to give me trouble when reading with fortran.

The NCL version is 6.0.0 and the type of system is Linux jaguarpf-ext5
2.6.32.36-0.5-default #1 SMP 2011-04-14 10:12:31 +0200 x86_64 x86_64 x86_64
GNU/Linux.

In my real problem, I have to output the binary within NCL through calling
fortran and later read such binary with fortran, and this binary
contains multiple date types (real, integer and character) per each record.
The above two simple cases do capture my real problem. I will appreciate if
someone can help me with this.

Thanks!
-Rui

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 6 11:31:24 2012

This archive was generated by hypermail 2.1.8 : Wed Aug 15 2012 - 08:12:08 MDT