Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 10047)
@@ -135,4 +135,8 @@
        <field id="OXY_INV"  field_ref="OXY_E3T"   long_name="OXY Inventory"               unit="mmol-O2/m2"   grid_ref="vert_sum" />
        <field id="SURF_OXY" field_ref="OXY"       long_name="OXY Surface concentration"   unit="mmol-O2/m3"   grid_ref="grid_T_surface_extract" />
+       <field id="OMD"      long_name="OMIP PI dissolved inorganic carbon"                unit="mmol-C/m3"  />
+       <field id="OMD_E3T"  long_name="OMD * E3T"                                         unit="mmol-C/m2"   > OMD * e3t </field >
+       <field id="OMD_INV"  field_ref="OMD_E3T"   long_name="OMD Inventory"               unit="mmol-C/m2"   grid_ref="vert_sum" />
+       <field id="SURF_OMD" field_ref="OMD"       long_name="OMD Surface concentration"   unit="mmol-C/m3"   grid_ref="grid_T_surface_extract" />
 
       <!-- Ideal traceurs : variables available with key_idtra -->
@@ -496,4 +500,22 @@
        <field id= "CO2STARAIR" long_name="MOCSY CO2star air"                         unit="mmol/m3"     />
        <field id= "OCN_DPCO2"  long_name="MOCSY delta pCO2"                          unit="uatm"        />
+
+       <!-- AXY (07/08/18): add new 2D OMIP diagnostics -->
+       <field id= "PI_ATM_PCO2"   long_name="OMIP PI Atmospheric pCO2"               unit="uatm"        />
+       <field id= "PI_OCN_PH"     long_name="OMIP PI Surface ocean pH"               unit="-"           />
+       <field id= "PI_OCN_PCO2"   long_name="OMIP PI Surface ocean pCO2"             unit="uatm"        />
+       <field id= "PI_OCNH2CO3"   long_name="OMIP PI Surface ocean H2CO3 conc"       unit="mmol-C/m3"    />
+       <field id= "PI_OCN_HCO3"   long_name="OMIP PI Surface ocean HCO3 conc"        unit="mmol-C/m3"    />
+       <field id= "PI_OCN_CO3"    long_name="OMIP PI Surface ocean CO3 conc"         unit="mmol-C/m3"    />
+       <field id= "PI_CO2FLUX"    long_name="OMIP PI Air-sea CO2 flux"               unit="mmol-C/m2/d"  />
+       <field id= "PI_FGCO2"      long_name="OMIP PI Surface Downward CO2 Flux"      unit="kg-CO2/m2/s" />
+       <field id= "PI_OM_CAL"     long_name="OMIP PI Omega calcite"                  unit="-"           />
+       <field id= "PI_OM_ARG"     long_name="OMIP PI Omega aragonite"                unit="-"           />
+       <field id= "PI_TCO2"       long_name="OMIP PI Total CO2"                      unit="umol/kg"     />
+       <field id= "PI_ATM_XCO2"   long_name="OMIP PI Atmospheric xCO2"               unit="ppm"         />
+       <field id= "PI_OCN_FCO2"   long_name="OMIP PI Surface ocean fCO2"             unit="uatm"        />
+       <field id= "PI_ATM_FCO2"   long_name="OMIP PI Atmospheric fCO2"               unit="uatm"        />
+       <field id= "PI_CO2STARAIR" long_name="OMIP PI MOCSY CO2star air"              unit="mmol/m3"     />
+       <field id= "PI_OCN_DPCO2"  long_name="OMIP PI MOCSY delta pCO2"               unit="uatm"        />
        
 
@@ -2465,3 +2487,27 @@
     </field_group>
 
+
+    <field_group id="groupMEDUSA_omip_dic" >
+      <!-- AXY (07/08/18): add new 2D OMIP diagnostics -->
+       <field field_ref= "PI_ATM_PCO2"   name="PI_ATM_PCO2"   />
+       <field field_ref= "PI_OCN_PH"     name="PI_OCN_PH"   />
+       <field field_ref= "PI_OCN_PCO2"   name="PI_OCN_PCO2"   />
+       <field field_ref= "PI_OCNH2CO3"   name="PI_OCNH2CO3"   />
+       <field field_ref= "PI_OCN_HCO3"   name="PI_OCN_HCO3"   />
+       <field field_ref= "PI_OCN_CO3"    name="PI_OCN_CO3"   />
+       <field field_ref= "PI_CO2FLUX"    name="PI_CO2FLUX"   />
+       <field field_ref= "PI_FGCO2"      name="PI_FGCO2"   />
+       <field field_ref= "PI_OM_CAL"     name="PI_OM_CAL"   />
+       <field field_ref= "PI_OM_ARG"     name="PI_OM_ARG"   />
+       <field field_ref= "PI_TCO2"       name="PI_TCO2"   />
+       <field field_ref= "PI_ATM_XCO2"   name="PI_ATM_XCO2"   /> 
+       <field field_ref= "PI_OCN_FCO2"   name="PI_OCN_FCO2"   />
+       <field field_ref= "PI_ATM_FCO2"   name="PI_ATM_FCO2"   />
+       <field field_ref= "PI_CO2STARAIR" name="PI_CO2STARAIR"   />
+       <field field_ref= "PI_OCN_DPCO2"  name="PI_OCN_DPCO2"   /> 
+
+
+    </field_group>
+
+
 </field_definition>
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn.F90	(revision 10047)
@@ -150,4 +150,6 @@
 CONTAINS
    SUBROUTINE bdy_dyn( kt )      ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in )           :: kt               ! Main time step counter
       WRITE(*,*) 'bdy_dyn: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdydyn3d.F90	(revision 10047)
@@ -309,9 +309,13 @@
 CONTAINS
    SUBROUTINE bdy_dyn3d( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn3d: You should not have seen this print! error?', kt
+   IMPLICIT NONE
+    INTEGER, INTENT( in ) :: kt     ! Main time step counter
+    WRITE(*,*) 'bdy_dyn3d: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn3d
 
    SUBROUTINE bdy_dyn3d_dmp( kt )      ! Empty routine
-      WRITE(*,*) 'bdy_dyn3d_dmp: You should not have seen this print! error?', kt
+   IMPLICIT NONE
+    INTEGER, INTENT( in ) :: kt     ! Main time step counter
+    WRITE(*,*) 'bdy_dyn3d_dmp: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_dyn3d_dmp
 
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 10047)
@@ -611,14 +611,19 @@
 CONTAINS
    SUBROUTINE bdytide_init             ! Empty routine
+   IMPLICIT NONE
       WRITE(*,*) 'bdytide_init: You should not have seen this print! error?'
    END SUBROUTINE bdytide_init
    SUBROUTINE bdytide_update( kt, jit )   ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in )            ::   kt          ! Main timestep counter
+      INTEGER,INTENT(in),OPTIONAL      ::   jit         ! Barotropic timestep counter (for timesplitting option)
       WRITE(*,*) 'bdytide_update: You should not have seen this print! error?', kt, jit
    END SUBROUTINE bdytide_update
    SUBROUTINE bdy_dta_tides( kt, kit, time_offset )     ! Empty routine
+   IMPLICIT NONE
       INTEGER, INTENT( in )            ::   kt          ! Dummy argument empty routine      
       INTEGER, INTENT( in ),OPTIONAL   ::   kit         ! Dummy argument empty routine
       INTEGER, INTENT( in ),OPTIONAL   ::   time_offset ! Dummy argument empty routine
-      WRITE(*,*) 'bdy_dta_tides: You should not have seen this print! error?', kt, jit
+      WRITE(*,*) 'bdy_dta_tides: You should not have seen this print! error?', kt, kit
    END SUBROUTINE bdy_dta_tides
 #endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdytra.F90	(revision 10047)
@@ -319,8 +319,12 @@
 CONTAINS
    SUBROUTINE bdy_tra(kt)      ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter   
       WRITE(*,*) 'bdy_tra: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_tra
 
    SUBROUTINE bdy_tra_dmp(kt)      ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in ) :: kt     ! Main time step counter   
       WRITE(*,*) 'bdy_tra_dmp: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_tra_dmp
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/BDY/bdyvol.F90	(revision 10047)
@@ -178,4 +178,6 @@
 CONTAINS
    SUBROUTINE bdy_vol( kt )        ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
       WRITE(*,*) 'bdy_vol: You should not have seen this print! error?', kt
    END SUBROUTINE bdy_vol
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/dyncor_c1d.F90	(revision 10047)
@@ -116,6 +116,10 @@
 CONTAINS
    SUBROUTINE cor_c1d              ! Empty routine
+   IMPLICIT NONE
    END SUBROUTINE cor_c1d   
+   
    SUBROUTINE dyn_cor_c1d ( kt )      ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index   
       WRITE(*,*) 'dyn_cor_c1d: You should not have seen this print! error?', kt
    END SUBROUTINE dyn_cor_c1d
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/C1D/step_c1d.F90	(revision 10047)
@@ -165,6 +165,8 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   SUBROUTINE stp_c1d ( kt )      ! dummy routine
-      WRITE(*,*) 'stp_c1d: You should not have seen this print! error?', kt
+   SUBROUTINE stp_c1d ( kstp )      ! dummy routine
+   IMPLICIT NONE
+   INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+      WRITE(*,*) 'stp_c1d: You should not have seen this print! error?', kstp
    END SUBROUTINE stp_c1d
 #endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 10047)
@@ -1302,8 +1302,10 @@
 
    SUBROUTINE dia_dct_init          ! Dummy routine
-      WRITE(*,*) 'dia_dct_init: You should not have seen this print! error?', kt
+   IMPLICIT NONE
+      WRITE(*,*) 'dia_dct_init: You should not have seen this print! error?'
    END SUBROUTINE dia_dct_init
 
    SUBROUTINE dia_dct( kt )         ! Dummy routine
+   IMPLICIT NONE
       INTEGER, INTENT( in ) :: kt   ! ocean time-step index
       WRITE(*,*) 'dia_dct: You should not have seen this print! error?', kt
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diahth.F90	(revision 10047)
@@ -343,5 +343,7 @@
 CONTAINS
    SUBROUTINE dia_hth( kt )         ! Empty routine
-      WRITE(*,*) 'dia_hth: You should not have seen this print! error?', kt
+   IMPLICIT NONE
+    INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+    WRITE(*,*) 'dia_hth: You should not have seen this print! error?', kt
    END SUBROUTINE dia_hth
 #endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 10047)
@@ -102,4 +102,5 @@
 
       !
+      z2d(:,:) = 0._wp
       z3d(:,:,:) = 0._wp
       IF( PRESENT( pvtr ) ) THEN
@@ -246,4 +247,6 @@
          !
          IF( iom_use("zotemglo") ) THEN    ! i-mean i-k-surface 
+            zmask(:,:,:) = 0._wp
+            zts(:,:,:,:) = 0._wp
             DO jk = 1, jpkm1
                DO jj = 1, jpj
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 10047)
@@ -246,4 +246,5 @@
             z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
          END DO
+         CALL lbc_lnk( z3d(:,:,:), 'W', 1. )
          CALL iom_put( "w_masstr" , z3d )  
          IF( iom_use('w_masstr2') )   CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )
@@ -252,8 +253,10 @@
       CALL iom_put( "avt" , avt                        )    ! T vert. eddy diff. coef.
       CALL iom_put( "avm" , avmu                       )    ! T vert. eddy visc. coef.
+#if defined key_zdftke
       IF( lk_zdftke ) THEN   
          CALL iom_put( "tke"      , en                               )    ! TKE budget: Turbulent Kinetic Energy   
          CALL iom_put( "tke_niw"  , e_niw                            )    ! TKE budget: Near-inertial waves   
       ENDIF 
+#endif
       CALL iom_put( "avs" , fsavs(:,:,:)               )    ! S vert. eddy diff. coef. (useful only with key_zdfddm)
                                                             ! Log of eddy diff coef
@@ -334,5 +337,7 @@
             z2d(:,:) = z2d(:,:) + z3d(:,:,jk)
          END DO
+         CALL lbc_lnk( z3d(:,:,:), 'U', -1. )
          CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
+         CALL lbc_lnk( z2d(:,:), 'U', -1. )
          CALL iom_put( "u_masstr_vint", z2d )             ! mass transport in i-direction vertical sum
       ENDIF
@@ -370,4 +375,5 @@
             z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk) * vmask(:,:,jk)
          END DO
+         CALL lbc_lnk( z3d(:,:,:), 'V', -1. )
          CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
       ENDIF
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 10047)
@@ -254,4 +254,7 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bathy                              !: ocean depth (meters)
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i, umask_i, vmask_i, fmask_i !: interior domain T-point mask
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tmask_i_diag     !: partial mask for use in T diagnostic mask calc. 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: umask_i_diag     !: partial mask for use in U diagnostic mask calc. 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: vmask_i_diag     !: partial mask for use in V diagnostic mask calc. 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   bmask                              !: land/ocean mask of barotropic stream function
 
@@ -406,5 +409,9 @@
 
       ALLOCATE( tmask(jpi,jpj,jpk) , umask(jpi,jpj,jpk),     & 
-         &      vmask(jpi,jpj,jpk) , fmask(jpi,jpj,jpk), STAT=ierr(11) )
+         &      vmask(jpi,jpj,jpk) , fmask(jpi,jpj,jpk),     &
+                tmask_i_diag(jpi,jpj,jpk),     &
+                umask_i_diag(jpi,jpj,jpk),     &
+                vmask_i_diag(jpi,jpj,jpk),     &
+                STAT=ierr(11) )
 
       ALLOCATE( wmask(jpi,jpj,jpk) , wumask(jpi,jpj,jpk), wvmask(jpi,jpj,jpk) , STAT=ierr(12) )
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/dommsk.F90	(revision 10047)
@@ -1,2 +1,3 @@
+
 MODULE dommsk
    !!======================================================================
@@ -30,4 +31,5 @@
    USE dynspg_oce      ! choice/control of key cpp for surface pressure gradient
    USE wrk_nemo        ! Memory allocation
+   USE domwri
    USE timing          ! Timing
 
@@ -138,4 +140,5 @@
       REAL(wp) ::  zphi_drake_passage, zshlat_antarc
       REAL(wp), POINTER, DIMENSION(:,:) ::  zwf
+      REAL(wp) :: uvt(jpi,jpj)   ! dummy array for masking purposes.
       !!
       NAMELIST/namlbc/ rn_shlat, ln_vorlat
@@ -223,4 +226,5 @@
       ! --------------------
       tmask_i(:,:) = ssmask(:,:)            ! (ISH) tmask_i = 1 even on the ice shelf
+
       iif = jpreci                         ! ???
       iil = nlci - jpreci + 1
@@ -246,4 +250,6 @@
          ENDIF
       ENDIF
+
+
       IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
          tpol(     1    :jpiglo) = 0._wp
@@ -263,5 +269,5 @@
                   &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
             END DO
-         END DO
+         END DO 
       END DO
       ! (ISF) MIN(1,SUM(umask)) is here to check if you have effectively at least 1 wet u point
@@ -282,4 +288,39 @@
       CALL lbc_lnk( vmask_i, 'V', 1._wp )
       CALL lbc_lnk( fmask_i, 'F', 1._wp )
