Index: branches/UKMO/AMM15_v3_6_STABLE_package_collate_BGC_DA/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- branches/UKMO/AMM15_v3_6_STABLE_package_collate_BGC_DA/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 10571)
+++ branches/UKMO/AMM15_v3_6_STABLE_package_collate_BGC_DA/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 10574)
@@ -52,4 +52,5 @@
    USE bdy_oce, ONLY: bdytmask  
 #endif  
+   USE asmbgc           ! Biogeochemistry assimilation
 
    IMPLICIT NONE
@@ -62,4 +63,5 @@
    PUBLIC   ssh_asm_inc    !: Apply the SSH increment
    PUBLIC   seaice_asm_inc !: Apply the seaice increment
+   PUBLIC   bgc_asm_inc    !: Apply the biogeochemistry increments
 
 #if defined key_asminc
@@ -76,4 +78,5 @@
    LOGICAL, PUBLIC :: ln_sshinc = .FALSE.      !: No sea surface height assimilation increment
    LOGICAL, PUBLIC :: ln_seaiceinc             !: No sea ice concentration increment
+   LOGICAL, PUBLIC :: lk_bgcinc = .FALSE.      !: No biogeochemistry increments
    LOGICAL, PUBLIC :: ln_salfix = .FALSE.      !: Apply minimum salinity check
    LOGICAL, PUBLIC :: ln_temnofreeze = .FALSE. !: Don't allow the temperature to drop below freezing
@@ -161,9 +164,16 @@
                                !               so only apply surft increments.
       !!
-      NAMELIST/nam_asminc/ ln_bkgwri, ln_avgbkg,                           &
+      NAMELIST/nam_asminc/ ln_bkgwri, ln_avgbkg, ln_balwri,                &
          &                 ln_trainc, ln_dyninc, ln_sshinc,                &
+         &                 ln_phytobal, ln_slchltotinc, ln_slchldiainc,    &
+         &                 ln_slchlnoninc, ln_schltotinc, ln_slphytotinc,  &
+         &                 ln_slphydiainc, ln_slphynoninc, ln_spco2inc,    &
+         &                 ln_sfco2inc, ln_plchltotinc, ln_pchltotinc,     &
+         &                 ln_pno3inc, ln_psi4inc, ln_pdicinc, ln_palkinc, &
+         &                 ln_pphinc, ln_po2inc,                           &
          &                 ln_asmdin, ln_asmiau,                           &
          &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
-         &                 ln_salfix, salfixmin, nn_divdmp, nitavgbkg, mld_choice
+         &                 ln_salfix, salfixmin, nn_divdmp, nitavgbkg,     &
+         &                 mld_choice, mld_choice_bgc, rn_maxchlinc
       !!----------------------------------------------------------------------
 
@@ -205,7 +215,8 @@
          WRITE(numout,*) 'asm_inc_init : Assimilation increment initialization :'
          WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namasm : set assimilation increment parameters'
+         WRITE(numout,*) '   Namelist nam_asminc : set assimilation increment parameters'
          WRITE(numout,*) '      Logical switch for writing out background state          ln_bkgwri = ', ln_bkgwri
          WRITE(numout,*) '      Logical switch for writing mean background state         ln_avgbkg = ', ln_avgbkg
+         WRITE(numout,*) '      Logical switch for writing out balancing increments      ln_balwri = ', ln_balwri
          WRITE(numout,*) '      Logical switch for applying tracer increments            ln_trainc = ', ln_trainc
          WRITE(numout,*) '      Logical switch for applying velocity increments          ln_dyninc = ', ln_dyninc
@@ -213,4 +224,22 @@
          WRITE(numout,*) '      Logical switch for Direct Initialization (DI)            ln_asmdin = ', ln_asmdin
          WRITE(numout,*) '      Logical switch for applying sea ice increments        ln_seaiceinc = ', ln_seaiceinc
