[Thread Prev][Thread Next][Index]

Re: [ferret_users] reading FORTRAN sequential access data - simplequestion



Hi Bob, Steve, Billy, Ryo & Dan,
                                  I made few experiments with
writing "sequential access" data in Fortran and reading it in
Ferret. Here is the summary.

1. Sequential access files with all the data written in a single
     stretch (as Bob wanted) should be readed in Ferret as
     "Format=STREAM" with /SKIP=1. (Don't be annoyed, it will
      work !!!). SKIP=1 will remove the first record information
      then the data is exactly same as that of "Direct Access".
      You have to specify TYPE=R4 or R8 according to your Fortran
      program.

      see Case_1 and Case_2 below.

2. Sequential access files with data written inside the loop (as
      in the example i suggested earlier) should be readed in
      Ferret as "Format=UNFORMATTED". Ferret will support only
      REAL*4 and not REAL*8 types.

      see Case_3 and Case_4 below.

Hope this will answer Bob's questions.

Regards

Jaison

---------------------------------------------------------------
Common to all cases
-------------------
      open(unit=10,access='sequential',form='unformatted',
     #              file='seq.bin')


case 1
------
  Fortran

      real*4 hrmean(nx,ny,nz)
      ..................
      write(10) hrmean

  Ferret

      file/skip=1/format=stream/type=R4/var=hrmean/\
                      grid=mygrid  seq.bin

case 2
------
  Fortran

      real*8 hrmean(nx,ny,nz)
      ..................
      write(10) hrmean

  Ferret

      file/skip=1/format=stream/type=R8/var=hrmean/\
                    grid=mygrid  seq.bin

case 3
------

  Fortran

      real*4 hrmean(nx,ny,nz)
      ...............
      DO k =1,nz
          Do j = 1,ny
              Do i = 1,nx
                    write(10) hrmean(i,j,k)
              ENDDO
          ENDDO
      ENDDO

  Ferret

      file/format=unformatted/type=R4/var=hrmean/\
                   grid=mygrid  seq.bin

case 4
------

  Fortran

      real*8 hrmean(nx,ny,nz)
      ...............
      DO k =1,nz
          Do j = 1,ny
              Do i = 1,nx
                    write(10) hrmean(i,j,k)
              ENDDO
          ENDDO
      ENDDO

  Ferret

      Ferret is not able to handle this dataset.

--------------------------------------------------------------------

On Thu, 6 Jul 2006, Ryo Furue wrote:

Hi,

| FORTRAN unformatted output is not really a standard.  It is system
| and compiler dependent how the concept of a "record" is implemented.

You are correct in principle.  In practice, unformatted files are
very compatible, *if* these two items are taken care of:

1) Endianness:  Compilers on little-endian machines usually
  have an option to convert to the big endian format on I/O.
  Ferret has one, too.  (The "swap" keyword.)

2) For direct access files, recl may not be in terms of bytes.
  On some compilers, recl can be in the units of 4 bytes.
  But, such compilers usually have an option to make it one byte.

For sequential files, most compilers follow the de facto standard
for the representation of records.  A direct-access file is almost
always represented as a uniform sequence of bytes, so there's no
record boundary or anything in the underlying data.

Cheers,
Ryo
--------------------------
On the three major OSes (Unix/Linux, Windows, & MacOS),
files aren't orgnized around "records".  From the user's point
of view, files are simply uniform sequences of bytes.  Fortran
direct-access files are almost always just that, on such OSes.
Fortran sequential files are a bit trickier because they do
have the notion of record.  But, most compilers follow the
de facto standard format to represent records.  To represent
floating-point numbers, the IEEE standard is the norm these
days, so, once the endianness is taken care of, the
floating-point number representation is almost always
compatible.  Unless you are using an old IBM mainframe
or a Cray (what about VMS?), that is.


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement