Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_BFM/EXP00/namelist_cfg	(revision 8841)
@@ -44,5 +44,5 @@
 !-----------------------------------------------------------------------
 &namcrs        !   Grid coarsening for dynamics output and/or
-               !   passive tracer coarsened online simulations
+!              !   passive tracer coarsened online simulations
 !-----------------------------------------------------------------------
 /
@@ -51,5 +51,5 @@
 !-----------------------------------------------------------------------
 !          ! file name ! frequency (hours)    ! variable ! time interp. ! clim  !'yearly' or ! weights  ! rotation !
-!          !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing  
+!          !           !  (if <0  months)     !   name   !  (logical)   ! (T/F) ! 'monthly'  ! filename ! pairing
    cn_dir        = './'      !  root directory for the location of the runoff files
    ln_tsd_init   = .false.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
@@ -87,7 +87,4 @@
 &namsbc_ssr    !   surface boundary condition : sea surface restoring
 !-----------------------------------------------------------------------
-   nn_sssr     =     0     !  add a damping     term in the surface freshwater flux (=2)
-   rn_deds     =   -27.7   !  magnitude of the damping on salinity   [mm/day]
-   ln_sssr_bnd =   .false. !  flag to bound erp term (associated with nn_sssr=2)
 /
 !-----------------------------------------------------------------------
@@ -204,4 +201,8 @@
 !-----------------------------------------------------------------------
    ln_dynvor_ene = .true.  !  enstrophy conserving scheme
+   ln_dynvor_ens = .false. !  energy conserving scheme
+   ln_dynvor_mix = .false. !  mixed scheme
+   ln_dynvor_een = .false. !  energy & enstrophy scheme
+      nn_een_e3f = 1             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
@@ -239,8 +240,4 @@
    rn_ahm_b      =      0.     !  background eddy viscosity for ldf_iso [m2/s]
    rn_bhm_0      =      0.     !  horizontal bilaplacian eddy viscosity [m4/s]
-   !
-   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
-/
-   rn_ahm_0_lap     = 100000.   !  horizontal laplacian eddy viscosity   [m2/s]
 /
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/EXP00/namelist_cfg	(revision 8841)
@@ -31,5 +31,5 @@
       !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
    ln_write_cfg= .false.   !  (=T) create the domain configuration file
-   !
+!
 /
 !-----------------------------------------------------------------------
@@ -60,5 +60,5 @@
 !-----------------------------------------------------------------------
    nn_fsbc     = 1         !  frequency of surface boundary condition computation
-   !                       !     (also = the frequency of sea-ice model call)
+                           !     (also = the frequency of sea-ice model call)
    ln_usr      = .true.    !  user defined formulation                  (T => check usrdef_sbc)
    ln_blk      = .false.   !  Bulk formulation                          (T => fill namsbc_blk )
@@ -240,8 +240,4 @@
    rn_ahm_b      =      0.     !  background eddy viscosity for ldf_iso [m2/s]
    rn_bhm_0      =      0.     !  horizontal bilaplacian eddy viscosity [m4/s]
-   !
-   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
-/
-   rn_ahm_0_lap     = 100000.   !  horizontal laplacian eddy viscosity   [m2/s]
 /
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/GYRE_PISCES/cpp_GYRE_PISCES.fcm	(revision 8841)
@@ -1,1 +1,1 @@
-bld::tool::fppkeys key_zdftke key_top key_mpp_mpi
+bld::tool::fppkeys key_zdftke key_top key_mpp_mpi key_iomput
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_cfg	(revision 8841)
@@ -20,9 +20,4 @@
 /
 !-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
-!-----------------------------------------------------------------------
-   ln_zps      = .true.    !  z-coordinate - partial steps
-/
-!-----------------------------------------------------------------------
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------  
@@ -46,5 +41,5 @@
 !-----------------------------------------------------------------------
    ln_blk      = .true.    !  CORE bulk formulation                     (T => fill namsbc_core)
-   nn_ice      = 0         !  =0 no ice boundary condition   ,
+   nn_ice      = 3         !  =0 no ice boundary condition   ,
                            !  =1 use observed ice-cover      ,
                            !  =2 ice-model used                         ("key_lim3" or "key_lim2)
@@ -90,4 +85,5 @@
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
+   nn_cln_update =    1    !  baroclinic update frequency
 /
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_ice_ref
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_ice_ref	(revision 8841)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/1_namelist_ice_ref	(revision 8841)
@@ -0,0 +1,1 @@
+link ../../SHARED/1_namelist_ice_ref
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo.xml
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo.xml	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/file_def_nemo.xml	(revision 8841)
@@ -95,11 +95,11 @@
 	  <field field_ref="avt"          name="difvho"   />
 	  <field field_ref="w_masstr"     name="vovematr" />
-          <!-- variables available with key_zdftmx_new -->
-          <field field_ref="av_wave"      name="av_wave"    />
-          <field field_ref="bn2"          name="bn2"        />
-          <field field_ref="bflx_tmx"     name="bflx_tmx"   />
-          <field field_ref="pcmap_tmx"    name="pcmap_tmx"  />
-          <field field_ref="emix_tmx"     name="emix_tmx"   />
-          <field field_ref="av_ratio"     name="av_ratio"   />
+     <!-- variables available with key_zdftmx_new -->
+     <field field_ref="av_wave"      name="av_wave"    />
+     <field field_ref="bn2"          name="bn2"        />
+     <field field_ref="bflx_tmx"     name="bflx_tmx"   />
+     <field field_ref="pcmap_tmx"    name="pcmap_tmx"  />
+     <field field_ref="emix_tmx"     name="emix_tmx"   />
+     <field field_ref="av_ratio"     name="av_ratio"   />
 	</file>
 
@@ -350,4 +350,2 @@
    </file_definition>
     
-  
-</simulation>
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/ORCA2_LIM3_PISCES/EXP00/namelist_cfg	(revision 8841)
@@ -17,9 +17,4 @@
       !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
       cn_domcfg = "ORCA_R2_zps_domcfg"    ! domain configuration filename
-/
-!-----------------------------------------------------------------------
-&namzgr        !   vertical coordinate
-!-----------------------------------------------------------------------
-   ln_zps      = .true.    !  z-coordinate - partial steps
 /
 !-----------------------------------------------------------------------
@@ -105,4 +100,9 @@
 /
 !-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+   nn_cln_update =    3    !  baroclinic update frequency
+/
+!-----------------------------------------------------------------------
 &nambfr        !   bottom friction
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/1_namelist_ice_ref
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/1_namelist_ice_ref	(revision 8841)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/1_namelist_ice_ref	(revision 8841)
@@ -0,0 +1,1 @@
+link namelist_ice_lim3_ref
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/field_def_nemo-opa.xml	(revision 8841)
@@ -20,4 +20,5 @@
       <field_group id="grid_T" grid_ref="grid_T_2D" >
          <field id="e3t"          long_name="T-cell thickness"   standard_name="cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
+         <field id="e3t_surf"     long_name="T-cell thickness"   field_ref="e3t"  standard_name="cell_thickness"   unit="m"   grid_ref="grid_T_SFC"/>
          <field id="e3t_0"        long_name="Initial T-cell thickness"   standard_name="ref_cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
 
@@ -207,5 +208,5 @@
 
          <!-- * variable related to ice shelf forcing * -->
-         <field id="fwfisf"       long_name="Ice shelf melting"                                            unit="Kg/m2/s"  />
+         <field id="fwfisf"       long_name="Ice shelf melting"                             unit="kg/m2/s"  />
          <field id="fwfisf3d"     long_name="Ice shelf melting"                             unit="kg/m2/s"  grid_ref="grid_T_3D" />
          <field id="qlatisf"      long_name="Ice shelf latent heat flux"                    unit="W/m2"     />
@@ -215,5 +216,5 @@
          <field id="isfgammat"    long_name="transfert coefficient for isf (temperature) "  unit="m/s"      />
          <field id="isfgammas"    long_name="transfert coefficient for isf (salinity)    "  unit="m/s"      />
- 	 <field id="stbl"         long_name="salinity in the Losh tbl                    "  unit="PSU"      />
+         <field id="stbl"         long_name="salinity in the Losh tbl                    "  unit="PSU"      />
          <field id="ttbl"         long_name="temperature in the Losh tbl                 "  unit="C"        />
          <field id="utbl"         long_name="zonal current in the Losh tbl at T point    "  unit="m/s"      />
@@ -238,5 +239,6 @@
          <field id="calving_cea"  long_name="Calving"                                   standard_name="water_flux_into_sea_water_from_icebergs"   unit="kg/m2/s"  />
          <field id="iceberg_cea"  long_name="Iceberg"                                   standard_name="water_flux_into_sea_water_from_icebergs"   unit="kg/m2/s"  />
-         <field id="iceshelf_cea"  long_name="Iceshelf"                                   standard_name="water_flux_into_sea_water_from_iceshelf"   unit="kg/m2/s"  />
+         <field id="iceshelf_cea" long_name="Iceshelf"                                  standard_name="water_flux_into_sea_water_from_iceshelf"   unit="kg/m2/s"  />
+
 
          <!-- available if key_oasis3 + conservative method -->
@@ -253,5 +255,7 @@
          <field id="hflx_ice_cea"  long_name="heat flux due to ice thermodynamics"                      standard_name="heat_flux_into_sea_water_due_to_sea_ice_thermodynamics"                        unit="W/m2"     />
          <field id="hflx_rnf_cea"  long_name="heat flux due to runoffs"                                 standard_name="temperature_flux_due_to_runoff_expressed_as_heat_flux_into_sea_water"          unit="W/m2"     />
-         <field id="hflx_cal_cea"  long_name="heat flux due to calving"                                 standard_name="heat_flux_into_sea_water_due_to_iceberg_thermodynamics"                        unit="W/m2"     />
+         <field id="hflx_cal_cea"  long_name="heat flux due to calving"                                 standard_name="heat_flux_into_sea_water_due_to_calving"                                       unit="W/m2"     />
+         <field id="hflx_icb_cea"  long_name="heat flux due to iceberg"                                 standard_name="heat_flux_into_sea_water_due_to_icebergs"                                      unit="W/m2"     />
+         <field id="hflx_isf_cea"  long_name="heat flux due to iceshelf"                                standard_name="heat_flux_into_sea_water_due_to_iceshelf"                                      unit="W/m2"     />
          <field id="bicemel_cea"   long_name="Rate of Melt at Sea Ice Base (cell average)"              standard_name="tendency_of_sea_ice_amount_due_to_basal_melting"                               unit="kg/m2/s"  />
          <field id="licepro_cea"   long_name="Lateral Sea Ice Growth Rate (cell average)"               standard_name="tendency_of_sea_ice_amount_due_to_lateral_growth_of_ice_floes"                 unit="kg/m2/s"  />
@@ -559,6 +563,19 @@
     -->
 
-    <field_group id="trendT" grid_ref="grid_T_3D">
-       <!-- variables available with ln_tra_trd -->
+   <!-- variables available with ln_tra_trd -->
+   <!-- Asselin trends  calculated on odd time steps-->
+   <field_group id="trendT_odd"  grid_ref="grid_T_3D">
+      <field id="ttrd_atf"      long_name="temperature-trend: asselin time filter"       unit="degree_C/s" />
+      <field id="strd_atf"      long_name="salinity   -trend: asselin time filter"       unit="0.001/s" />
+      <!-- Thickness weighted versions: -->
+      <field id="ttrd_atf_e3t"      unit="degC/s * m"  >  ttrd_atf * e3t </field>
+      <field id="strd_atf_e3t"      unit="1e-3/s * m"  >  strd_atf * e3t </field>
+      <!-- OMIP  layer-integrated trends -->
+      <field id="ttrd_atf_li"      long_name="layer integrated heat-trend: asselin time filter "       unit="W/m^2" > ttrd_atf_e3t * 1026.0 * 3991.86795711963  </field>
+      <field id="strd_atf_li"      long_name="layer integrated salt   -trend: asselin time filter "       unit="kg/(m^2 s)" > strd_atf_e3t * 1026.0 * 0.001 </field>
+    </field_group>
+
+    <!-- Other trends  calculated on even time steps-->
+    <field_group id="trendT_even" grid_ref="grid_T_3D">
        <field id="ttrd_xad"      long_name="temperature-trend: i-advection"                                                                                          unit="degC/s"                        />
        <field id="strd_xad"      long_name="salinity   -trend: i-advection"                                                                                          unit="1e-3/s"                        />
@@ -593,12 +610,8 @@
        <field id="ttrd_npc"      long_name="temperature-trend: non-penetrative conv."     unit="degC/s" />
        <field id="strd_npc"      long_name="salinity   -trend: non-penetrative conv."     unit="1e-3/s" />
-       <field id="ttrd_qns"      long_name="temperature-trend: non-solar flux + runoff"   unit="degC/s" />
-       <field id="strd_cdt"      long_name="salinity   -trend: C/D term       + runoff"   unit="degC/s" />
+       <field id="ttrd_qns"      long_name="temperature-trend: non-solar flux + runoff"   unit="degC/s" grid_ref="grid_T_2D" />
+       <field id="strd_cdt"      long_name="salinity   -trend: C/D term       + runoff"   unit="degC/s" grid_ref="grid_T_2D" />
        <field id="ttrd_qsr"      long_name="temperature-trend: solar penetr. heating"     unit="degC/s" />
        <field id="ttrd_bbc"      long_name="temperature-trend: geothermal heating"        unit="degC/s" />
-       <field id="ttrd_atf"      long_name="temperature-trend: asselin time filter"       unit="degC/s" />
-       <field id="strd_atf"      long_name="salinity   -trend: asselin time filter"       unit="1e-3/s" />
-       <field id="ttrd_tot"      long_name="temperature-trend: total model trend"         unit="degC/s" />
-       <field id="strd_tot"      long_name="salinity   -trend: total model trend"         unit="1e-3/s" />
 
        <!-- Thickness weighted versions: -->
@@ -637,10 +650,35 @@
        <field id="ttrd_qsr_e3t"      unit="degC/s * m"  >  ttrd_qsr * e3t </field>
        <field id="ttrd_bbc_e3t"      unit="degC/s * m"  >  ttrd_bbc * e3t </field>
-       <field id="ttrd_atf_e3t"      unit="degC/s * m"  >  ttrd_atf * e3t </field>
-       <field id="strd_atf_e3t"      unit="1e-3/s * m"  >  strd_atf * e3t </field>
+
+       <!-- OMIP  layer-integrated trends -->
+       <field id="ttrd_totad_li"    long_name="layer integrated heat-trend : total advection"       unit="W/m^2"     > ttrd_totad_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_totad_li"    long_name="layer integrated salt   -trend : total advection"      unit="kg/(m^2 s)"    > strd_totad_e3t * 1026.0 * 0.001  </field>
+       <field id="ttrd_evd_li"      long_name="layer integrated heat-trend : EVD convection"         unit="W/m^2"    > ttrd_evd_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_evd_li"      long_name="layer integrated salt   -trend : EVD convection"      unit="kg/(m^2 s)"  > strd_evd_e3t * 1026.0 * 0.001  </field>
+       <field id="ttrd_iso_li"      long_name="layer integrated heat-trend : isopycnal diffusion"    unit="W/m^2" > ttrd_iso_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_iso_li"      long_name="layer integrated salt   -trend : isopycnal diffusion"   unit="kg/(m^2 s)" > strd_iso_e3t * 1026.0 * 0.001  </field>
+       <field id="ttrd_zdfp_li"     long_name="layer integrated heat-trend : pure vert. diffusion"   unit="W/m^2" > ttrd_zdfp_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_zdfp_li"     long_name="layer integrated salt   -trend : pure vert. diffusion"   unit="kg/(m^2 s)" > strd_zdfp_e3t * 1026.0 * 0.001  </field>
+       <field id="ttrd_qns_li"      long_name="layer integrated heat-trend : non-solar flux + runoff"   unit="W/m^2" grid_ref="grid_T_2D"> ttrd_qns_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="ttrd_qsr_li"      long_name="layer integrated heat-trend : solar flux"   unit="W/m^2"  grid_ref="grid_T_3D"> ttrd_qsr_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="ttrd_bbl_li"      long_name="layer integrated heat-trend: bottom boundary layer "     unit="W/m^2" > ttrd_bbl_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_bbl_li"      long_name="layer integrated salt   -trend: bottom boundary layer "     unit="kg/(m^2 s)" > strd_bbl_e3t * 1026.0 * 0.001  </field>
+       <field id="ttrd_evd_li"      long_name="layer integrated heat -trend: evd convection "       unit="W/m^2" >ttrd_evd_e3t * 1026.0 * 3991.86795711963  </field>
+       <field id="strd_evd_li"      long_name="layer integrated salt -trend: evd convection "       unit="kg/(m^2 s)" > strd_evd_e3t * 1026.0 * 0.001  </field>
+
+    </field_group>
+
+    <!--  Total trends calculated every time step-->
+    <field_group id="trendT" grid_ref="grid_T_3D">
+       <field id="ttrd_tot"      long_name="temperature-trend: total model trend"         unit="degC/s" />
+       <field id="strd_tot"      long_name="salinity   -trend: total model trend"         unit="1e-3/s" />
+       <!-- Thickness weighted versions: -->
        <field id="ttrd_tot_e3t"      unit="degC/s * m"  >  ttrd_tot * e3t </field>
        <field id="strd_tot_e3t"      unit="1e-3/s * m"  >  strd_tot * e3t </field>
-
-
+       <!-- OMIP  layer-integrated total trends -->
+       <field id="ttrd_tot_li"      long_name="layer integrated heat-trend: total model trend :"         unit="W/m^2" > ttrd_tot_e3t * 1026.0 * 3991.86795711963 </field>
+       <field id="strd_tot_li"      long_name="layer integrated salt   -trend: total model trend :"         unit="kg/(m^2 s)" > strd_tot_e3t * 1026.0 * 0.001  </field>
+
+       <!-- **** these trends have not been apportioned to all/even/odd ts yet **** -->
        <!-- variables available with ln_KE_trd -->
        <field id="ketrd_hpg"     long_name="ke-trend: hydrostatic pressure gradient"          unit="W/s^3"                        />
@@ -733,4 +771,17 @@
     -->
 
+     <field_group id="TRD" >
+          <field field_ref="ttrd_totad_li"   name="opottempadvect"  />
+          <field field_ref="ttrd_iso_li"     name="opottemppmdiff"  />
+          <field field_ref="ttrd_zdfp_li"    name="opottempdiff"  />
+          <field field_ref="ttrd_evd_li"     name="opottempevd" />
+          <field field_ref="strd_evd_li"     name="osaltevd" />
+          <field field_ref="ttrd_qns_li"     name="opottempqns"  />
+          <field field_ref="ttrd_qsr_li"     name="rsdoabsorb" operation="accumulate" />
+          <field field_ref="strd_totad_li"   name="osaltadvect" />
+          <field field_ref="strd_iso_li"     name="osaltpmdiff"  />
+          <field field_ref="strd_zdfp_li"    name="osaltdiff" />
+    </field_group>
+    
     <field_group id="mooring" >
        <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"      />
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 8841)
@@ -59,5 +59,4 @@
 !!======================================================================
 !!   namcfg       parameters of the configuration
-!!   namzgr       vertical coordinate                                   (default: NO selection)
 !!   namdom       space and time domain (bathymetry, mesh, timestep)
 !!   namwad       Wetting and drying                                    (default F)
@@ -1125,14 +1124,4 @@
 /
 !-----------------------------------------------------------------------
-&namnc4        !   netcdf4 chunking and compression settings            ("key_netcdf4")
-!-----------------------------------------------------------------------
-   ln_diatmb   = .false.   !  Choose Top Middle and Bottom output or not
-/
-!-----------------------------------------------------------------------
-&nam_dia25h    !  25h Mean Output                                        (default F)
-!-----------------------------------------------------------------------
-   ln_dia25h   = .false.   ! Choose 25h mean output or not
-/
-!-----------------------------------------------------------------------
 &namnc4        !   netcdf4 chunking and compression settings             ("key_netcdf4")
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/EXP00/namelist_cfg	(revision 8841)
@@ -5,7 +5,5 @@
 &namusr_def    !   ISOMIP user defined namelist  
 !-----------------------------------------------------------------------
-   ln_zco      = .false.      ! z-coordinate
    ln_zps      = .true.       ! z-partial-step coordinate
-   ln_sco      = .false.      ! s-coordinate
    rn_lam0     =   0.0        !  longitude of first raw and column T-point (jphgr_msh = 1)
    rn_phi0     = -80.0        ! latitude  of first raw and column T-point (jphgr_msh = 1)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_hgr.F90	(revision 8841)
@@ -94,4 +94,5 @@
             pphiv(ji,jj) = rn_phi0 + rn_e2deg * zvj
             pphif(ji,jj) = rn_phi0 + rn_e2deg * zfj
+     !                       !==  Horizontal scale factors  ==!   (in meters)
      ! e1
             pe1t(ji,jj) = ra * rad * COS( rad * pphit(ji,jj) ) * rn_e1deg
@@ -106,6 +107,16 @@
          END DO
       END DO
+      !                             ! NO reduction of grid size in some straits 
+      ke1e2u_v = 0                  !    ==>> u_ & v_surfaces will be computed in dom_ghr routine
+      pe1e2u(:,:) = 0._wp           !    CAUTION: set to zero to avoid error with some compilers that
+      pe1e2v(:,:) = 0._wp           !             require an initialization of INTENT(out) arguments
       !
-      kff = 0 ! Coriolis parameter calculated on the sphere
+      !
+      !                       !==  Coriolis parameter  ==!
+      kff = 0                       ! Coriolis parameter calculated on the sphere
+      !
+      !
+      pff_f(:,:) = 0._wp            ! CAUTION: set to zero to avoid error with some compilers that
+      pff_t(:,:) = 0._wp            !             require an initialization of INTENT(out) arguments
       !
       IF( nn_timing == 1 )  CALL timing_stop('usr_def_hgr')
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_zgr.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_zgr.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_zgr.F90	(revision 8841)
@@ -80,6 +80,9 @@
       ! type of vertical coordinate
       ! ---------------------------
-      ! already set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
-      ld_isfcav = .TRUE.
+      ! set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
+      ln_zco    = .FALSE.      ! z-partial-step coordinate
+      ln_zps    = .TRUE.       ! z-partial-step coordinate
+      ln_sco    = .FALSE.      ! s-coordinate
+      ld_isfcav = .TRUE.       ! ISF Ice Shelves Flag
       !
       !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/file_def_nemo-opa.xml
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/file_def_nemo-opa.xml	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/LOCK_EXCHANGE/EXP00/file_def_nemo-opa.xml	(revision 8841)
@@ -8,5 +8,5 @@
     -->
     
-    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    <file_definition type="multiple_file" name="@expname@" sync_freq="10d" min_digits="4">
       <file_group id="30mi" output_freq="30mi"  output_level="10" enabled=".TRUE." >  <!-- 5d files -->  
  
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/file_def_nemo-opa.xml
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/file_def_nemo-opa.xml	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/file_def_nemo-opa.xml	(revision 8841)
@@ -8,5 +8,5 @@
     -->
     
-    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    <file_definition type="multiple_file" name="@expname@" sync_freq="10d" min_digits="4">
       <file_group id="30mi" output_freq="30mi"  output_level="10" enabled=".TRUE." >  <!-- 5d files -->  
  
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_cfg	(revision 8841)
@@ -78,9 +78,8 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
-   ln_eos80    = .true.          !  = Use EOS80 equation of state
+   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
    !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
+   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
+   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
    rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
    rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_sco_FCT2_flux_ubs_cfg	(revision 8841)
@@ -78,9 +78,8 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
-   ln_eos80    = .true.          !  = Use EOS80 equation of state
+   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
    !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
+   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
+   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
    rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
    rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT2_flux_ubs_cfg	(revision 8841)
@@ -78,9 +78,8 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
-   ln_eos80    = .true.          !  = Use EOS80 equation of state
+   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
    !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
+   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
+   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
    rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
    rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_flux_ubs_cfg	(revision 8841)
@@ -78,9 +78,8 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
-   ln_eos80    = .true.          !  = Use EOS80 equation of state
+   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
    !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
+   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
+   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
    rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
    rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/OVERFLOW/EXP00/namelist_zps_FCT4_vect_een_cfg	(revision 8841)
@@ -78,9 +78,8 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
-   ln_eos80    = .true.          !  = Use EOS80 equation of state
+   ln_seos     = .true.         !  = Use simplified equation of state (S-EOS)
    !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
