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

Dennis Shea shea at ucar.edu
Wed Sep 10 21:22:51 MDT 2014


NCL's binary write functions do not have the ability to write mixed type
records.
Further, fortran default sequential modepre/post-pend each record
with a 'hidden' record separator .

I'd suggest creating a fortran subroutine to do what you want. Untested f77

C NCLFORTSTART
      subroutine wrhead(fname, llc, urc, nlat, mlon, dx, dy, kk)
      implicit none
C                                                input
      integer nlat, mlon, llc(2), kk
      real     urc(2), dx, dy
      character*(*) fname
C NCLEND


      open(unit=11, file=fname, form="unformatted", access="sequential")

       write(11) llc(0), urc(0), llc(1), urc(1), dx, dy, nlat, nlon, kk)
       return
       end

C NCLFORTSTART
      subroutine wrrec(fname, ......)
      implicit none
      .....
C NCLEND

       return
       end


On Wed, Sep 10, 2014 at 5:54 PM, Jatin Kala <jatin.kala.jk at gmail.com> wrote:

> Hi,
> This may or may not help solve your problem.
> My general experience is, it's easier to deal with direct-access binary
> versus sequential.
> I would consider using fbindirwrite rather than fbinrecwrite.
>
> Also in our OPEN statement, have you tried to specify the "ACCESS=" option?
> Cheers,
> Jatin.
>
>
> On 10/09/14 8:33 PM, Ufuk Utku Turuncoglu (BE) wrote:
> > 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
> >
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140910/b88f3c43/attachment.html 


More information about the ncl-talk mailing list