c     combgr.for - dos version
c     J.Phillips, USGS, Denver, Colorado
c     changes from vms version are indicated by cv
c
      dimension gr(10000), cr(10000), id(14), pgm(2)
      character ifile1*50, ifile2*50, ofile*50
cv    data dval / '37777677777'o /      
      data dval / 1.0e+38 /
      data dlim / 1.0e+30 /
  799 format(a50)
    1 write(*, 800) 
  800 format(15h primary file: ,$)
      read(5, 799) ifile1
cv    open(10,file=ifile1,status='old',form='unformatted',iostat=ios)
cv    if(ios.ne.0) then
cv    open(10,file=ifile1,status='old',form='unformatted',readonly)
cv    endif
      open(10, file=ifile1, status='old', form='unformatted', err=1)
    2 write(*, 801) 
  801 format(13h crest file: ,$)
      read(5, 799) ifile2
cv    open(11,file=ifile2,status='old',form='unformatted',iostat=ios)
cv    if(ios.ne.0) then
cv    open(11,file=ifile2,status='old',form='unformatted',readonly)
cv    endif
      open(11, file=ifile2, status='old', form='unformatted', err=2)
      write(*, 802) 
  802 format(14h output file: ,$)
      read(5, 799) ofile
cv    open(12,file=ofile,status='new',form='unformatted')
      open(12, file=ofile, status='unknown', form='unformatted') 
      read(10) id, pgm, nc, nr, nz, xo, dx, yo, dy
      read(11) id
      write(12) id, pgm, nc, nr, nz, xo, dx, yo, dy
      do 80 k = 1, nr
      read(10) dlt, (gr(i),i = 1, nc)
      read(11) dlt, (cr(i),i = 1, nc)
      do 70 i = 1, nc
cv    if (cr(i) .eq. dval) goto 70
      if (cr(i) .ge. dlim) goto 70
      gr(i) = dval
   70 continue
      write(12) dlt, (gr(i),i = 1, nc)
   80 continue
      close(10) 
      close(11) 
      close(12) 
      stop 
      end
