      parameter (idm=1437,jdm=1437,imt=jdm,jmt=idm)
c note:change parameters in subroutines
      parameter (bad=1.e10)
      dimension b(idm,jdm)
      dimension plot(imt,jmt)
      character*80 fnam
      character util(idm*jdm+14)*2,text*8,preambl(5)*79
      character chday*3,ch2*2,chti*14,run*4
      common/topog/zbot(idm,jdm)
      dimension xlat(idm),xlon(jdm)
      data rad/57.29578/,pi/3.14159265/,grid/.08/,xpiv/1071./
      data rlong/-98.0/
      ALAT(DIST,GRIDD)=2.*ATAN(EXP(DIST*GRIDD/RAD))-PI/2.
c --- read topography
      open(9,file='/h/obelix2/zulema/micom/depthdamee.1437x1437',
     .     form='formatted',status='old')
      read (9,120) preambl,idim,jdim,length,(util(l),l=1,length)
 120  FORMAT (5(a79/),3i8/(40a2))
      close(9)
      call unpakk(zbot,idm,idim,jdim,util,length)
c--- latitudes
      DO I=1,IDM
      xlat(i)=alat(xpiv-i,grid)*rad
      enddo
      do j=1,jdm
      xlon(j)=rlong+(j-1)*grid
      enddo
      write(6,*)'enter stats start and end year'
      read(5,*)iy1,iy2
      write(6,*)'enter run'
      read(5,'(a)')run
      do iyr=iy1,iy2
      fnam='year??.stats.'//run
      write(fnam(5:6),'(I2.2)')iyr
      write(ch2,'(i2.2)')iyr
      open(14,file=fnam,form='unformatted',status='old')
      open(20,file='ssh.year'//ch2//'.fmt.'//run,form='formatted',
     .     status='unknown')

c --- surface height
      read (14)b
      do i=1,idm
      do j=1,jdm
      b(i,j)=b(i,j)/980.60
      if(zbot(i,j).lt.0.1)b(i,j)= 999.99
      enddo
      enddo
      call minmaxr(idm,jdm,0.,b,amin,amax)
      write(20,*)'latitudes xlat(i), i=1,1437'
      write(20,'(10f7.2)')(xlat(i),i=1,idm)
      write(20,*)'longitudes xlon(j), j=1,1437'
      write(20,'(10f7.2)')(xlon(j),j=1,jdm)
      write(20,*)'ssh (cm), ((ssh(i,j),i=1,1437),j=1,1437),i=lat,j=lon'
      write(20,'(10f7.2)')((b(i,j), i=1,idm),j=1,jdm)
      close(14)
      close(20)
      enddo
      stop
      end
      include '/h/obelix2/zulema/src/pakk.f'

      SUBROUTINE MINMAX
      DIMENSION IARRAY(IM,JM),ARRAY(IM,JM)
C
      ENTRY MINMAXI(im,jm,ibad,iarray,imin,imax)
c*** integer array
  100 continue
      IMIN=2**15
      IMAX=-IMIN
      DO 110 J=1,JM
      DO 110 I=1,IM
      IF(IARRAY(I,J).EQ.IBAD)GO TO 110
      IF(IARRAY(I,J).LE.IMIN)IMIN=IARRAY(I,J)
      IF(IARRAY(I,J).GE.IMAX)IMAX=IARRAY(I,J)
  110 CONTINUE
      WRITE(6,*)' IMIN IMAX ',IMIN,IMAX
      return
c
c*** real array
  200 continue

      ENTRY MINMAXR(im,jm,badno,array,amin,amax)
      AMIN=1.e12
      AMAX=-1.e12
      DO 210 J=1,JM
      DO 210 I=1,IM
      IF(ARRAY(I,J).EQ.BADNO)GO TO 210
      IF(ARRAY(I,J).LE.AMIN)AMIN=ARRAY(I,J)
      IF(ARRAY(I,J).GE.AMAX)AMAX=ARRAY(I,J)
  210 CONTINUE
      WRITE(6,*)' AMIN AMAX ',AMIN,AMAX
      return
      END


