Index: trunk/NEMO/OPA_SRC/step.F90
===================================================================
--- trunk/NEMO/OPA_SRC/step.F90	(revision 1482)
+++ trunk/NEMO/OPA_SRC/step.F90	(revision 1492)
@@ -5,8 +5,8 @@
    !!======================================================================
    !! History :  OPA  !  1991-03  (G. Madec)  Original code
-   !!                 !  1991-11  (G. Madec)
-   !!                 !  1992-06  (M. Imbard)  add a first output record
-   !!                 !  1996-04  (G. Madec)  introduction of dynspg
-   !!                 !  1996-04  (M.A. Foujols)  introduction of passive tracer
+   !!             -   !  1991-11  (G. Madec)
+   !!             -   !  1992-06  (M. Imbard)  add a first output record
+   !!             -   !  1996-04  (G. Madec)  introduction of dynspg
+   !!             -   !  1996-04  (M.A. Foujols)  introduction of passive tracer
    !!            8.0  !  1997-06  (G. Madec)  new architecture of call
    !!            8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
@@ -15,9 +15,10 @@
    !!   NEMO     1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
    !!             -   !  2004-08  (C. Talandier) New trends organization
-   !!                 !  2005-01  (C. Ethe) Add the KPP closure scheme
-   !!                 !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
-   !!                 !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
-   !!                 !  2006-07  (S. Masson)  restart using iom
+   !!             -   !  2005-01  (C. Ethe) Add the KPP closure scheme
+   !!             -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
+   !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             -   !  2006-07  (S. Masson)  restart using iom
    !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
+   !!             -   !  2009-06  (S. Masson, G. Madec)  TKE2 restart compatible with key_cpl
    !!----------------------------------------------------------------------
 
@@ -123,5 +124,5 @@
    PRIVATE
 
-   PUBLIC stp            ! called by opa.F90
+   PUBLIC   stp        ! called by opa.F90
 
    !! * Substitutions
@@ -129,5 +130,5 @@
 #  include "zdfddm_substitute.h90"
    !!----------------------------------------------------------------------
-   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
    !! $Id$
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
@@ -179,92 +180,76 @@
       ! Update data, open boundaries, surface boundary condition (including sea-ice)
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
       IF( lk_dtatem  )   CALL dta_tem( kstp )         ! update 3D temperature data
       IF( lk_dtasal  )   CALL dta_sal( kstp )         ! update 3D salinity data
-
                          CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
-
       IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
       IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