-   rn_a0       =  0.2         !  thermal expension coefficient (nn_eos= 1)
-   rn_b0       =  0.          !  saline  expension coefficient (nn_eos= 1)
+   rn_a0       =  0.2         !  thermal expension coefficient (for simplified equation of state)
+   rn_b0       =  0.          !  saline  expension coefficient (for simplified equation of state)
    rn_lambda1  =  0.          !  cabbeling coeff in T^2  (=0 for linear eos)
    rn_lambda2  =  0.          !  cabbeling coeff in S^2  (=0 for linear eos)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/TEST_CASES/SAS_BIPER/EXP00/namelist_cfg	(revision 8841)
@@ -26,5 +26,5 @@
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
-   ln_linssh   = .false.   !  =T  linear free surface  ==>>  model level are fixed in time
+   ln_linssh   = .true.   !  =T  linear free surface  ==>>  model level are fixed in time
    !
    nn_msh      =    1      !  create (>0) a mesh file or not (=0)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/makenemo
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/makenemo	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/CONFIG/makenemo	(revision 8841)
@@ -63,5 +63,5 @@
 # ::
 #
-#  $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM
+#  $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM3_PISCES
 #
 #
@@ -221,5 +221,5 @@
 	*)
 	    echo " \"$1\" BAD OPTION"
-	    exit
+	    exit 2
 	    ;;
 
@@ -267,10 +267,10 @@
 #-
 #- Choose a default configuration if needed ---
-#- ORCA2_LIM or last one used ---
+#- ORCA2_LIM3_PISCES or last one used ---
 . ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
 
 if [ ${#NEW_CONF} -eq 0 ] ; then
     if [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -eq 0 ] && [ ${#USP_CONF} -eq 0 ] ; then
-	echo "You are installing a new default (ORCA2_LIM) configuration"
+	echo "You are installing a new default (ORCA2_LIM3_PISCES) configuration"
 	ind=0
 	. ${COMPIL_DIR}/Fread_dir.sh OPA_SRC	 YES
@@ -280,9 +280,11 @@
 	. ${COMPIL_DIR}/Fread_dir.sh NST_SRC	 YES
 	. ${COMPIL_DIR}/Fread_dir.sh OFF_SRC	 NO
-	REF_CONF=ORCA2_LIM
+	. ${COMPIL_DIR}/Fread_dir.sh SAO_SRC	 NO
+	. ${COMPIL_DIR}/Fread_dir.sh SAS_SRC	 NO
+	REF_CONF=ORCA2_LIM3_PISCES
     elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ] && [ ${#USP_CONF} -eq 0 ] ; then
-	echo "You are  installing a new configuration based on ORCA2_LIM"
+	echo "You are  installing a new configuration based on ORCA2_LIM3_PISCES"
 	TAB=( ${NEM_SUBDIR} )
-	REF_CONF=ORCA2_LIM
+	REF_CONF=ORCA2_LIM3_PISCES
     elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
 	echo "You are  installing a new configuration based on ${REF_CONF}"
@@ -320,7 +322,7 @@
 #- Clean links and librairies ---
 #- Creating the good links, at first on OPA_SRC ---
-. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit
-
-. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
+. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit 3
+
+. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit 3
 
 # build the complete list of the cpp keys of this configuration
@@ -360,5 +362,5 @@
 #- At this stage cpp keys have been updated. we can check the arch file
 #- When used for the first time, choose a compiler ---
-. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit
+. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit 3
 
 #- At this stage the configuration has beeen chosen
@@ -368,5 +370,5 @@
 #- We look after agrif
 grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
-. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
+. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit 3
 
 #-
@@ -383,5 +385,5 @@
     if [ ${#x_c} -eq 0 ]; then
        if [ "$AGRIFUSE" == 1 ]; then 
-          fcm build --ignore-lock  -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit ;}
+          fcm build --ignore-lock  -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit 1 ;}
           echo ""
           echo "---------------------------------"
@@ -391,5 +393,5 @@
        fi
     fi
-    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
+    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD ||{ cd - ; exit 1 ;}
     [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/opa
 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/LIM_SRC_3/limthd.F90	(revision 8841)
@@ -205,6 +205,9 @@
       IF( .NOT. ln_limdO )  qlead(:,:) = 0._wp
       ! In case we bypass growing/melting from top and bottom: we suppose ice is impermeable => ocean is isolated from atmosphere
-      IF( .NOT. ln_limdH )  hfx_in(:,:) = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
-      IF( .NOT. ln_limdH )  fhtur (:,:) = 0._wp  ;  fhld  (:,:) = 0._wp
+      IF( .NOT. ln_limdH ) THEN
+         hfx_in(:,:) = pfrld(:,:) * ( qns_oce(:,:) + qsr_oce(:,:) ) + qemp_oce(:,:)
+         fhtur (:,:) = 0._wp
+         fhld  (:,:) = 0._wp
+      ENDIF
 
       ! ---------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90	(revision 8841)
@@ -548,39 +548,39 @@
 
       ! Find the factors of n.
-      IF( kn == 1 )   GOTO 20
-
-      ! nu holds the unfactorised part of the number.
-      ! knfax holds the number of factors found.
-      ! l points to the allowed factor list.
-      ! ifac holds the current factor.
-
-      inu   = kn
-      knfax = 0
-
-      DO jl = ntest, 1, -1
-         !
-         ifac = ilfax(jl)
-         IF( ifac > inu )   CYCLE
-
-         ! Test whether the factor will divide.
-
-         IF( MOD(inu,ifac) == 0 ) THEN
+      IF( kn .NE. 1 ) THEN
+
+         ! nu holds the unfactorised part of the number.
+         ! knfax holds the number of factors found.
+         ! l points to the allowed factor list.
+         ! ifac holds the current factor.
+   
+         inu   = kn
+         knfax = 0
+   
+         DO jl = ntest, 1, -1
             !
-            knfax = knfax + 1            ! Add the factor to the list
-            IF( knfax > kmaxfax ) THEN
-               kerr = 6
-               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
-               return
+            ifac = ilfax(jl)
+            IF( ifac > inu )   CYCLE
+   
+            ! Test whether the factor will divide.
+   
+            IF( MOD(inu,ifac) == 0 ) THEN
+               !
+               knfax = knfax + 1            ! Add the factor to the list
+               IF( knfax > kmaxfax ) THEN
+                  kerr = 6
+                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+                  return
+               ENDIF
+               kfax(knfax) = ifac
+               ! Store the other factor that goes with this one
+               knfax = knfax + 1
+               kfax(knfax) = inu / ifac
+               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
             ENDIF
-            kfax(knfax) = ifac
-            ! Store the other factor that goes with this one
-            knfax = knfax + 1
-            kfax(knfax) = inu / ifac
-            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
-         ENDIF
-         !
-      END DO
-
-   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+            !
+         END DO
+   
+      ENDIF
       !
    END SUBROUTINE factorise
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 8841)
@@ -86,4 +86,7 @@
    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ssh_bkg, ssh_bkginc   ! Background sea surface height and its increment
    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   seaice_bkginc         ! Increment to the background sea ice conc
+#if defined key_cice && defined key_asminc
+   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ndaice_da             ! ice increment tendency into CICE
+#endif
 
    !! * Substitutions
@@ -339,4 +342,7 @@
       ALLOCATE( ssh_iau(jpi,jpj)      )
 #endif
+#if defined key_cice && defined key_asminc
+      ALLOCATE( ndaice_da(jpi,jpj)      )
+#endif
       t_bkginc(:,:,:) = 0.0
       s_bkginc(:,:,:) = 0.0
@@ -347,4 +353,7 @@
 #if defined key_asminc
       ssh_iau(:,:)    = 0.0
+#endif
+#if defined key_cice && defined key_asminc
+      ndaice_da(:,:) = 0.0
 #endif
       IF ( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ).OR.( ln_seaiceinc ) ) THEN
@@ -759,4 +768,10 @@
             ENDIF
             !
+#if defined key_asminc
+         ELSE IF( kt == nitiaufin_r+1 ) THEN
+            !
+            ssh_iau(:,:) = 0._wp
+            !
+#endif
          ENDIF
          !                          !-----------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/BDY/bdydta.F90	(revision 8841)
@@ -266,5 +266,6 @@
                         IF( ln_full_vel_array(ib_bdy) ) THEN
                            CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
-                                     & kit=jit, kt_offset=time_offset , jpk_bdy=nb_jpk_bdy, fvl=ln_full_vel_array(ib_bdy)  )
+                                     & kit=jit, kt_offset=time_offset , jpk_bdy=nb_jpk_bdy,   &
+                                     & fvl=ln_full_vel_array(ib_bdy)  )
                         ELSE
                            CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), map=nbmap_ptr(jstart:jend),  &
@@ -335,5 +336,6 @@
                      jend = jstart + dta%nread(1) - 1
                      CALL fld_read( kt=kt, kn_fsbc=1, sd=bf(jstart:jend), &
-                                  & map=nbmap_ptr(jstart:jend), kt_offset=time_offset, jpk_bdy=nb_jpk_bdy, fvl=ln_full_vel_array(ib_bdy) )
+                                  & map=nbmap_ptr(jstart:jend), kt_offset=time_offset, jpk_bdy=nb_jpk_bdy,   &
+                                  & fvl=ln_full_vel_array(ib_bdy) )
                   ENDIF
                   ! If full velocities in boundary data then split into barotropic and baroclinic data
@@ -443,5 +445,4 @@
       TYPE(OBC_DATA), POINTER                ::   dta           ! short cut
 #if defined key_lim3
-      INTEGER, DIMENSION(3) ::   zdimsz   ! number of elements in each of the 4 dimensions (i.e. i,j,t,ice-cat) for an array
       INTEGER               ::   zndims   ! number of dimensions in an array (i.e. 3 = wo ice cat; 4 = w ice cat)
       INTEGER               ::   inum,id1 ! local integer
@@ -675,16 +676,16 @@
                ! Test for types of ice input (lim2 or lim3) 
                ! Build file name to find dimensions 
-               clname=TRIM(bn_a_i%clname)
+               clname=TRIM( cn_dir )//TRIM(bn_a_i%clname)
                IF( .NOT. bn_a_i%ln_clim ) THEN   
-                                                  WRITE(clname, '(a,"_y",i4.4)' ) TRIM( bn_a_i%clname ), nyear    ! add year
-                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"m" ,i2.2)' ) TRIM( clname        ), nmonth   ! add month
+                                                  WRITE(clname, '(a,"_y",i4.4)' ) TRIM( clname ), nyear    ! add year
+                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"m" ,i2.2)' ) TRIM( clname ), nmonth   ! add month
                ELSE
-                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"_m",i2.2)' ) TRIM( bn_a_i%clname ), nmonth   ! add month
+                  IF( bn_a_i%cltype /= 'yearly' ) WRITE(clname, '(a,"_m",i2.2)' ) TRIM( clname ), nmonth   ! add month
                ENDIF
                IF( bn_a_i%cltype == 'daily' .OR. bn_a_i%cltype(1:4) == 'week' ) &
-               &                                  WRITE(clname, '(a,"d" ,i2.2)' ) TRIM( clname        ), nday     ! add day
+               &                                  WRITE(clname, '(a,"d" ,i2.2)' ) TRIM( clname ), nday     ! add day
                !
                CALL iom_open  ( clname, inum )
-               id1 = iom_varid( inum, bn_a_i%clvar, kdimsz=zdimsz, kndims=zndims, ldstop = .FALSE. )
+               id1 = iom_varid( inum, bn_a_i%clvar, kndims=zndims, ldstop = .FALSE. )
                CALL iom_close ( inum )
 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90	(revision 8841)
@@ -316,5 +316,6 @@
 #endif
             cnt_25h = 1
-            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
+            IF (lwp)  WRITE(numout,*) 'dia_wri_tide :   &
+        &    After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
 
       ENDIF !  cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps * 24) == 0 .AND. kt .NE. nn_it000
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 8841)
@@ -212,35 +212,36 @@
       ! Exclude points where rn2 is negative as convection kicks in here and
       ! work is not being done against stratification
-          CALL wrk_alloc( jpi, jpj, zpe )
-          zpe(:,:) = 0._wp
-          IF( lk_zdfddm ) THEN
-             DO ji=1,jpi
-                DO jj=1,jpj
-                   DO jk=1,jpk
-                      zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
-                         &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) )
-                      !
-                      zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
-                      zbw = rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal)* zrw
-                      !
-                      zpe(ji, jj) = zpe(ji, jj) - MIN(0._wp, rn2(ji,jj,jk)) * &
-                           &       grav * (avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
-                           &       - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
-
-                   ENDDO
-                ENDDO
-             ENDDO
+         CALL wrk_alloc( jpi, jpj, zpe )
+         zpe(:,:) = 0._wp
+         IF( lk_zdfddm ) THEN
+            DO jk = 2, jpk
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( rn2(ji,jj,jk) > 0._wp ) THEN
+                        zrw =   ( gdepw_n(ji,jj,jk  ) - gdept_n(ji,jj,jk) )   &
+                           &  / ( gdept_n(ji,jj,jk-1) - gdept_n(ji,jj,jk) )
+                        !
+                        zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
+                        zbw = rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal)* zrw
+                        !
+                        zpe(ji, jj) = zpe(ji, jj)            &
+                           &        -  grav * (    avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
+                           &                   - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
+                     ENDIF
+                  END DO
+               END DO
+             END DO
           ELSE
-             DO ji = 1, jpi
-                DO jj = 1, jpj
-                   DO jk = 1, jpk
-                       zpe(ji,jj) = zpe(ji,jj) + avt(ji, jj, jk) * MIN(0._wp,rn2(ji, jj, jk)) * rau0 * e3w_n(ji, jj, jk)
-                   ENDDO
-                ENDDO
-             ENDDO
-          ENDIF
-          CALL lbc_lnk( zpe, 'T', 1._wp)         
-          CALL iom_put( 'tnpeo', zpe )
-          CALL wrk_dealloc( jpi, jpj, zpe )
+            DO jk = 1, jpk
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+                     zpe(ji,jj) = zpe(ji,jj) + avt(ji, jj, jk) * MIN(0._wp,rn2(ji, jj, jk)) * rau0 * e3w_n(ji, jj, jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         CALL lbc_lnk( zpe, 'T', 1._wp)         
+         CALL iom_put( 'tnpeo', zpe )
+         CALL wrk_dealloc( jpi, jpj, zpe )
       ENDIF
       !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diacfl.F90	(revision 8841)
@@ -151,9 +151,12 @@
             WRITE(numout,*) 'dia_cfl     : Maximum Courant number information for the run:'
             WRITE(numout,*) '~~~~~~~~~~~~'
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) = (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cu', cu_max, 'at (i, j, k) =   &
+                          &   (', cu_loc(1), cu_loc(2), cu_loc(3), ')'
             WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cu_max)
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) = (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cv', cv_max, 'at (i, j, k) =   &
+                          &   (', cv_loc(1), cv_loc(2), cv_loc(3), ')'
             WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cv_max)
-            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) = (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
+            WRITE(numout,FMT='(12x,a12,7x,f6.4,5x,a16,i4,1x,i4,1x,i4,a1)') 'Run Max Cw', cw_max, 'at (i, j, k) =   &
+                          &   (', cw_loc(1), cw_loc(2), cw_loc(3), ')'
             WRITE(numout,FMT='(12x,a8,11x,f7.1)') ' => dt/C', dt*(1.0/cw_max)
 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 8841)
@@ -240,5 +240,5 @@
            !debug this section computing ?
            lldebug=.FALSE.
-           IF( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND.  kt==nit000+nn_dct-1 .AND. lwp ) lldebug=.TRUE. 
+           IF( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND.  kt==nit000+nn_dct-1 ) lldebug=.TRUE. 
 
            !Compute transport through section  
@@ -249,5 +249,5 @@
         IF( MOD(kt,nn_dctwri)==0 )THEN
 
-           IF( lwp .AND. kt==nit000+nn_dctwri-1 )WRITE(numout,*)"      diadct: average transports and write at kt = ",kt         
+           IF( kt==nit000+nn_dctwri-1 )WRITE(numout,*)"      diadct: average transports and write at kt = ",kt         
   
            !! divide arrays by nn_dctwri/nn_dct to obtain average 
@@ -335,5 +335,5 @@
      DO jsec=1,nb_sec_max      !loop on the nb_sec sections
 
-        IF ( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) ) &
+        IF (  jsec==nn_secdebug .OR. nn_secdebug==-1  ) &
            & WRITE(numout,*)'debuging for section number: ',jsec 
 
@@ -355,5 +355,5 @@
         IF( jsec .NE. isec )  CALL ctl_stop( cltmp )
 
-        IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )WRITE(numout,*)"isec ",isec 
+        IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )WRITE(numout,*)"isec ",isec 
 
         READ(numdct_in)secs(jsec)%name
@@ -374,5 +374,5 @@
         !-----
 
-        IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+        IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
           
             WRITE(clformat,'(a,i2,a)') '(A40,', nb_class_max,'(f8.3,1X))' 
@@ -407,5 +407,5 @@
            !debug
            !-----
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points in global domain:"
               DO jpt=1,iptglo
@@ -441,5 +441,5 @@
            !debug
            !-----
-           IF(   lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points selected by the proc:"
               DO jpt = 1,iptloc
@@ -459,5 +459,5 @@
            !remove redundant points between processors
            !------------------------------------------
-           lldebug = .FALSE. ; IF ( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND. lwp ) lldebug = .TRUE.
+           lldebug = .FALSE. ; IF ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) lldebug = .TRUE.
            IF( iptloc .NE. 0 )THEN
               CALL removepoints(secs(jsec),'I','top_list',lldebug)
@@ -475,5 +475,5 @@
            !debug
            !-----
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points after removepoints:"
               iptloc = secs(jsec)%nb_point
@@ -487,5 +487,5 @@
 
         ELSE  ! iptglo = 0
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )&
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )&
               WRITE(numout,*)'   No points for this section.'
         ENDIF
@@ -695,5 +695,5 @@
             !     LOOP ON THE LEVEL     | 
             !---------------------------| 
-            DO jk = 1, mbathy(k%I,k%J)            !Sum of the transport on the vertical
+            DO jk = 1, mbkt(k%I,k%J)            !Sum of the transport on the vertical
             !           ! compute temperature, salinity, insitu & potential density, ssh and depth at U/V point 
             SELECT CASE( sec%direction(jseg) )
@@ -874,5 +874,5 @@
            !---------------------------| 
            !Sum of the transport on the vertical  
-           DO jk=1,mbathy(k%I,k%J) 
+           DO jk=1,mbkt(k%I,k%J) 
  
               ! compute temperature, salinity, insitu & potential density, ssh and depth at U/V point 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 8841)
@@ -282,15 +282,15 @@
       !
       IF ( iom_use("eken") ) THEN
-         rke(:,:,jk) = 0._wp                               !      kinetic energy 
+         rke(:,:,jpk) = 0._wp                               !      kinetic energy 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zztmp   = 1._wp / ( e1e2t(ji,jj) * e3t_n(ji,jj,jk) )
-                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)    &
-                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) )  &
+                  zztmp   = r1_e1e2t(ji,jj) / e3t_n(ji,jj,jk)
+                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e1e2u(ji-1,jj) * e3u_n(ji-1,jj,jk)    &
+                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e1e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) )  &
                      &          *  zztmp 
                   !
-                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * e3v_n(ji,jj-1,jk)    &
-                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) )  &
+                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1e2v(ji,jj-1) * e3v_n(ji,jj-1,jk)    &
+                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1e2v(ji,jj  ) * e3v_n(ji,jj  ,jk) )  &
                      &          *  zztmp 
                   !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 8841)
@@ -134,5 +134,6 @@
 
       ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')   &
+           &                   ' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
            &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  &
            &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 8841)
@@ -124,5 +124,5 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
    !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   ff_f, ff_t                      !: coriolis factor at f- and t-point         [1/s]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   ff_f, ff_t                      !: Coriolis factor at f- & t-points  [1/s]
    !!----------------------------------------------------------------------
    !! vertical coordinate and scale factors
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DOM/iscplrst.F90	(revision 8841)
@@ -219,5 +219,6 @@
                DO ji=1,jpi
                   IF (tmask(ji,jj,1) == 0._wp .OR. ptmask_b(ji,jj,1) == 0._wp) THEN
-                     e3t_n(ji,jj,jk) = e3t_0(ji,jj,jk) * ( 1._wp + sshn(ji,jj) / ( ht_0(ji,jj) + 1._wp - ssmask(ji,jj) ) * tmask(ji,jj,jk) )
+                     e3t_n(ji,jj,jk) = e3t_0(ji,jj,jk) * ( 1._wp + sshn(ji,jj) /   &
+                     &   ( ht_0(ji,jj) + 1._wp - ssmask(ji,jj) ) * tmask(ji,jj,jk) )
                   ENDIF
                END DO
@@ -390,5 +391,6 @@
             DO jj = 1,jpj
                DO ji = 1,jpi
-                  IF (zwmaskn(ji,jj,jk) * zwmaskb(ji,jj,jk) == 1._wp .AND. (tmask(ji,jj,1)==0._wp .OR. ptmask_b(ji,jj,1)==0._wp) ) THEN
+                  IF (zwmaskn(ji,jj,jk) * zwmaskb(ji,jj,jk) == 1._wp .AND.   &
+                  &      (tmask(ji,jj,1)==0._wp .OR. ptmask_b(ji,jj,1)==0._wp) ) THEN
                      !compute weight
                      zdzp1 = MAX(0._wp,gdepw_n(ji,jj,jk+1) - pdepw_b(ji,jj,jk+1))
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/DYN/dynvor.F90	(revision 8841)
@@ -181,5 +181,5 @@
          ELSE                                               ! total vorticity trend
                              CALL vor_een( kt, ntot, un , vn , ua, va )   ! total vorticity trend
-            IF( ln_stcor )   CALL vor_ene( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
+            IF( ln_stcor )   CALL vor_een( kt, ncor, usd, vsd, ua, va )   ! add the Stokes-Coriolis trend
          ENDIF
          !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ICB/icbtrj.F90	(revision 8841)
@@ -18,4 +18,5 @@
    USE lib_mpp        ! NEMO MPI library, lk_mpp in particular
    USE in_out_manager ! NEMO IO, numout in particular
+   USE ioipsl, ONLY : ju2ymds    ! for calendar
    USE netcdf
    !
@@ -60,11 +61,27 @@
       !
       INTEGER                               :: iret
+      INTEGER                               :: iyear, imonth, iday
+      REAL(wp)                              :: zfjulday, zsec
       CHARACTER(len=80)                     :: cl_filename
       TYPE(iceberg), POINTER                :: this
       TYPE(point)  , POINTER                :: pt
-      !!----------------------------------------------------------------------
-
-      IF( lk_mpp ) THEN   ;   WRITE(cl_filename,'("trajectory_icebergs_",I6.6,"_",I4.4,".nc")') ktend, narea-1
-      ELSE                ;   WRITE(cl_filename,'("trajectory_icebergs_",I6.6         ,".nc")') ktend
+      CHARACTER(LEN=20)                     :: cldate_ini, cldate_end
+      !!----------------------------------------------------------------------
+
+      ! compute initial time step date
+      CALL ju2ymds( fjulday, iyear, imonth, iday, zsec )
+      WRITE(cldate_ini, '(i4.4,2i2.2)') iyear, imonth, iday
+
+      ! compute end time step date
+      zfjulday = fjulday + rdt / rday * REAL( nitend - nit000 + 1 , wp)
+      IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday )   zfjulday = REAL(NINT(zfjulday),wp)   ! avoid truncation error
+      CALL ju2ymds( zfjulday, iyear, imonth, iday, zsec )
+      WRITE(cldate_end, '(i4.4,2i2.2)') iyear, imonth, iday
+
+      ! define trajectory output name
+      IF( lk_mpp ) THEN   ;   WRITE(cl_filename,'("trajectory_icebergs_",A,"-",A,"_",I4.4,".nc")')   &
+                          &   TRIM(ADJUSTL(cldate_ini)), TRIM(ADJUSTL(cldate_end)), narea-1
+      ELSE                ;   WRITE(cl_filename,'("trajectory_icebergs_",A,"-",A         ,".nc")')   &
+                          &   TRIM(ADJUSTL(cldate_ini)), TRIM(ADJUSTL(cldate_end))
       ENDIF
       IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, icb_trj_init: creating ',TRIM(cl_filename)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90	(revision 8841)
