[ncl-talk] problem in writing binary file ...

Ufuk Utku Turuncoglu (BE) u.utku.turuncoglu at be.itu.edu.tr
Wed Sep 10 04:33:38 MDT 2014


Hi,

I am trying to write a binary file, which is in following form,

header 1 - 6 float and 2 integer
header 2 - character (len = 14), holds time information
data 1 - 2 dimensional data written as a chunk of lons (inside a lat loop)
data 2 - 2 dimensional data written as a chunk of lons (inside a lat loop)
header 2
data 1
data 2
...
...

So, my ncl script writes the data as follows,

   ihead = (/ llc(0), urc(0), llc(1), urc(1), 0.25, 0.25, nlat, nlon, 3 /)
   fbinrecwrite(fname, -1, ihead)

   do k = 0, ntime-1
     print(k+" "+date_str(k))
     fbinrecwrite(fname, -1, date_str(k))
     do i = 0, nlat-1
       fbinrecwrite(fname, -1, uwnd_rmap(k,i,:))
     end do
     do i = 0, nlat-1
       fbinrecwrite(fname, -1, vwnd_rmap(k,i,:))
     end do
   end do

The problem is that the fortran code try to read "header 1" with a 
single read command. Like following,

       OPEN 
(UNIT=IU01,FILE=FILE01(1:LEN),FORM='UNFORMATTED',STATUS='OLD',IOSTAT=IOS)
       READ (IU01,IOSTAT=IOS) SOUTH, NORTH, WEST, EAST, D_LON, D_LAT, 
N_LAT, N_LON

but the data type are different for header (real for SOUTH, NORTH, WEST, 
EAST, D_LON, D_LAT and integer for N_LAT, N_LON). As it can be seen 
above, i tried to write the header as,

   ihead = (/ llc(0), urc(0), llc(1), urc(1), 0.25, 0.25, nlat, nlon, 3 /)

but fortran file can not read it correctly. It reads "header 1" 
correctly for SOUTH, NORTH, WEST, EAST, D_LON, D_LAT variables but 
N_LAT, N_LON is wrong. So, i think that i have to find another way to 
write header in a single record. I also check that NCL float and integer 
data types and both of them are 32 bits but even the size are same 
fortran reads them wrongly.

I just wonder that is there any other way to write this kind of header 
(has multiple data types) to the binary file.

Regards,

--ufuk



More information about the ncl-talk mailing list