-
       IF( lk_bdy     )   CALL bdy_dta( kstp )         ! update dynamic and tracer data at unstructured open boundary
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !                Ocean dynamics : ssh, wn, hdiv, rot                   !
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                       CALL div_cur( kstp )                 ! Horizontal divergence & Relative vorticity
-      IF( n_cla == 1 ) CALL div_cla( kstp )                 ! Cross Land Advection (Update Hor. divergence)
-                       CALL ssh_wzv( kstp )                 ! after ssh & vertical velocity
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
-      !-----------------------------------------------------------------------
-
-                       CALL bn2( tb, sb, rn2b )              ! before Brunt-Vaisala frequency
-                       CALL bn2( tn, sn, rn2  )              ! now    Brunt-Vaisala frequency
-
-      !-----------------------------------------------------------------------
-      !  VERTICAL PHYSICS
-      !-----------------------------------------------------------------------
-      !                                                     ! Vertical eddy viscosity and diffusivity coefficients
-      IF( lk_zdfric )   CALL zdf_ric( kstp )                       ! Richardson number dependent Kz
-
-      IF( lk_zdftke )   CALL zdf_tke ( kstp )                      ! TKE  closure scheme for Kz
-      IF( lk_zdftke2)   CALL zdf_tke2( kstp )                      ! TKE2 closure scheme for Kz
-
-      IF( lk_zdfkpp )   CALL zdf_kpp( kstp )                       ! KPP closure scheme for Kz
-
-      IF( lk_zdfcst )   THEN                                       ! Constant Kz (reset avt, avm[uv] to the background value)
+      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL div_cur( kstp )         ! Horizontal divergence & Relative vorticity
+      IF( n_cla == 1 )   CALL div_cla( kstp )         ! Cross Land Advection (Update Hor. divergence)
+                         CALL ssh_wzv( kstp )         ! after ssh & vertical velocity
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update                (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL bn2( tb, sb, rn2b )     ! before Brunt-Vaisala frequency
+                         CALL bn2( tn, sn, rn2  )     ! now    Brunt-Vaisala frequency
+      !
+      !  VERTICAL PHYSICS   
+      !                                               ! Vertical eddy viscosity and diffusivity coefficients
+      IF( lk_zdfric  )   CALL zdf_ric( kstp )         ! Richardson number dependent Kz
+      IF( lk_zdftke  )   CALL zdf_tke ( kstp )        ! TKE  closure scheme for Kz
+      IF( lk_zdftke2 )   CALL zdf_tke2( kstp )        ! TKE2 closure scheme for Kz
+      IF( lk_zdfkpp  )   CALL zdf_kpp( kstp )         ! KPP closure scheme for Kz
+      IF( lk_zdfcst  )   THEN                         ! Constant Kz (reset avt, avm[uv] to the background value)
          avt (:,:,:) = avt0 * tmask(:,:,:)
          avmu(:,:,:) = avm0 * umask(:,:,:)
          avmv(:,:,:) = avm0 * vmask(:,:,:)
       ENDIF
-
-      IF( ln_rnf_mouth ) THEN                                ! increase diffusivity at rivers mouths
+      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
          DO jk = 2, nkrnf   ;   avt(:,:,jk) = avt(:,:,jk) + 2.e0 * rn_avt_rnf * rnfmsk(:,:) * tmask(:,:,jk)   ;   END DO
       ENDIF
-
-      IF( ln_zdfevd )   CALL zdf_evd( kstp )                 ! enhanced vertical eddy diffusivity
-
-      IF( lk_zdftmx )   CALL zdf_tmx( kstp )                 ! tidal vertical mixing
+      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
+
+      IF( lk_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
 
       IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
-         &              CALL zdf_ddm( kstp )                 ! double diffusive mixing
-
-
-                        CALL zdf_bfr( kstp )                 ! bottom friction
-
-                        CALL zdf_mxl( kstp )                 ! mixed layer depth
-
-      IF( lrst_oce .AND. lk_zdftke2 )   &                    ! write tke2 information in the restart file
-         &               CALL tke2_rst( kstp, 'WRITE' )
-
-      !-----------------------------------------------------------------------
-      !  LATERAL PHYSICS
-      !-----------------------------------------------------------------------
-      IF( lk_ldfslp )   THEN 
-                           CALL eos( tb, sb, rhd, rhop )          ! before in situ density
-         IF( ln_zps )      CALL zps_hde( kstp, tb, sb, rhd,  &    ! Partial steps: before horizontal gradient
-            &                                gtu, gsu, gru,  &    ! of t, s, rd at the last ocean level
-            &                                gtv, gsv, grv )
-                               CALL ldf_slp( kstp, rhd, rn2b )      ! before slope of the lateral mixing
+         &               CALL zdf_ddm( kstp )         ! double diffusive mixing
+
+                         CALL zdf_bfr( kstp )         ! bottom friction
+
+                         CALL zdf_mxl( kstp )         ! mixed layer depth
+
+                                                      ! write tke2 information in the restart file
+      IF( lrst_oce .AND. lk_zdftke2 )   CALL tke2_rst( kstp, 'WRITE' )
+      !
+      !  LATERAL  PHYSICS 
+      !
+      IF( lk_ldfslp ) THEN                            ! slope of lateral mixing
+                         CALL eos( tb, sb, rhd, rhop )          ! before in situ density
+         IF( ln_zps )    CALL zps_hde( kstp, tb, sb, rhd,  &    ! Partial steps: before horizontal gradient
+            &                              gtu, gsu, gru,  &    ! of t, s, rd at the last ocean level
+            &                              gtv, gsv, grv )
+                         CALL ldf_slp( kstp, rhd, rn2b )        ! before slope of the lateral mixing
       ENDIF
 #if defined key_traldf_c2d
-      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )                 ! eddy induced velocity coefficient
+      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )      ! eddy induced velocity coefficient
 #  endif
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL dia_wri( kstp, indic )         ! ocean model: outputs
-      IF( lk_floats  )   CALL flo_stp( kstp )                ! drifting Floats
-      IF( lk_diaspr  )   CALL dia_spr( kstp )                ! Surface pressure diagnostics
-      IF( lk_diahth  )   CALL dia_hth( kstp )                ! Thermocline depth (20 degres isotherm depth)
-      IF( lk_diagap  )   CALL dia_gap( kstp )                ! basin averaged diagnostics
-      IF( lk_diahdy  )   CALL dia_hdy( kstp )                ! dynamical heigh diagnostics
-      IF( lk_diafwb  )   CALL dia_fwb( kstp )                ! Fresh water budget diagnostics
-      IF( ln_diaptr  )   CALL dia_ptr( kstp )                ! Poleward TRansports diagnostics
+      ! diagnostics and outputs             (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL dia_wri( kstp, indic )  ! ocean model: outputs
+      IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
+      IF( lk_diaspr  )   CALL dia_spr( kstp )         ! Surface pressure diagnostics
+      IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
+      IF( lk_diagap  )   CALL dia_gap( kstp )         ! basin averaged diagnostics
+      IF( lk_diahdy  )   CALL dia_hdy( kstp )         ! dynamical heigh diagnostics
+      IF( lk_diafwb  )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
+      IF( ln_diaptr  )   CALL dia_ptr( kstp )         ! Poleward TRansports diagnostics
 
 #if defined key_top
@@ -272,14 +257,10 @@
       ! Passive Tracer Model
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
-      !-----------------------------------------------------------------------
-                             CALL trc_stp( kstp )            ! time-stepping
-#endif
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Active tracers
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ua, va arrays are used as workspace in this section
-      !-----------------------------------------------------------------------
+                         CALL trc_stp( kstp )         ! time-stepping
+#endif
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers                              (ua, va used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                              ta(:,:,:) = 0.e0               ! set tracer trends to zero
                              sa(:,:,:) = 0.e0
@@ -300,67 +281,64 @@
                              CALL tra_zdf    ( kstp )       ! vertical mixing and after tracer fields
 
-      IF( .NOT. ln_dynhpg_imp  ) THEN                       ! centered hpg (default case)
-                               CALL eos( tn, sn, rhd, rhop )          ! now (swap=before) in situ density for dynhpg module
-         IF( ln_zps    )       CALL zps_hde( kstp, tn, sn, rhd,   &   ! Partial steps: now horizontal gradient
-            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
-            &                                     gtv, gsv, grv )
+      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg (time stepping then eos)
+         IF( ln_zdfnpc   )   CALL tra_npc    ( kstp )            ! update after fields by non-penetrative convection
+                             CALL tra_nxt    ( kstp )            ! tracer fields at next time step
+                             CALL eos( ta, sa, rhd, rhop )       ! Time-filtered in situ density for hpg computation
+         IF( ln_zps      )   CALL zps_hde( kstp, ta, sa, rhd,   &   ! Partial steps: time filtered hor. derivative
+            &                                   gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                   gtv, gsv, grv )
+         
+      ELSE                                                  ! centered hpg  (eos then time stepping)
+                             CALL eos( tn, sn, rhd, rhop )       ! now in situ density for hpg computation
+         IF( ln_zps      )   CALL zps_hde( kstp, tn, sn, rhd,   &   ! Partial steps: now horizontal derivative
+            &                                   gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
+            &                                   gtv, gsv, grv )
+         IF( ln_zdfnpc   )   CALL tra_npc    ( kstp )       ! update after fields by non-penetrative convection
+                             CALL tra_nxt    ( kstp )       ! tracer fields at next time step
       ENDIF 
-      IF( ln_zdfnpc      )   CALL tra_npc    ( kstp )       ! update after fields by non-penetrative convection
-                             CALL tra_nxt    ( kstp )       ! tracer fields at next time step
-      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg
-                               CALL eos( ta, sa, rhd, rhop )          ! Time-filtered in situ density used in dynhpg module
-         IF( ln_zps    )       CALL zps_hde( kstp, ta, sa, rhd,   &   ! Partial steps: time filtered hor. gradient
-            &                                     gtu, gsu, gru,  &   ! of t, s, rd at the bottom ocean level
-            &                                     gtv, gsv, grv )
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Dynamics
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ta, sa arrays are used as workspace in this section 
-      !-----------------------------------------------------------------------
-                               ua(:,:,:) = 0.e0               ! set dynamics trends to zero
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Dynamics                                    (ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                               ua(:,:,:) = 0.e0             ! set dynamics trends to zero
                                va(:,:,:) = 0.e0
 
-                               CALL dyn_adv( kstp )           ! advection (vector or flux form)
-                               CALL dyn_vor( kstp )           ! vorticity term including Coriolis
-                               CALL dyn_ldf( kstp )           ! lateral mixing
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn          ! momemtum sponge
-#endif
-                               CALL dyn_hpg( kstp )           ! horizontal gradient of Hydrostatic pressure
-                               CALL dyn_zdf( kstp )           ! vertical diffusion
+                               CALL dyn_adv( kstp )         ! advection (vector or flux form)
+                               CALL dyn_vor( kstp )         ! vorticity term including Coriolis
+                               CALL dyn_ldf( kstp )         ! lateral mixing
+#if defined key_agrif
+      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn        ! momemtum sponge
+#endif
+                               CALL dyn_hpg( kstp )         ! horizontal gradient of Hydrostatic pressure
+                               CALL dyn_zdf( kstp )         ! vertical diffusion
       IF( lk_dynspg_rl ) THEN
-         IF( lk_obc    )       CALL obc_spg( kstp )           ! surface pressure gradient at open boundaries
+         IF( lk_obc    )       CALL obc_spg( kstp )         ! surface pressure gradient at open boundaries
       ENDIF
                                indic=0
-                               CALL dyn_spg( kstp, indic )    ! surface pressure gradient
-                               CALL dyn_nxt( kstp )           ! lateral velocity at next time step
-
-                               CALL ssh_nxt( kstp )           ! sea surface height at next time step
+                               CALL dyn_spg( kstp, indic )  ! surface pressure gradient
+                               CALL dyn_nxt( kstp )         ! lateral velocity at next time step
+
+                               CALL ssh_nxt( kstp )         ! sea surface height at next time step
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       ! Control and restarts
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                                 CALL stp_ctl( kstp, indic )
-      IF( indic < 0          )   THEN
-                                 CALL ctl_stop( 'step: indic < 0' )
-                                 CALL dia_wri_state( 'output.abort', kstp )
-      ENDIF
-      IF( kstp == nit000     )   CALL iom_close( numror )             ! close input  ocean restart file
-      IF( lrst_oce           )   CALL rst_write    ( kstp )           ! write output ocean restart file
-      IF( lk_obc             )   CALL obc_rst_write( kstp )           ! write open boundary restart file
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Trends
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
-      !-----------------------------------------------------------------------
-
-      IF( nstop == 0 ) THEN                                 ! Diagnostics:
-         IF( lk_trddyn  )   CALL trd_dwr( kstp )                 ! trends: dynamics 
-         IF( lk_trdtra  )   CALL trd_twr( kstp )                 ! trends: active tracers
-         IF( lk_trdmld  )   CALL trd_mld( kstp )                 ! trends: Mixed-layer 
-         IF( lk_trdvor  )   CALL trd_vor( kstp )                 ! trends: vorticity budget
+                               CALL stp_ctl( kstp, indic )
+      IF( indic < 0        )   THEN
+                               CALL ctl_stop( 'step: indic < 0' )
+                               CALL dia_wri_state( 'output.abort', kstp )
+      ENDIF
+      IF( kstp == nit000   )   CALL iom_close( numror )     ! close input  ocean restart file
+      IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
+      IF( lk_obc           )   CALL obc_rst_write( kstp )   ! write open boundary restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Trends                              (ua, va, ta, sa used as workspace)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( nstop == 0 ) THEN                         
+         IF( lk_trddyn     )   CALL trd_dwr( kstp )         ! trends: dynamics 
+         IF( lk_trdtra     )   CALL trd_twr( kstp )         ! trends: active tracers
+         IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer 
+         IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
       ENDIF
 
@@ -368,6 +346,5 @@
       ! Coupled mode
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-      IF( lk_cpl )   CALL sbc_cpl_snd( kstp )                 ! coupled mode : field exchanges
+      IF( lk_cpl           )   CALL sbc_cpl_snd( kstp )     ! coupled mode : field exchanges
       !
       !