+
+
+      ! Set up mask for diagnostics on T points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      CALL dom_uniq( uvt, 'T' )
+      DO jk = 1, jpk
+         tmask_i_diag(:,:,jk) = tmask(:,:,jk) * uvt(:,:)
+      END DO
+
+      ! Set up mask for diagnostics on U points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      umask_i_diag(:,:,:) = 1.0
+      umask_i_diag(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)
+      CALL lbc_lnk( umask_i_diag, 'U', 1. )
+
+      ! Now mask out any duplicate points
+      CALL dom_uniq( uvt, 'U' )
+      DO jk = 1, jpk
+         umask_i_diag(:,:,jk) = umask_i_diag(:,:,jk) * uvt(:,:)
+      END DO
+
+
+      ! Set up mask for diagnostics on V points, to exclude duplicate
+      ! data points in wrap and N-fold regions. 
+      vmask_i_diag(:,:,:) = 1.0
+      vmask_i_diag(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)
+      CALL lbc_lnk( vmask_i_diag, 'V', 1. )
+
+      ! Now mask out any duplicate points
+      CALL dom_uniq( uvt, 'V' )
+      DO jk = 1, jpk
+         vmask_i_diag(:,:,jk) = vmask_i_diag(:,:,jk) * uvt(:,:)
+      END DO
+
+
 
       ! 3. Ocean/land mask at wu-, wv- and w points 
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DOM/domwri.F90	(revision 10047)
@@ -26,5 +26,5 @@
    PRIVATE
 
-   PUBLIC dom_wri        ! routine called by inidom.F90
+   PUBLIC dom_wri, dom_uniq  ! routines called by inidom.F90 and iom.F90
 
    !! * Substitutions
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_exp.F90	(revision 10047)
@@ -107,4 +107,6 @@
 CONTAINS
    SUBROUTINE dyn_spg_exp( kt )       ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT(in)  ::   kt   ! ocean time-step index  
       WRITE(*,*) 'dyn_spg_exp: You should not have seen this print! error?', kt
    END SUBROUTINE dyn_spg_exp
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/FLO/floats.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/FLO/floats.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/FLO/floats.F90	(revision 10047)
@@ -146,4 +146,6 @@
 CONTAINS
    SUBROUTINE flo_stp( kt )          ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step   
       WRITE(*,*) 'flo_stp: You should not have seen this print! error?', kt
    END SUBROUTINE flo_stp
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 10047)
@@ -1400,10 +1400,23 @@
       IF ( ln_mskland ) THEN
          ! mask land points, keep values on coast line -> specific mask for U, V and W points
+
+
          SELECT CASE ( cdgrd )
-         CASE('T')   ;   zmask(:,:,:)       = tmask(:,:,:)
-         CASE('U')   ;   zmask(2:jpim1,:,:) = tmask(2:jpim1,:,:) + tmask(3:jpi,:,:)   ;   CALL lbc_lnk( zmask, 'U', 1. )
-         CASE('V')   ;   zmask(:,2:jpjm1,:) = tmask(:,2:jpjm1,:) + tmask(:,3:jpj,:)   ;   CALL lbc_lnk( zmask, 'V', 1. )
-         CASE('W')   ;   zmask(:,:,2:jpk  ) = tmask(:,:,1:jpkm1) + tmask(:,:,2:jpk)   ;   zmask(:,:,1) = tmask(:,:,1)
-         END SELECT
+         ! The masks applied here are specifically used to mask out duplicate 
+         ! data points in wrap columns and N-fold rows in order to ensure bit 
+         ! reproducibility of diagnostics which have not undergone an explicit
+         ! lbc_lnk prior to writing. Such fields are prone to junk values at 
+         ! duplicate points since those points are often excluded from the 
+         ! core field computation process. 
+         CASE('T')   
+            zmask(:,:,:) = tmask_i_diag(:,:,:)
+         CASE('U')   	
+            zmask(:,:,:) = umask_i_diag(:,:,:)
+ 	 CASE('V')   
+            zmask(:,:,:) = vmask_i_diag(:,:,:)
+         CASE('W')   
+            zmask(:,:,2:jpk  ) = tmask_i_diag(:,:,1:jpkm1) + tmask_i_diag(:,:,2:jpk)   
+            zmask(:,:,1) = tmask_i_diag(:,:,1)
+        END SELECT
          !
 #if ! defined key_xios2
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_c3d.h90	(revision 10047)
@@ -210,4 +210,5 @@
       !
       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ztemp2d  ! temporary array to read ahmcoef file
+      LOGICAL ::  tempmask( jpi,jpj)   ! Temporary mask to avoid Cray compiler bug at cce 8.3.4
       !!----------------------------------------------------------------------
       !
@@ -252,6 +253,10 @@
          zemax = MAXVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
          zemin = MINVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
-         zeref = MAXVAL ( e1t(:,:) * e2t(:,:),   &
-             &   tmask(:,:,1) .GE. 0.5 .AND. ABS(gphit(:,:)) .GT. 50. )
+         tempmask(:,:) = .FALSE.
+         ! Pre calculate mask for zeref since embedding the following
+         ! term in the MAXVAL operation offends the Cray compiler for no 
+         ! justifiable reason under certain conditions. 
+         tempmask(:,:) = (tmask(:,:,1) .GE. 0.5) .AND. (ABS(gphit(:,:)) .GT. 50.)
+         zeref = MAXVAL ( e1t(:,:) * e2t(:,:), tempmask(:,:) )
  
          DO jj = 1, jpj
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_smag.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_smag.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldfdyn_smag.F90	(revision 10047)
@@ -294,4 +294,6 @@
 CONTAINS
    SUBROUTINE ldf_dyn_smag( kt )       ! Empty routine
+   IMPLICIT NONE
+      INTEGER :: kt                    ! timestep   
       WRITE(*,*) 'ldf_dyn_smag: You should not have seen this print! error? check keys ldf:c3d+smag', kt
    END SUBROUTINE ldf_dyn_smag
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra_smag.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra_smag.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/LDF/ldftra_smag.F90	(revision 10047)
@@ -204,5 +204,7 @@
 CONTAINS
    SUBROUTINE ldf_tra_smag( kt )       ! Empty routine
-      WRITE(*,*) 'ldf_dyn_smag: You should not have seen this print! error? check keys ldf:c3d+smag', kt
+   IMPLICIT NONE
+        INTEGER, INTENT( in ) ::   kt  ! ocean time-step inedx
+        WRITE(*,*) 'ldf_dyn_smag: You should not have seen this print! error? check keys ldf:c3d+smag', kt
    END SUBROUTINE ldf_tra_smag
 #endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbc_ice.F90	(revision 10047)
@@ -167,5 +167,5 @@
 
 #if defined key_cice
-      ALLOCATE( qla_ice(jpi,jpj,ncat) , qlw_ice(jpi,jpj,1)    , qsr_ice(jpi,jpj,1)    , &
+      ALLOCATE( qla_ice(jpi,jpj,ncat) , qlw_ice(jpi,jpj,1)    , qsr_ice(jpi,jpj,jpl)  , &
                 wndi_ice(jpi,jpj)     , tatm_ice(jpi,jpj)     , qatm_ice(jpi,jpj)     , &
                 wndj_ice(jpi,jpj)     , nfrzmlt(jpi,jpj)      , ss_iou(jpi,jpj)       , &
@@ -180,5 +180,5 @@
       IF( ln_cpl )   ALLOCATE( u_ice(jpi,jpj)        , fr1_i0(jpi,jpj)       , tn_ice (jpi,jpj,jpl)  , &
          &                     v_ice(jpi,jpj)        , fr2_i0(jpi,jpj)       , alb_ice(jpi,jpj,1)    , &
-         &                     emp_ice(jpi,jpj)      , qns_ice(jpi,jpj,1)    , dqns_ice(jpi,jpj,1)   , &
+         &                     emp_ice(jpi,jpj)      , qns_ice(jpi,jpj,jpl)  , dqns_ice(jpi,jpj,1)   , &
          &                     a_p(jpi,jpj,jpl)      , ht_p(jpi,jpj,jpl)     , tsfc_ice(jpi,jpj,jpl) , &
          &                     kn_ice(jpi,jpj,jpl) ,    STAT=ierr(2) )
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 10047)
@@ -1178,12 +1178,18 @@
 
    SUBROUTINE sbc_ice_cice ( kt, ksbc )     ! Dummy routine
+      IMPLICIT NONE
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
+      INTEGER, INTENT(in) ::   ksbc    ! surface forcing type
       WRITE(*,*) 'sbc_ice_cice: You should not have seen this print! error?', kt
    END SUBROUTINE sbc_ice_cice
 
    SUBROUTINE cice_sbc_init (ksbc)    ! Dummy routine
+      IMPLICIT NONE
+      INTEGER, INTENT(in) ::   ksbc    ! surface forcing type
       WRITE(*,*) 'cice_sbc_init: You should not have seen this print! error?'
    END SUBROUTINE cice_sbc_init
 
    SUBROUTINE cice_sbc_final     ! Dummy routine
+      IMPLICIT NONE
       WRITE(*,*) 'cice_sbc_final: You should not have seen this print! error?'
    END SUBROUTINE cice_sbc_final
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90	(revision 10047)
@@ -648,7 +648,11 @@
 CONTAINS
    SUBROUTINE sbc_ice_lim ( kt, kblk )     ! Dummy routine
+   IMPLICIT NONE
+      INTEGER, INTENT(in) ::   kt      ! ocean time step
+      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE, =5 COUPLED)
       WRITE(*,*) 'sbc_ice_lim: You should not have seen this print! error?', kt, kblk
    END SUBROUTINE sbc_ice_lim
    SUBROUTINE sbc_lim_init                 ! Dummy routine