+         WRITE(numout,*) '      Logical switch for phytoplankton balancing             ln_phytobal = ', ln_phytobal
+         WRITE(numout,*) '      Logical switch for applying slchltot increments     ln_slchltotinc = ', ln_slchltotinc
+         WRITE(numout,*) '      Logical switch for applying slchldia increments     ln_slchldiainc = ', ln_slchldiainc
+         WRITE(numout,*) '      Logical switch for applying slchlnon increments     ln_slchlnoninc = ', ln_slchlnoninc
+         WRITE(numout,*) '      Logical switch for applying schltot increments       ln_schltotinc = ', ln_schltotinc
+         WRITE(numout,*) '      Logical switch for applying slphytot increments     ln_slphytotinc = ', ln_slphytotinc
+         WRITE(numout,*) '      Logical switch for applying slphydia increments     ln_slphydiainc = ', ln_slphydiainc
+         WRITE(numout,*) '      Logical switch for applying slphynon increments     ln_slphynoninc = ', ln_slphynoninc
+         WRITE(numout,*) '      Logical switch for applying spco2 increments           ln_spco2inc = ', ln_spco2inc
+         WRITE(numout,*) '      Logical switch for applying sfco2 increments           ln_sfco2inc = ', ln_sfco2inc
+         WRITE(numout,*) '      Logical switch for applying plchltot increments     ln_plchltotinc = ', ln_plchltotinc
+         WRITE(numout,*) '      Logical switch for applying pchltot increments       ln_pchltotinc = ', ln_pchltotinc
+         WRITE(numout,*) '      Logical switch for applying pno3 increments             ln_pno3inc = ', ln_pno3inc
+         WRITE(numout,*) '      Logical switch for applying psi4 increments             ln_psi4inc = ', ln_psi4inc
+         WRITE(numout,*) '      Logical switch for applying pdic increments             ln_pdicinc = ', ln_pdicinc
+         WRITE(numout,*) '      Logical switch for applying palk increments             ln_palkinc = ', ln_palkinc
+         WRITE(numout,*) '      Logical switch for applying pph increments               ln_pphinc = ', ln_pphinc
+         WRITE(numout,*) '      Logical switch for applying po2 increments               ln_po2inc = ', ln_po2inc
          WRITE(numout,*) '      Logical switch for Incremental Analysis Updating (IAU)   ln_asmiau = ', ln_asmiau
          WRITE(numout,*) '      Timestep of background in [0,nitend-nit000-1]            nitbkg    = ', nitbkg
@@ -223,4 +252,6 @@
          WRITE(numout,*) '      Minimum salinity after applying the increments           salfixmin = ', salfixmin
          WRITE(numout,*) '      Choice of MLD for physics assimilation                  mld_choice = ', mld_choice
+         WRITE(numout,*) '      Choice of MLD for BGC assimilation                  mld_choice_bgc = ', mld_choice_bgc
+         WRITE(numout,*) '      Maximum absolute chlorophyll increment (<=0 = off)    rn_maxchlinc = ', rn_maxchlinc
       ENDIF
 
@@ -263,4 +294,12 @@
          WRITE(numout,*) '       iitavgbkg_date = ', iitavgbkg_date
       ENDIF
+      IF ( ln_slchltotinc .OR. ln_slchldiainc .OR. ln_slchlnoninc .OR. &
+         & ln_schltotinc  .OR. ln_slphytotinc .OR. ln_slphydiainc .OR. &
+         & ln_slphynoninc .OR. ln_spco2inc    .OR. ln_sfco2inc    .OR. &
+         & ln_plchltotinc .OR. ln_pchltotinc  .OR. ln_pno3inc     .OR. &
+         & ln_psi4inc     .OR. ln_pdicinc     .OR. ln_palkinc     .OR. &
+         & ln_pphinc      .OR. ln_po2inc ) THEN
+         lk_bgcinc = .TRUE.
+      ENDIF
 
       IF ( nacc /= 0 ) &
@@ -274,6 +313,8 @@
 
       IF (      ( ( .NOT. ln_asmdin ).AND.( .NOT. ln_asmiau ) ) &
-           .AND.( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ) .OR. ( ln_seaiceinc) )) &
-         & CALL ctl_stop( ' One or more of ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc is set to .true.', &
+         & .AND.( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ).OR.( ln_seaiceinc ).OR. &
+         &        ( lk_bgcinc ) )) &
+         & CALL ctl_stop( ' One or more of ln_trainc, ln_dyninc, ln_sshinc, ln_seaiceinc,', &
+         &                ' ln_(bgc-variable)inc is set to .true.', &
          &                ' but ln_asmdin and ln_asmiau are both set to .false. :', &
          &                ' Inconsistent options')