@@ -774,7 +774,9 @@
          istart(idmspc+1) = itime
 
-         IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN ; istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
+         IF( PRESENT(kstart) .AND. .NOT. ll_depth_spec ) THEN 
+            istart(1:idmspc) = kstart(1:idmspc) ; icnt(1:idmspc) = kcount(1:idmspc)
          ELSE
-            IF(           idom == jpdom_unknown ) THEN                                                ; icnt(1:idmspc) = idimsz(1:idmspc)
+            IF(idom == jpdom_unknown ) THEN
+               icnt(1:idmspc) = idimsz(1:idmspc)
             ELSE 
                IF( .NOT. PRESENT(pv_r1d) ) THEN   !   not a 1D array
@@ -1540,5 +1542,5 @@
       ALLOCATE( zlon(ni*nj) )       ;       zlon(:) = 0.
 
-      CALL dom_ngb( 180., 90., ix, iy, 'T' ) !  i-line that passes near the North Pole : Reference latitude (used in plots)
+      CALL dom_ngb( -168.53, 65.03, ix, iy, 'T' ) !  i-line that passes through Bering Strait: Reference latitude (used in plots)
       CALL iom_set_domain_attr("gznl", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj)
       CALL iom_set_domain_attr("gznl", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj)
@@ -1595,4 +1597,6 @@
       ! frequency of the call of iom_put (attribut: freq_op)
       f_op%timestep = 1        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('field_definition', freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = 2        ;  f_of%timestep = 0  ; CALL iom_set_field_attr('trendT_even'     , freq_op=f_op, freq_offset=f_of)
+      f_op%timestep = 2        ;  f_of%timestep = -1 ; CALL iom_set_field_attr('trendT_odd'      , freq_op=f_op, freq_offset=f_of)
       f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC'             , freq_op=f_op, freq_offset=f_of)
       f_op%timestep = nn_fsbc  ;  f_of%timestep = 0  ; CALL iom_set_field_attr('SBC_scalar'      , freq_op=f_op, freq_offset=f_of)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 8841)
@@ -235,5 +235,5 @@
 
       !! Look if more arrays to process
-      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dA, cd_typeA, psgnA ) 
+      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dB, cd_typeB, psgnB )
       IF(PRESENT (psgnC) )CALL lbc_lnk( pt2dC, cd_typeC, psgnC ) 
       IF(PRESENT (psgnD) )CALL lbc_lnk( pt2dD, cd_typeD, psgnD ) 
@@ -490,5 +490,5 @@
 
       !! Look if more arrays to process
-      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dA, cd_typeA, psgnA ) 
+      IF(PRESENT (psgnB) )CALL lbc_lnk( pt2dB, cd_typeB, psgnB )
       IF(PRESENT (psgnC) )CALL lbc_lnk( pt2dC, cd_typeC, psgnC ) 
       IF(PRESENT (psgnD) )CALL lbc_lnk( pt2dD, cd_typeD, psgnD ) 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 8841)
@@ -195,6 +195,6 @@
          WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
       ENDIF
-      
-      CALL oasis_def_partition ( id_part, paral, nerror )
+   
+      CALL oasis_def_partition ( id_part, paral, nerror, jpiglo*jpjglo )
       !
       ! ... Announce send variables. 
@@ -514,8 +514,9 @@
    END SUBROUTINE oasis_get_localcomm
 
-   SUBROUTINE oasis_def_partition(k1,k2,k3)
+   SUBROUTINE oasis_def_partition(k1,k2,k3,k4)
       INTEGER     , INTENT(  out) ::  k1,k3
       INTEGER     , INTENT(in   ) ::  k2(5)
-      k1 = k2(1) ; k3 = k2(5)
+      INTEGER     , INTENT(in   ) ::  k4
+      k1 = k2(1) ; k3 = k2(5)+k4
       WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
    END SUBROUTINE oasis_def_partition
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcapr.F90	(revision 8841)
@@ -23,5 +23,6 @@
    PRIVATE
 
-   PUBLIC   sbc_apr    ! routine called in sbcmod
+   PUBLIC   sbc_apr       ! routine called in sbcmod
+   PUBLIC   sbc_apr_init  ! routine called in sbcmod
    
    !                                !!* namsbc_apr namelist (Atmospheric PRessure) *
@@ -46,4 +47,68 @@
 CONTAINS
 
+   SUBROUTINE sbc_apr_init
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE sbc_apr  ***
+      !!
+      !! ** Purpose :   read atmospheric pressure fields in netcdf files.
+      !!
+      !! ** Method  : - Read namelist namsbc_apr
+      !!              - Read Patm fields in netcdf files 
+      !!              - Compute reference atmospheric pressure
+      !!              - Compute inverse barometer ssh
+      !! ** action  :   apr      : atmospheric pressure at kt
+      !!                ssh_ib   : inverse barometer ssh at kt
+      !!---------------------------------------------------------------------
+      INTEGER            ::   ierror  ! local integer 
+      INTEGER            ::   ios     ! Local integer output status for namelist read
+      !!
+      CHARACTER(len=100) ::  cn_dir   ! Root directory for location of ssr files
+      TYPE(FLD_N)        ::  sn_apr   ! informations about the fields to be read
+      !!
+      NAMELIST/namsbc_apr/ cn_dir, sn_apr, ln_ref_apr, rn_pref, ln_apr_obc
+      !!----------------------------------------------------------------------
+      REWIND( numnam_ref )              ! Namelist namsbc_apr in reference namelist : File for atmospheric pressure forcing
+      READ  ( numnam_ref, namsbc_apr, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_apr in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namsbc_apr in configuration namelist : File for atmospheric pressure forcing
+      READ  ( numnam_cfg, namsbc_apr, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_apr in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namsbc_apr )
+      !
+      ALLOCATE( sf_apr(1), STAT=ierror )           !* allocate and fill sf_sst (forcing structure) with sn_sst
+      IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_apr: unable to allocate sf_apr structure' )
+      !
+      CALL fld_fill( sf_apr, (/ sn_apr /), cn_dir, 'sbc_apr', 'Atmospheric pressure ', 'namsbc_apr' )
+                                ALLOCATE( sf_apr(1)%fnow(jpi,jpj,1)   )
+      IF( sn_apr%ln_tint )   ALLOCATE( sf_apr(1)%fdta(jpi,jpj,1,2) )
+                             ALLOCATE( ssh_ib(jpi,jpj) , ssh_ibb(jpi,jpj) )
+                             ALLOCATE( apr (jpi,jpj) )
+      !
+      IF( lwp )THEN                                 !* control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist namsbc_apr : Atmospheric PRessure as extrenal forcing'
+         WRITE(numout,*) '      ref. pressure: global mean Patm (T) or a constant (F)  ln_ref_apr = ', ln_ref_apr
+      ENDIF
+      !
+      IF( ln_ref_apr ) THEN                        !* Compute whole inner domain mean masked ocean surface
+         tarea = glob_sum( e1e2t(:,:) )
+         IF(lwp) WRITE(numout,*) '         Variable ref. Patm computed over a ocean surface of ', tarea*1e-6, 'km2'
+      ELSE
+         IF(lwp) WRITE(numout,*) '         Reference Patm used : ', rn_pref, ' N/m2'
+      ENDIF
+      !
+      r1_grau = 1.e0 / (grav * rau0)               !* constant for optimization
+      !
+      !                                            !* control check
+      IF ( ln_apr_obc  ) THEN
+         IF(lwp) WRITE(numout,*) '         Inverse barometer added to OBC ssh data'
+      ENDIF
+!jc: stop below should rather be a warning 
+      IF( ln_apr_obc .AND. .NOT.ln_apr_dyn   )   &
+            CALL ctl_warn( 'sbc_apr: use inverse barometer ssh at open boundary ONLY requires ln_apr_dyn=T' )
+      !
+   END SUBROUTINE sbc_apr_init
+
    SUBROUTINE sbc_apr( kt )
       !!---------------------------------------------------------------------
@@ -61,57 +126,5 @@
       INTEGER, INTENT(in)::   kt   ! ocean time step
       !
-      INTEGER            ::   ierror  ! local integer 
-      INTEGER            ::   ios     ! Local integer output status for namelist read
-      !!
-      CHARACTER(len=100) ::  cn_dir   ! Root directory for location of ssr files
-      TYPE(FLD_N)        ::  sn_apr   ! informations about the fields to be read
-      !!
-      NAMELIST/namsbc_apr/ cn_dir, sn_apr, ln_ref_apr, rn_pref, ln_apr_obc
       !!----------------------------------------------------------------------
-      !
-      !                                         ! -------------------- !
-      IF( kt == nit000 ) THEN                   ! First call kt=nit000 !
-         !                                      ! -------------------- !
-         REWIND( numnam_ref )              ! Namelist namsbc_apr in reference namelist : File for atmospheric pressure forcing
-         READ  ( numnam_ref, namsbc_apr, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_apr in reference namelist', lwp )
-
-         REWIND( numnam_cfg )              ! Namelist namsbc_apr in configuration namelist : File for atmospheric pressure forcing
-         READ  ( numnam_cfg, namsbc_apr, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_apr in configuration namelist', lwp )
-         IF(lwm) WRITE ( numond, namsbc_apr )
-         !
-         ALLOCATE( sf_apr(1), STAT=ierror )           !* allocate and fill sf_sst (forcing structure) with sn_sst
-         IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_apr: unable to allocate sf_apr structure' )
-         !
-         CALL fld_fill( sf_apr, (/ sn_apr /), cn_dir, 'sbc_apr', 'Atmospheric pressure ', 'namsbc_apr' )
-                                ALLOCATE( sf_apr(1)%fnow(jpi,jpj,1)   )
-         IF( sn_apr%ln_tint )   ALLOCATE( sf_apr(1)%fdta(jpi,jpj,1,2) )
-                                ALLOCATE( ssh_ib(jpi,jpj) , ssh_ibb(jpi,jpj) )
-                                ALLOCATE( apr (jpi,jpj) )
-         !
-         IF(lwp) THEN                                 !* control print
-            WRITE(numout,*)
-            WRITE(numout,*) '   Namelist namsbc_apr : Atmospheric PRessure as extrenal forcing'
-            WRITE(numout,*) '      ref. pressure: global mean Patm (T) or a constant (F)  ln_ref_apr = ', ln_ref_apr
-         ENDIF
-         !
-         IF( ln_ref_apr ) THEN                        !* Compute whole inner domain mean masked ocean surface
-            tarea = glob_sum( e1e2t(:,:) )
-            IF(lwp) WRITE(numout,*) '         Variable ref. Patm computed over a ocean surface of ', tarea*1e-6, 'km2'
-         ELSE
-            IF(lwp) WRITE(numout,*) '         Reference Patm used : ', rn_pref, ' N/m2'
-         ENDIF
-         !
-         r1_grau = 1.e0 / (grav * rau0)               !* constant for optimization
-         !
-         !                                            !* control check
-         IF ( ln_apr_obc  ) THEN
-            IF(lwp) WRITE(numout,*) '         Inverse barometer added to OBC ssh data'
-         ENDIF
-!jc: stop below should rather be a warning 
-         IF( ln_apr_obc .AND. .NOT.ln_apr_dyn   )   &
-            CALL ctl_stop( 'sbc_apr: use inverse barometer ssh at open boundary ONLY requires ln_apr_dyn=T' )
-      ENDIF
 
       !                                         ! ========================== !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcblk.F90	(revision 8841)
@@ -186,5 +186,5 @@
       !                             !** initialization of the chosen bulk formulae (+ check)
       !                                   !* select the bulk chosen in the namelist and check the choice
-      ;                                                        ioptio = 0
+                                                               ioptio = 0
       IF( ln_NCAR      ) THEN   ;   nblk =  np_NCAR        ;   ioptio = ioptio + 1   ;   ENDIF
       IF( ln_COARE_3p0 ) THEN   ;   nblk =  np_COARE_3p0   ;   ioptio = ioptio + 1   ;   ENDIF
@@ -219,4 +219,8 @@
          ALLOCATE( sf(ifpr)%fnow(jpi,jpj,1) )
          IF( slf_i(ifpr)%ln_tint )   ALLOCATE( sf(ifpr)%fdta(jpi,jpj,1,2) )
+
+           IF( slf_i(ifpr)%nfreqh .GT. 0._wp .AND. MOD( 3600._wp * slf_i(ifpr)%nfreqh , REAL(nn_fsbc, wp) * rdt) .NE. 0._wp  )   &
+            &  CALL ctl_warn( 'sbcmod time step rdt * nn_fsbc is NOT a submultiple of atmospheric forcing frequency' )
+
       END DO
       !                                      !- fill the bulk structure with namelist informations
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 8841)
@@ -1566,7 +1566,8 @@
       !!             qsr_tot = pfrld * qsr_oce + ( 1 - pfrld ) * qsr_ice   => provided
       !!
-      !!             emp_tot = emp_oce + emp_ice                           => calving is provided and added to emp_tot (and emp_oce)
-      !!                                                                      river runoff (rnf) is provided but not included here
-      !!
+      !!             emp_tot = emp_oce + emp_ice                           => calving is provided and added to emp_tot (and emp_oce).
+      !!                                                                      runoff (which includes rivers+icebergs) and iceshelf
+      !!                                                                      are provided but not included in emp here. Only runoff will
+      !!                                                                      be included in emp in other parts of NEMO code
       !! ** Action  :   update at each nf_ice time step:
       !!                   qns_tot, qsr_tot  non-solar and solar total heat fluxes
@@ -1584,5 +1585,5 @@
       !
       INTEGER ::   jl         ! dummy loop index
-      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zcptn, ztmp, zcptrain, zcptsnw, zicefr, zmsk, zsnw
+      REAL(wp), POINTER, DIMENSION(:,:  ) ::   zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw
       REAL(wp), POINTER, DIMENSION(:,:  ) ::   zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice
       REAL(wp), POINTER, DIMENSION(:,:  ) ::   zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice
@@ -1592,5 +1593,5 @@
       IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_flx')
       !
-      CALL wrk_alloc( jpi,jpj,     zcptn, ztmp, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
+      CALL wrk_alloc( jpi,jpj,     zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
       CALL wrk_alloc( jpi,jpj,     zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice )
       CALL wrk_alloc( jpi,jpj,     zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice )
@@ -1615,20 +1616,4 @@
          zemp_tot(:,:) =   frcv(jpr_tevp)%z3(:,:,1) - ztprecip(:,:)
          zemp_ice(:,:) = ( frcv(jpr_ievp)%z3(:,:,1) - frcv(jpr_snow)%z3(:,:,1) ) * zicefr(:,:)
-         IF( iom_use('precip') )          &
-            &  CALL iom_put( 'precip'       ,   frcv(jpr_rain)%z3(:,:,1) + frcv(jpr_snow)%z3(:,:,1)                              )  ! total  precipitation
-         IF( iom_use('rain') )            &
-            &  CALL iom_put( 'rain'         ,   frcv(jpr_rain)%z3(:,:,1)                                                         )  ! liquid precipitation 
-         IF( iom_use('rain_ao_cea') )   &
-            &  CALL iom_put( 'rain_ao_cea'  , frcv(jpr_rain)%z3(:,:,1)* p_frld(:,:) * tmask(:,:,1)      )   ! liquid precipitation 
-         IF( iom_use('hflx_rain_cea') )   &
-            CALL iom_put( 'hflx_rain_cea', frcv(jpr_rain)%z3(:,:,1) * zcptn(:,:) * tmask(:,:,1))   ! heat flux from liq. precip. 
-         IF( iom_use('hflx_prec_cea') )   &
-            CALL iom_put( 'hflx_prec_cea', ztprecip * zcptn(:,:) * tmask(:,:,1) * p_frld(:,:) )   ! heat content flux from all precip  (cell avg)
-         IF( iom_use('evap_ao_cea') .OR. iom_use('hflx_evap_cea') )   &
-            ztmp(:,:) = frcv(jpr_tevp)%z3(:,:,1) - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:)
-         IF( iom_use('evap_ao_cea'  ) )   &
-            CALL iom_put( 'evap_ao_cea'  , ztmp * tmask(:,:,1)                  )   ! ice-free oce evap (cell average)
-         IF( iom_use('hflx_evap_cea') )   &
-            CALL iom_put( 'hflx_evap_cea', ztmp(:,:) * zcptn(:,:) * tmask(:,:,1) )   ! heat flux from from evap (cell average)
       CASE( 'oce and ice'   )   ! received fields: jpr_sbpr, jpr_semp, jpr_oemp, jpr_ievp
          zemp_tot(:,:) = p_frld(:,:) * frcv(jpr_oemp)%z3(:,:,1) + zicefr(:,:) * frcv(jpr_sbpr)%z3(:,:,1)
@@ -1639,5 +1624,5 @@
 
 #if defined key_lim3
-      ! zsnw = snow fraction over ice after wind blowing
+      ! zsnw = snow fraction over ice after wind blowing (=zicefr if no blowing)
       zsnw(:,:) = 0._wp  ;  CALL lim_thd_snwblow( p_frld, zsnw )
       
@@ -1652,27 +1637,22 @@
       zevap_ice(:,:) = frcv(jpr_ievp)%z3(:,:,1)
       ! since the sensitivity of evap to temperature (devap/dT) is not prescribed by the atmosphere, we set it to 0
-      ! therefore, sublimation is not redistributed over the ice categories in case no subgrid scale fluxes are provided by atm.
+      ! therefore, sublimation is not redistributed over the ice categories when no subgrid scale fluxes are provided by atm.
       zdevap_ice(:,:) = 0._wp
       
-      ! --- runoffs (included in emp later on) --- !
-      IF( srcv(jpr_rnf)%laction )   rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
-
-      ! --- calving (put in emp_tot and emp_oce) --- !
-      IF( srcv(jpr_cal)%laction ) THEN 
+      ! --- Continental fluxes --- !
+      IF( srcv(jpr_rnf)%laction ) THEN   ! runoffs (included in emp later on)
+         rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
+      ENDIF
+      IF( srcv(jpr_cal)%laction ) THEN   ! calving (put in emp_tot and emp_oce)
          zemp_tot(:,:) = zemp_tot(:,:) - frcv(jpr_cal)%z3(:,:,1)
          zemp_oce(:,:) = zemp_oce(:,:) - frcv(jpr_cal)%z3(:,:,1)
-         CALL iom_put( 'calving_cea', frcv(jpr_cal)%z3(:,:,1) )
-      ENDIF
-
-      IF( srcv(jpr_icb)%laction )  THEN 
+      ENDIF
+      IF( srcv(jpr_icb)%laction ) THEN   ! iceberg added to runoffs
          fwficb(:,:) = frcv(jpr_icb)%z3(:,:,1)
-         rnf(:,:)    = rnf(:,:) + fwficb(:,:)   ! iceberg added to runoffs
-         CALL iom_put( 'iceberg_cea', frcv(jpr_icb)%z3(:,:,1) )
-      ENDIF
-      IF( srcv(jpr_isf)%laction )  THEN
-        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)  ! fresh water flux from the isf (fwfisf <0 mean melting)  
-        CALL iom_put( 'iceshelf_cea', frcv(jpr_isf)%z3(:,:,1) )
-      ENDIF
-
+         rnf(:,:)    = rnf(:,:) + fwficb(:,:)
+      ENDIF
+      IF( srcv(jpr_isf)%laction ) THEN   ! iceshelf (fwfisf <0 mean melting)
+        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)  
+      ENDIF
 
       IF( ln_mixcpl ) THEN
@@ -1698,29 +1678,20 @@
       ENDIF
 
-      IF( iom_use('subl_ai_cea') )   CALL iom_put( 'subl_ai_cea', zevap_ice(:,:) * zicefr(:,:)         )  ! Sublimation over sea-ice (cell average)
-                                     CALL iom_put( 'snowpre'    , sprecip(:,:)                         )  ! Snow
-      IF( iom_use('snow_ao_cea') )   CALL iom_put( 'snow_ao_cea', sprecip(:,:) * ( 1._wp - zsnw(:,:) ) )  ! Snow over ice-free ocean  (cell average)
-      IF( iom_use('snow_ai_cea') )   CALL iom_put( 'snow_ai_cea', sprecip(:,:) *           zsnw(:,:)   )  ! Snow over sea-ice         (cell average)
 #else
-      ! runoffs and calving (put in emp_tot)
-      IF( srcv(jpr_rnf)%laction )   rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
-      IF( iom_use('hflx_rnf_cea') )   &
-         CALL iom_put( 'hflx_rnf_cea' , rnf(:,:) * zcptn(:,:) )
-      IF( srcv(jpr_cal)%laction ) THEN 
+      zsnw(:,:) = zicefr(:,:)
+      ! --- Continental fluxes --- !
+      IF( srcv(jpr_rnf)%laction ) THEN   ! runoffs (included in emp later on)
+         rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
+      ENDIF
+      IF( srcv(jpr_cal)%laction ) THEN   ! calving (put in emp_tot)
          zemp_tot(:,:) = zemp_tot(:,:) - frcv(jpr_cal)%z3(:,:,1)
-         CALL iom_put( 'calving_cea', frcv(jpr_cal)%z3(:,:,1) )
-      ENDIF
-
-
-      IF( srcv(jpr_icb)%laction )  THEN 
+      ENDIF
+      IF( srcv(jpr_icb)%laction ) THEN   ! iceberg added to runoffs
          fwficb(:,:) = frcv(jpr_icb)%z3(:,:,1)
-         rnf(:,:)    = rnf(:,:) + fwficb(:,:)   ! iceberg added to runoffs
-         CALL iom_put( 'iceberg_cea', frcv(jpr_icb)%z3(:,:,1) )
-      ENDIF
-      IF( srcv(jpr_isf)%laction )  THEN
-        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)  ! fresh water flux from the isf (fwfisf <0 mean melting)  
-        CALL iom_put( 'iceshelf_cea', frcv(jpr_isf)%z3(:,:,1) )
-      ENDIF
-
+         rnf(:,:)    = rnf(:,:) + fwficb(:,:)
+      ENDIF
+      IF( srcv(jpr_isf)%laction ) THEN   ! iceshelf (fwfisf <0 mean melting)
+        fwfisf(:,:) = - frcv(jpr_isf)%z3(:,:,1)
+      ENDIF
 
       IF( ln_mixcpl ) THEN
@@ -1736,10 +1707,20 @@
       ENDIF
 
-      IF( iom_use('subl_ai_cea') )  CALL iom_put( 'subl_ai_cea', frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) )  ! Sublimation over sea-ice (cell average)
-                                    CALL iom_put( 'snowpre'    , sprecip(:,:)               )   ! Snow
-      IF( iom_use('snow_ao_cea') )  CALL iom_put( 'snow_ao_cea', sprecip(:,:) * p_frld(:,:) )   ! Snow over ice-free ocean  (cell average)
-      IF( iom_use('snow_ai_cea') )  CALL iom_put( 'snow_ai_cea', sprecip(:,:) * zicefr(:,:) )   ! Snow over sea-ice         (cell average)
 #endif
-
+      ! outputs
+!!      IF( srcv(jpr_rnf)%laction )   CALL iom_put( 'runoffs' , rnf(:,:) * tmask(:,:,1)                                 )  ! runoff
+!!      IF( srcv(jpr_isf)%laction )   CALL iom_put( 'iceshelf_cea', -fwfisf(:,:) * tmask(:,:,1)                         )  ! iceshelf
+      IF( srcv(jpr_cal)%laction )   CALL iom_put( 'calving_cea' , frcv(jpr_cal)%z3(:,:,1) * tmask(:,:,1)                )  ! calving
+      IF( srcv(jpr_icb)%laction )   CALL iom_put( 'iceberg_cea' , frcv(jpr_icb)%z3(:,:,1) * tmask(:,:,1)                )  ! icebergs
+      IF( iom_use('snowpre') )      CALL iom_put( 'snowpre'     , sprecip(:,:)                                          )  ! Snow
+      IF( iom_use('precip') )       CALL iom_put( 'precip'      , tprecip(:,:)                                          )  ! total  precipitation
+      IF( iom_use('rain') )         CALL iom_put( 'rain'        , tprecip(:,:) - sprecip(:,:)                           )  ! liquid precipitation 
+      IF( iom_use('snow_ao_cea') )  CALL iom_put( 'snow_ao_cea' , sprecip(:,:) * ( 1._wp - zsnw(:,:) )                  )  ! Snow over ice-free ocean  (cell average)
+      IF( iom_use('snow_ai_cea') )  CALL iom_put( 'snow_ai_cea' , sprecip(:,:) *           zsnw(:,:)                    )  ! Snow over sea-ice         (cell average)
+      IF( iom_use('subl_ai_cea') )  CALL iom_put( 'subl_ai_cea' , frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) * tmask(:,:,1) )  ! Sublimation over sea-ice (cell average)
+      IF( iom_use('evap_ao_cea') )  CALL iom_put( 'evap_ao_cea' , ( frcv(jpr_tevp)%z3(:,:,1)  &
+         &                                                        - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) ) * tmask(:,:,1) )  ! ice-free oce evap (cell average)
+      ! note: runoff output is done in sbcrnf (which includes icebergs too) and iceshelf output is done in sbcisf
+      !
       !                                                      ! ========================= !
       SELECT CASE( TRIM( sn_rcv_qns%cldes ) )                !   non solar heat fluxes   !   (qns)
