C
C
C________________________________________________________________
C
C     SUBROUTINE  O P E N C K
C________________________________________________________________
C
      subroutine openck(igrid,xo,yo,delx,dely,
     & xdata,nwork,iquad)
c
c  initialize grid input file.
c
      common /titls/ title1,title2,title3,fmtx,fmty
      common /setxy/ xx(2),yy(2),xp1(4),yp1(4),iplotr,sizel,
     & ncharx,nchary,sizex,sizey,adelx,adely,pllx,plly,
     & lintx,linty,xscale,yscale,xxscal,yyscal,mscale,delxx,delyy
      common /concom/ ncol,nrow,bmin,bmax,
     & grad,gflg,ijs,ije,ijsi,ijei,prime,ij4,cont,
     & fltmax,lmult(0:3),idashs,linet,sigma,nsig
      character*40 title1,title2,title3
      character*16 header
      character*16 fmtx,fmty
      dimension xdata(1),ipgm(2)
      data iprint/6/
c
      read(igrid,err=90,end=90,iostat=icheck) title1,header,ipgm,
     &                                        ncol,nrow,iquad,
     &                                        xo,delx,yo,dely
      delxx=delx
      delyy=dely
      if (ncol.lt.3.or.nrow.lt.3) go to 110
      if(iquad.eq.3.and.delx.eq.0..and.dely.eq.0.) go to 80
      if (ncol.gt.nwork) go to 150
      if (iquad.ne.1) go to 130
      if (delx.ne.0) go to 30
      read(igrid,end=90) (xdata(i),i=1,ncol)
      xx(1)=xdata(1)
      xx(2)=xdata(ncol)
      go to 40
   30 xx(1)=xo
      xx(2)=xo+(ncol-1)*delx
   40 if(dely.ne.0) go to 50
      call yread(igrid,yy,nrow)
      if(nrow.lt.3) go to 110
      go to 60
   50 yy(1)=yo
      yy(2)=yo+(nrow-1)*dely
   60 if(delx.ne.0..and.dely.ne.0.) return
   70 rewind igrid
      read(igrid)
      if(delx.eq.0.) read(igrid)
      return
   80 i=ncol*3
      if(i.gt.nwork) go to 150
      read(igrid)
      call xyread(igrid,xx,yy,xdata,i)
      if(nrow.lt.3) go to 110
      go to 70
   90 write(iprint,100) icheck
  100 format(' error no. ',i5,' reading header of grid',
     1       ' file')
      go to 170
  110 write(iprint,120)
  120 format(' %no. rows or columns less than 3')
      go to 170
  130 write(iprint,140)
  140 format(' %nz on header of standard file is greater than 1')
      go to 170
  150 write(iprint,160)
  160 format(' %core exceeded for x values')
c
  170 close (igrid)
      ncol=0
      return
      end
C
C________________________________________________________________
C
C     SUBROUTINE  Y R E A D
C________________________________________________________________
C
      subroutine yread(igrid,yr,nrow)
c
c     scans specified row grid
c
      dimension yr(2)
      nrow=0
      read(igrid,end=20) yr(1)
   10 nrow=nrow+1
      read(igrid,end=20) a
      yr(2)=a
      go to 10
   20 return
      end
C
C________________________________________________________________
C
C     SUBROUTINE  X Y R E A D
C________________________________________________________________
C
      subroutine xyread(igrid,xr,yr,work,ncol3)
c
c     scans quadrilateral grid for x-y range
c
      dimension xr(2),yr(2),work(ncol3)
      common /concom/ ncol,nrow,bmin,bmax,
     & grad,gflg,ijs,ije,ijsi,ijei,prime,ij4,cont,
     & fltmax,lmult(0:3),idashs,linet,sigma,nsig
c
c     initialize
c
      nrow=0
      read(igrid,end=70) dummy,work
      xmin=fltmax
      xmax=-fltmax
      ymin=fltmax
      ymax=-fltmax
c
c scan loop
c
   10 nrow=nrow+1
      if(work(i+2).gt.gflg) go to 55
      do 50 i=1,ncol3,3
      if(work(i).le.xmax) go to 20
      xmax=work(i)
      go to 30
   20 if(work(i).ge.xmin) go to 30
      xmin=work(i)
   30 if(work(i+1).ge.ymin) go to 40
      ymin=work(i+1)
      go to 50
   40 if(work(i+1).le.ymax) go to 50
      ymax=work(i+1)
   50 continue
   55 continue
c
      read(igrid,end=60) dummy,work
      go to 10
c
   60 xr(1)=xmin
      xr(2)=xmax
      yr(1)=ymin
      yr(2)=ymax
c
   70 return
      end
