Index: NEMO/trunk/src/OCE/nemogcm.F90
===================================================================
--- NEMO/trunk/src/OCE/nemogcm.F90	(revision 12214)
+++ NEMO/trunk/src/OCE/nemogcm.F90	(revision 12377)
@@ -46,5 +46,5 @@
    USE closea         ! treatment of closed seas (for ln_closea)
    USE usrdef_nam     ! user defined configuration
-   USE tideini        ! tidal components initialization   (tide_ini routine)
+   USE tide_mod, ONLY : tide_init ! tidal components initialization   (tide_init routine)
    USE bdy_oce,  ONLY : ln_bdy
    USE bdyini         ! open boundary cond. setting       (bdy_init routine)
@@ -59,6 +59,7 @@
    USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
    USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
-   USE diaharm        ! tidal harmonics diagnostics  (dia_harm_init routine)
+   USE diamlr         ! IOM context management for multiple-linear-regression analysis
    USE step           ! NEMO time-stepping                 (stp     routine)
+   USE isfstp         ! ice shelf                     (isf_stp_init routine)
    USE icbini         ! handle bergs, initialisation
    USE icbstp         ! handle bergs, calving, themodynamics and transport
@@ -69,8 +70,9 @@
    USE stopar         ! Stochastic param.: ???
    USE stopts         ! Stochastic param.: ???
-   USE diurnal_bulk   ! diurnal bulk SST 
+   USE diu_layers     ! diurnal bulk SST and coolskin
    USE step_diu       ! diurnal bulk SST timestepping (called from here if run offline)
    USE crsini         ! initialise grid coarsening utility
    USE dia25h         ! 25h mean output
+   USE diadetide      ! Weights computation for daily detiding of model diagnostics
    USE sbc_oce , ONLY : lk_oasis
    USE wet_dry        ! Wetting and drying setting   (wad_init routine)
@@ -139,4 +141,5 @@
       !                            !-----------------------!
 #if defined key_agrif
+      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
       CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
       CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA 
@@ -171,4 +174,5 @@
       !
       ! Recursive update from highest nested level to lowest:
+      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
       CALL Agrif_step_child_adj(Agrif_Update_All)
       !
@@ -262,5 +266,5 @@
       INTEGER ::   ios, ilocal_comm   ! local integers
       !!
-      NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
+      NAMELIST/namctl/ sn_cfctl,  nn_print, nn_ictls, nn_ictle,             &
          &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
          &             ln_timing, ln_diacfl
@@ -306,6 +310,6 @@
       IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
       ! open reference and configuration namelist files
-                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
-                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
+                  CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
+                  CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
       IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
       ! open /dev/null file to be able to supress output write easily
@@ -313,15 +317,31 @@
       !
       !                             !--------------------!
-      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
+      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
       !                             !--------------------!
       !
-      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
       READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
 901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
-      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
       READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
 902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
       !
-      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
+      ! finalize the definition of namctl variables
+      IF( sn_cfctl%l_allon ) THEN
+         ! Turn on all options.
+         CALL nemo_set_cfctl( sn_cfctl, .TRUE., .TRUE. )
+         ! Ensure all processors are active
+         sn_cfctl%procmin = 0 ; sn_cfctl%procmax = 1000000 ; sn_cfctl%procincr = 1
+      ELSEIF( sn_cfctl%l_config ) THEN
+         ! Activate finer control of report outputs
+         ! optionally switch off output from selected areas (note this only
+         ! applies to output which does not involve global communications)
+         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
+           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
+           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
+      ELSE
+         ! turn off all options.
+         CALL nemo_set_cfctl( sn_cfctl, .FALSE., .TRUE. )
+      ENDIF
+      !
+      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
       !
       IF(lwp) THEN                      ! open listing units
@@ -355,17 +375,4 @@
       ENDIF
       !
-      ! finalize the definition of namctl variables
-      IF( sn_cfctl%l_config ) THEN
-         ! Activate finer control of report outputs
-         ! optionally switch off output from selected areas (note this only
-         ! applies to output which does not involve global communications)
-         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
-           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
-           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
-      ELSE
-         ! Use ln_ctl to turn on or off all options.
-         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
-      ENDIF
-      !
       IF(lwm) WRITE( numond, namctl )
       !