@@ -1777,23 +1758,10 @@
             &                                           + pist(:,:,1) * zicefr(:,:) ) )
       END SELECT
-!!gm
-!!    currently it is taken into account in leads budget but not in the zqns_tot, and thus not in 
-!!    the flux that enter the ocean....
-!!    moreover 1 - it is not diagnose anywhere.... 
-!!             2 - it is unclear for me whether this heat lost is taken into account in the atmosphere or not...
-!!
-!! similar job should be done for snow and precipitation temperature
       !                                     
-      IF( srcv(jpr_cal)%laction ) THEN   ! Iceberg melting 
-         zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_cal)%z3(:,:,1) * lfus  ! add the latent heat of iceberg melting
-                                                                         ! we suppose it melts at 0deg, though it should be temp. of surrounding ocean
-         IF( iom_use('hflx_cal_cea') )   CALL iom_put( 'hflx_cal_cea', - frcv(jpr_cal)%z3(:,:,1) * lfus )   ! heat flux from calving
-      ENDIF
-
-!!chris     
-!!    The heat content associated to the ice shelf in removed in the routine sbcisf.F90
-      !
-      IF( srcv(jpr_icb)%laction )  zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_icb)%z3(:,:,1) * lfus ! remove heat content associated to iceberg melting
-
+      ! --- calving (removed from qns_tot) --- !
+      IF( srcv(jpr_cal)%laction )   zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_cal)%z3(:,:,1) * lfus  ! remove latent heat of calving
+                                                                                                    ! we suppose it melts at 0deg, though it should be temp. of surrounding ocean
+      ! --- iceberg (removed from qns_tot) --- !
+      IF( srcv(jpr_icb)%laction )   zqns_tot(:,:) = zqns_tot(:,:) - frcv(jpr_icb)%z3(:,:,1) * lfus  ! remove latent heat of iceberg melting
 
 #if defined key_lim3      
@@ -1821,6 +1789,6 @@
       zqemp_oce(:,:) = -  zevap_oce(:,:)                                      *   zcptn   (:,:)   &        ! evap
          &             + ( ztprecip(:,:) - zsprecip(:,:) )                    *   zcptrain(:,:)   &        ! liquid precip
-         &             +   zsprecip(:,:)                   * ( 1._wp - zsnw ) * zqprec_ice(:,:) * r1_rhosn ! solid precip over ocean + snow melting
-      zqemp_ice(:,:) =     zsprecip(:,:)                   * zsnw             * zqprec_ice(:,:) * r1_rhosn ! solid precip over ice (qevap_ice=0 since atm. does not take it into account)
+         &             +   zsprecip(:,:)                   * ( 1._wp - zsnw ) * ( zcptsnw (:,:) - lfus )   ! solid precip over ocean + snow melting
+      zqemp_ice(:,:) =     zsprecip(:,:)                   * zsnw             * ( zcptsnw (:,:) - lfus )   ! solid precip over ice (qevap_ice=0 since atm. does not take it into account)
 !!    zqemp_ice(:,:) = -   frcv(jpr_ievp)%z3(:,:,1)        * zicefr(:,:)      *   zcptsnw (:,:)   &        ! ice evap
 !!       &             +   zsprecip(:,:)                   * zsnw             * zqprec_ice(:,:) * r1_rhosn ! solid precip over ice
@@ -1850,15 +1818,12 @@
       ENDIF
 
-      ! some more outputs
-      IF( iom_use('hflx_snow_cea') )    CALL iom_put('hflx_snow_cea',   sprecip(:,:) * ( zcptn(:,:) - Lfus ) )                       ! heat flux from snow (cell average)
-      IF( iom_use('hflx_rain_cea') )    CALL iom_put('hflx_rain_cea', ( tprecip(:,:) - sprecip(:,:) ) * zcptn(:,:) )                 ! heat flux from rain (cell average)
-      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea',sprecip(:,:) * ( zcptn(:,:) - Lfus ) * (1._wp - zsnw(:,:)) ) ! heat flux from snow (cell average)
-      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea',sprecip(:,:) * ( zcptn(:,:) - Lfus ) * zsnw(:,:) )           ! heat flux from snow (cell average)
-
 #else
+      zcptsnw (:,:) = zcptn(:,:)
+      zcptrain(:,:) = zcptn(:,:)
+      
       ! clem: this formulation is certainly wrong... but better than it was...
-      zqns_tot(:,:) = zqns_tot(:,:)                       &            ! zqns_tot update over free ocean with:
-         &          - ztmp(:,:)                           &            ! remove the latent heat flux of solid precip. melting
-         &          - (  zemp_tot(:,:)                    &            ! remove the heat content of mass flux (assumed to be at SST)
+      zqns_tot(:,:) = zqns_tot(:,:)                            &          ! zqns_tot update over free ocean with:
+         &          - (  p_frld(:,:) * zsprecip(:,:) * lfus )  &          ! remove the latent heat flux of solid precip. melting
+         &          - (  zemp_tot(:,:)                         &          ! remove the heat content of mass flux (assumed to be at SST)
          &             - zemp_ice(:,:) ) * zcptn(:,:) 
 
@@ -1873,6 +1838,21 @@
          qns_ice(:,:,:) = zqns_ice(:,:,:)
       ENDIF
+
 #endif
-
+      ! outputs
+      IF( srcv(jpr_cal)%laction )    CALL iom_put('hflx_cal_cea' ,   &
+                                             &   - frcv(jpr_cal)%z3(:,:,1) * lfus) ! latent heat from calving
+      IF( srcv(jpr_icb)%laction )    CALL iom_put('hflx_icb_cea' , - frcv(jpr_icb)%z3(:,:,1) * lfus) ! latent heat from icebergs melting
+      IF( iom_use('hflx_snow_cea') ) CALL iom_put('hflx_snow_cea',  sprecip(:,:) * ( zcptsnw(:,:) - Lfus )) ! heat flux from snow (cell average)
+      IF( iom_use('hflx_rain_cea') ) CALL iom_put('hflx_rain_cea',( tprecip(:,:) - sprecip(:,:) ) * zcptrain(:,:)) ! heat flux from rain (cell average)
+      IF( iom_use('hflx_evap_cea') ) CALL iom_put('hflx_evap_cea',(frcv(jpr_tevp)%z3(:,:,1)   &
+                                             &    - frcv(jpr_ievp)%z3(:,:,1) * zicefr(:,:) & ! heat flux from from evap (cell average)
+         &                                                        ) * zcptn(:,:) * tmask(:,:,1) )
+      IF( iom_use('hflx_snow_ao_cea') ) CALL iom_put('hflx_snow_ao_cea',sprecip(:,:)   &
+                                             & * (zcptsnw(:,:) - Lfus) * (1._wp - zsnw(:,:))   ) ! heat flux from snow (over ocean)
+      IF( iom_use('hflx_snow_ai_cea') ) CALL iom_put('hflx_snow_ai_cea',sprecip(:,:) * (zcptsnw(:,:) - Lfus)   &
+                                             & *          zsnw(:,:)    ) ! heat flux from snow (over ice)
+      ! note: hflx for runoff and iceshelf are done in sbcrnf and sbcisf resp.
+      !
       !                                                      ! ========================= !
       SELECT CASE( TRIM( sn_rcv_qsr%cldes ) )                !      solar heat fluxes    !   (qsr)
@@ -1980,5 +1960,5 @@
       fr2_i0(:,:) = ( 0.82 * ( 1.0 - cldf_ice ) + 0.65 * cldf_ice )
 
-      CALL wrk_dealloc( jpi,jpj,     zcptn, ztmp, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
+      CALL wrk_dealloc( jpi,jpj,     zcptn, zcptrain, zcptsnw, zicefr, zmsk, zsnw )
       CALL wrk_dealloc( jpi,jpj,     zemp_tot, zemp_ice, zemp_oce, ztprecip, zsprecip, zevap_oce, zevap_ice, zdevap_ice )
       CALL wrk_dealloc( jpi,jpj,     zqns_tot, zqns_oce, zqsr_tot, zqsr_oce, zqprec_ice, zqemp_oce, zqemp_ice )
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90	(revision 8841)
@@ -168,6 +168,8 @@
 
          ! output
-         CALL iom_put('qlatisf' , qisf)
-         CALL iom_put('fwfisf'  , fwfisf)
+         IF( iom_use('iceshelf_cea') )   CALL iom_put( 'iceshelf_cea', -fwfisf(:,:)                      )   ! isf mass flux
+         IF( iom_use('hflx_isf_cea') )   CALL iom_put( 'hflx_isf_cea', risf_tsc(:,:,jp_tem) * rau0 * rcp )   ! isf sensible+latent heat (W/m2)
+         IF( iom_use('qlatisf' ) )       CALL iom_put( 'qlatisf'     , qisf(:,:)                         )   ! isf latent heat
+         IF( iom_use('fwfisf'  ) )       CALL iom_put( 'fwfisf'      , fwfisf(:,:)                       )   ! isf mass flux (opposite sign)
 
         ! Diagnostics
@@ -190,7 +192,10 @@
                      zqlatisf3d(ji,jj,jk) = zqlatisf3d(ji,jj,jk) + qisf     (ji,jj) * r1_hisf_tbl(ji,jj) * e3t_n(ji,jj,jk)
                   END DO
-                  zfwfisf3d (ji,jj,jk) = zfwfisf3d (ji,jj,jk) + fwfisf   (ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * e3t_n(ji,jj,jk)
-                  zqhcisf3d (ji,jj,jk) = zqhcisf3d (ji,jj,jk) + zqhcisf2d(ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * e3t_n(ji,jj,jk)
-                  zqlatisf3d(ji,jj,jk) = zqlatisf3d(ji,jj,jk) + qisf     (ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * e3t_n(ji,jj,jk)
+                  zfwfisf3d (ji,jj,jk) = zfwfisf3d (ji,jj,jk) + fwfisf   (ji,jj) * r1_hisf_tbl(ji,jj)   & 
+                     &                                                                   * ralpha(ji,jj) * e3t_n(ji,jj,jk)
+                  zqhcisf3d (ji,jj,jk) = zqhcisf3d (ji,jj,jk) + zqhcisf2d(ji,jj) * r1_hisf_tbl(ji,jj)   & 
+                     &                                                                   * ralpha(ji,jj) * e3t_n(ji,jj,jk)
+                  zqlatisf3d(ji,jj,jk) = zqlatisf3d(ji,jj,jk) + qisf     (ji,jj) * r1_hisf_tbl(ji,jj)   &  
+                     &                                                                   * ralpha(ji,jj) * e3t_n(ji,jj,jk)
                END DO
             END DO
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 8841)
@@ -41,4 +41,5 @@
    USE sbcssr         ! surface boundary condition: sea surface restoring
    USE sbcrnf         ! surface boundary condition: runoffs
+   USE sbcapr         ! surface boundary condition: atmo pressure 
    USE sbcisf         ! surface boundary condition: ice shelf
    USE sbcfwb         ! surface boundary condition: freshwater budget
@@ -332,4 +333,6 @@
                           CALL sbc_rnf_init            ! Runof initialization
       !
+      IF( ln_apr_dyn )    CALL sbc_apr_init            ! Atmo Pressure Forcing initialization
+      !
       IF( nn_ice == 3 )   CALL sbc_lim_init            ! LIM3 initialization
       !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 8841)
@@ -138,5 +138,6 @@
          IF( ln_rnf_sal )   rnf_tsc(:,:,jp_sal) = ( sf_s_rnf(1)%fnow(:,:,1) ) * rnf(:,:) * r1_rau0
          !                                                           ! else use S=0 for runoffs (done one for all in the init)
-         CALL iom_put( "runoffs", rnf )         ! output runoffs arrays
+         IF( iom_use('runoffs') )        CALL iom_put( 'runoffs'     , rnf(:,:)                         )   ! output runoff mass flux
+         IF( iom_use('hflx_rnf_cea') )   CALL iom_put( 'hflx_rnf_cea', rnf_tsc(:,:,jp_tem) * rau0 * rcp )   ! output runoff sensible heat (W/m2)
       ENDIF
       !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90	(revision 8841)
@@ -132,6 +132,6 @@
                zda_v = EXP( -2.0_wp*zkh_v ) / ( 1.0_wp + 8.0_wp*zkh_v )
                !
-               usd(ji,jj,jk) = zda_u * zk_u(ji,jj) * umask(ji,jj,jk)
-               vsd(ji,jj,jk) = zda_v * zk_v(ji,jj) * vmask(ji,jj,jk)
+               usd(ji,jj,jk) = zda_u * zu0_sd(ji,jj) * umask(ji,jj,jk)
+               vsd(ji,jj,jk) = zda_v * zv0_sd(ji,jj) * vmask(ji,jj,jk)
             END DO
          END DO
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90	(revision 8841)
@@ -545,10 +545,15 @@
       CALL wrk_dealloc( jpi, jpj, zmbk )
 
-      !                                 !* sign of grad(H) at u- and v-points
-      mgrhu(jpi,:) = 0   ;   mgrhu(:,jpj) = 0   ;   mgrhv(jpi,:) = 0   ;   mgrhv(:,jpj) = 0
+                                        !* sign of grad(H) at u- and v-points; zero if grad(H) = 0
+      mgrhu(:,:) = 0   ;   mgrhv(:,:) = 0
       DO jj = 1, jpjm1
          DO ji = 1, jpim1
-            mgrhu(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji+1,jj,mbkt(ji+1,jj)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
-            mgrhv(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji,jj+1,mbkt(ji,jj+1)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
+            IF( gdept_0(ji+1,jj,mbkt(ji+1,jj)) - gdept_0(ji,jj,mbkt(ji,jj)) /= 0._wp ) THEN
+               mgrhu(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji+1,jj,mbkt(ji+1,jj)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
+            ENDIF
+            !
+            IF( gdept_0(ji,jj+1,mbkt(ji,jj+1)) - gdept_0(ji,jj,mbkt(ji,jj)) /= 0._wp ) THEN
+               mgrhv(ji,jj) = INT(  SIGN( 1.e0, gdept_0(ji,jj+1,mbkt(ji,jj+1)) - gdept_0(ji,jj,mbkt(ji,jj)) )  )
+            ENDIF
          END DO
       END DO
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 8841)
@@ -121,6 +121,6 @@
       IF( l_trdtra )   THEN                    
          CALL wrk_alloc( jpi, jpj, jpk, ztrdt, ztrds )
-         ztrdt(:,:,jk) = 0._wp
-         ztrds(:,:,jk) = 0._wp
+         ztrdt(:,:,jpk) = 0._wp
+         ztrds(:,:,jpk) = 0._wp
          IF( ln_traldf_iso ) THEN              ! diagnose the "pure" Kz diffusive trend 
             CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdfp, ztrdt )
@@ -128,15 +128,18 @@
          ENDIF
          ! total trend for the non-time-filtered variables. 
-            zfact = 1.0 / rdt
+         zfact = 1.0 / rdt
+         ! G Nurser 23 Mar 2017. Recalculate trend as Delta(e3t*T)/e3tn; e3tn cancel from tsn terms
          DO jk = 1, jpkm1
-            ztrdt(:,:,jk) = ( tsa(:,:,jk,jp_tem) - tsn(:,:,jk,jp_tem) ) * zfact 
-            ztrds(:,:,jk) = ( tsa(:,:,jk,jp_sal) - tsn(:,:,jk,jp_sal) ) * zfact 
+            ztrdt(:,:,jk) = ( tsa(:,:,jk,jp_tem)*e3t_a(:,:,jk) / e3t_n(:,:,jk) - tsn(:,:,jk,jp_tem)) * zfact
+            ztrds(:,:,jk) = ( tsa(:,:,jk,jp_sal)*e3t_a(:,:,jk) / e3t_n(:,:,jk) - tsn(:,:,jk,jp_sal)) * zfact
          END DO
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_tot, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_tot, ztrds )
-         ! Store now fields before applying the Asselin filter 
-         ! in order to calculate Asselin filter trend later.
-         ztrdt(:,:,:) = tsn(:,:,:,jp_tem) 
-         ztrds(:,:,:) = tsn(:,:,:,jp_sal)
+         IF( ln_linssh ) THEN 
+            ! Store now fields before applying the Asselin filter 
+            ! in order to calculate Asselin filter trend later.
+            ztrdt(:,:,:) = tsn(:,:,:,jp_tem) 
+            ztrds(:,:,:) = tsn(:,:,:,jp_sal)
+         ENDIF
       ENDIF
 
@@ -147,4 +150,11 @@
             END DO
          END DO
+         IF (l_trdtra .AND. .NOT. ln_linssh) THEN  ! Zero Asselin filter contribution must be explicitly written out since for vvl
+                                                   ! Asselin filter is output by tra_nxt_vvl that is not called on this time step
+            ztrdt(:,:,:) = 0._wp
+            ztrds(:,:,:) = 0._wp
+            CALL trd_tra( kt, 'TRA', jp_tem, jptra_atf, ztrdt )
+            CALL trd_tra( kt, 'TRA', jp_sal, jptra_atf, ztrds )
+         END IF
          !
       ELSE                                            ! Leap-Frog + Asselin filter time stepping
@@ -162,7 +172,7 @@
       ENDIF     
       !
-      IF( l_trdtra ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt     
+      IF( l_trdtra .AND. ln_linssh ) THEN      ! trend of the Asselin filter (tb filtered - tb)/dt     
+         zfact = 1._wp / r2dt             
          DO jk = 1, jpkm1
-            zfact = 1._wp / r2dt             
             ztrdt(:,:,jk) = ( tsb(:,:,jk,jp_tem) - ztrdt(:,:,jk) ) * zfact
             ztrds(:,:,jk) = ( tsb(:,:,jk,jp_sal) - ztrds(:,:,jk) ) * zfact
@@ -170,6 +180,6 @@
          CALL trd_tra( kt, 'TRA', jp_tem, jptra_atf, ztrdt )
          CALL trd_tra( kt, 'TRA', jp_sal, jptra_atf, ztrds )
-         CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       END IF
+      IF( l_trdtra ) CALL wrk_dealloc( jpi, jpj, jpk, ztrdt, ztrds )
       !
       !                        ! control print
@@ -259,6 +269,7 @@
       LOGICAL  ::   ll_traqsr, ll_rnf, ll_isf   ! local logical
       INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
-      REAL(wp) ::   zfact1, ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
+      REAL(wp) ::   zfact, zfact1, ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
       REAL(wp) ::   zfact2, ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrd_atf
       !!----------------------------------------------------------------------
       !
@@ -279,4 +290,9 @@
       ENDIF
       !
+      IF( ( l_trdtra .and. cdtype == 'TRA' ) .OR. ( l_trdtrc .and. cdtype == 'TRC' ) )   THEN
+         CALL wrk_alloc( jpi, jpj, jpk, kjpt, ztrd_atf )
+         ztrd_atf(:,:,:,:) = 0.0_wp
+      ENDIF
+      zfact = 1._wp / r2dt
       DO jn = 1, kjpt      
          DO jk = 1, jpkm1
@@ -331,4 +347,8 @@
                   ptn(ji,jj,jk,jn) = pta(ji,jj,jk,jn)     ! ptn <-- pta
                   !
+                  IF( ( l_trdtra .and. cdtype == 'TRA' ) .OR. ( l_trdtrc .and. cdtype == 'TRC' ) ) THEN
+                     ztrd_atf(ji,jj,jk,jn) = (ztc_f - ztc_n) * zfact/ze3t_n
+                  ENDIF
+                  !
                END DO
             END DO
@@ -337,4 +357,16 @@
       END DO
       !
+      IF( l_trdtra .and. cdtype == 'TRA' ) THEN 
+         CALL trd_tra( kt, cdtype, jp_tem, jptra_atf, ztrd_atf(:,:,:,jp_tem) )
+         CALL trd_tra( kt, cdtype, jp_sal, jptra_atf, ztrd_atf(:,:,:,jp_sal) )
+         CALL wrk_dealloc( jpi, jpj, jpk, kjpt, ztrd_atf )
+      ENDIF
+      IF( l_trdtrc .and. cdtype == 'TRC' ) THEN
+         DO jn = 1, kjpt
+            CALL trd_tra( kt, cdtype, jn, jptra_atf, ztrd_atf(:,:,:,jn) )
+         END DO
+         CALL wrk_dealloc( jpi, jpj, jpk, kjpt, ztrd_atf )
+      ENDIF
+      !
    END SUBROUTINE tra_nxt_vvl
 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRA/trazdf.F90	(revision 8841)
@@ -89,6 +89,8 @@
       IF( l_trdtra )   THEN                      ! save the vertical diffusive trends for further diagnostics
          DO jk = 1, jpkm1
-            ztrdt(:,:,jk) = ( ( tsa(:,:,jk,jp_tem) - tsb(:,:,jk,jp_tem) ) / r2dt ) - ztrdt(:,:,jk)
-            ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal) - tsb(:,:,jk,jp_sal) ) / r2dt ) - ztrds(:,:,jk)
+            ztrdt(:,:,jk) = ( ( tsa(:,:,jk,jp_tem)*e3t_a(:,:,jk) - tsb(:,:,jk,jp_tem)*e3t_b(:,:,jk) ) &
+                 & / (e3t_n(:,:,jk)*r2dt) ) - ztrdt(:,:,jk)
+            ztrds(:,:,jk) = ( ( tsa(:,:,jk,jp_sal)*e3t_a(:,:,jk) - tsb(:,:,jk,jp_sal)*e3t_b(:,:,jk) ) &
+                 & / (e3t_n(:,:,jk)*r2dt) ) - ztrds(:,:,jk)
          END DO
 !!gm this should be moved in trdtra.F90 and done on all trends
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90	(revision 8841)
@@ -104,4 +104,5 @@
                                  ztrds(:,:,:) = 0._wp
                                  CALL trd_tra_mng( trdt, ztrds, ktrd, kt )
+         CASE( jptra_evd )   ;   avt_evd(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
          CASE DEFAULT                 ! other trends: masked trends
             trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)              ! mask & store
@@ -311,44 +312,57 @@
 !!gm Rq: mask the trends already masked in trd_tra, but lbc_lnk should probably be added
       !
+      ! Trends evaluated every time step that could go to the standard T file and can be output every ts into a 1ts file if 1ts output is selected
       SELECT CASE( ktrd )
-      CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
-                               CALL iom_put( "strd_xad" , ptrdy )
-      CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
-                               CALL iom_put( "strd_yad" , ptrdy )
-      CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
-                               CALL iom_put( "strd_zad" , ptrdy )
-                               IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
-                               	 CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
-                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
-                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
-                                  CALL iom_put( "ttrd_sad", z2dx )
-                                  CALL iom_put( "strd_sad", z2dy )
-                                  CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
-                               ENDIF
-      CASE( jptra_totad  ) ;   CALL iom_put( "ttrd_totad" , ptrdx )      ! total   advection
-                               CALL iom_put( "strd_totad" , ptrdy )
-      CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
-                               CALL iom_put( "strd_ldf" , ptrdy )
-      CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
-                               CALL iom_put( "strd_zdf" , ptrdy )
-      CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
-                               CALL iom_put( "strd_zdfp", ptrdy )
-      CASE( jptra_evd )    ;   CALL iom_put( "ttrd_evd", ptrdx )         ! EVD trend (convection)
-                               CALL iom_put( "strd_evd", ptrdy )
-      CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
-                               CALL iom_put( "strd_dmp" , ptrdy )
-      CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
-                               CALL iom_put( "strd_bbl" , ptrdy )
-      CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
-                               CALL iom_put( "strd_npc" , ptrdy )
-      CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx(:,:,1) )        ! surface forcing + runoff (ln_rnf=T)
-                               CALL iom_put( "strd_cdt" , ptrdy(:,:,1) )        ! output as 2D surface fields
-      CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
-      CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
-      CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
-                               CALL iom_put( "strd_atf" , ptrdy )
-      CASE( jptra_tot  )   ;   CALL iom_put( "ttrd_tot" , ptrdx )        ! model total trend
-                               CALL iom_put( "strd_tot" , ptrdy )
+      ! This total trend is done every time step
+      CASE( jptra_tot  )   ;   CALL iom_put( "ttrd_tot" , ptrdx )           ! model total trend
+         CALL iom_put( "strd_tot" , ptrdy )
       END SELECT
