Index: branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/OPA_SRC/ASM/asmbgc.F90
===================================================================
--- branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/OPA_SRC/ASM/asmbgc.F90	(revision 13190)
+++ branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/OPA_SRC/ASM/asmbgc.F90	(revision 13191)
@@ -33,12 +33,12 @@
    USE oce, ONLY:           & ! active tracer variables
       & tsn
-   USE zdfmxl, ONLY :       & ! mixed layer depth 
+   USE zdfmxl, ONLY :       & ! mixed layer depth
 #if defined key_karaml
       & hmld_kara,          &
       & ln_kara,            &
-#endif   
-      & hmld,               & 
+#endif
+      & hmld,               &
       & hmlp,               &
-      & hmlpt 
+      & hmlpt
    USE asmpar, ONLY:        & ! assimilation parameters
       & c_asmbkg,           &
@@ -89,5 +89,5 @@
 
    IMPLICIT NONE
-   PRIVATE                   
+   PRIVATE
 
    PUBLIC  asm_bgc_check_options  ! called by asm_inc_init in asminc.F90
@@ -290,35 +290,35 @@
 
       ! Allocate and read increments
-      
+
       IF ( ln_slchltotinc ) THEN
          ALLOCATE( slchltot_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinslchltot', slchltot_bkginc )
       ENDIF
-      
+
       IF ( ln_slchldiainc ) THEN
          ALLOCATE( slchldia_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinslchldia', slchldia_bkginc )
       ENDIF
-      
+
       IF ( ln_slchlnoninc ) THEN
          ALLOCATE( slchlnon_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinslchlnon', slchlnon_bkginc )
       ENDIF
-      
+
       IF ( ln_schltotinc ) THEN
          ALLOCATE( schltot_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinschltot', schltot_bkginc )
       ENDIF
-      
+
       IF ( ln_slphytotinc ) THEN
          ALLOCATE( slphytot_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinslphytot', slphytot_bkginc )
       ENDIF
-      
+
       IF ( ln_slphydiainc ) THEN
          ALLOCATE( slphydia_bkginc(jpi,jpj) )
          CALL asm_bgc_read_incs_2d( knum, 'bckinslphydia', slphydia_bkginc )
       ENDIF
-      
+
       IF ( ln_slphynoninc ) THEN
          ALLOCATE( slphynon_bkginc(jpi,jpj) )
@@ -335,40 +335,40 @@
          CALL asm_bgc_read_incs_2d( knum, 'bckinspco2', sfco2_bkginc )
       ENDIF
-      
+
       IF ( ln_plchltotinc ) THEN
          ALLOCATE( plchltot_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinplchltot', plchltot_bkginc )
       ENDIF
-      
+
       IF ( ln_pchltotinc ) THEN
          ALLOCATE( pchltot_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpchltot', pchltot_bkginc )
       ENDIF
-      
+
       IF ( ln_pno3inc ) THEN
          ALLOCATE( pno3_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpno3', pno3_bkginc )
       ENDIF
-      
+
       IF ( ln_psi4inc ) THEN
          ALLOCATE( psi4_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpsi4', psi4_bkginc )
       ENDIF
-      
+
       IF ( ln_pdicinc ) THEN
          ALLOCATE( pdic_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpdic', pdic_bkginc )
       ENDIF
-      
+
       IF ( ln_palkinc ) THEN
          ALLOCATE( palk_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpalk', palk_bkginc )
       ENDIF
-      
+
       IF ( ln_pphinc ) THEN
          ALLOCATE( pph_bkginc(jpi,jpj,jpk) )
          CALL asm_bgc_read_incs_3d( knum, 'bckinpph', pph_bkginc )
       ENDIF
-      
+
       IF ( ln_po2inc ) THEN
          ALLOCATE( po2_bkginc(jpi,jpj,jpk) )
@@ -377,5 +377,5 @@
 
       ! Allocate balancing increments
-      
+
       IF ( ln_slchltotinc .OR. ln_slchldiainc .OR. ln_slchlnoninc .OR. &
          & ln_schltotinc  .OR. ln_slphytotinc .OR. ln_slphydiainc .OR. &
@@ -388,5 +388,5 @@
 #endif
       ENDIF
-      
+
       IF ( ln_plchltotinc .OR. ln_pchltotinc ) THEN
 #if defined key_top
@@ -443,11 +443,11 @@
       ! Initialise
       p_incs(:,:) = 0.0
-      
+
       ! read from file
       CALL iom_get( knum, jpdom_autoglo, TRIM(cd_bgcname), p_incs(:,:), 1 )
-      
+
       ! Apply the masks
       p_incs(:,:) = p_incs(:,:) * tmask(:,:,1)
-      
+
       ! Set missing increments to 0.0 rather than 1e+20
       ! to allow for differences in masks
@@ -481,11 +481,11 @@
       ! Initialise
       p_incs(:,:,:) = 0.0
-      
+
       ! read from file
       CALL iom_get( knum, jpdom_autoglo, TRIM(cd_bgcname), p_incs(:,:,:), 1 )
-      
+
       ! Apply the masks
       p_incs(:,:,:) = p_incs(:,:,:) * tmask(:,:,:)
-      
+
       ! Set missing increments to 0.0 rather than 1e+20
       ! to allow for differences in masks
@@ -538,5 +538,5 @@
          cchl_p_bkg(:,:,:) = 0.0
 #endif
-         
+
          !--------------------------------------------------------------------
          ! Read background variables for phytoplankton assimilation
@@ -558,5 +558,5 @@
          CALL iom_get( inum, jpdom_autoglo, 'medusa_pds', tracer_bkg(:,:,:,jppds) )
 #endif
-         
+
          IF ( ln_phytobal ) THEN
 
@@ -602,9 +602,9 @@
 
          CALL iom_close( inum )
-         
+
          DO jt = 1, jptra
             tracer_bkg(:,:,:,jt) = tracer_bkg(:,:,:,jt) * tmask(:,:,:)
          END DO
-      
+
       ELSE IF ( ln_spco2inc .OR. ln_sfco2inc .OR. ln_pphinc ) THEN
 
@@ -615,5 +615,5 @@
 
          CALL iom_open( c_asmbkg, inum )
-         
+
 #if defined key_hadocc
          CALL iom_get( inum, jpdom_autoglo, 'hadocc_dic', tracer_bkg(:,:,:,jp_had_dic) )
@@ -626,10 +626,10 @@
 
          CALL iom_close( inum )
-         
+
          DO jt = 1, jptra
             tracer_bkg(:,:,:,jt) = tracer_bkg(:,:,:,jt) * tmask(:,:,:)
          END DO
          mld_max_bkg(:,:) = mld_max_bkg(:,:) * tmask(:,:,1)
-      
+
       ENDIF
 #else
@@ -655,5 +655,5 @@
       !!
       !! ** Action  :
-      !!                   
+      !!
       !! References :
       !!
@@ -669,5 +669,5 @@
       REAL(wp)          :: zdate         ! Date
       !!------------------------------------------------------------------------
-     
+
       ! Set things up
       zdate = REAL( ndastp )
@@ -680,5 +680,5 @@
             &                    TRIM( c_asmbal ) // ' at timestep = ', kt
 
-         ! Define the output file       
+         ! Define the output file
          CALL iom_open( c_asmbal, inum, ldwrt = .TRUE., kiolib = jprstlib)
 
@@ -767,5 +767,5 @@
             &                    TRIM( c_asmbal ) // ' at timestep = ', kt
       ENDIF
-                                 
+
    END SUBROUTINE asm_bgc_bal_wri
 
@@ -847,5 +847,5 @@
       !! ** Action  :   return non-log increments
       !!
-      !! References :   
+      !! References :
       !!------------------------------------------------------------------------
       !!
@@ -879,5 +879,5 @@
       !!------------------------------------------------------------------------
       !!                    ***  ROUTINE phyto2d_asm_inc  ***
-      !!          
+      !!
       !! ** Purpose : Apply the chlorophyll assimilation increments.
       !!
@@ -886,5 +886,5 @@
       !!              Direct initialization or Incremental Analysis Updating.
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!------------------------------------------------------------------------
       INTEGER,  INTENT(IN) :: kt        ! Current time step
@@ -914,5 +914,5 @@
 #endif
       !!------------------------------------------------------------------------
-      
+
       IF ( kt <= nit000 ) THEN
 
@@ -920,5 +920,5 @@
          ! Remember that two sets of non-log increments should not be
          ! expected to be in the same ratio as their log equivalents
-         
+
          ! Total chlorophyll
          IF ( ln_slchltotinc ) THEN
@@ -1074,5 +1074,5 @@
 
             IF(lwp) THEN
-               WRITE(numout,*) 
+               WRITE(numout,*)
                WRITE(numout,*) 'phyto2d_asm_inc : phyto2d IAU at time step = ', &
                   &  kt,' with IAU weight = ', pwgtiau(it)
@@ -1105,10 +1105,10 @@
          ENDIF
 
-      ELSEIF ( ll_asmdin ) THEN 
+      ELSEIF ( ll_asmdin ) THEN
 
          !--------------------------------------------------------------------
          ! Direct Initialization
          !--------------------------------------------------------------------
-         
+
          IF ( kt == nitdin_r ) THEN
 
@@ -1134,5 +1134,5 @@
             END WHERE
 #endif
- 
+
             ! Do not deallocate arrays - needed by asm_bgc_bal_wri
             ! which is called at end of model run
@@ -1150,5 +1150,5 @@
       !!------------------------------------------------------------------------
       !!                    ***  ROUTINE phyto3d_asm_inc  ***
-      !!          
+      !!
       !! ** Purpose : Apply the profile chlorophyll assimilation increments.
       !!
@@ -1156,5 +1156,5 @@
       !!              Direct initialization or Incremental Analysis Updating.
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!------------------------------------------------------------------------
       INTEGER,  INTENT(IN) :: kt        ! Current time step
@@ -1261,5 +1261,5 @@
 
             IF(lwp) THEN
-               WRITE(numout,*) 
+               WRITE(numout,*)
                WRITE(numout,*) 'phyto3d_asm_inc : phyto3d IAU at time step = ', &
                   &  kt,' with IAU weight = ', pwgtiau(it)
@@ -1292,10 +1292,10 @@
          ENDIF
 
-      ELSEIF ( ll_asmdin ) THEN 
+      ELSEIF ( ll_asmdin ) THEN
 
          !--------------------------------------------------------------------
          ! Direct Initialization
          !--------------------------------------------------------------------
-         
+
          IF ( kt == nitdin_r ) THEN
 
@@ -1321,5 +1321,5 @@
             END WHERE
 #endif
- 
+
             ! Do not deallocate arrays - needed by asm_bgc_bal_wri
             ! which is called at end of model run
@@ -1338,5 +1338,5 @@
       !!------------------------------------------------------------------------
       !!                    ***  ROUTINE pco2_asm_inc  ***
-      !!          
+      !!
       !! ** Purpose : Apply the pco2/fco2 assimilation increments.
       !!
@@ -1345,5 +1345,5 @@
       !!              Direct initialization or Incremental Analysis Updating.
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!------------------------------------------------------------------------
       INTEGER, INTENT(IN)                   :: kt           ! Current time step
@@ -1495,4 +1495,5 @@
                jkmax = jpk-1
                DO jk = jpk-1, 1, -1
+#if defined key_vvl
                   IF ( ( zmld(ji,jj) >  gdepw_n(ji,jj,jk)   ) .AND. &
                      & ( zmld(ji,jj) <= gdepw_n(ji,jj,jk+1) ) ) THEN
@@ -1500,4 +1501,11 @@
                      jkmax = jk
                   ENDIF
+#else
+                  IF ( ( zmld(ji,jj) >  gdepw_0(ji,jj,jk)   ) .AND. &
+                     & ( zmld(ji,jj) <= gdepw_0(ji,jj,jk+1) ) ) THEN
+                     zmld(ji,jj) = gdepw_0(ji,jj,jk+1)
+                     jkmax = jk
+                  ENDIF
+#endif
                END DO
                !
@@ -1526,5 +1534,5 @@
 
             IF(lwp) THEN
-               WRITE(numout,*) 
+               WRITE(numout,*)
                IF ( ln_spco2inc ) THEN
                   WRITE(numout,*) 'pco2_asm_inc : pco2 IAU at time step = ', &
@@ -1563,10 +1571,10 @@
          ENDIF
 
-      ELSEIF ( ll_asmdin ) THEN 
+      ELSEIF ( ll_asmdin ) THEN
 
          !--------------------------------------------------------------------
          ! Direct Initialization
          !--------------------------------------------------------------------
-         
+
          IF ( kt == nitdin_r ) THEN
 
@@ -1592,5 +1600,5 @@
             END WHERE
 #endif
- 
+
             ! Do not deallocate arrays - needed by asm_bgc_bal_wri
             ! which is called at end of model run
@@ -1609,5 +1617,5 @@
       !!------------------------------------------------------------------------
       !!                    ***  ROUTINE ph_asm_inc  ***
-      !!          
+      !!
       !! ** Purpose : Apply the pH assimilation increments.
       !!
@@ -1616,5 +1624,5 @@
       !!              Direct initialization or Incremental Analysis Updating.
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!------------------------------------------------------------------------
       INTEGER,                          INTENT(IN) :: kt        ! Current time step
@@ -1626,5 +1634,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: pt_bkginc ! T increments
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(IN) :: ps_bkginc ! S increments
-      
+
       REAL(wp)                         :: zsearch = 10.0 ! Increment to DIC/alk in pH calculation
       REAL(wp)                         :: DIC_IN, ALK_IN ! DIC/alk in pH calculation
@@ -1679,5 +1687,5 @@
             sil_bkg_temp(:,:,:) = tracer_bkg(:,:,:,jpsil)
          ENDIF
-         
+
          ! Account for pCO2 balancing if required
          IF ( ln_sfco2inc .OR. ln_spco2inc ) THEN
@@ -1685,5 +1693,5 @@
             alk_bkg_temp(:,:,:) = alk_bkg_temp(:,:,:) + pco2_balinc(:,:,:,jpalk)
          ENDIF
-         
+
          ! Loop over grid points and calculate dpH/dDIC and dpH/dAlk
          ! This requires three calls to the MOCSY carbonate package
@@ -1750,7 +1758,7 @@
                      ph_balinc(ji,jj,jk,jpdic) = weight * dph_ddic
                      ph_balinc(ji,jj,jk,jpalk) = weight * dph_dalk
-                     
+
                   ENDIF
-                  
+
                END DO
             END DO
@@ -1758,5 +1766,5 @@
 
       ENDIF
-      
+
       IF ( ll_asmiau ) THEN
 
@@ -1772,5 +1780,5 @@
 
             IF(lwp) THEN
-               WRITE(numout,*) 
+               WRITE(numout,*)
                WRITE(numout,*) 'ph_asm_inc : pH IAU at time step = ', &
                   &  kt,' with IAU weight = ', pwgtiau(it)
@@ -1794,10 +1802,10 @@
          ENDIF
 
-      ELSEIF ( ll_asmdin ) THEN 
+      ELSEIF ( ll_asmdin ) THEN
 
          !--------------------------------------------------------------------
          ! Direct Initialization
          !--------------------------------------------------------------------
-         
+
          IF ( kt == nitdin_r ) THEN
 
@@ -1814,5 +1822,5 @@
                trb(:,:,:,jp_msa0:jp_msa1) = trn(:,:,:,jp_msa0:jp_msa1)
             END WHERE
- 
+
             ! Do not deallocate arrays - needed by asm_bgc_bal_wri
             ! which is called at end of model run
@@ -1820,5 +1828,5 @@
          !
       ENDIF
-#endif      
+#endif
       !
    END SUBROUTINE ph_asm_inc
@@ -1831,10 +1839,10 @@
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE dyn_asm_inc  ***
-      !!          
+      !!
       !! ** Purpose : Apply generic 3D biogeochemistry assimilation increments.
       !!
       !! ** Method  : Direct initialization or Incremental Analysis Updating.
       !!
-      !! ** Action  : 
+      !! ** Action  :
       !!----------------------------------------------------------------------
       INTEGER,  INTENT(IN) :: kt        ! Current time step
@@ -1983,5 +1991,5 @@
 
             IF(lwp) THEN
-               WRITE(numout,*) 
+               WRITE(numout,*)
                WRITE(numout,*) 'bgc3d_asm_inc : 3D BGC IAU at time step = ', &
                   &  kt,' with IAU weight = ', pwgtiau(it)
@@ -2071,5 +2079,5 @@
 #endif
             ENDIF
-           
+
             IF ( kt == nitiaufin_r ) THEN
                IF ( ln_pno3inc ) DEALLOCATE( pno3_bkginc )
@@ -2082,10 +2090,10 @@
          ENDIF
 
-      ELSEIF ( ll_asmdin ) THEN 
+      ELSEIF ( ll_asmdin ) THEN
 
          !--------------------------------------------------------------------
          ! Direct Initialization
          !--------------------------------------------------------------------
-         
+
          IF ( kt == nitdin_r ) THEN
 
@@ -2179,5 +2187,5 @@
 #endif
             ENDIF
- 
+
             IF ( ln_pno3inc ) DEALLOCATE( pno3_bkginc )
             IF ( ln_psi4inc ) DEALLOCATE( psi4_bkginc )
