Index: /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/field_def.xml
===================================================================
--- /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 5248)
+++ /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/field_def.xml	(revision 5249)
@@ -45,4 +45,5 @@
          <field id="mldr10_1max"  long_name="max of Mixed Layer Depth 0.01 ref.10m" field_ref="mldr10_1"  operation="maximum" />
          <field id="mldr10_1min"  long_name="min of Mixed Layer Depth 0.01 ref.10m" field_ref="mldr10_1"  operation="minimum" />
+         <field id="mldzint"      long_name="vertically-interpolated mixing layer depth"           unit="m"           />
          <field id="heatc"        long_name="Heat content vertically integrated"        unit="J/m2"                     />
          <field id="saltc"        long_name="Salt content vertically integrated"        unit="PSU*kg/m2"                />
Index: /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5248)
+++ /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5249)
@@ -886,4 +886,5 @@
 !!    namzdf_ddm    double diffusive mixing parameterization            ("key_zdfddm")
 !!    namzdf_tmx    tidal mixing parameterization                       ("key_zdftmx")
+!!    namzdf_mldzint vertically-interpolated mixed-layer depth parameters
 !!======================================================================
 !
@@ -991,4 +992,12 @@
    ln_tmx_itf  = .true.    !  ITF specific parameterisation
    rn_tfe_itf  = 1.        !  ITF tidal dissipation efficiency
+/
+!------------------------------------------------------------------------------------------
+&namzdf_mldzint    !   Parameters for vertically-interpolated mixed-layer depth diagnostic
+!------------------------------------------------------------------------------------------
+         nn_mld_type   = 1      ! mixed layer type
+         rn_zref       = 10.0   ! depth of initial reference temperature
+         rn_dT_crit    = 0.2    ! critical temperature difference
+         rn_iso_frac   = 0.1    ! fraction of critical temperature difference used
 /
 
Index: /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90
===================================================================
--- /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 5248)
+++ /branches/UKMO/dev_r5107_mld_zint/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfmxl.F90	(revision 5249)
@@ -18,4 +18,5 @@
    USE phycst          ! physical constants
    USE iom             ! I/O library
+   USE eosbn2          ! for zdf_mxl_zint
    USE lib_mpp         ! MPP library
    USE wrk_nemo        ! work arrays
@@ -32,7 +33,16 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlp    !: mixed layer depth  (rho=rho0+zdcrit) [m]
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmlpt   !: mixed layer depth at t-points        [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hmld_zint  !: vertically-interpolated mixed layer depth   [m] 
+   LOGICAL, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)    :: ll_found   ! Is T_b to be found by interpolation ? 
+   LOGICAL, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)  :: ll_belowml ! Flag points below mixed layer when ll_found=F
 
    REAL(wp), PUBLIC ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
    REAL(wp)         ::   avt_c = 5.e-4_wp   ! Kz criterion for the turbocline depth
+
+   ! Namelist variables for  namzdf_mldzint
+   INTEGER          :: nn_mld_type         ! mixed layer type            
+   REAL(wp)         :: rn_zref            ! depth of initial T_ref
+   REAL(wp)         :: rn_dT_crit          ! Critical temp diff 
+   REAL(wp)         :: rn_iso_frac         ! Fraction of rn_dT_crit used 
 
    !! * Substitutions
@@ -51,5 +61,6 @@
       zdf_mxl_alloc = 0      ! set to zero if no array to be allocated
       IF( .NOT. ALLOCATED( nmln ) ) THEN
-         ALLOCATE( nmln(jpi,jpj), hmld(jpi,jpj), hmlp(jpi,jpj), hmlpt(jpi,jpj), STAT= zdf_mxl_alloc )
+         ALLOCATE( nmln(jpi,jpj), hmld(jpi,jpj), hmlp(jpi,jpj), hmlpt(jpi,jpj), hmld_zint(jpi,jpj),       &
+        &          ll_found(jpi,jpj), ll_belowml(jpi,jpj,jpk), STAT= zdf_mxl_alloc )
          !
          IF( lk_mpp             )   CALL mpp_sum ( zdf_mxl_alloc )
@@ -137,4 +148,10 @@
       ENDIF
       
+      ! Vertically-interpolated mixed-layer depth diagnostic
+      IF( iom_use( "mldzint" ) ) THEN
+         CALL zdf_mxl_zint( kt )
+         CALL iom_put( "mldzint" , hmld_zint )
+      ENDIF
+
       IF(ln_ctl)   CALL prt_ctl( tab2d_1=REAL(nmln,wp), clinfo1=' nmln : ', tab2d_2=hmlp, clinfo2=' hmlp : ', ovlap=1 )
       !
@@ -144,4 +161,189 @@
       !
    END SUBROUTINE zdf_mxl