+   IMPLICIT NONE
    END SUBROUTINE sbc_lim_init
 #endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/traadv_tvd.F90	(revision 10047)
@@ -33,4 +33,5 @@
    USE wrk_nemo       ! Memory Allocation
    USE timing         ! Timing
+   USE phycst         ! Physical constants
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
    USE iom
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 10047)
@@ -134,6 +134,7 @@
       INTEGER  ::   ierror              ! local integer
       !
-      TYPE(FLD_N)        ::   sn_qgh    ! informations about the geotherm. field to be read
-      CHARACTER(len=256) ::   cn_dir    ! Root directory for location of ssr files
+      TYPE(FLD_N), DIMENSION (1)  ::   slf_q     ! array of namelist informations on the fields to read
+      TYPE(FLD_N)                 ::   sn_qgh    ! informations about the geotherm. field to be read
+      CHARACTER(len=256)          ::   cn_dir    ! Root directory for location of ssr files
       !
       NAMELIST/nambbc/ln_trabbc, nn_geoflx, rn_geoflx_cst, sn_qgh, cn_dir 
@@ -173,4 +174,6 @@
             IF(lwp) WRITE(numout,*) '      *** variable geothermal heat flux'
             !
+            slf_q(1) = sn_qgh
+            !
             ALLOCATE( sf_qgh(1), STAT=ierror )
             IF( ierror > 0 ) THEN
@@ -179,7 +182,7 @@
             ENDIF
             ALLOCATE( sf_qgh(1)%fnow(jpi,jpj,1)   )
-            IF( sn_qgh%ln_tint )ALLOCATE( sf_qgh(1)%fdta(jpi,jpj,1,2) )
+            IF( slf_q(1)%ln_tint )   ALLOCATE( sf_qgh(1)%fdta(jpi,jpj,1,2) )
             ! fill sf_chl with sn_chl and control print
-            CALL fld_fill( sf_qgh, (/ sn_qgh /), cn_dir, 'tra_bbc_init',   &
+            CALL fld_fill( sf_qgh, slf_q, cn_dir, 'tra_bbc_init',   &
                &          'bottom temperature boundary condition', 'nambbc' )
 
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/TRD/trdken.F90	(revision 10047)
@@ -195,4 +195,5 @@
                     CALL ken_p2k( kt , zke )
                       CALL iom_put( "ketrd_convP2K", zke )     ! conversion -rau*g*w
+# if defined key_ldfslp || key_esopa
         CASE( jpdyn_eivke )
             ! CMIP6 diagnostic tknebto = tendency of KE from
@@ -216,4 +217,5 @@
             CALL iom_put("ketrd_eiv", zke2d)
             CALL wrk_dealloc( jpi, jpj, zke2d )
+#endif
          !
       END SELECT
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfgls.F90	(revision 10047)
@@ -1231,10 +1231,16 @@
 CONTAINS
    SUBROUTINE zdf_gls_init           ! Empty routine
+   IMPLICIT NONE
       WRITE(*,*) 'zdf_gls_init: You should not have seen this print! error?'
    END SUBROUTINE zdf_gls_init
+   
    SUBROUTINE zdf_gls( kt )          ! Empty routine
+   IMPLICIT NONE
+      INTEGER, INTENT(in) ::   kt ! ocean time step   
       WRITE(*,*) 'zdf_gls: You should not have seen this print! error?', kt
    END SUBROUTINE zdf_gls
+   
    SUBROUTINE gls_rst( kt, cdrw )          ! Empty routine
+   IMPLICIT NONE
       INTEGER         , INTENT(in) ::   kt         ! ocean time-step
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfkpp.F90	(revision 10047)
@@ -1576,13 +1576,20 @@
 CONTAINS
    SUBROUTINE zdf_kpp_init           ! Dummy routine
+   IMPLICIT NONE
       WRITE(*,*) 'zdf_kpp_init: You should not have seen this print! error?'
    END SUBROUTINE zdf_kpp_init
    SUBROUTINE zdf_kpp( kt )          ! Dummy routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
       WRITE(*,*) 'zdf_kpp: You should not have seen this print! error?', kt
    END SUBROUTINE zdf_kpp
    SUBROUTINE tra_kpp( kt )          ! Dummy routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
       WRITE(*,*) 'tra_kpp: You should not have seen this print! error?', kt
    END SUBROUTINE tra_kpp
    SUBROUTINE trc_kpp( kt )          ! Dummy routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
       WRITE(*,*) 'trc_kpp: You should not have seen this print! error?', kt
    END SUBROUTINE trc_kpp
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 10047)
@@ -307,6 +307,9 @@
 CONTAINS
    SUBROUTINE zdf_ric_init         ! Dummy routine
+   IMPLICIT NONE
    END SUBROUTINE zdf_ric_init
    SUBROUTINE zdf_ric( kt )        ! Dummy routine
+   IMPLICIT NONE
+      INTEGER, INTENT( in ) ::   kt                           ! ocean time-step
       WRITE(*,*) 'zdf_ric: You should not have seen this print! error?', kt
    END SUBROUTINE zdf_ric
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/oce.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/OPA_SRC/oce.F90	(revision 10047)
@@ -101,4 +101,5 @@
       INTEGER :: ierr(5)
       !!----------------------------------------------------------------------
