c  grdmax.for
c  for grid max,min
c  Histogram option deleted, for histogram,
c    median, and standard deviation, use
c    program "this".
      dimension  r(2000)
	character  id*56,p*8
	iswt = 10

	print 1
1	format(' input file :'$)
	read(5,37) id
37	format(a56)

	open(unit=iswt,file=id,status='old',form='unformatted')
	read(10) id,p,nc,nr,nz,xo,dx,yo,dy

	zmx   = -1.e37
	zmn   =  1.e37
	ndval =  0
      ave   =  0
      total=nc*nr

	do 20 j=1,nr
        call rowio(nc,r,-1,10,10,ier)
	if (ier.ne.0) then
	print 10,j
10	format(' eof before row ',i4)
	stop
	endif

	do 20 i=1,nc
	if ( r(i) .gt. 1.e37 ) then
	  ndval = ndval + 1
	  else if ( r(i) .gt. zmx ) then
	    zmx=r(i)
	    mxcol=i
	    mxrow=j
	  else if ( r(i) .lt. zmn ) then
	    zmn=r(i)
	    mcol=i
	    mrow=j
	endif
20	continue

	print 30, zmn, mcol, mrow
30	format(' min =',1pg20.7,'    col row ',2i4)
	print 40, zmx, mxcol, mxrow
40    format(' max =',1pg20.7,'    col row ',2i4)
      pcent=ndval*100.0
      pcent=100.-(pcent/total)
      write(6,50)ndval,pcent
50    format(1x,i10,' dvals;',f6.1,'% of the grid is defined.')
      close(10)
	stop
        end
      subroutine rowio(n,z,iop,idev,jdev,iend)
c  read iop<0, write iop=0, r&w iop=1
	dimension z(n)
	iend=0
	if(iop)1,2,1
1	read(idev,end=10) y,z
	if(iop)9,9,2
2	write(jdev) y,z
9	return
10	iend=1
	return
	end
