c     stdbndy.for - dos version
c     J.Phillips, USGS, Denver, Colorado
c     changes from vms version are indicated by cv
c
      program stdbndy
      dimension xbuf(10000, 3), ybuf(10000), id(14), pgm(2)
      character ifile*50, ofile*50
      data ndim / 1000 /
cv    data dval / '3777767777'o /      
      data dval / 1.0e+38 /
    1 write(*, 800) 
  800 format(8h ifile: ,$)
      read(5, 801) ifile
  801 format(a50)
      open(10, file=ifile, status='old', form='unformatted', err=1)
cv    open(10,file=ifile,status='old',form='unformatted',iostat=ios)
cv    if(ios.ne.0) then
cv    open(10,file=ifile,status='old',form='unformatted',readonly)
cv    endif
      write(*, 802) 
  802 format(8h ofile: ,$)
      read(5, 801) ofile
      open(11, file=ofile, status='unknown', form='unformatted') 
      write(*, 804) 
  804 format(39h background dvals (0) or negative (1): ,$)
      read(5, *) jcode
      val = -1.0
      if (jcode .eq. 0) val = dval
      read(10) id, pgm, nc, nr, nz, xo, dx, yo, dy
      write(11) id, pgm, nc, nr, nz, xo, dx, yo, dy
      do 42 j = 1, 2
   42 read(10) delta, (xbuf(i,j),i = 1, nc)
      call thinx(xbuf, ybuf, nc, val)
      write(11) delta, (ybuf(i),i = 1, nc)
      do 50 j = 3, nr
      read(10) delta, (xbuf(i,3),i = 1, nc)
      call thinxy(xbuf, ybuf, nc, ndim, val)
      write(11) delta, (ybuf(i),i = 1, nc)
      do 50 i = 1, nc
      xbuf(i,1) = xbuf(i,2)
   50 xbuf(i,2) = xbuf(i,3)
      call thinx(xbuf(1,2), ybuf, nc, val)
      write(11) delta, (ybuf(i),i = 1, nc)
      close(10) 
      close(11) 
      stop 
      end
      subroutine thinx(xbuf[HUGE], ybuf[HUGE], n, val)
      dimension xbuf(n), ybuf(n)
      ist = 0
      xb1 = xbuf(1)
      ybuf(1) = val
      do 40 i = 2, n - 1
      xb2 = xbuf(i)
      ybuf(i) = val
      if (xb1 - xb2) 10, 40, 20
   10 ist = i
      goto 40
   20 if (ist .eq. 0) goto 40
      do 30 j = ist, i - 1
   30 ybuf(j) = xb1
      ist = 0
   40 xb1 = xb2
      ybuf(n) = val
      return 
      end
      subroutine thinxy(xbuf[HUGE], ybuf[HUGE], n, ndim, val)
      dimension xbuf(ndim, 3), ybuf(ndim)
      ist = 0
      xb1 = xbuf(1,2)
      ybuf(1) = val
      if ((xb1 .ge. xbuf(1,1)) .and. (xb1 .ge. xbuf(1,3))) ybuf(1) = xb1
      do 40 i = 2, n - 1
      xb2 = xbuf(i,2)
      ybuf(i) = val
      if ((xb2 .ge. xbuf(i,1)) .and. (xb2 .ge. xbuf(i,3))) ybuf(i) = xb2
      if (xb1 - xb2) 10, 40, 20
   10 ist = i
      goto 40
   20 if (ist .eq. 0) goto 40
      do 30 j = ist, i - 1
   30 ybuf(j) = xb1
      ist = 0
   40 xb1 = xb2
      ybuf(n) = val
      xb1 = xbuf(n,2)
      if ((xb1 .ge. xbuf(n,1)) .and. (xb1 .ge. xbuf(n,3))) ybuf(n) = xb1
      return 
      end
