!                                                                   !
! This routine is an example for reading 2D or 3D parameters        !
! Also included is information about the parameters and model grid  ! 
!                                                                   !
      parameter(nx1=600,ny1=300,nx=nx1,ny=ny1,imt=nx1,jmt=ny1,km=40)
c      parameter(nyear1=2013,nyear2=2013,nday=365,nmon=12)
      parameter(nyear1=2020,nyear2=2020,nday=365,nmon=12)

      dimension heff(imt,jmt),aiday(imt,jmt),snow(imt,jmt)
      dimension ossw(imt,jmt),hiday(imt,jmt),ampday(imt,jmt)
      dimension uice(imt,jmt),vice(imt,jmt),ssh(imt,jmt)
      dimension uo(imt,jmt,km),vo(imt,jmt,km),vdc(imt,jmt,km)
      dimension zoo1(imt,jmt,km),to(imt,jmt,km)
      dimension zoo2(imt,jmt,km),wo(imt,jmt,km)
      dimension zoo3(imt,jmt,km),nitrat(imt,jmt,km)
      dimension flagel(imt,jmt,km),diatom(imt,jmt,km)
      dimension flageli(imt,jmt,km),diatomi(imt,jmt,km)
      dimension clon(imt,jmt),clat(imt,jmt),kmt(imt,jmt)
      dimension ulat(imt,jmt),ulon(imt,jmt),HTN(imt,jmt),HTE(imt,jmt)
     &,HUS(imt,jmt),HUW(imt,jmt),angle(imt,jmt),dxt(imt,jmt)
     &,dyt(imt,jmt)
      dimension dz(km),ZDZ (KM),ZDZZ(KM+1)
      character *80 fopen(5),f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13
     &,f14,f15,f16,f17,f18
      character *4 cyear(1900:2100),cyear1(1900:2100)
      character *12 char
      integer SLEN

      f7='hiday.H'            ! 2D daily sea ice thickness (m)
      f8='ampdayIceArea.H'    ! 2D daily melt pond area fraction
      f9='aiday.H'            ! 2D daily ice concentration (fraction)

cccc-notes---
c model is on B grid, all data except W are at the center of each ocean level
c wo is centered at a scalar grid cell at the base of each ocean level
cccc

c read lon/lat for scalar fields (like ice thickness, ocean T & biology)
c the lon/lat is also for W
      open(20,file='grid.dat.rot')
      read(20,'(10f8.2)') ((clon(i,j),i=1,nx1),j=1,ny1)
      read(20,'(10f8.2)') ((clat(i,j),i=1,nx1),j=1,ny1)
      close(20)

c read lon/lat for vector fields (like ice & ocean veclocities, except W)
      open(24,file='grid.dat.pop')
        read(24,'(10f8.2)') ((ulat(i,j),i=1,nx),j=1,ny)
        read(24,'(10f8.2)') ((ulon(i,j),i=1,nx),j=1,ny)
c HTN, HTE are lengths of the northern and eastern sides of a scaler grid cell in km, HTN*HTE is the area of a scaler grid cell in km**2
c HUS, HUW are lengths of the southern and western sides of a vector grid cell in km
        read(24,'(10f8.2)') ((HTN  (i,j),i=1,nx),j=1,ny) 
        read(24,'(10f8.2)') ((HTE  (i,j),i=1,nx),j=1,ny)
        read(24,'(10f8.2)') ((HUS  (i,j),i=1,nx),j=1,ny)
        read(24,'(10f8.2)') ((HUW  (i,j),i=1,nx),j=1,ny)
c angle is the angle between latitude line and  grid cell x-coordinate line, needed for vector rotation for plotting the vectors in spherical lat-lon coordinate system
c** Do not use the angle variable any more because the rotation has already be made **
        read(24,'(10f8.2)') ((angle(i,j),i=1,nx),j=1,ny)
      close(24)

c read model grid mask with ocean levels; ocean: levels > 0, land: levels = 0
      open(20,file='levels_40_t_aBering1')
      read(20,'(600i2)') kmt
      close(20)

c read ocean level thickness dz(k) in cm, converted to m
      open(20,file='dz.dta40')
      do k=1,km
        read(20,*)dz(k)
        dz(k)=dz(k)*0.01
      end do
      ZDZ(1)=DZ(1)
      do k=2,km
        ZDZ(K)=ZDZ(K-1)+DZ(K)
      end do
      do k=1,km
        zdzz(k)=zdz(k)-0.5*dz(k)
      end do
      close(20)

      do 999 iyear=nyear1,nyear2

      write(unit=cyear(iyear),fmt='(i4)') iyear

      i=slen(f7)
      open(7,file=f7(1:i)//cyear(iyear)
     &,access='direct',form='unformatted',recl=nx1*ny1*4
     &,status='old')
 
      i=slen(f8)
      open(8,file=f8(1:i)//cyear(iyear)
     &,access='direct',form='unformatted',recl=nx1*ny1*4
     &,status='old')
 
      i=slen(f9)
      open(9,file=f9(1:i)//cyear(iyear)
     &,access='direct',form='unformatted',recl=nx1*ny1*4
     &,status='old')
 
      do iday=1,nday

        read(7)((hiday(i,j),i=1,nx1),j=1,ny1) ! sea ice thickness
        read(8)((ampday(i,j),i=1,nx1),j=1,ny1) ! melt pond fraction
        read(9)((aiday(i,j),i=1,nx1),j=1,ny1) ! sea ice concentration

        i=nx/2
        j=ny/2
        write(*,'(2i6, 2f12.3, 2f8.2)') iyear, iday
     &, clon(i,j), clat(i,j), hiday(i,j), ampday(i,j)

      end do ! iday

      close(2)
      close(3)
      close(4)
      close(5)
      close(61)
      close(7)
      close(8)
      close(9)
      close(10)
      close(11)
      close(12)
      close(13)
      close(14)
999   continue
      
      stop  
      end

      INTEGER FUNCTION slen (string)
C ---
C --- this function computes the length of a character string less
C --- trailing blanks
C --- slen > 0, length of string less trailing blanks
C ---      = 0, character string is blank
C ---
      CHARACTER*(*) string
      CHARACTER*1 cblank
      INTEGER i
      DATA cblank/' '/
C ---
      DO 50 i = LEN(string), 1, -1
         IF (string(i:i) .NE. ' ')  GO TO 100
50    CONTINUE
      i = 0
100   CONTINUE
      slen = i
      RETURN
      END
