
      program rdgrid
c
      character*40 fname
      character*80 histvol,field,lab,labx,laby
      dimension xx(100),yy(100),f(100,100)
      data lurd/9/
c
      do 200 iii=1,1000
        write(6,"(' ')")
        write(6,"('Enter file name (zzz to stop): ',$)")
        read(5,*) fname
        if (fname(1:3).eq.'zzz') stop 'bye'
        open(lurd,file=fname,status='OLD',err=901)
c
c Read data from each frame:
c
 100    continue
        read(lurd,"(a)",end=900) histvol
        read(lurd,"(a)") field
        read(lurd,"(6x,i4)") iframe
        read(lurd,"(a)") lab
        read(lurd,"(a)") labx
        read(labx,"(3x,i4)") nx
        if (nx.gt.1) read(lurd,"(6e13.5)") (xx(i),i=1,nx)
        read(lurd,"(a)") laby
        read(laby,"(3x,i4)") ny
        if (ny.gt.1) read(lurd,"(6e13.5)") (yy(i),i=1,ny)
c
        if (nx.gt.1.and.ny.gt.1) then
          read(lurd,"(6e13.5)") ((f(i,ii),i=1,nx),ii=1,ny)
        elseif (nx.eq.1.and.ny.gt.1) then
          read(lurd,"(6e13.5)") (f(1,i),i=1,ny)
        elseif (ny.eq.1.and.nx.gt.1) then
          read(lurd,"(6e13.5)") (f(i,1),i=1,nx)
        endif
        nfr = nfr+1
c
        write(6,"(' ')")
        write(6,"(a)") histvol(1:lenstr(histvol))
        write(6,"(a)") field(1:lenstr(field))
        write(6,"('Frame ',i4)") iframe
        write(6,"(a)") lab(1:lenstr(lab))
        goto 100
c
 900    continue
        write(6,"('EOF encountered on file ',a,' (lu ',i3,')')")
     +    fname,lurd
        close(lurd)
        goto 200
 901    write(6,"('Error opening file ',a)") fname
 200  continue
      stop
      end
c
      function lenstr(str)
      character*(*) str
c
c Return index to last non-blank char in str
c
      length = len(str)
      do i=length,1,-1
        if (str(i:i).ne.' ') then
          lenstr = i
          return
        endif
      enddo
      lenstr = 0
      return
      end
c
      subroutine clearstr(str)
c 
c Set given string to all blanks 
c 
      character*(*) str
      length = len(str)
      do i=1,length
        str(i:i) = ' '
      enddo
      return
      end
