      subroutine gcheck(type,iunit,ifile,jerr)
      character*1 type
      character*64 id
      character*(*) ifile
      character*9 ifile1,ifile2,ifile3,ifile4,ifile5,ifile6
      dimension z(90),zz(60)
      logical opn
      data ifile1/'lcgrv.grd'/,ifile2/'lcter.grd'/,ifile3/'lcgrv.xyz'/
      data ifile4/'LCGRV.GRD'/,ifile5/'LCTER.GRD'/,ifile6/'LCGRV.XYZ'/
      data xmin/1.0e38/,xmax/-1.0e38/,ymin/1.0e38/,ymax/-1.0e38/,
     &     wmin/1.0e38/,wmax/-1.0e38/,tol/.000001/
      jerr = 0
      if(type.eq.'g') then
        inquire(file=ifile,opened=opn)
        if(opn) close(iunit)
        open(iunit,file=ifile,status='old',form='unformatted',
     &  err=90,iostat=icheck)
        read(iunit,err=90,iostat=icheck) id,nc,nr,nz,xo,dx,yo,dy
        if(ifile.eq.ifile1.or.ifile.eq.ifile4) then
          if(nc.eq.90.and.nr.eq.51.and.xo.eq.-107.5.and.dx.eq.
     &       .258330e-2.and.yo.eq.37.9.and.dy.eq..258330e-2) then
            read(iunit,err=90,iostat=icheck) y,z
            if((z(1)-(-.2787958e+3).lt.tol).and.
     &         (z(5)-(-.2822142e+3).lt.tol).and.
     &         (z(9)-(-.2877052e+3).lt.tol)) then
              read(iunit,err=90,iostat=icheck) y,z
            if((z(3)-(-.2800866e+3).gt.tol).or.
     &         (z(6)-(-.2837608e+3).gt.tol).or.
     &         (z(8)-(-.2864243e+3).gt.tol)) go to 90
            else
              go to 90
            endif
          else
            go to 90
          endif
        else if(ifile.eq.ifile2.or.ifile.eq.ifile5) then
          if(nc.eq.60.and.nr.eq.60.and.xo-(-.1074980e+3).lt.tol.and.
     &      dx.eq..416660e-2.and.(yo-.3781444e+2).lt.tol.and.
     &      dy.eq..416660e-2) then
            read(iunit,err=90,iostat=icheck) y,zz
            if(zz(1).eq..37660e+4.and.zz(5).eq..36130e+4.and.
     &         zz(9).eq..35340e+4) then
              read(iunit,err=90,iostat=icheck) y,zz
              if(zz(3).ne..36460e+4.or.zz(6).ne..35910e+4.or.
     &          zz(8).ne..36590e+4) go to 90
            else
              go to 90
            endif
          else
            go to 90
          endif
        else 
          go to 90
        endif
c*****XYZ FILE
      else
        inquire(file=ifile,opened=opn)
        if(opn) close(iunit)
        open(iunit,file=ifile,status='old',form='formatted',
     &  err=90,iostat=icheck)
        if(ifile.ne.ifile3.and.ifile.ne.ifile6) go to 90
        ic = 0
30      read(iunit,*,err=90,end=40) x,y,w
        ic = ic + 1
        if ( x .lt. xmin ) xmin = x
        if ( x .gt. xmax ) xmax = x
        if ( y .lt. ymin ) ymin = y
        if ( y .gt. ymax ) ymax = y
        if ( w .lt. wmin ) wmin = w
        if ( w .gt. wmax ) wmax = w
        go to 30
40      if(ic.ne.109) go to 90
        if(xmin.ne.-107.5.or.xmax.ne.-107.27.or.
     &     ymin.ne.37.9.or.ymax.ne.38.03.or.
     &     wmin.ne.-295.53.or.wmax.ne.-277.04) go to 90
      endif
50      close(iunit) 
      if(type.eq.'g') then
        open(iunit,file=ifile,status='old',form='unformatted',
     &  err=90,iostat=icheck)
      else
        open(iunit,file=ifile,status='old',form='formatted',
     &  err=90,iostat=icheck)
      endif
        return
90      close(iunit)
        print *,'DEMO PROGRAM CAN ONLY BE RUN WITH SUPPLIED FILES'
        jerr = 1
        return
        end
