C***********************************************************************
C***********************************************************************
C23456789012345678901234567890123456789012345678901234567890123456789012
      SUBROUTINE lin_stress(kd,seckd,ncall,ak,akmin,nn) 
C
C Read linearized bottom friction coefficients from data files.
C Constuct the bottom friction coefficient at current time. 
C Step 1: the mean 
C
	 INCLUDE 'CASCO.DIM' 
	 integer ncall
	 integer kd     
	 real    seckd 
	 real    ak(nndim)
	 real    akmin 
	 integer nn
C
C ak(I): linear bottom friction parameter.
C akmin: minimum value for the bottom friction parameter.
C Index range:  I=1,NN. where NN - number of horizontal nodes
C kd, seckd the current time in Gregorian days
C ncall = 0 at first call
C ncall <>0 otherwise. 
C Presently only called once (at startup). 
C
C**local variables
	 real    akmean(nndim) 
	 character*80  fileak, header
	 save    akmean 
	 integer ii,i 

         fileak = 'ak0.s2r'

	 if(ncall.eq.0) then 
	    write(*,'(a)')' Reading linear bottom friction from'
	    write(*,'(a)')fileak
	    open(41,file=fileak,status='old')
	    read(41,'(a)')header
	    read(41,'(a)')header
	    do i = 1, nn
	       read(41,*,end=1001)ii, akmean(i) 
	    enddo
	    close(41)
	 endif

         do ii = 1, nn
	    ak(ii) = max(akmean(ii),akmin) 
	 enddo

         if(ncall.eq.1) then 
	   write(*,*)'LIN_STRESS: ncall = 1 ' 
	   write(*,*)'ak(1),ak(nn),nn', ak(1), ak(nn),nn
	 endif

      RETURN
1001  continue
      write(*,*)'LIN_STRESS: data ended too soon ' 
      write(*,*)'number read ', i 
      write(*,*)'number required (nn) ', nn 
      END

C***********************************************************************
C***********************************************************************
C23456789012345678901234567890123456789012345678901234567890123456789012
      SUBROUTINE lin_enz(kd,seckd,ncall,enz,enzmin,nn,nnv) 
C
C Read vertical eddy viscosity coefficients from data files.
C Construct the vertical eddy viscosity profiles at the current time. 
C Step 1: the mean 
C
C Problem.  Q4 (and thus SACO) use the vertical eddy viscosity 
C               as a vertical element based quantity. 
C           F5 (and thus Truxton) use a vertical node based 
C               vertical eddy viscosity. 
C           Thus a different en.s3r is required for the different
C           applications.  This code does not distinguish since 
C           in Q4 ENZM is dimensioned ENZM(NNDIM,NNVDIM) and the 
C           same reading code can serve both masters *IF* the 
C           input is formatted correctly.  That is, if in Q4 applications 
C           the element values are written to the first NNV-1 positions
C           and a zero is inserted at NNV. 
C
C May 14, 1998 Charles G. Hannah
C
	 INCLUDE 'CASCO.DIM' 
	 integer ncall
	 integer kd     
	 real    seckd 
	 real    enz(nndim,nnvdim)
	 real    enzmin 
	 integer nn, nnv
C
C enz(I,J): vertical eddy viscosity.
C ekmin: minimum value for the  vertical eddy viscosity.
C Index range:  I=1,NN, where NN - number of horizontal nodes
C               J=1,NNV, where NNV - number of vertical nodes 
C kd, seckd the current time in Gregorian days
C ncall = 0 at first call
C ncall <>0 otherwise. 
C Presently only called once (at startup). 

C**local variables
	 real    enzmean(nndim,nnvdim) 
	 character*80  fileenz, header
	 save    enzmean 

         integer i,j
	 integer ii
	 real    zij
	 integer nnv_en

         fileenz = 'en0.s3r'

	 if(ncall.eq.0) then 
	    write(*,'(a)')' Reading vertical eddy viscosity from'
	    write(*,'(a)')fileenz
	    open(41,file=fileenz,status='old')
	    read(41,'(a)')header
	    read(41,'(a)')header
	    read(41,*)nnv_en
	    if(nnv_en.ne.nnv) goto 2001
	    do i = 1, nn
               do j = 1, nnv
	          read(41,*,end=1001)ii,zij, enzmean(i,j) 
               enddo
	    enddo
	    close(41)
	 endif

         do i = 1, nn
            do j = 1, nnv
	       enz(i,j) = max(enzmean(i,j),enzmin)
            enddo
	 enddo

	 if(ncall.eq.1) then 
	   write(*,*)'LIN_ENZ: ncall = ', ncall
	   write(2,*)'enz(1,1), enz(nn,nnv-1)', enz(1,1), enz(nn,nnv-1) 
	 endif

      RETURN
1001  continue
      write(*,*)'LIN_ENZ: data ended too soon ' 
      write(*,*)'number read i,j ', i,j 
      write(*,*)'number required (nn) ', nn 
      stop
2001  continue
        write(*,*)'LIN_ENZ: different ideas about nnv'
	write(*,*)'nnv from file, nnv from main ',nnv_en,nnv
      stop
      END

C***********************************************************************
C***********************************************************************