+
+      ! These trends are done every second time step. When 1ts output is selected must go different (2ts) file from standard T-file
+      IF( MOD( kt, 2 ) == 0 ) THEN
+         SELECT CASE( ktrd )
+         CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
+            CALL iom_put( "strd_xad" , ptrdy )
+         CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
+            CALL iom_put( "strd_yad" , ptrdy )
+         CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
+            CALL iom_put( "strd_zad" , ptrdy )
+            IF( ln_linssh ) THEN                   ! cst volume : adv flux through z=0 surface
+               CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
+               z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / e3t_n(:,:,1)
+               z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / e3t_n(:,:,1)
+               CALL iom_put( "ttrd_sad", z2dx )
+               CALL iom_put( "strd_sad", z2dy )
+               CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
+            ENDIF
+         CASE( jptra_totad  ) ;   CALL iom_put( "ttrd_totad" , ptrdx )      ! total   advection
+            CALL iom_put( "strd_totad" , ptrdy )
+         CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
+            CALL iom_put( "strd_ldf" , ptrdy )
+         CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
+            CALL iom_put( "strd_zdf" , ptrdy )
+         CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
+            CALL iom_put( "strd_zdfp", ptrdy )
+         CASE( jptra_evd )    ;   CALL iom_put( "ttrd_evd", ptrdx )         ! EVD trend (convection)
+            CALL iom_put( "strd_evd", ptrdy )
+         CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
+            CALL iom_put( "strd_dmp" , ptrdy )
+         CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
+            CALL iom_put( "strd_bbl" , ptrdy )
+         CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
+            CALL iom_put( "strd_npc" , ptrdy )
+         CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
+         CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx(:,:,1) ) ! surface forcing + runoff (ln_rnf=T)
+            CALL iom_put( "strd_cdt" , ptrdy(:,:,1) )        ! output as 2D surface fields
+         CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
+         END SELECT
+         ! the Asselin filter trend  is also every other time step but needs to be lagged one time step
+         ! Even when 1ts output is selected can go to the same (2ts) file as the trends plotted every even time step.
+      ELSE IF( MOD( kt, 2 ) == 1 ) THEN
+         SELECT CASE( ktrd )
+         CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
+            CALL iom_put( "strd_atf" , ptrdy )
+         END SELECT
+      END IF
       !
    END SUBROUTINE trd_tra_iom
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90	(revision 8841)
@@ -384,4 +384,8 @@
             END IF
          ENDIF
+         !
+         bfrua(:,:) = - bfrcoef2d(:,:)
+         bfrva(:,:) = - bfrcoef2d(:,:)
+         !
          !
       CASE DEFAULT
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfddm_substitute.h90	(revision 8841)
@@ -5,5 +5,5 @@
    !!      with a constant or 1D or 2D or 3D array, using CPP macro.
    !!----------------------------------------------------------------------
-#if defined key_zdfddm
+#if defined key_zdfddm  && ! defined key_offline
 !   'key_zdfddm' :                      avs: 3D array defined in zdfddm module
 #   define   fsavs(i,j,k)       avs(i,j,k)
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfric.F90	(revision 8841)
@@ -183,5 +183,5 @@
             zrhos          = rhop(ji,jj,1) + zflageos * ( 1. - tmask(ji,jj,1) )
             zustar         = SQRT( taum(ji,jj) / ( zrhos +  rsmall ) )
-            ekm_dep(ji,jj) = rn_ekmfc * zustar / ( ABS( ff(ji,jj) ) + rsmall )
+            ekm_dep(ji,jj) = rn_ekmfc * zustar / ( ABS( ff_t(ji,jj) ) + rsmall )
             ekm_dep(ji,jj) = MAX(ekm_dep(ji,jj),rn_mldmin) ! Minimun allowed
             ekm_dep(ji,jj) = MIN(ekm_dep(ji,jj),rn_mldmax) ! Maximum allowed
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/ZDF/zdftmx.F90	(revision 8841)
@@ -225,4 +225,5 @@
 
       !                             ! compute the form function using N2 at each time step
+      zdn2dz     (:,:,jpk) = 0.e0
       zempba_3d_1(:,:,jpk) = 0.e0
       zempba_3d_2(:,:,jpk) = 0.e0
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 8841)
@@ -206,10 +206,8 @@
       !
 #if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-                         CALL Agrif_ParentGrid_To_ChildGrid()
-         IF( ln_diaobs ) CALL dia_obs_wri
-         IF( nn_timing == 1 )   CALL timing_finalize
-                                CALL Agrif_ChildGrid_To_ParentGrid()
-      ENDIF
+      CALL Agrif_ParentGrid_To_ChildGrid()
+      IF( ln_diaobs ) CALL dia_obs_wri
+      IF( nn_timing == 1 )   CALL timing_finalize
+      CALL Agrif_ChildGrid_To_ParentGrid()
 #endif
       IF( nn_timing == 1 )   CALL timing_finalize
@@ -452,4 +450,5 @@
       !                                      ! external forcing 
 !!gm to be added : creation and call of sbc_apr_init
+!==> cbr: sbc_apr_init in sbcmod as sbc_rnf_init
                             CALL    tide_init   ! tidal harmonics
                             CALL     sbc_init   ! surface boundary conditions (including sea-ice)
@@ -751,39 +750,39 @@
       !
       ! Find the factors of n.
-      IF( kn == 1 )   GOTO 20
-
-      ! nu holds the unfactorised part of the number.
-      ! knfax holds the number of factors found.
-      ! l points to the allowed factor list.
-      ! ifac holds the current factor.
-      !
-      inu   = kn
-      knfax = 0
-      !
-      DO jl = ntest, 1, -1
+      IF( kn .NE. 1 ) THEN
+
+         ! nu holds the unfactorised part of the number.
+         ! knfax holds the number of factors found.
+         ! l points to the allowed factor list.
+         ! ifac holds the current factor.
          !
-         ifac = ilfax(jl)
-         IF( ifac > inu )   CYCLE
-
-         ! Test whether the factor will divide.
-
-         IF( MOD(inu,ifac) == 0 ) THEN
+         inu   = kn
+         knfax = 0
+         !
+         DO jl = ntest, 1, -1
             !
-            knfax = knfax + 1            ! Add the factor to the list
-            IF( knfax > kmaxfax ) THEN
-               kerr = 6
-               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
-               return
+            ifac = ilfax(jl)
+            IF( ifac > inu )   CYCLE
+   
+            ! Test whether the factor will divide.
+   
+            IF( MOD(inu,ifac) == 0 ) THEN
+               !
+               knfax = knfax + 1            ! Add the factor to the list
+               IF( knfax > kmaxfax ) THEN
+                  kerr = 6
+                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+                  return
+               ENDIF
+               kfax(knfax) = ifac
+               ! Store the other factor that goes with this one
+               knfax = knfax + 1
+               kfax(knfax) = inu / ifac
+               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
             ENDIF
-            kfax(knfax) = ifac
-            ! Store the other factor that goes with this one
-            knfax = knfax + 1
-            kfax(knfax) = inu / ifac
-            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
-         ENDIF
+            !
+         END DO
          !
-      END DO
-      !
-   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+      ENDIF
       !
    END SUBROUTINE factorise
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/stpctl.F90	(revision 8841)
@@ -21,4 +21,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
+   USE lib_fortran     ! Fortran routines library 
 
    IMPLICIT NONE
@@ -51,5 +52,5 @@
       INTEGER  ::   ji, jj, jk             ! dummy loop indices
       INTEGER  ::   ii, ij, ik             ! local integers
-      REAL(wp) ::   zumax, zsmin, zssh2    ! local scalars
+      REAL(wp) ::   zumax, zsmin, zssh2, zsshmax    ! local scalars
       INTEGER, DIMENSION(3) ::   ilocu     ! 
       INTEGER, DIMENSION(2) ::   ilocs     ! 
@@ -146,11 +147,40 @@
       ENDIF
       !
-      zssh2 = SUM( sshn(:,:) * sshn(:,:) * tmask_i(:,:) )
-      IF( lk_mpp )   CALL mpp_sum( zssh2 )      ! sum over the global domain
+      zsshmax = 0.e0
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( tmask(ji,jj,1) == 1) zsshmax = MAX( zsshmax, ABS(sshn(ji,jj)) )
+         END DO
+      END DO
+      IF( lk_mpp )   CALL mpp_max( zsshmax )                ! min over the global domain
       !
-      IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
+      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' ssh max:', zsshmax
       !
-9200  FORMAT('it:', i8, ' iter:', i4, ' r: ',e16.10, ' b: ',e16.10 )
-9300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
+      IF( zsshmax > 10.e0 ) THEN 
+         IF (lk_mpp) THEN
+            CALL mpp_maxloc( ABS(sshn(:,:)),tmask(:,:,1),zsshmax,ii,ij)
+         ELSE
+            ilocs = MAXLOC( ABS(sshn(:,:)) )
+            ii = ilocs(1) + nimpp - 1
+            ij = ilocs(2) + njmpp - 1
+         ENDIF
+         !
+         IF(lwp) THEN
+            WRITE(numout,cform_err)
+            WRITE(numout,*) 'stp_ctl : the ssh is larger than 10m'
+            WRITE(numout,*) '======= '
+            WRITE(numout,9600) kt, zsshmax, ii, ij
+            WRITE(numout,*)
+            WRITE(numout,*) '          output of last fields in numwso'
+         ENDIF
+         kindic = -3
+      ENDIF
+9600  FORMAT (' kt=',i6,' max ssh: ',1pg11.4,', i j: ',2i5)
+      !
+      zssh2 = glob_sum( sshn(:,:) * sshn(:,:) )
+      !
+      IF(lwp) WRITE(numsol,9700) kt, zssh2, zumax, zsmin      ! ssh statistics
+      !
+9700  FORMAT(' it :', i8, ' ssh2: ', d23.16, ' Umax: ',d23.16,' Smin: ',d23.16)
       !
    END SUBROUTINE stp_ctl
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/OPA_SRC/trc_oce.F90	(revision 8841)
@@ -25,6 +25,6 @@
 
    LOGICAL , PUBLIC                                      ::   l_co2cpl  = .false.   !: atmospheric pco2 recieved from oasis
-   LOGICAL , PUBLIC                                     ::   l_offline = .false.   !: offline passive tracers flag
-   INTEGER , PUBLIC                                      ::   nn_dttrc      !: frequency of step on passive tracers
+   LOGICAL , PUBLIC                                      ::   l_offline = .false.   !: offline passive tracers flag
+   INTEGER , PUBLIC                                      ::   nn_dttrc = 1     !: frequency of step on passive tracers
    REAL(wp), PUBLIC                                      ::   r_si2         !: largest depth of extinction (blue & 0.01 mg.m-3)  (RGB)
    REAL(wp), PUBLIC, SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   etot3         !: light absortion coefficient
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90	(revision 8841)
@@ -499,39 +499,39 @@
       !
       ! Find the factors of n.
-      IF( kn == 1 )   GOTO 20
-
-      ! nu holds the unfactorised part of the number.
-      ! knfax holds the number of factors found.
-      ! l points to the allowed factor list.
-      ! ifac holds the current factor.
-      !
-      inu   = kn
-      knfax = 0
-      !
-      DO jl = ntest, 1, -1
-         !
-         ifac = ilfax(jl)
-         IF( ifac > inu )   CYCLE
-
-         ! Test whether the factor will divide.
-
-         IF( MOD(inu,ifac) == 0 ) THEN
+      IF( kn .NE. 1 ) THEN
+
+         ! nu holds the unfactorised part of the number.
+         ! knfax holds the number of factors found.
+         ! l points to the allowed factor list.
+         ! ifac holds the current factor.
+         !
+         inu   = kn
+         knfax = 0
+         !
+         DO jl = ntest, 1, -1
             !
-            knfax = knfax + 1            ! Add the factor to the list
-            IF( knfax > kmaxfax ) THEN
-               kerr = 6
-               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
-               return
+            ifac = ilfax(jl)
+            IF( ifac > inu )   CYCLE
+   
+            ! Test whether the factor will divide.
+   
+            IF( MOD(inu,ifac) == 0 ) THEN
+               !
+               knfax = knfax + 1            ! Add the factor to the list
+               IF( knfax > kmaxfax ) THEN
+                  kerr = 6
+                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+                  return
+               ENDIF
+               kfax(knfax) = ifac
+               ! Store the other factor that goes with this one
+               knfax = knfax + 1
+               kfax(knfax) = inu / ifac
+               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
             ENDIF
-            kfax(knfax) = ifac
-            ! Store the other factor that goes with this one
-            knfax = knfax + 1
-            kfax(knfax) = inu / ifac
-            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
-         ENDIF
-         !
-      END DO
-      !
-   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+            !
+         END DO
+         !
+      ENDIF
       !
    END SUBROUTINE factorise
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/daymod.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/daymod.F90	(revision 8841)
@@ -2,36 +2,35 @@
    !!======================================================================
    !!                       ***  MODULE  daymod  ***
-   !! Ocean        :  calendar 
+   !! Ocean :   management of the model calendar
    !!=====================================================================
    !! History :  OPA  ! 1994-09  (M. Pontaud M. Imbard)  Original code
    !!                 ! 1997-03  (O. Marti)
-   !!                 ! 1997-05  (G. Madec) 
+   !!                 ! 1997-05  (G. Madec)
    !!                 ! 1997-08  (M. Imbard)
    !!   NEMO     1.0  ! 2003-09  (G. Madec)  F90 + nyear, nmonth, nday
    !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj
    !!                 ! 2006-08  (G. Madec)  surface module major update
-   !!----------------------------------------------------------------------      
+   !!                 ! 2015-11  (D. Lea) Allow non-zero initial time of day
+   !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
    !!   day        : calendar
-   !!  
-   !!           -------------------------------
-   !!           ----------- WARNING -----------
-   !!
-   !!   we suppose that the time step is deviding the number of second of in a day
-   !!             ---> MOD( rday, rdt ) == 0
-   !!
-   !!           ----------- WARNING -----------
-   !!           -------------------------------
-   !!  
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   USE iom             ! 
-   USE ioipsl, ONLY :   ymds2ju   ! for calendar
-   USE prtctl          ! Print control
-   USE restart         ! 
-   USE timing          ! Timing
+   !!----------------------------------------------------------------------
+   !!                    ----------- WARNING -----------
+   !!                    -------------------------------
+   !!   sbcmod assume that the time step is dividing the number of second of 
+   !!   in a day, i.e. ===> MOD( rday, rdt ) == 0 
+   !!   except when user defined forcing is used (see sbcmod.F90)
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE ioipsl  , ONLY :   ymds2ju      ! for calendar
+   USE trc_oce , ONLY :   l_offline   ! offline flag
+   !
+   USE in_out_manager ! I/O manager
+   USE prtctl         ! Print control
+   USE iom            !
+   USE timing         ! Timing
+   USE restart        ! restart
 
    IMPLICIT NONE
@@ -40,9 +39,10 @@
    PUBLIC   day        ! called by step.F90
    PUBLIC   day_init   ! called by istate.F90
-
-   INTEGER ::   nsecd, nsecd05, ndt, ndt05
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   PUBLIC   day_mth    ! Needed by TAM
+
+   INTEGER, PUBLIC ::   nsecd, nsecd05, ndt, ndt05   !: (PUBLIC for TAM)
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -53,6 +53,6 @@
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE day_init  ***
-      !! 
-      !! ** Purpose :   Initialization of the calendar values to their values 1 time step before nit000 
+      !!
+      !! ** Purpose :   Initialization of the calendar values to their values 1 time step before nit000
       !!                because day will be called at the beginning of step
       !!
@@ -67,6 +67,6 @@
       !!              - nmonth_len, nyear_len, nmonth_half, nmonth_end through day_mth
       !!----------------------------------------------------------------------
-      INTEGER  ::   inbday, idweek
-      REAL(wp) ::   zjul
+      INTEGER  ::   inbday, idweek   ! local integers
+      REAL(wp) ::   zjul             ! local scalar
       !!----------------------------------------------------------------------
       !
@@ -76,33 +76,28 @@
             &           'You must do a restart at higher frequency (or remove this stop and recompile the code in I8)' )
       ENDIF
-      ! all calendar staff is based on the fact that MOD( rday, rdt ) == 0
-      IF( MOD( rday , rdt ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
-      IF( MOD( rday , 2.  ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
-      IF( MOD( rdt  , 2.  ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
-      nsecd   = NINT(rday       )
-      nsecd05 = NINT(0.5 * rday )
-      ndt     = NINT(      rdt  )
-      ndt05   = NINT(0.5 * rdt  )
-
-      ! ==> clem: here we read the ocean restart for the date (only if it exists)
-      !           It is not clean and another solution should be found
-      CALL day_rst( nit000, 'READ' )
-      ! ==>
-
-      ! set the calendar from ndastp (read in restart file and namelist)
-
+      nsecd   = NINT( rday       )
+      nsecd05 = NINT( 0.5 * rday )
+      ndt     = NINT(       rdt  )
+      ndt05   = NINT( 0.5 * rdt  )
+
+      IF( .NOT. l_offline )   CALL day_rst( nit000, 'READ' )
+
+      ! set the calandar from ndastp (read in restart file and namelist)
       nyear   =   ndastp / 10000
       nmonth  = ( ndastp - (nyear * 10000) ) / 100
-      nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
-
-      CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
+      nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 )
+
+      nhour   =   nn_time0 / 100
+      nminute = ( nn_time0 - nhour * 100 )
+
+      CALL ymds2ju( nyear, nmonth, nday, nhour*3600._wp+nminute*60._wp, fjulday )  
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1)
+      IF( nn_time0*3600 - ndt05 .lt. 0 ) fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1)
 
       nsec1jan000 = 0
       CALL day_mth
-      
+
       IF ( nday == 0 ) THEN     !   for ex if ndastp = ndate0 - 1
-         nmonth = nmonth - 1  
+         nmonth = nmonth - 1
          nday = nmonth_len(nmonth)
       ENDIF
@@ -113,22 +108,34 @@
          IF( nleapy == 1 )   CALL day_mth
       ENDIF
-      
+
       ! day since january 1st
       nday_year = nday + SUM( nmonth_len(1:nmonth - 1) )
 
-      !compute number of days between last monday and today      
+      !compute number of days between last monday and today
       CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday)
-      inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day  
-      idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day  
+      inbday = FLOOR(fjulday - zjul)            ! compute nb day between  01.01.1900 and start of current day
+      idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day
+      IF (idweek .lt. 0) idweek=idweek+7       ! Avoid negative values for dates before 01.01.1900
 
       ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step
-      nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step
-      nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step
-      nsec_week  = idweek    * nsecd - ndt05
-      nsec_day   =             nsecd - ndt05
+      IF (nhour*3600+nminute*60-ndt05 .gt. 0) THEN
+         ! 1 timestep before current middle of first time step is still the same day
+         nsec_year  = (nday_year-1) * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = (nday-1)      * nsecd + nhour*3600+nminute*60 - ndt05    
+      ELSE
+         ! 1 time step before the middle of the first time step is the previous day 
+         nsec_year  = nday_year * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = nday      * nsecd + nhour*3600+nminute*60 - ndt05   
+      ENDIF
+      nsec_week  = idweek    * nsecd + nhour*3600+nminute*60 - ndt05
+      nsec_day   =             nhour*3600+nminute*60 - ndt05 
+      IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd
+      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7
 
       ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')   &
+           &                   ' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  &
+           &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year
 
       ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
@@ -142,5 +149,5 @@
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE day_init  ***
-      !! 
+      !!
       !! ** Purpose :   calendar values related to the months
       !!
@@ -154,5 +161,5 @@
 
       ! length of the month of the current year (from nleapy, read in namelist)
-      IF ( nleapy < 2 ) THEN 
+      IF ( nleapy < 2 ) THEN
          nmonth_len(:) = (/ 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 /)
          nyear_len(:) = 365
@@ -177,5 +184,5 @@
       ! time since Jan 1st   0     1     2    ...    11    12    13
       !          ---------*--|--*--|--*--| ... |--*--|--*--|--*--|--------------------------------------
-      !                 <---> <---> <--->  ...  <---> <---> <--->        
+      !                 <---> <---> <--->  ...  <---> <---> <--->
       ! month number      0     1     2    ...    11    12    13
       !
@@ -190,6 +197,6 @@
          nmonth_end(jm) = nmonth_end(jm-1) + nsecd * nmonth_len(jm)
       END DO
-      !           
-   END SUBROUTINE 
+      !
+   END SUBROUTINE
 
 
@@ -197,5 +204,5 @@
       !!----------------------------------------------------------------------
       !!                      ***  ROUTINE day  ***
-      !! 
+      !!
       !! ** Purpose :   Compute the date with a day iteration IF necessary.
       !!
@@ -209,5 +216,5 @@
       !!              - adatrj    : date in days since the beginning of the run
       !!              - nsec_year : current time of the year (in second since 00h, jan 1st)
-      !!----------------------------------------------------------------------      
+      !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt        ! ocean time-step indices
       !
@@ -220,13 +227,13 @@
       zprec = 0.1 / rday
       !                                                 ! New time-step
-      nsec_year  = nsec_year  + ndt 
-      nsec_month = nsec_month + ndt                 
+      nsec_year  = nsec_year  + ndt
+      nsec_month = nsec_month + ndt
       nsec_week  = nsec_week  + ndt
-      nsec_day   = nsec_day   + ndt                
+      nsec_day   = nsec_day   + ndt
       adatrj  = adatrj  + rdt / rday
       fjulday = fjulday + rdt / rday
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < zprec )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
       IF( ABS(adatrj  - REAL(NINT(adatrj ),wp)) < zprec )   adatrj  = REAL(NINT(adatrj ),wp)   ! avoid truncation error
-      
+
       IF( nsec_day > nsecd ) THEN                       ! New day
          !
@@ -261,5 +268,5 @@
 
       IF( nsec_week > 7*nsecd )   nsec_week = ndt05     ! New week
-      
+
       IF(ln_ctl) THEN
          WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
@@ -267,16 +274,7 @@
       ENDIF
 
-      ! since we no longer call rst_opn, need to define nitrst here, used by ice restart routine
-      IF( kt == nit000 )  THEN
-         nitrst = nitend
-         lrst_oce = .FALSE.  ! init restart ocean (done in rst_opn when not SAS)
-      ENDIF
-
-      IF( MOD( kt - 1, nstock ) == 0 ) THEN
-         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
-         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
-         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
-      ENDIF
-
+      IF( .NOT. l_offline ) CALL rst_opn( kt )               ! Open the restart file if needed and control lrst_oce
+      IF( lrst_oce         ) CALL day_rst( kt, 'WRITE' )      ! write day restart information
+      !
       IF( nn_timing == 1 )  CALL timing_stop('day')
       !
@@ -312,5 +310,6 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !
-      REAL(wp) ::   zkt, zndastp
+      REAL(wp) ::   zkt, zndastp, zdayfrac, ksecs, ktime
+      INTEGER  ::   ihour, iminute
       !!----------------------------------------------------------------------
 
@@ -337,17 +336,47 @@
             ! define ndastp and adatrj
             IF ( nrstdt == 2 ) THEN
-               ! read the parameters correspondting to nit000 - 1 (last time step of previous run)
+               ! read the parameters corresponding to nit000 - 1 (last time step of previous run)
                CALL iom_get( numror, 'ndastp', zndastp )
                ndastp = NINT( zndastp )
                CALL iom_get( numror, 'adatrj', adatrj  )
+	       CALL iom_get( numror, 'ntime', ktime )
+	       nn_time0=INT(ktime)
+               ! calculate start time in hours and minutes
+	       zdayfrac=adatrj-INT(adatrj)
+	       ksecs = NINT(zdayfrac*86400)	       ! Nearest second to catch rounding errors in adatrj	       
+	       ihour = INT(ksecs/3600)
+	       iminute = ksecs/60-ihour*60
+ 	        
+               ! Add to nn_time0
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+	       nminute=nminute+iminute
+	       
+	       IF( nminute >= 60 ) THEN
+	          nminute=nminute-60
+		  nhour=nhour+1
+	       ENDIF
+	       nhour=nhour+ihour
+	       IF( nhour >= 24 ) THEN
+		  nhour=nhour-24
+	          adatrj=adatrj+1
+	       ENDIF	       
+	       nn_time0 = nhour * 100 + nminute
+	       adatrj = INT(adatrj)                    ! adatrj set to integer as nn_time0 updated	       
             ELSE
-               ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
+               ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+               IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
                adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
          ELSE
-            ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-            ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
+            ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+            ndastp = ndate0           ! ndate0 read in the namelist in dom_nam
+            nhour   =   nn_time0 / 100
+	    nminute = ( nn_time0 - nhour * 100 )
+            IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
             adatrj = ( REAL( nit000-1, wp ) * rdt ) / rday
          ENDIF
@@ -358,4 +387,5 @@
             WRITE(numout,*) '   date ndastp                                      : ', ndastp
             WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
+	    WRITE(numout,*) '   nn_time0                                         : ',nn_time0
             WRITE(numout,*)
          ENDIF
@@ -373,7 +403,9 @@
          CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
          !                                                                     ! the begining of the run [s]
+	 CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
       !
    END SUBROUTINE day_rst
+
    !!======================================================================
 END MODULE daymod
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90	(revision 8841)
@@ -25,4 +25,5 @@
    USE usrdef_nam     ! user defined configuration
    USE daymod         ! calendar
+   USE restart        ! open  restart file
    USE step           ! NEMO time-stepping                 (stp     routine)
    USE cpl_oasis3     !
@@ -364,4 +365,5 @@
       IF( ln_ctl      )     CALL prt_ctl_init   ! Print control
                             CALL day_init   ! model calendar (using both namelist and restart infos)
+      IF( ln_rstart )       CALL rst_read_open
 
                             CALL sbc_init   ! Forcings : surface module 
@@ -596,39 +598,39 @@
       !
       ! Find the factors of n.
-      IF( kn == 1 )   GOTO 20
-
-      ! nu holds the unfactorised part of the number.
-      ! knfax holds the number of factors found.
-      ! l points to the allowed factor list.
-      ! ifac holds the current factor.
-      !
-      inu   = kn
-      knfax = 0
-      !
-      DO jl = ntest, 1, -1
-         !
-         ifac = ilfax(jl)
-         IF( ifac > inu )   CYCLE
-
-         ! Test whether the factor will divide.
-
-         IF( MOD(inu,ifac) == 0 ) THEN
+      IF( kn .NE. 1 ) THEN
+
+         ! nu holds the unfactorised part of the number.
+         ! knfax holds the number of factors found.
+         ! l points to the allowed factor list.
+         ! ifac holds the current factor.
+         !
+         inu   = kn
+         knfax = 0
+         !
+         DO jl = ntest, 1, -1
             !
-            knfax = knfax + 1            ! Add the factor to the list
-            IF( knfax > kmaxfax ) THEN
-               kerr = 6
-               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
-               return
+            ifac = ilfax(jl)
+            IF( ifac > inu )   CYCLE
+   
+            ! Test whether the factor will divide.
+   
+            IF( MOD(inu,ifac) == 0 ) THEN
+               !
+               knfax = knfax + 1            ! Add the factor to the list
+               IF( knfax > kmaxfax ) THEN
+                  kerr = 6
+                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+                  return
+               ENDIF
+               kfax(knfax) = ifac
+               ! Store the other factor that goes with this one
+               knfax = knfax + 1
+               kfax(knfax) = inu / ifac
+               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
             ENDIF
-            kfax(knfax) = ifac
-            ! Store the other factor that goes with this one
-            knfax = knfax + 1
-            kfax(knfax) = inu / ifac
-            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
-         ENDIF
-         !
-      END DO
-      !
-   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+            !
+         END DO
+         !
+      ENDIF
       !
    END SUBROUTINE factorise
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 8841)
@@ -180,7 +180,9 @@
       !
       IF( lk_iomput ) THEN