@@ -374,8 +381,6 @@
       !                             !------------------------------------!
       !
-      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
       READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
 903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
-      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
       READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
 904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
@@ -397,4 +402,7 @@
       CALL nemo_alloc()
 
+      ! Initialise time level indices
+      Nbb = 1; Nnn = 2; Naa = 3; Nrhs = Naa
+
       !                             !-------------------------------!
       !                             !  NEMO general initialization  !
@@ -411,33 +419,35 @@
       IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
                            CALL     wad_init        ! Wetting and drying options
-                           CALL     dom_init("OPA") ! Domain
-      IF( ln_crs       )   CALL     crs_init        ! coarsened grid: domain initialization 
-      IF( ln_ctl       )   CALL prt_ctl_init        ! Print control
+                           CALL     dom_init( Nbb, Nnn, Naa, "OPA") ! Domain
+      IF( ln_crs       )   CALL     crs_init(      Nnn )       ! coarsened grid: domain initialization 
+      IF( sn_cfctl%l_prtctl )   &
+         &                 CALL prt_ctl_init        ! Print control
       
-      CALL diurnal_sst_bulk_init                ! diurnal sst
+                           CALL diurnal_sst_bulk_init       ! diurnal sst
       IF( ln_diurnal   )   CALL diurnal_sst_coolskin_init   ! cool skin   
       !                            
-      IF( ln_diurnal_only ) THEN                   ! diurnal only: a subset of the initialisation routines
-         CALL  istate_init                            ! ocean initial state (Dynamics and tracers)
-         CALL     sbc_init                            ! Forcings : surface module
-         CALL tra_qsr_init                            ! penetrative solar radiation qsr
-         IF( ln_diaobs ) THEN                         ! Observation & model comparison
-            CALL dia_obs_init                            ! Initialize observational data
-            CALL dia_obs( nit000 - 1 )                   ! Observation operator for restart
+      IF( ln_diurnal_only ) THEN                    ! diurnal only: a subset of the initialisation routines
+         CALL  istate_init( Nbb, Nnn, Naa )         ! ocean initial state (Dynamics and tracers)
+         CALL     sbc_init( Nbb, Nnn, Naa )         ! Forcings : surface module
+         CALL tra_qsr_init                          ! penetrative solar radiation qsr
+         IF( ln_diaobs ) THEN                       ! Observation & model comparison
+            CALL dia_obs_init( Nnn )                ! Initialize observational data
+            CALL dia_obs( nit000 - 1, Nnn )         ! Observation operator for restart
          ENDIF     
-         IF( lk_asminc )   CALL asm_inc_init          ! Assimilation increments
+         IF( lk_asminc )   CALL asm_inc_init( Nbb, Nnn, Nrhs )   ! Assimilation increments
          !
          RETURN                                       ! end of initialization
       ENDIF
+      !
       
-                           CALL  istate_init    ! ocean initial state (Dynamics and tracers)
+                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
 
       !                                      ! external forcing 
-                           CALL    tide_init    ! tidal harmonics
-                           CALL     sbc_init    ! surface boundary conditions (including sea-ice)
-                           CALL     bdy_init    ! Open boundaries initialisation
+                           CALL    tide_init                     ! tidal harmonics
+                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
+                           CALL     bdy_init                     ! Open boundaries initialisation
 
       !                                      ! Ocean physics
-                           CALL zdf_phy_init    ! Vertical physics
+                           CALL zdf_phy_init( Nnn )    ! Vertical physics
                                      
       !                                         ! Lateral physics
@@ -455,14 +465,14 @@
 
       !                                      ! Dynamics
-      IF( lk_c1d       )   CALL dyn_dmp_init      ! internal momentum damping
-                           CALL dyn_adv_init      ! advection (vector or flux form)
-                           CALL dyn_vor_init      ! vorticity term including Coriolis
-                           CALL dyn_ldf_init      ! lateral mixing
-                           CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
-                           CALL dyn_spg_init      ! surface pressure gradient
+      IF( lk_c1d       )   CALL dyn_dmp_init         ! internal momentum damping
+                           CALL dyn_adv_init         ! advection (vector or flux form)
+                           CALL dyn_vor_init         ! vorticity term including Coriolis
+                           CALL dyn_ldf_init         ! lateral mixing
+                           CALL dyn_hpg_init( Nnn )  ! horizontal gradient of Hydrostatic pressure
+                           CALL dyn_spg_init         ! surface pressure gradient
 
 #if defined key_top
       !                                      ! Passive tracers