+      ierr(:) = 0
       !
       ALLOCATE( ub   (jpi,jpj,jpk)      , un   (jpi,jpj,jpk)      , ua(jpi,jpj,jpk)       ,     &
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/C14b/trcsms_c14b.F90	(revision 10047)
@@ -330,4 +330,6 @@
 CONTAINS
    SUBROUTINE trc_sms_c14b( kt )       ! Empty routine
+      IMPLICIT NONE
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
       WRITE(*,*) 'trc_freons: You should not have seen this print! error?', kt
    END SUBROUTINE trc_sms_c14b
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/air_sea.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/air_sea.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/air_sea.F90	(revision 10047)
@@ -59,26 +59,29 @@
                                    zalk, zdic, zoxy, zsal, ztmp,          &
 #  if defined key_omip_dic
-                                   pi_fgco2,                               &
-                                   f_pi_co2flux, f_pi_co2flux2d,           &
-                                   f_pi_co2starair_2d, f_pi_co3,           &
-                                   f_pi_fco2a_2d, f_pi_fco2w_2d,           &
-                                   f_pi_h2co3, f_pi_hco3,                  &
-                                   f_pi_ocndpco2_2d,                       &
-                                   f_pi_omarg, f_pi_omcal,                 &
-                                   f_pi_pco2a2d, f_pi_pco2atm, f_pi_pco2w, &
-                                   f_pi_pco2w2d, f_pi_ph,                  &
-                                   f_pi_TDIC, f_pi_TDIC2d,                 &
-                                   f_pi_xco2a, f_pi_xco2a_2d,              &
-                                   zomd,                                   &
-#  endif                                   
-# endif
+                                   pi_fgco2,                                 &
+                                   f_pi_co2flux, f_pi_co2flux_2d,            &
+                                   f_pi_co2starair_2d, f_pi_co3,             &
+                                   f_pi_fco2a_2d, f_pi_fco2w_2d,             &
+                                   f_pi_h2co3, f_pi_hco3,                    &
+                                   f_pi_ocndpco2_2d,                         &
+                                   f_pi_omarg, f_pi_omcal,                   &
+                                   f_pi_pco2a_2d, f_pi_pco2atm, f_pi_pco2w,  &
+                                   f_pi_pco2w_2d, f_pi_ph,                   &
+                                   f_pi_TDIC, f_pi_TDIC_2d,                  &
+                                   f_pi_xco2a, f_pi_xco2a_2d,                &
+				   f_pi_ph_2d, f_pi_omcal_2d, f_pi_omarg_2d, &
+				   f_pi_h2co3_2d, f_pi_hco3_2d, f_pi_co3_2d, &
+                                   zomd,                                     &
+#  endif   !! key_omip_dic                                
+# endif  !! key_roam
 # if defined key_mocsy
                                    zpho,                                  &
+# endif 
+                                   zchd, zchn, zdin, zsil
+      USE dom_oce,           ONLY: e3t_0, gphit, tmask, mig, mjg
+# if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n
 # endif
-                                   zchd, zchn, zdin, zsil
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gphit, tmask, mig, mjg
-# if defined key_iomput
       USE iom,               ONLY: lk_iomput
-# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE par_kind,          ONLY: wp
@@ -101,5 +104,5 @@
 #  else
       USE trcco2_medusa,     ONLY: trc_co2_medusa
-#  endif
+#  endif 
       USE trcdms_medusa,     ONLY: trc_dms_medusa
       USE trcoxy_medusa,     ONLY: trc_oxy_medusa
@@ -136,4 +139,7 @@
 #  if defined key_omip_dic
       !! AXY (06/08/18): output variables that are not different for OMIP DIC
+      REAL(wp), DIMENSION(jpi,jpj) :: f_pi_fco2w
+      REAL(wp), DIMENSION(jpi,jpj) :: f_pi_fco2atm
+      REAL(wp), DIMENSION(jpi,jpj) :: f_pi_co2starair, f_pi_dpco2
       REAL(wp) :: f_rhosw_dum, f_schmidtco2_dum, f_kwco2_dum,f_K0_dum
 #  endif
@@ -208,5 +214,4 @@
       call trc_rst_dia_stat(zpho(:,:), 'zpho')
 #  endif
-
 #  if defined key_axy_carbchem
 #   if defined key_mocsy
@@ -330,5 +335,5 @@
                !! mmol / m3 -> umol / kg
                f_pi_TDIC(ji,jj) = (zomd(ji,jj) / f_rhosw(ji,jj)) * 1000.
-#    endif
+#    endif  !! omip
             ENDIF
          ENDDO
@@ -355,5 +360,5 @@
 #    endif
                
-#   else   
+#   else   !! mocsy
       !!-----------------------------------------------------------
       !! Blackford et al. (2007) carbonate chemistry
@@ -392,6 +397,6 @@
       ENDDO
 
-#   endif
-#  else
+#   endif !! mocsy 
+#  else  !! carbchem
       !!-----------------------------------------------------------
       !! No carbonate chemistry
@@ -434,5 +439,5 @@
          ENDDO
       ENDDO
-#  endif
+#  endif  !! carbchem 
 
 #  if defined key_axy_killco2flux
@@ -634,15 +639,15 @@
                   !! AXY (06/08/18): diagnostics for OMIP PI DIC
                   IF( med_diag%PI_ATM_PCO2%dgsave ) THEN
-                     f_pi_pco2a2d(ji,jj) = f_pi_pco2atm(ji,jj)
-                  ENDIF
-                  IF( med_diag%OCN_PCO2%dgsave ) THEN
-                     f_pi_pco2w2d(ji,jj) = f_pi_pco2w(ji,jj)
+                     f_pi_pco2a_2d(ji,jj) = f_pi_pco2atm(ji,jj)
+                  ENDIF
+                  IF( med_diag%PI_OCN_PCO2%dgsave ) THEN
+                     f_pi_pco2w_2d(ji,jj) = f_pi_pco2w(ji,jj)
                   ENDIF
                   IF( med_diag%PI_CO2FLUX%dgsave ) THEN
                      !! mmol/m3/d -> mmol/m2/d
-                     f_pi_co2flux2d(ji,jj) = f_pi_co2flux(ji,jj) * fse3t(ji,jj,1)
+                     f_pi_co2flux_2d(ji,jj) = f_pi_co2flux(ji,jj) * fse3t(ji,jj,1)
                   ENDIF
                   IF( med_diag%PI_TCO2%dgsave ) THEN
-                     f_PI_TDIC2d(ji,jj) = f_PI_TDIC(ji,jj)
+                     f_PI_TDIC_2d(ji,jj) = f_PI_TDIC(ji,jj)
                   ENDIF
                   IF( med_diag%PI_ATM_XCO2%dgsave ) THEN
@@ -667,4 +672,22 @@
                           CO2flux_conv
                   ENDIF
+                  IF( med_diag%PI_OCN_PH%dgsave ) THEN
+                     f_pi_ph_2d(ji,jj) = f_pi_ph(ji,jj)
+                  ENDIF                  
+                  IF( med_diag%PI_OCNH2CO3%dgsave ) THEN
+                     f_pi_h2co3_2d(ji,jj) = f_pi_h2co3(ji,jj)
+                  ENDIF                  
+                  IF( med_diag%PI_OCN_HCO3%dgsave ) THEN
+                     f_pi_hco3_2d(ji,jj) = f_pi_hco3(ji,jj)
+                  ENDIF                  
+                  IF( med_diag%PI_OCN_CO3%dgsave ) THEN
+                     f_pi_co3_2d(ji,jj) = f_pi_co3(ji,jj)
+                  ENDIF                  
+                  IF( med_diag%PI_OM_CAL%dgsave ) THEN
+                     f_pi_omcal_2d(ji,jj) = f_pi_omcal(ji,jj)
+                  ENDIF                  
+                  IF( med_diag%PI_OM_ARG%dgsave ) THEN
+                     f_pi_omarg_2d(ji,jj) = f_pi_omarg(ji,jj)
+                  ENDIF                  
 #   endif                  
                ENDIF
@@ -672,6 +695,4 @@
          ENDDO
       ENDDO
-
-#  endif
 
       !!-----------------------------------------------------------------
@@ -766,9 +787,9 @@
          ENDDO
       ENDDO
-# endif
+# endif  !! Roam
       
    END SUBROUTINE air_sea
 
-#else
+#else  !! medusa
    !!======================================================================
    !!  Dummy module :                                   No MEDUSA bio-model
@@ -778,5 +799,5 @@
       WRITE(*,*) 'air_sea: You should not have seen this print! error?'
    END SUBROUTINE air_sea
-#endif 
+#endif  !! medusa
 
    !!======================================================================
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_med_diag_iomput.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_med_diag_iomput.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_med_diag_iomput.F90	(revision 10047)
@@ -31,5 +31,8 @@
       !!-------------------------------------------------------------------
       USE bio_medusa_mod
-      USE dom_oce,           ONLY: e3t_0, e3t_n, mbathy, tmask
+      USE dom_oce,           ONLY: e3t_0, mbathy, tmask
+# if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n
+# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE par_oce,           ONLY: jpim1, jpjm1
@@ -718,4 +721,5 @@
 CONTAINS
    SUBROUTINE bio_med_diag_iomput( )                    ! Empty routine
+      IMPLICIT NONE
       WRITE(*,*) 'bio_med_diag_iomput: You should not have seen this print! error?'
    END SUBROUTINE bio_med_diag_iomput
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag.F90	(revision 10047)
@@ -32,10 +32,10 @@
       USE bio_med_diag_iomput_mod,  ONLY: bio_med_diag_iomput
       USE bio_medusa_mod
-      USE dom_oce,                  ONLY: e3t_0, e3t_n,                  &
-                                          gdepw_0, gdepw_n, tmask
+      USE dom_oce,                  ONLY: e3t_0, gdepw_0, tmask
+# if defined key_vvl
+      USE dom_oce,                  ONLY: e3t_n, gdepw_n
+# endif
       USE in_out_manager,           ONLY: lwp, numout
-# if defined key_iomput
       USE iom,                      ONLY: lk_iomput
-# endif
       USE par_oce,                  ONLY: jpim1, jpjm1
       USE sms_medusa,               ONLY: xrfn, xthetapd, xthetapn,      &
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag_slice.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag_slice.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_diag_slice.F90	(revision 10047)
@@ -36,7 +36,5 @@
       USE dom_oce,           ONLY: tmask
       USE in_out_manager,    ONLY: lwp, numout
-# if defined key_iomput
       USE iom,               ONLY: iom_put
-# endif
       USE lbclnk,            ONLY: lbc_lnk
       USE oce,               ONLY: CO2Flux_out_cpl, DMS_out_cpl
@@ -245,30 +243,30 @@
       !!----------------------------------------------------------------------
          IF( med_diag%PI_ATM_PCO2%dgsave ) THEN
-            CALL iom_put( "PI_ATM_PCO2"  , f_pi_pco2a2d )
-            DEALLOCATE( f_pi_pco2a2d )
+            CALL iom_put( "PI_ATM_PCO2"  , f_pi_pco2a_2d )
+            DEALLOCATE( f_pi_pco2a_2d )
          ENDIF
          IF( med_diag%PI_OCN_PH%dgsave ) THEN
-            CALL iom_put( "PI_OCN_PH"  , f_pi_ph2d )
-            DEALLOCATE( f_pi_ph2d )
+            CALL iom_put( "PI_OCN_PH"  , f_pi_ph_2d )
+            DEALLOCATE( f_pi_ph_2d )
          ENDIF
          IF( med_diag%PI_OCN_PCO2%dgsave ) THEN
-            CALL iom_put( "PI_OCN_PCO2"  , f_pi_pco2w2d )
-            DEALLOCATE( f_pi_pco2w2d )
+            CALL iom_put( "PI_OCN_PCO2"  , f_pi_pco2w_2d )
+            DEALLOCATE( f_pi_pco2w_2d )
          ENDIF
          IF( med_diag%PI_OCNH2CO3%dgsave ) THEN
-            CALL iom_put( "PI_OCNH2CO3"  , f_pi_h2co32d )
-            DEALLOCATE( f_pi_h2co32d )
+            CALL iom_put( "PI_OCNH2CO3"  , f_pi_h2co3_2d )
+            DEALLOCATE( f_pi_h2co3_2d )
          ENDIF
          IF( med_diag%PI_OCN_HCO3%dgsave ) THEN
-            CALL iom_put( "PI_OCN_HCO3"  , f_pi_hco32d )
-            DEALLOCATE( f_pi_hco32d )
+            CALL iom_put( "PI_OCN_HCO3"  , f_pi_hco3_2d )
+            DEALLOCATE( f_pi_hco3_2d )
          ENDIF
          IF( med_diag%PI_OCN_CO3%dgsave ) THEN
-            CALL iom_put( "PI_OCN_CO3"  , f_pi_co32d )
-            DEALLOCATE( f_pi_co32d )
+            CALL iom_put( "PI_OCN_CO3"  , f_pi_co3_2d )
+            DEALLOCATE( f_pi_co3_2d )
          ENDIF
          IF( med_diag%PI_CO2FLUX%dgsave ) THEN
-            CALL iom_put( "PI_CO2FLUX"  , f_pi_co2flux2d )
-            DEALLOCATE( f_pi_co2flux2d )
+            CALL iom_put( "PI_CO2FLUX"  , f_pi_co2flux_2d )
+            DEALLOCATE( f_pi_co2flux_2d )
          ENDIF
          IF( med_diag%PI_FGCO2%dgsave ) THEN
@@ -277,25 +275,25 @@
          ENDIF
          IF( med_diag%PI_OM_CAL%dgsave ) THEN
-            CALL iom_put( "PI_OM_CAL"  , f_pi_omcal )
-            !! AXY: WHY IS THIS NOT DEALLOCATED?
+            CALL iom_put( "PI_OM_CAL"  , f_pi_omcal_2d )
+	    DEALLOCATE( f_pi_omcal_2d )
          ENDIF
          IF( med_diag%PI_OM_ARG%dgsave ) THEN
-            CALL iom_put( "PI_OM_ARG"  , f_pi_omarg )
-            !! AXY: WHY IS THIS NOT DEALLOCATED?
+            CALL iom_put( "PI_OM_ARG"  , f_pi_omarg_2d )
+	    DEALLOCATE( f_pi_omarg_2d )
          ENDIF
          IF( med_diag%PI_TCO2%dgsave ) THEN
-            CALL iom_put( "PI_TCO2"  , f_pi_TDIC2d )
-            DEALLOCATE( f_pi_TDIC2d )
+            CALL iom_put( "PI_TCO2"  , f_pi_TDIC_2d )
+            DEALLOCATE( f_pi_TDIC_2d )
          ENDIF
          IF( med_diag%PI_ATM_XCO2%dgsave ) THEN
-            CALL iom_put( "PI_ATM_XCO2"  ,   f_pi_xco2a_2d      )
+            CALL iom_put( "PI_ATM_XCO2"  ,   f_pi_xco2a_2d )
             DEALLOCATE( f_pi_xco2a_2d )
          ENDIF
          IF( med_diag%PI_OCN_FCO2%dgsave ) THEN
-            CALL iom_put( "PI_OCN_FCO2"  ,   f_pi_fco2w_2d      )
+            CALL iom_put( "PI_OCN_FCO2"  ,   f_pi_fco2w_2d )
             DEALLOCATE( f_pi_fco2w_2d )
          ENDIF
          IF( med_diag%PI_ATM_FCO2%dgsave ) THEN
-            CALL iom_put( "PI_ATM_FCO2"  ,   f_pi_fco2a_2d      )
+            CALL iom_put( "PI_ATM_FCO2"  ,   f_pi_fco2a_2d )
             DEALLOCATE( f_pi_fco2a_2d )
          ENDIF
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_fin.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_fin.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_fin.F90	(revision 10047)
@@ -33,9 +33,7 @@
       !!----------------------------------------------------------------------
       USE bio_medusa_mod
-      USE dom_oce,           ONLY: atfp, atfp1, neuler, rdt, e3t_n, tmask
+      USE dom_oce,           ONLY: atfp, atfp1, neuler, rdt, tmask
       USE in_out_manager,    ONLY: lwp, numout
-# if defined key_iomput
-      USE iom,               ONLY: iom_put, lk_iomput
-# endif
+      USE iom,               ONLY: iom_put
       USE lbclnk,            ONLY: lbc_lnk
       USE oce,               ONLY: chloro_out_cpl 
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_init.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_init.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_init.F90	(revision 10047)
@@ -38,10 +38,8 @@
       USE sms_medusa,        ONLY: jdms
       USE trc,               ONLY: ln_diatrc, med_diag, nittrc000 
-      USE in_out_manager,    ONLY: lwp
-
-# if defined key_iomput
-      USE iom,               ONLY: lk_iomput, numout
+      USE in_out_manager,    ONLY: lwp, numout
+
+      USE iom,               ONLY: lk_iomput
       USE trcnam_medusa,     ONLY: trc_nam_iom_medusa
-# endif
 
       !! time (integer timestep)
@@ -179,5 +177,10 @@
       zdic(:,:)  = 0.0
       zsil(:,:)  = 0.0
+# if defined key_mocsy
+      ! zpho is only defined if key_mocsy
+      ! is active, so we must protect this
+      ! initialisation accordingly. 
       zpho(:,:)  = 0.0
+# endif
       f_co2flux(:,:)  = 0.0 
       f_pco2atm(:,:)  = 0.0
@@ -398,6 +401,6 @@
 #  if defined key_omip_dic         
          IF( med_diag%PI_ATM_PCO2%dgsave ) THEN
-            ALLOCATE( f_pi_pco2a2d(1:jpi, 1:jpj) )
-            f_pi_pco2a2d(:,:)      = 0.0 !!
+            ALLOCATE( f_pi_pco2a_2d(1:jpi, 1:jpj) )
+            f_pi_pco2a_2d(:,:)      = 0.0 !!
          ENDIF
 #  endif
@@ -405,4 +408,10 @@
 !! skip OCN_PH diagnostic here
 !!
+#  if defined key_omip_dic         
+         IF( med_diag%PI_OCN_PH%dgsave ) THEN
+            ALLOCATE( f_pi_ph_2d(1:jpi, 1:jpj) )
+            f_pi_ph_2d(:,:)   = 0.0 !!
+         ENDIF
+#  endif
          IF( med_diag%OCN_PCO2%dgsave ) THEN
             ALLOCATE( f_pco2w2d(1:jpi, 1:jpj) )
@@ -411,6 +420,6 @@
 #  if defined key_omip_dic         
          IF( med_diag%PI_OCN_PCO2%dgsave ) THEN
-            ALLOCATE( f_pi_pco2w2d(1:jpi, 1:jpj) )
-            f_pi_pco2w2d(:,:)   = 0.0 !!
+            ALLOCATE( f_pi_pco2w_2d(1:jpi, 1:jpj) )
+            f_pi_pco2w_2d(:,:)   = 0.0 !!
          ENDIF
 #  endif
@@ -418,4 +427,19 @@
 !! skip OCNH2CO3, OCN_HCO3, OCN_CO3 diagnostics here
 !!
+#  if defined key_omip_dic         
+         IF( med_diag%PI_OCNH2CO3%dgsave ) THEN
+            ALLOCATE( f_pi_h2co3_2d(1:jpi, 1:jpj) )
+            f_pi_h2co3_2d(:,:)   = 0.0 !!
+         ENDIF
+         IF( med_diag%PI_OCN_HCO3%dgsave ) THEN
+            ALLOCATE( f_pi_hco3_2d(1:jpi, 1:jpj) )
+            f_pi_hco3_2d(:,:)   = 0.0 !!
+         ENDIF
+         IF( med_diag%PI_OCN_CO3%dgsave ) THEN
+            ALLOCATE( f_pi_co3_2d(1:jpi, 1:jpj) )
+            f_pi_co3_2d(:,:)   = 0.0 !!
+         ENDIF
+#  endif
+
          IF( med_diag%CO2FLUX%dgsave ) THEN
             ALLOCATE( f_co2flux2d(1:jpi, 1:jpj) )
@@ -431,4 +455,14 @@
 !! skip OM_XXX diagnostics here
 !!
+#  if defined key_omip_dic         
+         IF( med_diag%PI_OM_CAL%dgsave ) THEN
+            ALLOCATE( f_pi_omcal_2d(1:jpi, 1:jpj) )
+            f_pi_omcal_2d(:,:)   = 0.0 !!
+         ENDIF
+         IF( med_diag%PI_OM_ARG%dgsave ) THEN
+            ALLOCATE( f_pi_omarg_2d(1:jpi, 1:jpj) )
+            f_pi_omarg_2d(:,:)   = 0.0 !!
+         ENDIF
+#  endif
          IF( med_diag%TCO2%dgsave ) THEN
             ALLOCATE( f_TDIC2d(1:jpi, 1:jpj) )
@@ -928,4 +962,5 @@
 CONTAINS
    SUBROUTINE bio_medusa_init( )                   ! Empty routine
+      IMPLICIT NONE
       WRITE(*,*) 'bio_medusa_init: You should not have seen this print! error?'
    END SUBROUTINE bio_medusa_init
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_mod.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_mod.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_mod.F90	(revision 10047)
@@ -256,4 +256,8 @@
    REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_co2starair_2d
    REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_ocndpco2_2d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_pco2a_2d, f_pi_pco2w_2d, f_pi_co2flux_2d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_TDIC_2d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_ph_2d, f_pi_omcal_2d, f_pi_omarg_2d
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: f_pi_h2co3_2d, f_pi_hco3_2d, f_pi_co3_2d
 #  endif
 # endif
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/bio_medusa_update.F90	(revision 10047)
@@ -75,5 +75,8 @@
 # endif
                                    zpds, zphd, zphn
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gphit, mbathy, tmask
+      USE dom_oce,           ONLY: e3t_0, gphit, mbathy, tmask
+# if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n
+# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE lib_mpp,           ONLY: ctl_stop
@@ -86,5 +89,8 @@
                                    jpdic_lc, jpdin_lc, jpdtc_lc, jpfer_lc,   & 
                                    jpoxy_lc, jppds_lc, jpphd_lc, jpphn_lc,   &
-                                   jpsil_lc, jpzme_lc, jpzmi_lc
+# if defined key_omip_dic
+                                   jpomd, jpomd_lc,                          &
+# endif
+                                   jpsil_lc, jpzme_lc, jpzmi_lc             
       USE par_oce,           ONLY: jpi, jpim1, jpj, jpjm1, jpk
       USE par_trc,           ONLY: jptra
@@ -271,5 +277,5 @@
                              ! mort. loss
                          ((1.0 - xfdfrac1) * fdpds(ji,jj)) +                 &
-                             &  ! egestion of grazed Si
+                             ! egestion of grazed Si
                          ((1.0 - xfdfrac3) * fgmepds(ji,jj)) +               &
                              ! fast diss. and metab. losses
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/carb_chem.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/carb_chem.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/carb_chem.F90	(revision 10047)
@@ -41,6 +41,8 @@
 # endif
                                    zalk, zdic, zsal, zsil, ztmp 
-      USE dom_oce,           ONLY: gdept_0, gdept_n, gdepw_0, gdepw_n,    &
-                                   gphit, mbathy, tmask
+      USE dom_oce,           ONLY: gdept_0, gdepw_0, gphit, mbathy, tmask
+# if defined key_vvl
+      USE dom_oce,           ONLY: gdept_n, gdepw_n
+# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE oce,               ONLY: PCO2a_in_cpl, tsb, tsn
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus.F90	(revision 10047)
@@ -45,5 +45,8 @@
                                         fun_T, fun_Q10, zdet, zdtc
       USE detritus_fast_sink_mod, ONLY: detritus_fast_sink
-      USE dom_oce,                ONLY: mbathy, e3t_0, e3t_n, gphit, tmask
+      USE dom_oce,                ONLY: mbathy, e3t_0, gphit, tmask
+# if defined key_vvl
+      USE dom_oce,                ONLY: e3t_n
+# endif
       USE in_out_manager,         ONLY: lwp, numout
       USE par_oce,                ONLY: jpim1, jpjm1
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus_fast_sink.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus_fast_sink.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/detritus_fast_sink.F90	(revision 10047)
@@ -66,6 +66,8 @@
                                    idf, idfval,                            &
                                    zdet, zdtc
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gdepw_0, gdepw_n,         &
-                                   gphit, mbathy, tmask
+      USE dom_oce,           ONLY: e3t_0, gdepw_0, gphit, mbathy, tmask
+# if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n, gdepw_n
+# endif
       USE in_out_manager,    ONLY: lwp, numout
       USE oce,               ONLY: tsn
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/iron_chem_scav.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/iron_chem_scav.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/iron_chem_scav.F90	(revision 10047)
@@ -35,6 +35,8 @@
                                    zdet, zfer, zphd, zphn, zzme, zzmi,    &
                                    idf, idfval                          
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gdepw_0, gdepw_n,        &
-                                   mbathy, tmask
+      USE dom_oce,           ONLY: e3t_0, gdepw_0, mbathy, tmask
+#if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n, gdepw_n
+#endif
       USE par_kind,          ONLY: wp
       USE in_out_manager,    ONLY: lwp, numout
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 10047)
@@ -68,5 +68,5 @@
 #  if defined key_omip_dic
    INTEGER, PUBLIC, PARAMETER ::   jpomd  =  jp_lm + 16     !: OMIP preindustrial DIC