+         jl = 0
          DO jn = jp_cfc0, jp_cfc1
-            CALL iom_put( 'qtr_'//ctrcnm(jn) , qtr_cfc (:,:,jn) )
-            CALL iom_put( 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) )
+            jl = jl + 1
+            CALL iom_put( 'qtr_'//TRIM(ctrcnm(jn)) , qtr_cfc (:,:,jl) )
+            CALL iom_put( 'qint_'//TRIM(ctrcnm(jn)), qint_cfc(:,:,jl) )
          ENDDO
       END IF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P2Z/p2zopt.F90	(revision 8841)
@@ -119,5 +119,5 @@
       !                                          ! --------------
       neln(:,:) = 1                                   ! euphotic layer level
-      DO jk = 1, jpk                                  ! (i.e. 1rst T-level strictly below EL bottom)
+      DO jk = 1, jpkm1                                  ! (i.e. 1rst T-level strictly below EL bottom)
          DO jj = 1, jpj
            DO ji = 1, jpi
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zlim.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zlim.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zlim.F90	(revision 8841)
@@ -207,4 +207,9 @@
                   &                                / ( oxymin + trb(ji,jj,jk,jpoxy) )  )
                nitrfac(ji,jj,jk) = MIN( 1., nitrfac(ji,jj,jk) )
+               !
+               ! denitrification factor computed from NO3 levels
+               nitrfac2(ji,jj,jk) = MAX( 0.e0,       ( 1.E-6 - trb(ji,jj,jk,jpno3) )  &
+                  &                                / ( 1.E-6 + trb(ji,jj,jk,jpno3) ) )
+               nitrfac2(ji,jj,jk) = MIN( 1., nitrfac2(ji,jj,jk) )
             END DO
          END DO
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmeso.F90	(revision 8841)
@@ -95,5 +95,5 @@
                !  no real reason except that it seems to be more stable and may mimic predation
                !  ---------------------------------------------------------------
-               ztortz2   = mzrat2 * 1.e6 * zfact * trb(ji,jj,jk,jpmes)
+               ztortz2   = mzrat2 * 1.e6 * zfact * trb(ji,jj,jk,jpmes)  * (1. - nitrfac(ji,jj,jk) )
                !
                zcompadi  = MAX( ( trb(ji,jj,jk,jpdia) - xthresh2dia ), 0.e0 )
@@ -125,8 +125,10 @@
                !  ----------------------------------
                zgrazffeg = grazflux  * xstep * wsbio4(ji,jj,jk)      &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes)
+               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpgoc) * trb(ji,jj,jk,jpmes) &
+               &           * (1. - nitrfac(ji,jj,jk))
                zgrazfffg = zgrazffeg * trb(ji,jj,jk,jpbfe) / (trb(ji,jj,jk,jpgoc) + rtrn)
                zgrazffep = grazflux  * xstep *  wsbio3(ji,jj,jk)     &
-               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpmes)
+               &           * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jppoc) * trb(ji,jj,jk,jpmes) &
+               &           * (1. - nitrfac(ji,jj,jk))
                zgrazfffp = zgrazffep * trb(ji,jj,jk,jpsfe) / (trb(ji,jj,jk,jppoc) + rtrn)
               !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zmicro.F90	(revision 8841)
@@ -93,5 +93,5 @@
                !  no real reason except that it seems to be more stable and may mimic predation.
                !  ---------------------------------------------------------------
-               ztortz = mzrat * 1.e6 * zfact * trb(ji,jj,jk,jpzoo)
+               ztortz = mzrat * 1.e6 * zfact * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk))
 
                zcompadi  = MIN( MAX( ( trb(ji,jj,jk,jpdia) - xthreshdia ), 0.e0 ), xsizedia )
@@ -105,5 +105,5 @@
                zdenom    = zfoodlim / ( xkgraz + zfoodlim )
                zdenom2   = zdenom / ( zfood + rtrn )
-               zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpzoo) 
+               zgraze    = grazrat * xstep * tgfunc2(ji,jj,jk) * trb(ji,jj,jk,jpzoo) * (1. - nitrfac(ji,jj,jk))
 
                zgrazp    = zgraze  * xpref2p * zcompaph  * zdenom2 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zopt.F90	(revision 8841)
@@ -34,5 +34,5 @@
 
    TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_par      ! structure of input par
-   INTEGER , PARAMETER :: nbtimes = 365  !: maximum number of times record in a file
+   INTEGER , PARAMETER :: nbtimes = 366  !: maximum number of times record in a file
    INTEGER  :: ntimes_par                ! number of time steps in a file
    REAL(wp), ALLOCATABLE, SAVE,   DIMENSION(:,:) :: par_varsw    !: PAR fraction of shortwave
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 8841)
@@ -65,4 +65,5 @@
       REAL(wp) ::   zsatur, zsatur2, znusil, znusil2, zdep, zdepmin, zfactdep
       REAL(wp) ::   zbactfer, zolimit, zonitr, zrfact2
+      REAL(wp) ::   zammonic, zoxyrem
       REAL(wp) ::   zosil, ztem, zdenitnh4, zolimic, zolimin, zolimip, zdenitrn, zdenitrp
       CHARACTER (len=25) :: charout
@@ -118,17 +119,20 @@
                   ! Ammonification in suboxic waters with denitrification
                   ! -------------------------------------------------------
-                  denitr(ji,jj,jk)  = MIN(  ( trb(ji,jj,jk,jpno3) - rtrn ) / rdenit,   &
-                     &                     zremik * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc)  )
+                  zammonic = zremik * nitrfac(ji,jj,jk) * trb(ji,jj,jk,jpdoc)
+                  denitr(ji,jj,jk)  = zammonic * ( 1. - nitrfac2(ji,jj,jk) )
+                  zoxyrem           = zammonic *        nitrfac2(ji,jj,jk)
                   !
                   zolimi (ji,jj,jk) = MAX( 0.e0, zolimi (ji,jj,jk) )
                   denitr (ji,jj,jk) = MAX( 0.e0, denitr (ji,jj,jk) )
+                  zoxyrem           = MAX( 0.e0, zoxyrem  )
+
                   !
-                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk)
-                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk)
+                  tra(ji,jj,jk,jppo4) = tra(ji,jj,jk,jppo4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyrem
+                  tra(ji,jj,jk,jpnh4) = tra(ji,jj,jk,jpnh4) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyrem
                   tra(ji,jj,jk,jpno3) = tra(ji,jj,jk,jpno3) - denitr (ji,jj,jk) * rdenit
-                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zolimi (ji,jj,jk) - denitr(ji,jj,jk)
+                  tra(ji,jj,jk,jpdoc) = tra(ji,jj,jk,jpdoc) - zolimi (ji,jj,jk) - denitr(ji,jj,jk) - zoxyrem
                   tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) - zolimi (ji,jj,jk) * o2ut
-                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zolimi (ji,jj,jk) + denitr(ji,jj,jk)
-                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zolimi(ji,jj,jk)    &
+                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + zolimi (ji,jj,jk) + denitr(ji,jj,jk) + zoxyrem
+                  tra(ji,jj,jk,jptal) = tra(ji,jj,jk,jptal) + rno3 * ( zolimi(ji,jj,jk) + zoxyrem    &
                   &                     + ( rdenit + 1.) * denitr(ji,jj,jk) )
                END DO
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 8841)
@@ -54,5 +54,5 @@
       REAL(wp) ::  zwflux, zfminus, zfplus
       REAL(wp) ::  zlim, zfact, zfactcal
-      REAL(wp) ::  zo2, zno3, zflx, zpdenit, z1pdenit, zdenitt, zolimit
+      REAL(wp) ::  zo2, zno3, zflx, zpdenit, z1pdenit, zolimit
       REAL(wp) ::  zsiloss, zcaloss, zws3, zws4, zwsc, zdep
       REAL(wp) ::  zwstpoc, zwstpon, zwstpop
@@ -319,6 +319,6 @@
                tra(ji,jj,ikt,jptal) =  tra(ji,jj,ikt,jptal) + zcaloss * zrivalk * 2.0
                tra(ji,jj,ikt,jpdic) =  tra(ji,jj,ikt,jpdic) + zcaloss * zrivalk
-               zsedcal(ji,jj) = (1.0 - zrivalk) * zcaloss / zdep
-               zsedsi (ji,jj) = (1.0 - zrivsil) * zsiloss / zdep
+               zsedcal(ji,jj) = (1.0 - zrivalk) * zcaloss * e3t_n(ji,jj,ikt) 
+               zsedsi (ji,jj) = (1.0 - zrivsil) * zsiloss * e3t_n(ji,jj,ikt) 
             END DO
          END DO
@@ -365,6 +365,6 @@
 
       IF( .NOT.lk_sed ) THEN
-         ! The 0.5 factor in zpdenit and zdenitt is to avoid negative NO3 concentration after both denitrification
-         ! in the sediments and just above the sediments. Not very clever, but simpliest option.
+         ! The 0.5 factor in zpdenit is to avoid negative NO3 concentration after
+         ! denitrification in the sediments. Not very clever, but simpliest option.
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -378,19 +378,18 @@
                z1pdenit = zwstpoc * zrivno3 - zpdenit
                zolimit = MIN( ( trb(ji,jj,ikt,jpoxy) - rtrn ) / o2ut, z1pdenit * ( 1.- nitrfac(ji,jj,ikt) ) )
-               zdenitt = MIN(  0.5 * ( trb(ji,jj,ikt,jpno3) - rtrn ) / rdenit, z1pdenit * nitrfac(ji,jj,ikt) )
-               tra(ji,jj,ikt,jpdoc) = tra(ji,jj,ikt,jpdoc) + z1pdenit - zolimit - zdenitt
-               tra(ji,jj,ikt,jppo4) = tra(ji,jj,ikt,jppo4) + zpdenit + zolimit + zdenitt
-               tra(ji,jj,ikt,jpnh4) = tra(ji,jj,ikt,jpnh4) + zpdenit + zolimit + zdenitt
-               tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) - rdenit * (zpdenit + zdenitt)
+               tra(ji,jj,ikt,jpdoc) = tra(ji,jj,ikt,jpdoc) + z1pdenit - zolimit
+               tra(ji,jj,ikt,jppo4) = tra(ji,jj,ikt,jppo4) + zpdenit + zolimit
+               tra(ji,jj,ikt,jpnh4) = tra(ji,jj,ikt,jpnh4) + zpdenit + zolimit
+               tra(ji,jj,ikt,jpno3) = tra(ji,jj,ikt,jpno3) - rdenit * zpdenit
                tra(ji,jj,ikt,jpoxy) = tra(ji,jj,ikt,jpoxy) - zolimit * o2ut
-               tra(ji,jj,ikt,jptal) = tra(ji,jj,ikt,jptal) + rno3 * (zolimit + (1.+rdenit) * (zpdenit + zdenitt) )
-               tra(ji,jj,ikt,jpdic) = tra(ji,jj,ikt,jpdic) + zpdenit + zolimit + zdenitt
+               tra(ji,jj,ikt,jptal) = tra(ji,jj,ikt,jptal) + rno3 * (zolimit + (1.+rdenit) * zpdenit )
+               tra(ji,jj,ikt,jpdic) = tra(ji,jj,ikt,jpdic) + zpdenit + zolimit 
                sdenit(ji,jj) = rdenit * zpdenit * e3t_n(ji,jj,ikt)
-               zsedc(ji,jj)   = (1. - zrivno3) * zwstpoc / zdep
+               zsedc(ji,jj)   = (1. - zrivno3) * zwstpoc * e3t_n(ji,jj,ikt)
                IF( ln_p5z ) THEN
                   zwstpop              = trb(ji,jj,ikt,jpgop) * zws4 + trb(ji,jj,ikt,jppop) * zws3
                   zwstpon              = trb(ji,jj,ikt,jpgon) * zws4 + trb(ji,jj,ikt,jppon) * zws3
-                  tra(ji,jj,ikt,jpdon) = tra(ji,jj,ikt,jpdon) + (z1pdenit - zolimit - zdenitt) * zwstpon / (zwstpoc + rtrn)
-                  tra(ji,jj,ikt,jpdop) = tra(ji,jj,ikt,jpdop) + (z1pdenit - zolimit - zdenitt) * zwstpop / (zwstpoc + rtrn)
+                  tra(ji,jj,ikt,jpdon) = tra(ji,jj,ikt,jpdon) + ( z1pdenit - zolimit ) * zwstpon / (zwstpoc + rtrn)
+                  tra(ji,jj,ikt,jpdop) = tra(ji,jj,ikt,jpdop) + ( z1pdenit - zolimit ) * zwstpop / (zwstpoc + rtrn)
                ENDIF
             END DO
@@ -494,17 +493,17 @@
       IF( lk_iomput ) THEN
          IF( knt == nrdttrc ) THEN
-            zfact = 1.e+3 * rfact2r * rno3  !  conversion from molC/l/kt  to molN/m3/s
-            IF( iom_use("Nfix"   ) ) CALL iom_put( "Nfix", nitrpot(:,:,:) * nitrfix * zfact * tmask(:,:,:) )  ! nitrogen fixation 
+            zfact = 1.e+3 * rfact2r !  conversion from molC/l/kt  to molN/m3/s
+            IF( iom_use("Nfix"   ) ) CALL iom_put( "Nfix", nitrpot(:,:,:) * nitrfix * rno3 * zfact * tmask(:,:,:) )  ! nitrogen fixation 
             IF( iom_use("INTNFIX") ) THEN   ! nitrogen fixation rate in ocean ( vertically integrated )
                zwork1(:,:) = 0.
                DO jk = 1, jpkm1
-                 zwork1(:,:) = zwork1(:,:) + nitrpot(:,:,jk) * nitrfix * zfact * e3t_n(:,:,jk) * tmask(:,:,jk)
+                 zwork1(:,:) = zwork1(:,:) + nitrpot(:,:,jk) * nitrfix * rno3 * zfact * e3t_n(:,:,jk) * tmask(:,:,jk)
                ENDDO
                CALL iom_put( "INTNFIX" , zwork1 ) 
             ENDIF
-            IF( iom_use("SedCal" ) ) CALL iom_put( "SedCal", zsedcal(:,:) * 1.e+3 )
-            IF( iom_use("SedSi" ) )  CALL iom_put( "SedSi",  zsedsi (:,:) * 1.e+3 )
-            IF( iom_use("SedC" ) )   CALL iom_put( "SedC",   zsedc  (:,:) * 1.e+3 )
-            IF( iom_use("Sdenit" ) ) CALL iom_put( "Sdenit", sdenit (:,:) * 1.e+3 * rno3 )
+            IF( iom_use("SedCal" ) ) CALL iom_put( "SedCal", zsedcal(:,:) * zfact )
+            IF( iom_use("SedSi" ) )  CALL iom_put( "SedSi",  zsedsi (:,:) * zfact )
+            IF( iom_use("SedC" ) )   CALL iom_put( "SedC",   zsedc  (:,:) * zfact )
+            IF( iom_use("Sdenit" ) ) CALL iom_put( "Sdenit", sdenit (:,:) * zfact * rno3 )
          ENDIF
       ENDIF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 8841)
@@ -431,11 +431,11 @@
 
       IF( kt == nittrc000 ) THEN 