@@ -284,6 +325,7 @@
 
       IF ( ( .NOT. ln_trainc ).AND.( .NOT. ln_dyninc ).AND.( .NOT. ln_sshinc ).AND.( .NOT. ln_seaiceinc ) &
-         &                     )  &
-         & CALL ctl_warn( ' ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc are set to .false. :', &
+         & .AND.( .NOT. lk_bgcinc ) )  &
+         & CALL ctl_warn( ' ln_trainc, ln_dyninc, ln_sshinc, ln_seaiceinc,', &
+         &                ' ln_(bgc-variable)inc are set to .false. :', &
          &                ' The assimilation increments are not applied')
 
@@ -310,4 +352,6 @@
          &                ' Assim bkg averaging period is outside', &
          &                ' the cycle interval')
+      
+      IF ( lk_bgcinc ) CALL asm_bgc_check_options
 
       IF ( nstop > 0 ) RETURN       ! if there are any errors then go no further
@@ -412,5 +456,6 @@
       ssh_iau(:,:)    = 0.0
 #endif
-      IF ( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ).OR.( ln_seaiceinc ) ) THEN
+      IF ( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ).OR.( ln_seaiceinc ) &
+         &  .OR.( lk_bgcinc ) ) THEN
 
          !--------------------------------------------------------------------
@@ -545,4 +590,8 @@
          ENDIF
 
+         IF ( lk_bgcinc ) THEN
+            CALL asm_bgc_init_incs( inum )
+         ENDIF
+
          CALL iom_close( inum )
  
@@ -655,4 +704,8 @@
          CALL iom_close( inum )
 
+      ENDIF
+         
+      IF ( lk_bgcinc ) THEN
+         CALL asm_bgc_init_bkg
       ENDIF
       !
@@ -1276,4 +1329,57 @@
 
    END SUBROUTINE seaice_asm_inc
+
+
+   SUBROUTINE bgc_asm_inc( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE bgc_asm_inc  ***
+      !!          
+      !! ** Purpose : Apply the biogeochemistry assimilation increments
+      !!
+      !! ** Method  : Call relevant routines in asmbgc
+      !!
+      !! ** Action  : Call relevant routines in asmbgc
+      !!
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER, INTENT(in   ) :: kt        ! Current time step
+      !
+      INTEGER                :: icycper   ! Dimension of wgtiau
+      !!
+      !!----------------------------------------------------------------------
+      
+      icycper = SIZE( wgtiau )
+      
+      ! Ocean colour variables first
+      IF ( ln_slchltotinc .OR. ln_slchldiainc .OR. ln_slchlnoninc .OR. &
+         & ln_schltotinc  .OR. ln_slphytotinc .OR. ln_slphydiainc .OR. &
+         & ln_slphynoninc ) THEN
+         CALL phyto2d_asm_inc( kt, ln_asmdin, ln_asmiau, icycper, wgtiau )
+      ENDIF
+      
+      ! Surface pCO2/fCO2 next
+      IF ( ln_sfco2inc .OR. ln_spco2inc ) THEN
+         CALL pco2_asm_inc( kt, ln_asmdin, ln_asmiau, icycper, wgtiau, &
+            &               ln_trainc, t_bkginc, s_bkginc )
+      ENDIF
+      
+      ! Profile pH next
+      IF ( ln_pphinc ) THEN
+         CALL ph_asm_inc( kt, ln_asmdin, ln_asmiau, icycper, wgtiau, &
+            &             ln_trainc, t_bkginc, s_bkginc )
+      ENDIF
+      
+      ! Then chlorophyll profiles
+      IF ( ln_plchltotinc .OR. ln_pchltotinc ) THEN
+         CALL phyto3d_asm_inc( kt, ln_asmdin, ln_asmiau, icycper, wgtiau )
+      ENDIF
+      
+      ! Remaining bgc profile variables
+      IF ( ln_pno3inc .OR. ln_psi4inc .OR. ln_pdicinc .OR. &
+         & ln_palkinc .OR. ln_po2inc ) THEN
+         CALL bgc3d_asm_inc( kt, ln_asmdin, ln_asmiau, icycper, wgtiau )
+      ENDIF
+
+   END SUBROUTINE bgc_asm_inc
    
    !!======================================================================
