From 0e1f0510a6e97ee373cc46007f4ef23c4d0be4e5 Mon Sep 17 00:00:00 2001
From: Daley Calvert <daley.calvert@metoffice.gov.uk>
Date: Thu, 18 Jul 2024 12:31:55 +0000
Subject: [PATCH] Resolve "Bug fixes for GOSI10 to pass SETTE tests"

---
 cfgs/SHARED/field_def_nemo-oce.xml | 49 ++++++++++++++++++++++++++----
 cfgs/SHARED/namelist_ref           |  7 ++++-
 src/OCE/DIA/diawri.F90             |  8 ++---
 src/OCE/ICB/icbrst.F90             |  2 +-
 src/OCE/SBC/cpl_oasis3.F90         |  6 +---
 src/OCE/SBC/sbcblk.F90             |  4 +--
 src/OCE/SBC/sbcssm.F90             | 12 ++++----
 7 files changed, 63 insertions(+), 25 deletions(-)

diff --git a/cfgs/SHARED/field_def_nemo-oce.xml b/cfgs/SHARED/field_def_nemo-oce.xml
index abc8301f..e1d4525d 100644
--- a/cfgs/SHARED/field_def_nemo-oce.xml
+++ b/cfgs/SHARED/field_def_nemo-oce.xml
@@ -117,7 +117,11 @@ that are available in the tidal-forcing implementation (see
     <field id="e3t_vsum300"  field_ref="e3t_300"            grid_ref="grid_T_vsum"   detect_missing_value="true" />
     <field id="masscello"    long_name="Sea Water Mass per unit area"   standard_name="sea_water_mass_per_unit_area"   unit="kg/m2"   grid_ref="grid_T_3D"/>
     <field id="volcello"     long_name="Ocean Volume"                   standard_name="ocean_volume"   unit="m3"       grid_ref="grid_T_3D" />
-  
+    <field id="toce"         long_name="temperature"                         standard_name="sea_water_potential_temperature"   unit="degC"     grid_ref="grid_T_3D"/>
+    <field id="toce_e3t"     long_name="temperature (thickness weighted)"                                                      unit="degC"     grid_ref="grid_T_3D" > toce * e3t </field >
+    <field id="soce"         long_name="salinity"                            standard_name="sea_water_practical_salinity"      unit="1e-3"     grid_ref="grid_T_3D"/>
+    <field id="soce_e3t"     long_name="salinity    (thickness weighted)"                                                      unit="1e-3"     grid_ref="grid_T_3D" > soce * e3t </field >
+
     <!-- EOS80 -->
     <field id="toce_pot"         long_name="potential temperature"           standard_name="sea_water_potential_temperature"      unit="degC"     grid_ref="grid_T_3D"/>
     <field id="toce_pot_e3t"     long_name="potential temperature (thickness weighted)"                                           unit="degC"     grid_ref="grid_T_3D" > toce_pot * e3t </field >
@@ -146,12 +150,31 @@ that are available in the tidal-forcing implementation (see
     <field id="sssgrad2"    long_name="square of module of surface salinity gradient"    unit="1e-6/m2"  grid_ref="grid_T_2D_inner"/>
     <field id="ke"          long_name="kinetic energy"          standard_name="specific_kinetic_energy_of_sea_water"   unit="m2/s2"  grid_ref="grid_T_3D" />
     <field id="ke_int"      long_name="vertical integration of kinetic energy"   unit="m3/s2"  grid_ref="grid_T_2D_inner" />
-    <field id="salt2c"      long_name="Salt content vertically integrated"       unit="1e-3*kg/m2" />
 
     <!-- t-eddy viscosity coefficients (ldfdyn) -->
     <field id="ahmt_2d"      long_name=" surface t-eddy viscosity coefficient"   unit="m2/s or m4/s"                      />
     <field id="ahmt_3d"      long_name=" 3D      t-eddy viscosity coefficient"   unit="m2/s or m4/s"  grid_ref="grid_T_3D"/>
 
+    <field id="sst"          long_name="Bulk sea surface temperature"                       standard_name="bulk_sea_surface_temperature"        unit="degC"     />
+    <field id="t_skin"       long_name="Skin temperature aka SSST"                          standard_name="skin_temperature"                    unit="degC"     />
+    <field id="sst2"         long_name="square of sea surface temperature"                  standard_name="square_of_sea_surface_temperature"   unit="degC2"     > sst * sst </field >
+    <field id="sstmax"       long_name="max of sea surface temperature"   field_ref="sst"   operation="maximum"                                                 />
+    <field id="sstmin"       long_name="min of sea surface temperature"   field_ref="sst"   operation="minimum"                                                 />
+    <field id="sstgrad"      long_name="module of sst gradient"                                                                                 unit="degC/m"   grid_ref="grid_T_2D_inner" />
+    <field id="sstgrad2"     long_name="square of module of sst gradient"                                                                       unit="degC2/m2" grid_ref="grid_T_2D_inner" />
+    <field id="sbt"          long_name="sea bottom temperature"                                                                                 unit="degC"     grid_ref="grid_T_2D_inner" />
+    <field id="tosmint"      long_name="vertical integral of temperature times density"     standard_name="integral_wrt_depth_of_product_of_density_and_potential_temperature"  unit="(kg m2) degree_C" grid_ref="grid_T_2D_inner" />
+    <field id="sst_wl"       long_name="Delta SST of warm layer"                                                                                unit="degC"     />
+    <field id="sst_cs"       long_name="Delta SST of cool skin"                                                                                 unit="degC"     />
+    <field id="temp_3m"      long_name="temperature at 3m"                                                                                      unit="degC"     />
+
+    <field id="sss"          long_name="sea surface salinity"                               standard_name="sea_surface_salinity"                unit="1e-3"     />
+    <field id="sss2"         long_name="square of sea surface salinity"                                                                         unit="1e-6"      > sss * sss </field >
+    <field id="sssmax"       long_name="max of sea surface salinity"      field_ref="sss"   operation="maximum"                                                 />
+    <field id="sssmin"       long_name="min of sea surface salinity"      field_ref="sss"   operation="minimum"                                                 />
+    <field id="sbs"          long_name="sea bottom salinity"                                                                                    unit="0.001"   grid_ref="grid_T_2D_inner" />
+    <field id="somint"       long_name="vertical integral of salinity times density"        standard_name="integral_wrt_depth_of_product_of_density_and_salinity"  unit="(kg m2) x (1e-3)" grid_ref="grid_T_2D_inner" />
+
     
        <!-- EOS80 -->
         <field id="sst_pot"          long_name="sea surface potential temperature"                            standard_name="sea_surface_temperature"             unit="degC"     />
@@ -245,7 +268,7 @@ that are available in the tidal-forcing implementation (see
     <field id="mldhtc_5"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"   grid_ref="grid_T_2D"    />
     <field id="heatc"        long_name="Heat content vertically integrated"                 standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"   grid_ref="grid_T_2D_inner" />
     <field id="saltc"        long_name="Salt content vertically integrated"                                                                                                                   unit="1e-3.m"    grid_ref="grid_T_2D_inner" />
-    <field id="saltc2"       long_name="square of Salt content vertically integrated"                                                                                                         unit="1e-6.m2"   grid_ref="grid_T_2D_inner" />
+    <field id="salt2c"       long_name="square of Salt content vertically integrated"                                                                                                         unit="1e-6.m2"   grid_ref="grid_T_2D_inner" />
 
     <!-- EOS -->
     <field id="alpha"        long_name="thermal expansion"                                                         unit="degC-1" grid_ref="grid_T_3D" />
@@ -1267,6 +1290,8 @@ that are available in the tidal-forcing implementation (see
   </field_group>
 
   <field_group id="mooring" >
+    <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"      />
+    <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                   />
 
     <!-- EOS80 -->
     <field field_ref="toce_pot"     name="thetao_pot"   long_name="sea_water_potential_temperature"  />
@@ -1284,6 +1309,11 @@ that are available in the tidal-forcing implementation (see
     <field field_ref="avt"          name="difvho"   long_name="ocean_vertical_heat_diffusivity"      />
     <field field_ref="avm"          name="difvmo"   long_name="ocean_vertical_momentum_diffusivity"  />
 
+    <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+    <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+    <field field_ref="sstgrad"      name="tosgrad"  long_name="module_of_sea_surface_temperature_gradient"    />
+    <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+
       <!-- EOS80 -->
     <field field_ref="sst_pot"          name="tos_pot"      long_name="sea_surface_potential_temperature"                       />
     <field field_ref="sst2_pot"         name="tossq_pot"    long_name="square_of_sea_surface_potential_temperature"             />
@@ -1321,6 +1351,12 @@ that are available in the tidal-forcing implementation (see
   </field_group>
 
   <field_group id="groupT" >
+    <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"               />
+    <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                            />
+    <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+    <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+    <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+
   <!-- EOS80 -->
     <field id="toce_pot"           long_name="sea_water_potential_temperature"                grid_ref="grid_T_3D"      />
     <field id="soce_pra"           long_name="sea_water_practical_salinity"                   grid_ref="grid_T_3D"      />
@@ -1423,7 +1459,10 @@ that are available in the tidal-forcing implementation (see
 
   <!-- 25h diagnostic output -->
   <field_group id="25h_grid_T" grid_ref="grid_T_3D_inner" operation="instant">
-    <field id="tempis25h"         name="insitu temperature 25h mean"       unit="degC" />
+    <field id="temper25h"         name="potential temperature 25h mean"    unit="degC" />
+    <field id="tempis25h"         name="insitu temperature 25h mean"    unit="degC" />
+    <field id="salin25h"          name="salinity 25h mean"                 unit="psu"  />
+    <field id="ssh25h"            name="sea surface height 25h mean"  grid_ref="grid_T_2D_inner"      unit="m"    />
 
     <!-- EOS80 -->
     <field id="temper25h_pot"     name="potential temperature 25h mean"    unit="degC" />
@@ -1434,8 +1473,6 @@ that are available in the tidal-forcing implementation (see
     <!-- SEOS -->
     <field id="temper25h_seos"    name="temperature 25h mean"              unit="degC" />
     <field id="salin25h_seos"     name="salinity 25h mean"                 unit="psu"  />
-    
-    <field id="ssh25h"            name="sea surface height 25h mean"       unit="m" grid_ref="grid_T_2D"   />
   </field_group>
 
   <field_group id="25h_grid_U" grid_ref="grid_U_3D_inner" operation="instant" >
diff --git a/cfgs/SHARED/namelist_ref b/cfgs/SHARED/namelist_ref
index 5dccf858..d104e501 100644
--- a/cfgs/SHARED/namelist_ref
+++ b/cfgs/SHARED/namelist_ref
@@ -41,6 +41,7 @@
    nn_time0    =       0   !  initial time of day in hhmm
    nn_leapy    =       0   !  Leap year calendar (1) or not (0)
    ln_rstart   = .false.,   !  start from rest (F) or from a restart file (T)
+      ln_rstdate   = .false.,  !  restart file name contains timestep number (F) or date (T)
       ln_1st_euler = .false.,  !  =T force a start with forward time step (ln_rstart=T)
       nn_rstctl    =    0     !  restart control ==> activated only if ln_rstart=T
       !                          !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
@@ -65,7 +66,7 @@
    nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
    ln_xios_read = .false.,  !  use XIOS to read restart file (only for a single file restart)
    nn_wxios = 0      !  use XIOS to write restart file 0 - no, 1 - single file output, 2 - multiple file output
-   ln_rst_eos = .TRUE.,     ! check if the equation of state used to produce the restart is consistent with model
+   ln_rst_eos = .false.,     ! check if the equation of state used to produce the restart is consistent with model
 /
 !-----------------------------------------------------------------------
 &namdom        !   time and space domain
@@ -269,6 +270,7 @@
    !
    rn_pfac    = 1.          !  multipl. factor for precipitation (total & snow)
    rn_efac    = 1.          !  multipl. factor for evaporation (0. or 1.)
+   rn_vfac    = 0.          !
    !
    ln_crt_fbk = .false.,     !  Add surface current feedback to the wind stress (Renault et al. 2020, doi: 10.1029/2019MS001715)
          rn_stau_a = -2.9e-3   !     Alpha from eq. 10: Stau = Alpha * Wnd + Beta
@@ -688,6 +690,7 @@
    !                       !  free slip  !   partial slip  !   no slip   ! strong slip
    rn_shlat    =  -9999.   !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
    ln_vorlat   = .false.,   !  consistency of vorticity boundary condition with analytical Eqs.
+   ln_shlat2d  = .false.,  !
 /
 !-----------------------------------------------------------------------
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
@@ -974,6 +977,7 @@
       rn_Ue        = 0.02           !  lateral diffusive velocity [m/s] (nn_aht_ijk_t= 0, 10, 20, 30)
       rn_Le        = 200.e+3        !  lateral diffusive length   [m]   (nn_aht_ijk_t= 0, 10)
       !
+      nn_ldfeiv_shape = 0           !
       ln_ldfeiv_dia =.false.,   ! diagnose eiv stream function and velocities
 /
 !-----------------------------------------------------------------------
@@ -1168,6 +1172,7 @@
    !                       ! gravity wave-driven vertical mixing
    ln_zdfiwm   = .false.,      ! internal wave-induced mixing            (T =>   fill namzdf_iwm)
    ln_zdfswm   = .false.,      ! surface  wave-induced mixing            (T => ln_wave=ln_sdw=T )
+   ln_zdftmx   = .false.,      !
    !
    !                       ! coefficients
    rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
diff --git a/src/OCE/DIA/diawri.F90 b/src/OCE/DIA/diawri.F90
index 9a6c3586..a967f3a8 100644
--- a/src/OCE/DIA/diawri.F90
+++ b/src/OCE/DIA/diawri.F90
@@ -140,16 +140,16 @@ CONTAINS
             ELSE
                ttype='con' ; stype='abs'   ! teos-10 using conservative temperature and absolute salinity
             ENDIF 
-         ELSE IF( ln_EOS80  ) THEN
+         ELSE IF ( ln_SEOS) THEN
+            ttype='seos' ; stype='seos' ! seos using Simplified Equation of state
+         ELSE
             IF ( iom_use("toce_con") .OR. iom_use("soce_abs") .OR. iom_use("sst_con") .OR. iom_use("sss_abs") &
                   & .OR. iom_use("sbt_con") .OR. iom_use("sbs_abs") .OR. iom_use("sstgrad_con") .OR. iom_use("sstgrad2_con") &
-                  & .OR. iom_use("tosmint_con") .OR. iom_use("somint_abs"))  THEN 
+                  & .OR. iom_use("tosmint_con") .OR. iom_use("somint_abs"))  THEN
                CALL ctl_stop( 'diawri: conservative temperature and absolute salinity not available with ln_EOS80' )
             ELSE
                ttype='pot' ; stype='pra'   ! eos-80 using potential temperature and practical salinity
             ENDIF
-         ELSE IF ( ln_SEOS) THEN
-            ttype='seos' ; stype='seos' ! seos using Simplified Equation of state
          ENDIF
       ENDIF
 
diff --git a/src/OCE/ICB/icbrst.F90 b/src/OCE/ICB/icbrst.F90
index ed32fed4..48f7ed26 100644
--- a/src/OCE/ICB/icbrst.F90
+++ b/src/OCE/ICB/icbrst.F90
@@ -226,7 +226,7 @@ CONTAINS
             ELSE                        ;   WRITE(cl_kt, '(i8.8)') kt
             ENDIF
          ENDIF
-         cl_filename = TRIM(cexper)//"_"//cl_kt//"_"//TRIM(cn_icbrst_out)
+         cl_filename = TRIM(cexper)//"_"//TRIM(cl_kt)//"_"//TRIM(cn_icbrst_out)
          IF( lk_mpp ) THEN
             idg = MAX( INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1, 4 )          ! how many digits to we need to write? min=4, max=9
             WRITE(clfmt, "('(a,a,i', i1, '.', i1, ',a)')") idg, idg          ! '(a,a,ix.x,a)'
diff --git a/src/OCE/SBC/cpl_oasis3.F90 b/src/OCE/SBC/cpl_oasis3.F90
index 2769435c..dcf6213d 100644
--- a/src/OCE/SBC/cpl_oasis3.F90
+++ b/src/OCE/SBC/cpl_oasis3.F90
@@ -37,7 +37,7 @@ MODULE cpl_oasis3
    USE in_out_manager               ! I/O manager
    USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp
-#if defined key_agrif
+#if defined key_agrif || ! defined key_mpi_off
    USE MPI
 #endif
 
@@ -50,10 +50,6 @@ MODULE cpl_oasis3
    END INTERFACE
 #endif 
 
-#if ! defined key_mpi_off
-   INCLUDE 'mpif.h'
-#endif
-
    PUBLIC   cpl_init
    PUBLIC   cpl_define
    PUBLIC   cpl_snd
diff --git a/src/OCE/SBC/sbcblk.F90 b/src/OCE/SBC/sbcblk.F90
index 3f0b413b..48dc0288 100644
--- a/src/OCE/SBC/sbcblk.F90
+++ b/src/OCE/SBC/sbcblk.F90
@@ -696,7 +696,7 @@ CONTAINS
       END_2D
 #else
       ! ... scalar wind module at T-point (not masked)
-      DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
+      DO_2D( 0, 0, 0, 0 )
          zwnd_i(ji,jj) = (  pwndi(ji,jj) - rn_vfac * 0.5 * ( pu(ji-1,jj  ) + pu(ji,jj) )  )
          zwnd_j(ji,jj) = (  pwndj(ji,jj) - rn_vfac * 0.5 * ( pv(ji  ,jj-1) + pv(ji,jj) )  )
       END_2D
@@ -1038,7 +1038,7 @@ CONTAINS
       !    Wind module relative to the moving ice ( U10m - U_ice )   !
       ! ------------------------------------------------------------ !
       ! C-grid ice dynamics :   U & V-points (same as ocean)
-      DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
+      DO_2D( 0, 0, 0, 0 )
          zwndi_t = (  pwndi(ji,jj) - rn_vfac * 0.5 * ( puice(ji-1,jj  ) + puice(ji,jj) )  )
          zwndj_t = (  pwndj(ji,jj) - rn_vfac * 0.5 * ( pvice(ji  ,jj-1) + pvice(ji,jj) )  )
          wndm_ice(ji,jj) = SQRT( zwndi_t * zwndi_t + zwndj_t * zwndj_t )* tmask(ji,jj,1)
diff --git a/src/OCE/SBC/sbcssm.F90 b/src/OCE/SBC/sbcssm.F90
index 63567c95..13c15275 100644
--- a/src/OCE/SBC/sbcssm.F90
+++ b/src/OCE/SBC/sbcssm.F90
@@ -63,12 +63,12 @@ CONTAINS
       !!--------------------------------------------------------------------- 
       IF( kt == nit000 ) THEN 
          IF( ln_TEOS10 ) THEN 
-            stype='abs'   ! teos-10: using absolute salinity (sst is converted to potential temperature for the surface module) 
-         ELSE IF( ln_EOS80  ) THEN 
-            stype='pra'   ! eos-80: using practical salinity 
-         ELSE IF ( ln_SEOS) THEN 
-            stype='seos' ! seos using Simplified Equation of state (sst is converted to potential temperature for the surface module) 
-         ENDIF 
+            stype='abs'    ! teos-10: using absolute salinity (sst is converted to potential temperature for the surface module)
+         ELSE IF( ln_SEOS ) THEN
+            stype='seos'   ! seos: using Simplified Equation of state (sst is converted to potential temperature for the surface module)
+         ELSE
+            stype='pra'    ! eos-80: using practical salinity
+         ENDIF
       ENDIF 
       !
       !                                        !* surface T-, U-, V- ocean level variables (T, S, depth, velocity)
-- 
GitLab