-                           CALL     trc_init
+                           CALL     trc_init( Nbb, Nnn, Naa )
 #endif
       IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
@@ -470,4 +480,7 @@
       !                                      ! Icebergs
                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
+
+                                                ! ice shelf
+                           CALL isf_init( Nbb, Nnn, Naa )
 
       !                                      ! Misc. options
@@ -476,17 +489,18 @@
      
       !                                      ! Diagnostics
-                           CALL     flo_init    ! drifting Floats
+                           CALL     flo_init( Nnn )    ! drifting Floats
       IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
-                           CALL dia_ptr_init    ! Poleward TRansports initialization
+!                           CALL dia_ptr_init    ! Poleward TRansports initialization
                            CALL dia_dct_init    ! Sections tranports
-                           CALL dia_hsb_init    ! heat content, salt content and volume budgets
-                           CALL     trd_init    ! Mixed-layer/Vorticity/Integral constraints trends
-                           CALL dia_obs_init    ! Initialize observational data
-                           CALL dia_25h_init    ! 25h mean  outputs
-                           CALL dia_harm_init   ! tidal harmonics outputs
-     IF( ln_diaobs    )    CALL dia_obs( nit000-1 )   ! Observation operator for restart
+                           CALL dia_hsb_init( Nnn )    ! heat content, salt content and volume budgets
+                           CALL     trd_init( Nnn )    ! Mixed-layer/Vorticity/Integral constraints trends
+                           CALL dia_obs_init( Nnn )    ! Initialize observational data
+                           CALL dia_25h_init( Nbb )    ! 25h mean  outputs
+                           CALL dia_detide_init ! Weights computation for daily detiding of model diagnostics
+      IF( ln_diaobs    )   CALL dia_obs( nit000-1, Nnn )   ! Observation operator for restart
+                           CALL dia_mlr_init    ! Initialisation of IOM context management for multiple-linear-regression analysis
 
       !                                      ! Assimilation increments
-      IF( lk_asminc    )   CALL asm_inc_init    ! Initialize assimilation increments
+      IF( lk_asminc    )   CALL asm_inc_init( Nbb, Nnn, Nrhs )   ! Initialize assimilation increments
       !
       IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
@@ -511,5 +525,6 @@
          WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namctl'
-         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
+         WRITE(numout,*) '                              sn_cfctl%l_glochk  = ', sn_cfctl%l_glochk
+         WRITE(numout,*) '                              sn_cfctl%l_allon   = ', sn_cfctl%l_allon
          WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
          WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
@@ -517,6 +532,7 @@
          WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
          WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
-         WRITE(numout,*) '                              sn_cfctl%l_mppout  = ', sn_cfctl%l_mppout
-         WRITE(numout,*) '                              sn_cfctl%l_mpptop  = ', sn_cfctl%l_mpptop
+         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
+         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
+         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
          WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin  
          WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax  
@@ -556,5 +572,5 @@
       !                             ! Parameter control
       !
-      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
+      IF( sn_cfctl%l_prtctl .OR. sn_cfctl%l_prttrc ) THEN              ! sub-domain area indices for the control prints
          IF( lk_mpp .AND. jpnij > 1 ) THEN
             isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
@@ -617,9 +633,5 @@
       IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
       IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
-      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
-      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
       IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
-      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
-      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
       IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
       IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
@@ -686,6 +698,7 @@
       sn_cfctl%l_oceout  = setto
       sn_cfctl%l_layout  = setto
-      sn_cfctl%l_mppout  = setto
-      sn_cfctl%l_mpptop  = setto
+      sn_cfctl%l_prtctl  = setto
+      sn_cfctl%l_prttrc  = setto
+      sn_cfctl%l_oasout  = setto
    END SUBROUTINE nemo_set_cfctl
 
