c  fixter.for - dos version
c  J.Phillips, USGS, Denver, Colorado
c  changes from vms version are indicated by cv
c
c   To convert unchanged grid cells to dvals.
c
      character file1*50, file2*50
      character pgm*8
      dimension a1(10000), id(14)
      data ddval / 1.e30 /
    1 write(6, 2) 
    2 format(1x,32hEnter terrace4 output file name:/1x1h*$)
      read(5, 101) file1
  101 format(a50)
cv    open(11,file=file1,form='unformatted',status='old',iostat=ios)
cv    if(ios.ne.0) then
cv    open(11,file=file1,form='unformatted',status='old',readonly)
cv    endif
      open(11, file=file1, form='unformatted', status='old', err=1)
      write(6, 3) 
    3 format(1x,23hEnter output file name:/1x1h*$)
      read(5, 101) file2
cv    open (12,file=file2,form='unformatted',status='new')
      open(12, file=file2, form='unformatted', status='unknown') 
      read(11) id, pgm, ncol, nrow, nz, x0, dx, y0, dy
      pgm = 'terrace '
      if ((nz .ne. 1) .or. (ncol .gt. 2000)) goto 99
      write(12) id, pgm, ncol, nrow, nz, x0, dx, y0, dy
      do 10 j = 1, nrow
      call rowio(a1, y, nz, ncol, 11, 1)
      do 21 i = 3, ncol - 2
      if (a1(i) .ge. ddval) then
      if ((a1(i + 1) .lt. ddval) .and. (a1(i + 2) .lt. ddval)) a1(i + 1)
     & = a1(i + 2)
      if ((a1(i - 1) .lt. ddval) .and. (a1(i - 2) .lt. ddval)) a1(i - 1)
     & = a1(i - 2)
      end if
   21 continue
      call rowio(a1, y, nz, ncol, 12, 2)
   10 continue
   99 continue
      stop 
      end
      subroutine rowio(a[HUGE], y, nz, ncol, ld, key)
      dimension a(nz, ncol)
      goto (1, 2), key
    1 read(ld) y, a
      goto 90
    2 write(ld) y, a
   90 return 
      end