+
+   SUBROUTINE zdf_mxl_zint( kt ) 
+      !!---------------------------------------------------------------------------------- 
+      !!                    ***  ROUTINE zdf_mxl_zint  *** 
+      !                                                                        
+      !   Calculate vertically-interpolated mixed layer depth diagnostic. 
+      !            
+      !   This routine can calculate the mixed layer depth diagnostic suggested by
+      !   Kara et al, 2000, JGR, 105, 16803, but is more general and can calculate
+      !   vertically-interpolated mixed-layer depth diagnostics with other parameter
+      !   settings set in the namzdf_mldzint namelist.  
+      ! 
+      !   If mld_type=1 the mixed layer depth is calculated as the depth at which the  
+      !   density has increased by an amount equivalent to a temperature difference of  
+      !   0.8C at the surface. 
+      ! 
+      !   For other values of mld_type the mixed layer is calculated as the depth at  
+      !   which the temperature differs by 0.8C from the surface temperature.  
+      !                                                                        
+      !   David Acreman, Daley Calvert                                      
+      ! 
+      !!----------------------------------------------------------------------------------- 
+
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      !
+      ! Local variables
+      INTEGER, POINTER, DIMENSION(:,:) :: ikmt          ! number of active tracer levels 
+      INTEGER, POINTER, DIMENSION(:,:) :: ik_ref        ! index of reference level 
+      INTEGER, POINTER, DIMENSION(:,:) :: ik_iso        ! index of last uniform temp level 
+      REAL, POINTER, DIMENSION(:,:,:)  :: zT            ! Temperature or density 
+      REAL, POINTER, DIMENSION(:,:)    :: ppzdep        ! depth for use in calculating d(rho) 
+      REAL, POINTER, DIMENSION(:,:)    :: zT_ref        ! reference temperature 
+      REAL    :: zT_b                                   ! base temperature 
+      REAL, POINTER, DIMENSION(:,:,:)  :: zdTdz         ! gradient of zT 
+      REAL, POINTER, DIMENSION(:,:,:)  :: zmoddT        ! Absolute temperature difference 
+      REAL    :: zdz                                    ! depth difference 
+      REAL    :: zdT                                    ! temperature difference 
+      REAL, POINTER, DIMENSION(:,:)    :: zdelta_T      ! difference critereon 
+      REAL, POINTER, DIMENSION(:,:)    :: zRHO1, zRHO2  ! Densities 
+      INTEGER :: ji, jj, jk                             ! loop counter 
+      INTEGER :: ios
+
+      NAMELIST/namzdf_mldzint/ nn_mld_type, rn_zref, rn_dT_crit, rn_iso_frac
+
+      !!------------------------------------------------------------------------------------- 
+      !  
+      CALL wrk_alloc( jpi, jpj, ikmt, ik_ref, ik_iso) 
+      CALL wrk_alloc( jpi, jpj, ppzdep, zT_ref, zdelta_T, zRHO1, zRHO2 ) 
+      CALL wrk_alloc( jpi, jpj, jpk, zT, zdTdz, zmoddT ) 
+ 
+      IF( kt == nit000 ) THEN
+         REWIND( numnam_ref )              ! Namelist namzdf_mldzint in reference namelist 
+         READ  ( numnam_ref, namzdf_mldzint, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_mldzint in reference namelist', lwp )
+
+         REWIND( numnam_cfg )              ! Namelist namzdf_mldzint in configuration namelist 
+         READ  ( numnam_cfg, namzdf_mldzint, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_mldzint in configuration namelist', lwp )
+         IF(lwm) WRITE ( numond, namzdf_mldzint )
+
+         WRITE(numout,*) '===== Vertically-interpolated mixed layer ====='
+         WRITE(numout,*) 'nn_mld_type = ',nn_mld_type
+         WRITE(numout,*) 'rn_zref = ',rn_zref
+         WRITE(numout,*) 'rn_dT_crit = ',rn_dT_crit
+         WRITE(numout,*) 'rn_iso_frac = ',rn_iso_frac
+         WRITE(numout,*) '==============================================='
+      ENDIF
+ 
+      ! Set the mixed layer depth criterion at each grid point 
+      IF (nn_mld_type == 1) THEN                                         
+         ppzdep(:,:)=0.0 
+         call eos ( tsn(:,:,1,:), ppzdep(:,:), zRHO1(:,:) ) 
+! Use zT temporarily as a copy of tsn with rn_dT_crit added to SST 
+! [assumes number of tracers less than number of vertical levels] 
+         zT(:,:,1:jpts)=tsn(:,:,1,1:jpts) 
+         zT(:,:,jp_tem)=zT(:,:,1)+rn_dT_crit 
+         CALL eos( zT(:,:,1:jpts), ppzdep(:,:), zRHO2(:,:) ) 
+         zdelta_T(:,:) = abs( zRHO1(:,:) - zRHO2(:,:) ) * rau0 
+         ! RHO from eos (2d version) doesn't calculate north or east halo: 
+         CALL lbc_lnk( zdelta_T, 'T', 1. ) 
+         zT(:,:,:) = rhop(:,:,:) 
+      ELSE 
+         zdelta_T(:,:) = rn_dT_crit                      
+         zT(:,:,:) = tsn(:,:,:,jp_tem)                           
+      END IF 
+
+      ! Calculate the gradient of zT and absolute difference for use later 
+      DO jk = 1 ,jpk-2 
+         zdTdz(:,:,jk)  =    ( zT(:,:,jk+1) - zT(:,:,jk) ) / fse3w(:,:,jk+1) 
+         zmoddT(:,:,jk) = abs( zT(:,:,jk+1) - zT(:,:,jk) ) 
+      END DO 
+
+      ! Find density/temperature at the reference level (Kara et al use 10m).          
+      ! ik_ref is the index of the box centre immediately above or at the reference level 
+      ! Find rn_zref in the array of model level depths and find the ref    
+      ! density/temperature by linear interpolation.                                   
+      DO jk = jpkm1, 2, -1 
+         WHERE ( fsdept(:,:,jk) > rn_zref ) 
+           ik_ref(:,:) = jk - 1 
+           zT_ref(:,:) = zT(:,:,jk-1) + zdTdz(:,:,jk-1) * ( rn_zref - fsdept(:,:,jk-1) ) 
+         END WHERE 
+      END DO 
+
+      ! If the first grid box centre is below the reference level then use the 
+      ! top model level to get zT_ref 
+      WHERE ( fsdept(:,:,1) > rn_zref )  
+         zT_ref = zT(:,:,1) 
+         ik_ref = 1 
+      END WHERE 
+
+      ! The number of active tracer levels is 1 less than the number of active w levels 
+      ikmt(:,:) = mbathy(:,:) - 1 
+
+      ! Search for a uniform density/temperature region where adjacent levels          
+      ! differ by less than rn_iso_frac * deltaT.                                      
+      ! ik_iso is the index of the last level in the uniform layer  
+      ! ll_found indicates whether the mixed layer depth can be found by interpolation 
+      ik_iso(:,:)   = ik_ref(:,:) 
+      ll_found(:,:) = .false. 
+      DO jj = 1, nlcj 
+         DO ji = 1, nlci 
+!CDIR NOVECTOR 
+            DO jk = ik_ref(ji,jj), ikmt(ji,jj)-1 
+               IF ( zmoddT(ji,jj,jk) > ( rn_iso_frac * zdelta_T(ji,jj) ) ) THEN 
+                  ik_iso(ji,jj)   = jk 
+                  ll_found(ji,jj) = ( zmoddT(ji,jj,jk) > zdelta_T(ji,jj) ) 
+                  EXIT 
+               END IF 
+            END DO 
+         END DO 
+      END DO 
+
+      ! Use linear interpolation to find depth of mixed layer base where possible 
+      hmld_zint(:,:) = rn_zref 
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+            IF (ll_found(ji,jj) .and. tmask(ji,jj,1) == 1.0) THEN 
+               zdz =  abs( zdelta_T(ji,jj) / zdTdz(ji,jj,ik_iso(ji,jj)) ) 
+               hmld_zint(ji,jj) = fsdept(ji,jj,ik_iso(ji,jj)) + zdz 
+            END IF 
+         END DO 
+      END DO 
+
+      ! If ll_found = .false. then calculate MLD using difference of zdelta_T    
+      ! from the reference density/temperature 
+ 
+! Prevent this section from working on land points 
+      WHERE ( tmask(:,:,1) /= 1.0 ) 
+         ll_found = .true. 
+      END WHERE 
+ 
+      DO jk=1, jpk 
+         ll_belowml(:,:,jk) = abs( zT(:,:,jk) - zT_ref(:,:) ) >= zdelta_T(:,:)  
+      END DO 
+ 
+! Set default value where interpolation cannot be used (ll_found=false)  
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+            IF ( .not. ll_found(ji,jj) )  hmld_zint(ji,jj) = fsdept(ji,jj,ikmt(ji,jj)) 
+         END DO 
+      END DO 
+
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+!CDIR NOVECTOR 
+            DO jk = ik_ref(ji,jj)+1, ikmt(ji,jj) 
+               IF ( ll_found(ji,jj) ) EXIT 
+               IF ( ll_belowml(ji,jj,jk) ) THEN                
+                  zT_b = zT_ref(ji,jj) + zdelta_T(ji,jj) * SIGN(1.0, zdTdz(ji,jj,jk-1) ) 
+                  zdT  = zT_b - zT(ji,jj,jk-1)                                      
+                  zdz  = zdT / zdTdz(ji,jj,jk-1)                                       
+                  hmld_zint(ji,jj) = fsdept(ji,jj,jk-1) + zdz 
+                  EXIT                                                   
+               END IF 
+            END DO 
+         END DO 
+      END DO 
+
+      hmld_zint(:,:) = hmld_zint(:,:)*tmask(:,:,1) 
+      !  
+      CALL wrk_dealloc( jpi, jpj, ikmt, ik_ref, ik_iso) 
+      CALL wrk_dealloc( jpi, jpj, ppzdep, zT_ref, zdelta_T, zRHO1, zRHO2 ) 
+      CALL wrk_dealloc( jpi,jpj, jpk, zT, zdTdz, zmoddT ) 
+      ! 
+   END SUBROUTINE zdf_mxl_zint
 
    !!======================================================================
