      program readgts
      implicit none

C sample program to read Goddard Time Series data
C data file has 300 byte header followed by 304x448 byte array

      integer ival, irec, lbyte, width, height, hdrsiz
      parameter(width=304,height=448,hdrsiz=300)
      character*1 header(hdrsiz)
      character*1 logrec(4)
      integer values(width*height)

C open file
C recl=4 is the largest common denominator between 300 and 304
C on some systems recl is specified in words, in which case recl=1
      open(unit=1,file='199701.N13',form='unformatted',
     1    access='direct', recl=4)

C read 4 byte logical records and pack them into header and data arrays

C read header and display
      ival = 1
      do irec=1,hdrsiz/4
        read(1,rec=irec) logrec
        do lbyte=1,4
          header(ival) = logrec(lbyte)
          ival = ival + 1
        enddo
      enddo

      write(*,*) header

C read data and write to text file
      ival = 1
      do irec=1,width*height/4
        read(1,rec=irec+hdrsiz/4) logrec
        do lbyte=1,4
          values(ival) = ichar(logrec(lbyte))
          ival = ival+1
        enddo
      enddo

      write(*,*) ival-1, ' values read'

      open(unit=2,file='199701.txt')

      write(2,*) values

      stop
      end