-#  end   
+#  endif   
 # endif
 
@@ -90,5 +90,5 @@
 #  if defined key_omip_dic
    INTEGER, PUBLIC, PARAMETER ::   jpomd_lc  =  16     !: OMIP preindustrial DIC
-#  end   
+#  endif   
 # endif
 
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/phytoplankton.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/phytoplankton.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/phytoplankton.F90	(revision 10047)
@@ -44,5 +44,8 @@
                                    zfer, zpds, zphd, zphn, zsil,         &
                                    zzme, zzmi, fchl_ml
-      USE dom_oce,           ONLY: e3t_0, e3t_n, gdepw_0, gdepw_n, tmask
+      USE dom_oce,           ONLY: e3t_0, gdepw_0, tmask
+#if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n, gdepw_n
+#endif
       USE in_out_manager,    ONLY: lwp, numout
       USE oce,               ONLY: tsn
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 10047)
@@ -75,5 +75,5 @@
 # endif
 # if defined key_omip_dic
-                                            zomd,                           &
+                                            zomd,f_pi_xco2a,                &
 # endif                                            
 # if defined key_mocsy
@@ -83,16 +83,16 @@
                                             zfer, zpds, zphd, zphn, zsil,   &
                                             zzme, zzmi
-      USE dom_oce,                    ONLY: e3t_0, e3t_n,                   &
-                                            gdept_0, gdept_n,               &
-                                            gdepw_0, gdepw_n,               &
-                                            nday_year, nsec_day,            &
+      USE dom_oce,                    ONLY: e3t_0, gdept_0,  gdepw_0,       &
+                                            nday_year, nsec_day,            & 
                                             nyear, nyear_len, ndastp,       &
                                             nsec_month,                     &
                                             rdt, tmask, mig, mjg, nimpp,    &
                                             njmpp 