+         xfact1 = rfact2r * 12. / 1.e15 * ryyss    ! conversion molC/kt --> PgC/yr
+         xfact2 = 1.e+3 * rno3 * 14. / 1.e12 * ryyss   ! conversion molC/l/s ----> TgN/m3/yr
+         xfact3 = 1.e+3 * rfact2r * rno3   ! conversion molC/l/kt ----> molN/m3/s
          IF( ln_check_mass .AND. lwp) THEN      !   Open budget file of NO3, ALK, Si, Fer
             CALL ctl_opn( numco2, 'carbon.budget'  , 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
             CALL ctl_opn( numnut, 'nutrient.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
             CALL ctl_opn( numnit, 'nitrogen.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-            xfact1 = rfact2r * 12. / 1.e15 * ryyss    ! conversion molC/kt --> PgC/yr
-            xfact2 = 1.e+3 * rno3 * 14. / 1.e12 * ryyss   ! conversion molC/l/s ----> TgN/m3/yr
-            xfact3 = 1.e+3 * rfact2r * rno3   ! conversion molC/l/kt ----> molN/m3/s
             cltxt='time-step   Alkalinity        Nitrate        Phosphorus         Silicate           Iron'
             IF( lwp ) WRITE(numnut,*)  TRIM(cltxt)
@@ -517,17 +517,13 @@
       IF( iom_use( "tnfix" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
          znitrpottot  = glob_sum ( nitrpot(:,:,:) * nitrfix * cvol(:,:,:) )
-         CALL iom_put( "tnfix"  , znitrpottot * 1.e+3 * rno3 )  ! Global  nitrogen fixation molC/l  to molN/m3 
+         CALL iom_put( "tnfix"  , znitrpottot * xfact3 )  ! Global  nitrogen fixation molC/l  to molN/m3 
       ENDIF
       !
       IF( iom_use( "tdenit" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
-         zrdenittot   = glob_sum ( denitr(:,:,:) * rdenit * xnegtr(:,:,:) * cvol(:,:,:) )
-         CALL iom_put( "tdenit"  , zrdenittot * 1.e+3 * rno3 )  ! Total denitrification molC/l to molN/m3 
-      ENDIF
-      !
-      IF( iom_use( "Sdenit" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
-         zsdenittot   = glob_sum ( sdenit(:,:) * e1e2t(:,:) )
-         CALL iom_put( "Sdenit", sdenit(:,:) * xfact3 * tmask(:,:,1) )  ! Nitrate reduction in the sediments
-      ENDIF
-
+         zrdenittot = glob_sum ( denitr(:,:,:) * rdenit * xnegtr(:,:,:) * cvol(:,:,:) )
+         zsdenittot = glob_sum ( sdenit(:,:) * e1e2t(:,:) * tmask(:,:,1) )
+         CALL iom_put( "tdenit" , ( zrdenittot + zsdenittot ) * xfact3 )  ! Total denitrification molC/l to molN/m3 
+      ENDIF
+      !
       IF( ln_check_mass .AND. kt == nitend ) THEN   ! Compute the budget of NO3, ALK, Si, Fer
          t_atm_co2_flx  = t_atm_co2_flx / glob_sum( e1e2t(:,:) )
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedco3.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedco3.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/SED/sedco3.F90	(revision 8841)
@@ -75,6 +75,5 @@
 
       DO jk = 1, jpksed
-10001    CONTINUE
-         IF( itime <= 2 ) THEN
+         DO WHILE( itime <= 2 )
             lconv  = .FALSE.
             IF( itime > 0 ) THEN  
@@ -154,5 +153,4 @@
 !                     WRITE(numsed,*) '    with re-initialization of initial PH field '       
                      itime = 2
-                     GOTO 10001
                   ELSE
 !                     WRITE(numsed,*) ' convergence after iter =', jiter, ' iterations ;  res =',zresm 
@@ -165,5 +163,5 @@
 !                     &               '  after iter =', jiter, ' iterations ;  res =',zresm  
 !                  WRITE(numsed,*) ' '
-                  itime = 0
+                  itime = 3
                ENDIF
             ELSE
@@ -172,5 +170,4 @@
                IF ( itime == 1 ) THEN
                   WRITE(numsed,*) ' try one more time with more iterations and higher relax. value'
-                  GOTO 10001
                ELSE IF ( itime == 2 ) THEN
                   WRITE(numsed,*) ' try one more time for with more iterations, higher relax. value'               
@@ -181,5 +178,5 @@
                ENDIF
             ENDIF
-         ENDIF
+         ENDDO ! End of WHILE LOOP
      ENDDO
 
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/sms_pisces.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/sms_pisces.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/PISCES/sms_pisces.F90	(revision 8841)
@@ -97,4 +97,5 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xfracal    !: ??
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   nitrfac    !: ??
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   nitrfac2   !: ??
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   orem       !: ??
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xdiss      !: ??
@@ -159,7 +160,7 @@
          !
          !*  SMS for the organic matter
-         ALLOCATE( xfracal (jpi,jpj,jpk), nitrfac(jpi,jpj,jpk) ,    &
-            &      orem    (jpi,jpj,jpk),                           &
-            &      prodcal(jpi,jpj,jpk),  xdiss   (jpi,jpj,jpk),    &
+         ALLOCATE( xfracal (jpi,jpj,jpk), orem(jpi,jpj,jpk)    ,    &
+            &      nitrfac(jpi,jpj,jpk), nitrfac2(jpi,jpj,jpk) ,    &
+            &      prodcal(jpi,jpj,jpk) , xdiss   (jpi,jpj,jpk),    &
             &      prodpoc(jpi,jpj,jpk) , conspoc(jpi,jpj,jpk) ,    &
             &      prodgoc(jpi,jpj,jpk) , consgoc(jpi,jpj,jpk) ,  STAT=ierr(4) )
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90	(revision 8841)
@@ -44,4 +44,6 @@
    PUBLIC   trc_nxt          ! routine called by step.F90
 
+   REAL(wp) ::   rfact1, rfact2
+
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3 , NEMO Consortium (2010)
@@ -104,14 +106,19 @@
       ENDIF
       !                                ! Leap-Frog + Asselin filter time stepping
-      IF( neuler == 0 .AND. kt == nittrc000 ) THEN    ! Euler time-stepping at first time-step (only swap)
+      IF( (neuler == 0 .AND. kt == nittrc000) .OR. ln_top_euler ) THEN    ! Euler time-stepping (only swap)
          DO jn = 1, jptra
             DO jk = 1, jpkm1
                trn(:,:,jk,jn) = tra(:,:,jk,jn)
+               trb(:,:,jk,jn) = trn(:,:,jk,jn)  
             END DO
          END DO
-      ELSE                                            ! Asselin filter + swap
-         IF( ln_linssh ) THEN   ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )  !     linear ssh
-         ELSE                   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
-           &                                                                   sbc_trc, sbc_trc_b, jptra )  ! non-linear ssh
+      ELSE     
+         IF( .NOT. l_offline ) THEN ! Leap-Frog + Asselin filter time stepping
+            IF( ln_linssh ) THEN   ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )  !     linear ssh
+            ELSE                   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
+              &                                                                   sbc_trc, sbc_trc_b, jptra )  ! non-linear ssh
+            ENDIF
+         ELSE
+                                       CALL trc_nxt_off( kt )       ! offline 
          ENDIF
          !
@@ -143,4 +150,82 @@
       !
    END SUBROUTINE trc_nxt
+
+
+   SUBROUTINE trc_nxt_off( kt )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE tra_nxt_vvl  ***
+      !!
+      !! ** Purpose :   Time varying volume: apply the Asselin time filter  
+      !!                and swap the tracer fields.
+      !! 
+      !! ** Method  : - Apply a thickness weighted Asselin time filter on now fields.
+      !!              - save in (ta,sa) a thickness weighted average over the three 
+      !!             time levels which will be used to compute rdn and thus the semi-
+      !!             implicit hydrostatic pressure gradient (ln_dynhpg_imp = T)
+      !!              - swap tracer fields to prepare the next time_step.
+      !!                This can be summurized for tempearture as:
+      !!             ztm = ( e3t_n*tn + rbcp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )   ln_dynhpg_imp = T
+      !!                  /( e3t_n    + rbcp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )   
+      !!             ztm = 0                                                       otherwise
+      !!             tb  = ( e3t_n*tn + atfp*[ e3t_b*tb - 2 e3t_n*tn + e3t_a*ta ] )
+      !!                  /( e3t_n    + atfp*[ e3t_b    - 2 e3t_n    + e3t_a    ] )
+      !!             tn  = ta 
+      !!             ta  = zt        (NB: reset to 0 after eos_bn2 call)
+      !!
+      !! ** Action  : - (tb,sb) and (tn,sn) ready for the next time step
+      !!              - (ta,sa) time averaged (t,s)   (ln_dynhpg_imp = T)
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )   ::  kt       ! ocean time-step index
+      !!     
+      INTEGER  ::   ji, jj, jk, jn              ! dummy loop indices
+      REAL(wp) ::   ztc_a , ztc_n , ztc_b , ztc_f , ztc_d    ! local scalar
+      REAL(wp) ::   ze3t_b, ze3t_n, ze3t_a, ze3t_f, ze3t_d   !   -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nittrc000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'trc_nxt_off : time stepping'
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         IF( .NOT. ln_linssh ) THEN
+            rfact1 = atfp * rdttrc
+            rfact2 = rfact1 / rau0
+         ENDIF
+        !  
+      ENDIF
+      !
+      DO jn = 1, jptra      
+         DO jk = 1, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ze3t_b = e3t_b(ji,jj,jk)
+                  ze3t_n = e3t_n(ji,jj,jk)
+                  ze3t_a = e3t_a(ji,jj,jk)
+                  !                                         ! tracer content at Before, now and after
+                  ztc_b  = trb(ji,jj,jk,jn) * ze3t_b
+                  ztc_n  = trn(ji,jj,jk,jn) * ze3t_n
+                  ztc_a  = tra(ji,jj,jk,jn) * ze3t_a
+                  !
+                  ze3t_d = ze3t_a - 2. * ze3t_n + ze3t_b
+                  ztc_d  = ztc_a  - 2. * ztc_n  + ztc_b
+                  !
+                  ze3t_f = ze3t_n + atfp * ze3t_d
+                  ztc_f  = ztc_n  + atfp * ztc_d
+                  !
+                  IF( .NOT. ln_linssh .AND. jk == mikt(ji,jj) ) THEN           ! first level 
+                     ze3t_f = ze3t_f - rfact2 * ( emp_b(ji,jj)      - emp(ji,jj)   ) 
+                     ztc_f  = ztc_f  - rfact1 * ( sbc_trc(ji,jj,jn) - sbc_trc_b(ji,jj,jn) )
+                  ENDIF
+
+                  ze3t_f = 1.e0 / ze3t_f
+                  trb(ji,jj,jk,jn) = ztc_f * ze3t_f       ! ptb <-- ptn filtered
+                  trn(ji,jj,jk,jn) = tra(ji,jj,jk,jn)     ! ptn <-- pta
+                  !
+               END DO
+            END DO
+         END DO
+         ! 
+      END DO
+      !
+   END SUBROUTINE trc_nxt_off
 
 #else
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/oce_trc.F90	(revision 8841)
@@ -7,9 +7,4 @@
    !!             2.0  !  2007-12 (C. Ethe, G. Madec)  rewritting
    !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
-   !
    !                                            !* Domain size *
    USE par_oce , ONLY :   jpi      =>   jpi        !: first  dimension of grid --> i 
@@ -117,14 +112,3 @@
    USE zdfmxl , ONLY :   hmlpt       =>   hmlpt       !: mixed layer depth at t-points (m)
 
-#else
-   !!----------------------------------------------------------------------
-   !!  Empty module :                                     No passive tracer
-   !!----------------------------------------------------------------------
-#endif
-
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Id$
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================
 END MODULE oce_trc
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/prtctl_trc.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/prtctl_trc.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/prtctl_trc.F90	(revision 8841)
@@ -6,8 +6,4 @@
    !! History :    -   !  2005-07  (C. Talandier) original code for OPA
    !!             1.0  !  2005-10  (C. Ethe     ) adapted to passive tracer
-   !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
    !!----------------------------------------------------------------------
    !!   prt_ctl_trc      :   control print in mpp for passive tracers
@@ -299,14 +295,3 @@
    END SUBROUTINE prt_ctl_trc_init
 
-#else
-   !!----------------------------------------------------------------------
-   !!   Dummy module :                                    NO passive tracer
-   !!----------------------------------------------------------------------
-#endif
- 
-   !!----------------------------------------------------------------------
-   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
-   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
-   !!======================================================================   
 END MODULE prtctl_trc
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 8841)
@@ -8,11 +8,7 @@
    !!   NEMO      1.0  !  2004-03  (C. Ethe)  Free form and module
    !!----------------------------------------------------------------------
-#if defined key_top
-   !!----------------------------------------------------------------------
-   !!   'key_top'                                                TOP models
-   !!----------------------------------------------------------------------
    USE par_oce
    USE par_trc
-   USE bdy_oce, only: ln_bdy, nb_bdy, OBC_DATA
+   USE bdy_oce, only: jp_bdy, ln_bdy, nb_bdy, OBC_DATA
    
    IMPLICIT NONE
@@ -173,11 +169,11 @@
 # endif
    !
-   CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc_dflt          ! Default OBC condition for all tracers
-   CHARACTER(len=20), PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  cn_trc               ! Choice of boundary condition for tracers
-   INTEGER,           PUBLIC, ALLOCATABLE,  SAVE,  DIMENSION(:)   ::  nn_trcdmp_bdy        !: =T Tracer damping
+   CHARACTER(len=20), PUBLIC, DIMENSION(jp_bdy) :: cn_trc_dflt   ! Default OBC condition for all tracers
+   CHARACTER(len=20), PUBLIC, DIMENSION(jp_bdy) :: cn_trc        ! Choice of boundary condition for tracers
+   INTEGER,           PUBLIC, DIMENSION(jp_bdy) :: nn_trcdmp_bdy !: =T Tracer damping
+!$AGRIF_DO_NOT_TREAT
    ! External data structure of BDY for TOP. Available elements: cn_obc, ll_trc, trcnow, dmp
    TYPE(OBC_DATA),    PUBLIC, ALLOCATABLE, DIMENSION(:,:), TARGET ::  trcdta_bdy           !: bdy external data (local process)
-   !
-
+!$AGRIF_END_DO_NOT_TREAT
    !!----------------------------------------------------------------------
    !! NEMO/TOP 3.3.1 , NEMO Consortium (2010)
@@ -210,7 +206,5 @@
       !
       IF ( ln_bdy ) THEN
-         ALLOCATE( cn_trc_dflt(nb_bdy)   , cn_trc(nb_bdy)     , nn_trcdmp_bdy(nb_bdy) ,       &
-         &      trcdta_bdy(jptra,nb_bdy)                                              ,       &
-         &      STAT = ierr(2)  )
+         ALLOCATE( trcdta_bdy(jptra, jp_bdy), STAT = ierr(2) )
       ENDIF
       !
@@ -224,10 +218,4 @@
    END FUNCTION trc_alloc
 
-#else
-   !!----------------------------------------------------------------------
-   !!  Empty module :                                     No passive tracer
-   !!----------------------------------------------------------------------
-#endif
-
    !!======================================================================
 END MODULE trc
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcdta.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcdta.F90	(revision 8841)
@@ -227,10 +227,10 @@
                      ik = mbkt(ji,jj) 
                      IF( ik > 1 ) THEN
-                        zl = ( gdept_1d(ik) - gdept_n(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
+                        zl = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
                         ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik-1)
                      ENDIF
                      ik = mikt(ji,jj)
                      IF( ik > 1 ) THEN
-                        zl = ( gdept_n(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
+                        zl = ( gdept_0(ji,jj,ik) - gdept_1d(ik) ) / ( gdept_1d(ik+1) - gdept_1d(ik) )
                         ptrcdta(ji,jj,ik) = (1.-zl) * ptrcdta(ji,jj,ik) + zl * ptrcdta(ji,jj,ik+1)
                      ENDIF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 8841)
@@ -69,5 +69,4 @@
       !
       CALL trc_ini_sms   ! SMS
-      CALL trc_ini_inv   ! Inventories
       CALL trc_ini_trp   ! passive tracers transport
       CALL trc_ice_ini   ! Tracers in sea ice
@@ -78,4 +77,6 @@
       IF( nn_dttrc /= 1 ) &
       CALL trc_sub_ini    ! Initialize variables for substepping passive tracers
+      !
+      CALL trc_ini_inv   ! Inventories
       !
       IF( nn_timing == 1 )   CALL timing_stop('trc_init')
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ALTIX_NAUTILUS_MPT
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ALTIX_NAUTILUS_MPT	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ALTIX_NAUTILUS_MPT	(revision 8841)
@@ -65,4 +65,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-IBM_EKMAN_INGV
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-IBM_EKMAN_INGV	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-IBM_EKMAN_INGV	(revision 8841)
@@ -47,4 +47,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW6_CALYPSO
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW6_CALYPSO	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW6_CALYPSO	(revision 8841)
@@ -43,4 +43,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: anches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW6_VARGAS
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW6_VARGAS	(revision 8840)
+++ 	(revision )
@@ -1,79 +1,0 @@
-#!/bin/bash 
-#!
-# @ job_name = MPI_config
-# standard output file  
-# @ output = $(job_name).$(jobid)
-# standard error file
-# @ error =  $(job_name).$(jobid)
-# job type
-# @ job_type = parallel
-# Number of procs 
-# @ total_tasks = NPROCS
-# time
-# @ wall_clock_limit = 1:30:00
-# @ queue
-
-#
-# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
-# (via sed operating on this template job file). 
-#
-  OCEANCORES=NPROCS
-  export SETTE_DIR=DEF_SETTE_DIR
-
-###############################################################
-#
-# set up mpp computing environment
-#
-# Local settings for machine IBM Power6 (VARGAS at IDRIS France)
-#
-export MPIRUN="mpiexec -n $OCEANCORES"
-
-#
-# load sette functions (only post_test_tidyup needed)
-#
-  . ${SETTE_DIR}/all_functions.sh
-#
-
-# Don't remove neither change the following line
-# BODY
-
-#
-# These variables are needed by post_test_tidyup function in all_functions.sh
-#
-  export EXE_DIR=DEF_EXE_DIR
-  export INPUT_DIR=DEF_INPUT_DIR
-  export CONFIG_DIR=DEF_CONFIG_DIR
-  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
-  export NEW_CONF=DEF_NEW_CONF
-  export CMP_NAM=DEF_CMP_NAM
-  export TEST_NAME=DEF_TEST_NAME
-#
-# end of set up
-###############################################################
-#
-# change to the working directory 
-#
-cd ${EXE_DIR}
-
-  echo Running on host `hostname`
-  echo Time is `date`
-  echo Directory is `pwd`
-# 
-#  Run the parallel MPI executable 
-#
-  echo "Running time ${MPIRUN} ./opa"
-#
-  if [ MPI_FLAG == "yes" ]; then
-     time ${MPIRUN} ./opa
-  else
-     time ./opa
-  fi
-
-#
-  post_test_tidyup
-
-# END_BODY
-# Don't remove neither change the previous line
-
-
-  exit
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_METO
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_METO	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_METO	(revision 8841)
@@ -48,4 +48,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_MONSOON
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_MONSOON	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-PW7_MONSOON	(revision 8841)
@@ -47,4 +47,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA	(revision 8841)
@@ -11,5 +11,5 @@
 # @ total_tasks = NPROCS
 # time
-# @ wall_clock_limit = 1:30:00
+# @ wall_clock_limit = 00:59:00
 # @ queue
 
@@ -44,4 +44,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_DEBUG
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_DEBUG	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_DEBUG	(revision 8841)
@@ -11,5 +11,5 @@
 # @ total_tasks = NPROCS
 # time
-# @ wall_clock_limit = 1:30:00
+# @ wall_clock_limit = 00:59:00
 # @ queue
 
@@ -44,4 +44,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_O0
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_O0	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_ADA_O0	(revision 8841)
@@ -11,5 +11,5 @@
 # @ total_tasks = NPROCS
 # time
-# @ wall_clock_limit = 1:30:00
+# @ wall_clock_limit = 00:59:00
 # @ queue
 
@@ -45,4 +45,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_CURIE
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_CURIE	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_CURIE	(revision 8841)
@@ -45,4 +45,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_MOBILIS	(revision 8841)
@@ -42,4 +42,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: anches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_TITANE
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-X64_TITANE	(revision 8840)
+++ 	(revision )
@@ -1,72 +1,0 @@
-#!/bin/bash 
-#!
-#MSUB -T 3600                # Limite de temps elapsed du job ici 3600s
-#MSUB -r SETTE_JOB           # Nom du job                
-#MSUB -n NPROCS              # Reservation de NPROCS(number of processus)
-##########################################################################
-#
-# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
-# (via sed operating on this template job file). 
-#
-  OCEANCORES=NPROCS
-  export SETTE_DIR=DEF_SETTE_DIR
-#
-# set up mpp computing environment
-#
-# Local settings for machine BULL (TITANE at CCRT France)
-#
-export MPIRUN="mpirun -np $OCEANCORES"
-
-#
-# load sette functions (only post_test_tidyup needed)
-#
-  . ${SETTE_DIR}/all_functions.sh
-#
-
-# modules to load
-module load netcdf
-
-# Don't remove neither change the following line
-# BODY
-
-#
-# These variables are needed by post_test_tidyup function in all_functions.sh
-#
-  export EXE_DIR=DEF_EXE_DIR
-  export INPUT_DIR=DEF_INPUT_DIR
-  export CONFIG_DIR=DEF_CONFIG_DIR
-  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
-  export NEW_CONF=DEF_NEW_CONF
-  export CMP_NAM=DEF_CMP_NAM
-  export TEST_NAME=DEF_TEST_NAME
-#
-# end of set up
-###############################################################
-#
-# change to the working directory 
-#
-cd ${EXE_DIR}
-
-  echo Running on host `hostname`
-  echo Time is `date`
-  echo Directory is `pwd`
-# 
-#  Run the parallel MPI executable 
-#
-  if [ MPI_FLAG == "yes" ]; then
-  echo "Running time ${MPIRUN} ./opa"
-     time ${MPIRUN} ./opa
-  else
-  echo "Running time ./opa"
-     time ./opa
-  fi
-
-#
-  post_test_tidyup
-
-# END_BODY
-# Don't remove neither change the previous line
-
-
-  exit
-
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC40_METO	(revision 8841)
@@ -40,4 +40,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-XC_ARCHER_INTEL	(revision 8841)
@@ -50,4 +50,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena	(revision 8841)
@@ -43,4 +43,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-ifort_athena_xios	(revision 8841)
@@ -49,4 +49,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx	(revision 8841)
@@ -44,4 +44,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx_debug
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx_debug	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-macport_osx_debug	(revision 8841)
@@ -44,4 +44,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-mpmd-ALTIX_NAUTILUS_MPT
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-mpmd-ALTIX_NAUTILUS_MPT	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-mpmd-ALTIX_NAUTILUS_MPT	(revision 8841)
@@ -68,4 +68,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-openmpi_NAVITI_MERCATOR
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-openmpi_NAVITI_MERCATOR	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/batch-openmpi_NAVITI_MERCATOR	(revision 8841)
@@ -40,4 +40,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/sette_batch_template
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/sette_batch_template	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/BATCH_TEMPLATE/sette_batch_template	(revision 8841)
@@ -44,4 +44,5 @@
   export INPUT_DIR=DEF_INPUT_DIR
   export CONFIG_DIR=DEF_CONFIG_DIR
+  export TOOLS_DIR=DEF_TOOLS_DIR
   export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
   export NEW_CONF=DEF_NEW_CONF
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/all_functions.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/all_functions.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/all_functions.sh	(revision 8841)
@@ -172,4 +172,5 @@
 echo "COMPILER is : ${CMP_NAM}"
 echo "TEST is : ${TEST_NAME}"
+echo "TOOLS directory is : ${TOOLS_DIR}"
 ################################################################
 # SMALL DEBUG
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/prepare_job.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/prepare_job.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/prepare_job.sh	(revision 8841)
@@ -151,24 +151,4 @@
 fi
 ################################################################
-
-##########################################################################
-# COPY RESTART FILES (if needed; i.e. only for SHORT job in RESTART TESTS)
-# get the input tarfile if needed
-# SF : not ok for the moment because at this point is needed cn_exp variable,
-# SF : here it it not known.
-#\cd ${EXE_DIR}
-#if [ "$(echo ${TEST_NAME} | grep -c "SHORT" )" -ne 0 ] ; then
-#    for (( i=1; i<=${NB_PROC}; ${NB_PROC}++)) ; do
-#        L_NPROC=`printf "%04d\n" $i`
-#        ln -sf ../LONG/${NEW_CONF}_00000060_restart_${L_NPROC-1}.nc .
-#    done
-#fi
-## SF : other way
-##      for file in ../LONG/${NEW_CONF}_*restart_0*.nc ; do
-##              ncpu=`echo $file | awk -F '_' '{print $NF}' | cut -f 1 -d '.'`
-##              ln -sf ${file}  .
-##      done
-##fi
-##########################################################################
 
 ################################################################
@@ -309,4 +289,5 @@
              -e"s:DEF_EXE_DIR:${EXE_DIR}:" \
              -e"s:DEF_CONFIG_DIR:${CONFIG_DIR}:" \
+             -e"s:DEF_TOOLS_DIR:${TOOLS_DIR}:" \
              -e"s:MPI_FLAG:${MPI_FLAG}:" \
              -e"s:DEF_NEMO_VALIDATION:${NEMO_VALIDATION_DIR}:" -e"s:DEF_NEW_CONF:${NEW_CONF}:" \
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette.sh	(revision 8841)
@@ -144,5 +144,4 @@
 
 for config in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-
 do
 
@@ -661,5 +660,5 @@
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n AMM12_LONG -r AMM12 -j 8 add_key "key_tide" del_key ${DEL_KEYS}
+    . ./makenemo -m ${CMP_NAM} -n AMM12_LONG -r AMM12 -j 8 del_key ${DEL_KEYS}
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -800,6 +799,6 @@
     set_namelist namelist_cfg cn_exp \"SAS\"
     set_namelist namelist_cfg nn_it000 1
-    set_namelist namelist_cfg nn_itend 100
-    set_namelist namelist_cfg nn_stock 50
+    set_namelist namelist_cfg nn_itend 240
+    set_namelist namelist_cfg nn_stock 120
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
@@ -823,6 +822,6 @@
     cd ${EXE_DIR}
     set_namelist namelist_cfg cn_exp \"SAS\"
-    set_namelist namelist_cfg nn_it000 51
-    set_namelist namelist_cfg nn_itend 100
+    set_namelist namelist_cfg nn_it000 121
+    set_namelist namelist_cfg nn_itend 240
     set_namelist namelist_cfg ln_ctl .false.
     set_namelist namelist_cfg ln_clobber .true.
@@ -835,5 +834,7 @@
     set_namelist namelist_cfg ln_rstart .true.
     set_namelist namelist_cfg nn_rstctl 2
-    set_namelist namelist_ice_cfg cn_icerst_in \"SAS_00000050_restart_ice\"
+    set_namelist namelist_cfg nn_date0 010106
+    set_namelist namelist_cfg cn_ocerst_in \"SAS_00000120_restart\"
+    set_namelist namelist_ice_cfg cn_icerst_in \"SAS_00000120_restart_ice\"
     if [ ${USING_MPMD} == "yes" ] ; then
        set_xio_using_server iodef.xml true
@@ -844,5 +845,6 @@
         L_NPROC=$(( $i - 1 ))
         L_NPROC=`printf "%04d\n" ${L_NPROC}`
-        ln -sf ../LONG/SAS_00000050_restart_ice_${L_NPROC}.nc .
+        ln -sf ../LONG/SAS_00000120_restart_${L_NPROC}.nc .
+        ln -sf ../LONG/SAS_00000120_restart_ice_${L_NPROC}.nc .
     done
     cd ${SETTE_DIR}
@@ -1219,5 +1221,5 @@
     export TEST_NAME="LONG"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_LONG -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_zdftmx key_top"
+    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_LONG -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif key_zdftmx" del_key "key_zdftmx_new key_top"
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -1245,4 +1247,5 @@
     set_namelist 1_namelist_cfg nn_itend 300
     set_namelist 1_namelist_cfg nn_stock 150
+    set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_ctl .false.
     set_namelist 1_namelist_cfg ln_clobber .true.
@@ -1283,4 +1286,5 @@
     set_namelist 1_namelist_cfg nn_itend 300
     set_namelist 1_namelist_cfg nn_stock 150
+    set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_rstart .true.
     set_namelist 1_namelist_cfg nn_rstctl 2
@@ -1293,4 +1297,5 @@
     set_namelist namelist_ice_cfg cn_icerst_in \"O2LP_LONG_00000075_restart_ice\"
     set_namelist 1_namelist_cfg cn_ocerst_in \"O2LP_LONG_00000150_restart\"
+    set_namelist 1_namelist_ice_cfg cn_icerst_in \"O2LP_LONG_00000150_restart_ice\"
 
     for (( i=1; i<=$NPROC; i++)) ; do
@@ -1300,4 +1305,5 @@
         ln -sf ../LONG/O2LP_LONG_00000075_restart_ice_${L_NPROC}.nc .
         ln -sf ../LONG/1_O2LP_LONG_00000150_restart_${L_NPROC}.nc .
+        ln -sf ../LONG/1_O2LP_LONG_00000150_restart_ice_${L_NPROC}.nc .
     done
     if [ ${USING_MPMD} == "yes" ] ; then
@@ -1316,5 +1322,5 @@
     export TEST_NAME="REPRO_4_4"
     cd ${CONFIG_DIR0}
-    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_16 -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif" del_key "key_zdftmx key_top"
+    . ./makenemo -m ${CMP_NAM} -n ORCA2AGUL_16 -r ORCA2_LIM3_PISCES -d "OPA_SRC LIM_SRC_3 NST_SRC" -j 8 add_key "key_agrif key_zdftmx" del_key "key_zdftmx_new key_top"
     cd ${SETTE_DIR}
     . ./param.cfg
@@ -1339,4 +1345,5 @@
     set_namelist 1_namelist_cfg nn_it000 1
     set_namelist 1_namelist_cfg nn_itend 150
+    set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_ctl .false.
     set_namelist 1_namelist_cfg ln_clobber .true.
@@ -1377,4 +1384,5 @@
     set_namelist 1_namelist_cfg nn_it000 1
     set_namelist 1_namelist_cfg nn_itend 150
+    set_namelist 1_namelist_cfg nn_fsbc 1
     set_namelist 1_namelist_cfg ln_ctl .false.
     set_namelist 1_namelist_cfg ln_clobber .true.
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette_rpt.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette_rpt.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/SETTE/sette_rpt.sh	(revision 8841)
@@ -1,3 +1,4 @@
 #!/bin/bash -f
+#set -vx
 #
 # simple SETTE report generator.
@@ -10,4 +11,71 @@
 ######################### Start of function definitions #################################
 ##
+
+function restfile() {
+# Rebuild ice restart for SAS CONFIG, and restartability checks. Expects LONG and SHORT run directories.
+# For Stand Alone Surface configuration ocean is not running, just run ice model; so no outputs ocean files.
+# Compares LONG rebuild restart ice file with equivalent entry from the SHORT rebuild restart ice file.
+#
+  vdir=$1
+  nam=$2
+  pass=$3
+#
+  if [ -d $vdir/$nam ]; then
+    dorv=`ls -1rt $vdir/$nam/$mach/ | tail -1l `
+    dorv=`echo $dorv | sed -e 's:.*/::'`
+    rep1=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -2l | head -1 `
+    rep2=`ls -1rt $vdir/$nam/$mach/$dorv/ | tail -1l`
+    cd ${SAS_RESTART_DIR}/LONG
+    #SF add here compilation of rebuild_tools to rebuild restart files, and add comparison of restart files
+    cd ${TOOLS_DIR}
+    ./maketools -n REBUILD_NEMO -m ${mach} > /dev/null 2>&1
+    cd ${TOOLS_DIR}/REBUILD_NEMO
+    #SF echo "REBUILD LONG restart SAS files, without standard output"
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/LONG/SAS_00000100_restart_ice  $NPROC > /dev/null 2>&1
+    #SF echo "REBUILD SHORT restart SAS files, without standard output"
+    ./rebuild_nemo -t 4 ../../CONFIG/SAS_LONG/SHORT/SAS_00000100_restart_ice $NPROC >&-
+    cd ${SAS_RESTART_DIR}/LONG
+    #SF echo "COPY rebuild restart files"
+    cp SAS_00000100_restart_ice.nc $vdir/$nam/$mach/$dorv/LONG/.
+    cp ../SHORT/SAS_00000100_restart_ice.nc $vdir/$nam/$mach/$dorv/SHORT/.
+
+    f1o=$vdir/$nam/$mach/$dorv/LONG/SAS_00000100_restart_ice.nc
+    f2o=$vdir/$nam/$mach/$dorv/SHORT/SAS_00000100_restart_ice.nc
+    if  [ ! -f $f1o ] &&  [ ! -f $f2o ] ; then
+      printf "%-20s %s\n" $nam " REBUILD SAS restart ice DOES NOT exists; incomplete test";
+      return;
+    fi
+    #
+    done_oce=0
+    #
+    if  [  -f $f1o ] && [  -f $f2o ]; then
+      cmp -s $f1o $f2o 
+      #SF  cmp SAS_00000100_restart_ice.nc  ../SHORT/SAS_00000100_restart_ice.nc  > diff_restart.txt
+      if [ $? == 0 ]; then
+        if [ $pass == 0 ]; then
+          printf "%-20s %s %s\n" $nam  " SAS restart files are IDENTICAL :  passed : " $dorv
+        fi
+      else
+        printf "%-20s %s %s\n" $nam  " SAS restart files are DIFFERENT : FAILED : " $dorv 
+        #
+	# Offer view of differences on the second pass
+	#
+        if [ $pass == 1 ]; then
+          echo "BE CAREFUL:  NEED cdo to see differences!!!!! "
+          echo "DO which cdo and replace cdo PATH to the cdo command in SETTE_rpt.sh "
+          echo "IF cdo is not available you need to do difference of netcdf file by hand"
+          echo "<return> to view restart_ice.nc differences"
+          read y
+          cdo -diffv $f1o $f2o
+          done_oce=1
+          #echo "<return> to continue"
+          #read y
+        fi
+      fi
+    fi
+#
+fi
+}
+
 function resttest() { 
 #
@@ -199,4 +267,13 @@
   mach=`grep "COMPILER=" ./sette.sh | sed -e 's/COMPILER=//'`
   NEMO_VALID=`grep "NEMO_VALIDATION_DIR=" ./param.cfg | sed -e 's/NEMO_VALIDATION_DIR=//'`
+# Directory to run the tests
+ SETTE_DIR=$(cd $(dirname "$0"); pwd)
+ MAIN_DIR=$(dirname $SETTE_DIR)
+ CONFIG_DIR0=${MAIN_DIR}/CONFIG
+ TOOLS_DIR=${MAIN_DIR}/TOOLS
+ COMPIL_DIR=${TOOLS_DIR}/COMPILE
+ NPROC=32
+
+  SAS_RESTART_DIR=${CONFIG_DIR0}/SAS_LONG
 #
   if [ ! -d $NEMO_VALID ]; then
@@ -205,4 +282,5 @@
   fi
 #
+
 # The script also needs the date or revision tag. Currently this is taken from the latest sub-directory found in each directory
 #  
@@ -212,7 +290,16 @@
  if [ $pass == 1 ]; then echo "---------------2nd pass------------------";fi
 #
+
+# Rebuild and restartability test for SAS
+#
+ for restart_file in WSAS_LONG
+ do
+ #  restfile $SAS_RESTART_DIR LONG $pass
+   restfile $NEMO_VALID $restart_file $pass
+ done
+#
 # Restartability test
 #
- for restart_test in WGYREPIS_LONG WORCA2LIM3PIS_LONG WORCA2OFFPIS_LONG WAMM12_LONG WSAS_LONG WISOMIP_LONG WORCA2AGUL_LONG
+ for restart_test in WGYREPIS_LONG WORCA2LIM3PIS_LONG WORCA2OFFPIS_LONG WAMM12_LONG WISOMIP_LONG WORCA2AGUL_LONG
  do
    resttest $NEMO_VALID $restart_test $pass
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fadd_keys.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fadd_keys.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fadd_keys.sh	(revision 8841)
@@ -65,5 +65,5 @@
  echo "Adding keys in : ${NEW_CONF}" 
  for i in ${list_add_key} ; do
-	if [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "$i" )" -ne 0 ] ; then
+	if [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "\<$i\>" )" -ne 0 ] ; then
  	   echo "key $i already present in cpp_${NEW_CONF}.fcm" 
 	else
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fdel_keys.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fdel_keys.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fdel_keys.sh	(revision 8841)
@@ -60,16 +60,22 @@
 #
 #-
- echo "Removing keys in : ${NEW_CONF}"
- for i in ${list_del_key} ; do
-        if [ "$(echo ${i} | grep -c key_nproc )" -ne 0 ] ; then
-	        sed -e "s/key_nproc[ij]=.* //"  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm >  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp
-                mv ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp   ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm
-                echo " "
-        elif [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "$i" )" -ne 0 ] ; then
-        	sed -e "s/${i}//"  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm >  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp
-        	mv ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp   ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm
-        	echo "deleted key $i in ${NEW_CONF}"
-        fi
- done
 
- unset -v list_del_key
+echo "Removing keys in : ${NEW_CONF}"
+
+for i in ${list_del_key} ; do
+
+     if [ "$(echo ${i} | grep -c key_nproc )" -ne 0                                      ]; then
+        sed -e "s/key_nproc[ij]=.* //" ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm \
+	    >  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp
+        mv ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm
+        echo " "
+     elif [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "$i" )" -ne 0 ]; then
+         sed -e "s/\b${i}\b//" ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm \
+	     >  ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp
+         mv ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm.tmp ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm
+         echo "deleted key $i in ${NEW_CONF}"
+     fi
+
+done
+
+unset -v list_del_key
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fmake_WORK.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fmake_WORK.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/COMPILE/Fmake_WORK.sh	(revision 8841)
@@ -105,5 +105,5 @@
 done
 
-for i in `(cd ${ZCONF}/MY_SRC ; ls *.[Ffh]90 2>/dev/null ) `
+for i in `(cd ${ZCONF}/MY_SRC ; \ls *.[Ffh]90 2>/dev/null ) `
    do
       [ -f ${ZCONF}/MY_SRC/$i ] &&  ln -sf $PWD/${ZCONF}/MY_SRC/${i} ${ZCONF}/WORK/.
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/DOMAINcfg/src/domzgr.f90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/DOMAINcfg/src/domzgr.f90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/DOMAINcfg/src/domzgr.f90	(revision 8841)
@@ -2078,4 +2078,6 @@
       hbatt(:,:) = zenv(:,:) 
       IF( MINVAL( gphit(:,:) ) * MAXVAL( gphit(:,:) ) <= 0._wp ) THEN
+          IF ( jphgr_msh == 2 .OR. jphgr_msh == 3) CALL ctl_stop( 'dom:zgr_sco:  if jphgr_msh = 2 or 3 and  & 
+                                      & s-coordinates stop, if not correction at Equator is applied, but it is wrong')
          CALL ctl_warn( ' s-coordinates are tapered in vicinity of the Equator' )
          DO jj = 1, jpj
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh	(revision 8841)
@@ -37,5 +37,5 @@
 	    echo '      ./chk_iomput.sh'
 	    echo '      ./chk_iomput.sh --help'
-	    echo '      ./chk_iomput.sh ../../CONFIG/ORCA2_LIM/EXP00/iodef.xml "../../NEMO/OPA_SRC/ ../../NEMO/LIM_SRC_2/"'
+	    echo '      ./chk_iomput.sh ../../CONFIG/ORCA2_LIM/EXP00/context_nemo.xml "../../NEMO/OPA_SRC/ ../../NEMO/LIM_SRC_2/"'
 	    echo
 	    exit ;;
@@ -51,5 +51,11 @@
 done 
 #
-[ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
+echo $xmlfile
+echo $srcdir
+
+for i in $xmlfile
+do
+    [ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
+done
 for i in $srcdir 
 do
@@ -60,11 +66,26 @@
 #
 external=$( grep -c "<field_definition  *\([^ ].* \)*src=" $xmlfile )
-if [ $external -eq 1 ]
+if [ $external -ge 1 ]
 then
     xmlfield_def=$( grep "<field_definition  *\([^ ].* \)*src=" $xmlfile | sed -e 's/.*src="\([^"]*\)".*/\1/' )
-    xmlfield_def=$( dirname $xmlfile )/$xmlfield_def   
+    tmp_def=""
+    for fdef in $xmlfield_def ; do tmp_def="$tmp_def $( dirname $xmlfile )/$fdef" ; done
+    xmlfield_def=$tmp_def
+    echo $xmlfield_def
 else
     xmlfield_def=$xmlfile
 fi
+external=$( grep -c "<file_definition  *\([^ ].* \)*src=" $xmlfile )
+if [ $external -ge 1 ]
+then
+    xmlfile_def=$( grep "<file_definition  *\([^ ].* \)*src=" $xmlfile | sed -e 's/.*src="\([^"]*\)".*/\1/' )
+    tmp_def=""
+    for fdef in $xmlfile_def ; do tmp_def="$tmp_def $( dirname $xmlfile )/$fdef" ; done
+    xmlfile_def=$tmp_def
+    echo $xmlfile_def
+else
+    xmlfile_def=$xmlfile
+fi
+
 [ $inxml -eq 1 ] && grep "< *field  *\([^ ].* \)*id *=" $xmlfield_def
 [ $insrc -eq 1 ] && find $srcdir -name "*.[Ffh]90" -exec grep -iH "^[^\!]*call  *iom_put *(" {} \;
@@ -95,5 +116,5 @@
 # list of variables to be outputed in the xml file
 #
-varlistout=$( grep "< *field  *\([^ ].* \)*field_ref *=" $xmlfile  | sed -e "s/^.*< *field .*field_ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
+varlistout=$( grep "< *field  *\([^ ].* \)*field_ref *=" $xmlfile_def  | sed -e "s/^.*< *field .*field_ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
 #
 echo "--------------------------------------------------"
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/icb_pp.py
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/icb_pp.py	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/MISCELLANEOUS/icb_pp.py	(revision 8841)
@@ -12,19 +12,26 @@
 # cases the missing instances are filled with invalid (NaN) values.
 #
+# Version 2.0 August 2017. Adapted to process all variables and retain original
+#                          datatypes. (acc@noc.ac.uk)
 
-parser = ArgumentParser(description='produce collated trajectory file from distributed output\
-                                     files, e.g. \n python ./icb_pp.py \
-                                     -t  trajectory_icebergs_004248_ -n 296 -o trajsout.nc' )
+parser = ArgumentParser(description='produce collated trajectory file \
+                                     from distributed output files, e.g. \
+                                     \n python ./icb_pp.py \
+                                     -t  trajectory_icebergs_004248_ \
+                                     -n 296 -o trajsout.nc' )
 
-parser.add_argument('-t',dest='froot',help='fileroot_of_distrbuted_data; root name of \
-                     distributed trajectory output (usually completed with XXXX.nc, where \
-                     XXXX is the 4 digit processor number)', 
-                     default='trajectory_icebergs_004248_')
+parser.add_argument('-t',dest='froot',
+                         help='fileroot_of_distrbuted_data; root name \
+                               of  distributed trajectory output (usually \
+                               completed with XXXX.nc, where  XXXX is the \
+                               4 digit processor number)', 
+                      default='trajectory_icebergs_004248_')
 
 parser.add_argument('-n',dest='fnum',help='number of distributed files to process', 
-                     type=int, default=None)
+                         type=int, default=None)
 
-parser.add_argument('-o',dest='fout',help='collated_output_file; file name to receive the \
-                     collated trajectory data', default='trajsout.nc')
+parser.add_argument('-o',dest='fout',
+                         help='collated_output_file; file name to receive \
+                              the collated trajectory data', default='trajsout.nc')
 
 args = parser.parse_args()
@@ -64,17 +71,22 @@
 #
 for n in range(procnum):
- nn = '%4.4d' % n
- fw = Dataset(pathstart+nn+'.nc')
- if len(fw.dimensions['n']) > 0:
-   print pathstart+nn+'.nc'
-   ic = fw.variables['iceberg_number'][:,0]
-   ts = fw.variables['timestep'][:]
-   icv = np.unique(ic)
-   ts = np.unique(ts)
-   print('Min Max ts: ',ts.min(), ts.max())
-   print('Number unique icebergs= ',icv.shape[0])
-   icu.append(icv)
-   times.append(ts)
- fw.close()
+    nn = '%4.4d' % n
+    fw = Dataset(pathstart+nn+'.nc')
+    # keep a list of the variables in the first dataset
+    if n == 0:
+        varlist = fw.variables
+    #
+    # skip any files with no icebergs
+    if len(fw.dimensions['n']) > 0:
+        print pathstart+nn+'.nc'
+        ic = fw.variables['iceberg_number'][:,0]
+        ts = fw.variables['timestep'][:]
+        icv = np.unique(ic)
+        ts = np.unique(ts)
+        print('Min Max ts: ',ts.min(), ts.max())
+        print('Number unique icebergs= ',icv.shape[0])
+        icu.append(icv)
+        times.append(ts)
+    fw.close()
 #
 # Now flatten the lists and reduce to the unique spanning set
@@ -89,71 +101,87 @@
 print('times range from:        ',times.min(), 'to: ', times.max())
 #
-# Declare 2-D arrays to receive the data from all files
+# Declare array to receive data from all files
 #
 nt = times.shape[0]
-lons = np.zeros((ntraj, nt))
-lats = np.zeros((ntraj, nt))
-tims = np.zeros((ntraj, nt))
-xis  = np.zeros((ntraj, nt))
-yjs  = np.zeros((ntraj, nt))
+#
+n=0
+for key, value in varlist.iteritems() :
+    if key != "iceberg_number" :
+        n = n + 1
+inarr = np.zeros((n, ntraj, nt))
 #
 # initially fill with invalid data
 #
-lons.fill(np.nan)
-lats.fill(np.nan)
-xis.fill(np.nan)
-yjs.fill(np.nan)
-tims.fill(np.nan)
+inarr.fill(np.nan)
+#
+# Declare some lists to store variable names, types and long_name and units attributes
+# iceberg_number gets special treatment
+innam = []
+intyp = []
+inlngnam = []
+inunits = []
+for key, value in varlist.iteritems() :
+    if key != "iceberg_number" :
+        innam.append(key)
+#
+# reopen the first datset to collect variable attributes
+# (long_name and units only)
+#
+nn = '%4.4d' % 0
+fw = Dataset(pathstart+nn+'.nc')
+for key, value in varlist.iteritems() :
+    if key != "iceberg_number" :
+        intyp.append(fw.variables[key].dtype)
+        inlngnam.append(fw.variables[key].getncattr('long_name'))
+        inunits.append(fw.variables[key].getncattr('units'))
+fw.close()
 #
 # loop through distributed datasets again, this time
 # checking indices against icu and times lists and
 # inserting data into the correct locations in the 
-# 2-D collated sets.
+# collated sets.
 #
 for n in range(procnum):
- nn = '%4.4d' % n
- fw = Dataset(pathstart+nn+'.nc')
+    nn = '%4.4d' % n
+    fw = Dataset(pathstart+nn+'.nc')
+#
 # Note many distributed datafiles will contain no iceberg data
 # so skip quickly over these
- m  = len(fw.dimensions['n'])
- if m > 0:
-   inx = np.zeros(m, dtype=int)
-   tsx = np.zeros(m, dtype=int)
-   print pathstart+nn+'.nc'
-   ic = fw.variables['iceberg_number'][:,0]
-   ts = fw.variables['timestep'][:]
-   lns = fw.variables['lon'][:]
-   lts = fw.variables['lat'][:]
-   xxs = fw.variables['xi'][:]
-   yys = fw.variables['yj'][:]
-   for k in range(m):
-     inxx   = np.where(icu == ic[k])
-     inx[k] = inxx[0]
-   for k in range(m):
-     inxx   = np.where(times == ts[k])
-     tsx[k] = inxx[0]
-   lons[inx[:],tsx[:]] = lns[:]
-   lats[inx[:],tsx[:]] = lts[:]
-   tims[inx[:],tsx[:]] = ts[:]
-   xis[inx[:],tsx[:]] = xxs[:]
-   yjs[inx[:],tsx[:]] = yys[:]
- fw.close()
-
+    m  = len(fw.dimensions['n'])
+    if m > 0:
+        inx = np.zeros(m, dtype=int)
+        tsx = np.zeros(m, dtype=int)
+        #print pathstart+nn+'.nc'
+        ic = fw.variables['iceberg_number'][:,0]
+        ts = fw.variables['timestep'][:]
+        for k in range(m):
+            inxx   = np.where(icu == ic[k])
+            inx[k] = inxx[0]
+        for k in range(m):
+            inxx   = np.where(times == ts[k])
+            tsx[k] = inxx[0]
+        n = 0
+        for key, value in varlist.iteritems() :
+            if key != "iceberg_number" :
+                insmall = fw.variables[innam[n]][:]
+                inarr[n,inx[:],tsx[:]] = insmall[:]
+                n = n + 1
+    fw.close()
+#
 # Finally create the output file and write out the collated sets
 #
-fo = Dataset(pathout, 'w', format='NETCDF4')
+fo = Dataset(pathout, 'w', format='NETCDF4_CLASSIC')
 ntrj = fo.createDimension('ntraj', ntraj)
 nti  = fo.createDimension('ntime', None)
-olon = fo.createVariable('lon', 'f4',('ntraj','ntime'))
-olat = fo.createVariable('lat', 'f4',('ntraj','ntime'))
-otim = fo.createVariable('ttim', 'f4',('ntraj','ntime'))
-oxis = fo.createVariable('xis', 'f4',('ntraj','ntime'))
-oyjs = fo.createVariable('yjs', 'f4',('ntraj','ntime'))
-icbn = fo.createVariable('icbn', 'f4',('ntraj'))
-olon[:,:] = lons
-olat[:,:] = lats
-otim[:,:] = tims
-oxis[:,:] = xis
-oyjs[:,:] = yjs
+icbn = fo.createVariable('iceberg_number', 'i4',('ntraj'))
 icbn[:] = icu
+n = 0
+for key, value in varlist.iteritems() :
+    if key != "iceberg_number" :
+        oout = fo.createVariable(innam[n], intyp[n], ('ntraj','ntime'),
+                                 zlib=True, complevel=1, chunksizes=(1,nt))
+        oout[:,:] = inarr[n,:,:]
+        oout.long_name = inlngnam[n]
+        oout.units = inunits[n]
+        n = n + 1
 fo.close()
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_create_bathy.f90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_create_bathy.f90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_create_bathy.f90	(revision 8841)
@@ -54,5 +54,5 @@
   REAL*8, DIMENSION(:,:),POINTER :: save_gdepw,rx,ry,maskedtopo
   REAL*8  :: Cell_lonmin,Cell_lonmax,Cell_latmin,Cell_latmax,wghts
-  LOGICAL :: Pacifique
+  LOGICAL :: Pacifique=.FALSE.
   INTEGER :: boundary,xpos,ypos,iimin,iimax,jjmax,jjmin
   INTEGER :: nbloops,nxhr,nyhr,ji,jj,nbiter,nbloopmax
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_readwrite.f90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_readwrite.f90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/NESTING/src/agrif_readwrite.f90	(revision 8841)
@@ -232,5 +232,5 @@
     CHARACTER(len=1),DIMENSION(2) :: dimnames
     !
-    status = nf90_create(name,NF90_WRITE,ncid)
+    status = nf90_create(name,NF90_NOCLOBBER,ncid)
     status = nf90_close(ncid)          
     !
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/SECTIONS_DIADCT/src/compute_sections.f90
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/SECTIONS_DIADCT/src/compute_sections.f90	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TOOLS/SECTIONS_DIADCT/src/compute_sections.f90	(revision 8841)
@@ -681,6 +681,6 @@
      IF( sec%nb_point .ne. 0 )THEN
         IF (  sec%listPoint(sec%nb_point)%I .NE.  sec%listPoint(1)%I ) THEN
-           sec%slopeSection = ( sec%listPoint(sec%nb_point)%J - sec%listPoint(1)%J ) /  &
-                              ( sec%listPoint(sec%nb_point)%I - sec%listPoint(1)%I )      
+           sec%slopeSection = REAL( ( sec%listPoint(sec%nb_point)%J - sec%listPoint(1)%J ) , wp )/  &
+                              REAL( ( sec%listPoint(sec%nb_point)%I - sec%listPoint(1)%I ) , wp )     
         ELSE
            sec%slopeSection = 10000._wp
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/AMM12/namelist_cfg	(revision 8841)
@@ -201,8 +201,4 @@
 /
 !-----------------------------------------------------------------------
-&namobc        !   open boundaries parameters                           ("key_obc")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
Index: /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg
===================================================================
--- /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg	(revision 8840)
+++ /branches/UKMO/ROMS_WAD_7832/NEMOGCM/TRUST/inputs/GYRE/namelist_cfg	(revision 8841)
@@ -155,8 +155,4 @@
 /
 !-----------------------------------------------------------------------
-&namobc        !   open boundaries parameters                           ("key_obc")
-!-----------------------------------------------------------------------
-/
-!-----------------------------------------------------------------------
 &namagrif      !  AGRIF zoom                                            ("key_agrif")
 !-----------------------------------------------------------------------