+#if defined key_vvl
+      USE dom_oce,                    ONLY: e3t_n, gdept_n,  gdepw_n
+#endif
+
       USE in_out_manager,             ONLY: lwp, numout, nn_date0
-# if defined key_iomput
       USE iom,                        ONLY: lk_iomput
-# endif
       USE lbclnk,                     ONLY: lbc_lnk
       USE lib_mpp,                    ONLY: mpp_max, mpp_maxloc,            & 
@@ -384,5 +384,5 @@
 
 #  if defined key_omip_dic
-         f_xco2a(:,:) = 284.317          !! CMIP6 pre-industrial pCO2
+         f_pi_xco2a(:,:) = 284.317          !! CMIP6 pre-industrial pCO2
 #  endif
       
@@ -708,5 +708,5 @@
                            ji, jj, jk, kt
                      endif
-#  if defined key_omip_dic
+#   if defined key_omip_dic
                      if (trn(ji,jj,jk,jpomd).lt.0.) then
                         IF (lwp) write (numout,*)                            &
@@ -717,4 +717,5 @@
                            ji, jj, jk, kt
                      endif
+#   endif
 #  endif
                   endif
@@ -839,5 +840,5 @@
       !! temporary variables
       REAL(wp), INTENT( in ), DIMENSION(3,3) :: tiny_var, tiny_mask
-      CHARACTER(25), INTENT( in )            :: var_nm
+      CHARACTER(3), INTENT( in )            :: var_nm
       REAL(wp), INTENT( in )                 :: mini, maxi
       REAL(wp), INTENT( out )                :: varout
@@ -1043,4 +1044,5 @@
 CONTAINS
    SUBROUTINE trc_bio_medusa( kt )                   ! Empty routine
+      IMPLICIT NONE
       INTEGER, INTENT( in ) ::   kt
       WRITE(*,*) 'trc_bio_medusa: You should not have seen this print! error?', kt
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/zooplankton.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/zooplankton.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/MEDUSA/zooplankton.F90	(revision 10047)
@@ -41,5 +41,8 @@
                                    idf, idfval,                          &
                                    zdet, zdtc, zphd, zphn, zzme, zzmi
-      USE dom_oce,           ONLY: e3t_0, e3t_n, tmask
+      USE dom_oce,           ONLY: e3t_0, tmask
+#if defined key_vvl
+      USE dom_oce,           ONLY: e3t_n
+#endif
       USE par_kind,          ONLY: wp
       USE in_out_manager,    ONLY: lwp, numout
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/TRP/trcbbl.F90	(revision 10047)
@@ -51,7 +51,9 @@
       !!
       !!----------------------------------------------------------------------  
+      IMPLICIT NONE
       INTEGER, INTENT( in ) ::   kt   ! ocean time-step 
       CHARACTER (len=22) :: charout
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   ztrtrd
+      INTEGER :: jn                   ! Local loop index
       !!----------------------------------------------------------------------
       !
@@ -108,4 +110,6 @@
 CONTAINS
    SUBROUTINE trc_bbl( kt )              ! Empty routine
+      IMPLICIT NONE
+      INTEGER, INTENT(in) ::   kt    ! ocean time-step index
       WRITE(*,*) 'tra_bbl: You should not have seen this print! error?', kt
    END SUBROUTINE trc_bbl
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 10047)
@@ -110,5 +110,5 @@
    END TYPE DIAG
 
-#if defined key_medusa && defined key_iomput
+#if defined key_medusa
    TYPE, PUBLIC :: BDIAG
       LOGICAL              :: dgsave
@@ -145,4 +145,10 @@
                   FGCO2, INTDISSIC, INTDISSIN, INTDISSISI, INTTALK, O2min, ZO2min,                   &
                   FBDDTALK, FBDDTDIC, FBDDTDIFE, FBDDTDIN, FBDDTDISI,                                & 
+#  if defined key_omip_dic
+! JPALM (08/08/18): additional OMIP PI DIC 2D diag
+                  PI_ATM_PCO2, PI_OCN_PH, PI_OCN_PCO2, PI_OCNH2CO3, PI_OCN_HCO3, PI_OCN_CO3,         &
+		  PI_CO2FLUX, PI_FGCO2, PI_OM_CAL, PI_OM_ARG, PI_TCO2,                               &
+                  PI_ATM_XCO2, PI_OCN_FCO2, PI_ATM_FCO2, PI_CO2STARAIR, PI_OCN_DPCO2,                &
+#  endif
 ! AXY (11/11/16): additional CMIP6 3D diagnostics
                   TPPD3,                                                                             &
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 10047)
@@ -726,6 +726,5 @@
       !!----------------------------------------------------------------------
       INTEGER  :: ji, jj, jk, jn
-      REAL(wp) :: zsum3d, zsum2d, zinvt, zdelta, zratio, loc_vol, loc_are
-      REAL(wp) :: zq1, zq2, loc_vol, loc_area
+      REAL(wp) :: zsum3d, zsum2d, zinvt, zdelta, zratio
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: z3d, zvol
       REAL(wp), DIMENSION(jpi,jpj)     :: z2d, zarea
Index: /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcstat.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcstat.F90	(revision 10046)
+++ /branches/NERC/dev_r5518_GO6_under_ice_relax/NEMOGCM/NEMO/TOP_SRC/trcstat.F90	(revision 10047)
@@ -28,6 +28,8 @@
    USE par_oce,           ONLY: jpi, jpj
    USE par_trc,           ONLY: jptra
-   USE dom_oce,           ONLY: e3t_0, e3t_a, e3t_n, gdepw_0, gdepw_n,     &
-                          tmask, e1e2t
+   USE dom_oce,           ONLY: e3t_0, gdepw_0, tmask, e1e2t
+#if defined key_vvl
+   USE dom_oce,           ONLY: e3t_a, e3t_n, gdepw_n
+#endif
    !* MPP library                         
    USE lib_mpp
