Index: NEMO/trunk/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- NEMO/trunk/src/OCE/DYN/dynspg_ts.F90	(revision 12377)
+++ NEMO/trunk/src/OCE/DYN/dynspg_ts.F90	(revision 12489)
@@ -72,6 +72,6 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv , vn_adv   !: Advection vel. at "now" barocl. step
    !
-   INTEGER, SAVE :: icycle      ! Number of barotropic sub-steps for each internal step nn_baro <= 2.5 nn_baro
-   REAL(wp),SAVE :: rdtbt       ! Barotropic time step
+   INTEGER, SAVE :: icycle      ! Number of barotropic sub-steps for each internal step nn_e <= 2.5 nn_e
+   REAL(wp),SAVE :: rDt_e       ! Barotropic time step
    !
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   wgtbtp1, wgtbtp2   ! 1st & 2nd weights used in time filtering of barotropic fields
@@ -102,5 +102,5 @@
       ierr(:) = 0
       !
-      ALLOCATE( wgtbtp1(3*nn_baro), wgtbtp2(3*nn_baro), zwz(jpi,jpj), STAT=ierr(1) )
+      ALLOCATE( wgtbtp1(3*nn_e), wgtbtp2(3*nn_e), zwz(jpi,jpj), STAT=ierr(1) )
       IF( ln_dynvor_een .OR. ln_dynvor_eeT )   &
          &     ALLOCATE( ftnw(jpi,jpj) , ftne(jpi,jpj) , ftsw(jpi,jpj) , ftse(jpi,jpj), STAT=ierr(2)   )
@@ -150,5 +150,5 @@
       LOGICAL  ::   ll_init               ! =T : special startup of 2d equations
       INTEGER  ::   noffset               ! local integers  : time offset for bdy update
-      REAL(wp) ::   r1_2dt_b, z1_hu, z1_hv          ! local scalars
+      REAL(wp) ::   r1_Dt_b, z1_hu, z1_hv          ! local scalars
       REAL(wp) ::   za0, za1, za2, za3              !   -      -
       REAL(wp) ::   zztmp, zldg               !   -      -
@@ -180,12 +180,10 @@
 !     zwdramp = 1._wp / (rn_wdmin2 - rn_wdmin1) ! more general ramp
       !                                         ! inverse of baroclinic time step 
-      IF( kt == nit000 .AND. neuler == 0 ) THEN   ;   r1_2dt_b = 1._wp / (         rdt )
-      ELSE                                        ;   r1_2dt_b = 1._wp / ( 2._wp * rdt )
-      ENDIF
+      r1_Dt_b = 1._wp / rDt 
       !
       ll_init     = ln_bt_av                    ! if no time averaging, then no specific restart 
       ll_fw_start = .FALSE.
       !                                         ! time offset in steps for bdy data update
-      IF( .NOT.ln_bt_fw ) THEN   ;   noffset = - nn_baro
+      IF( .NOT.ln_bt_fw ) THEN   ;   noffset = - nn_e
       ELSE                       ;   noffset =   0 
       ENDIF
@@ -198,7 +196,7 @@
          IF(lwp) WRITE(numout,*)
          !
-         IF( neuler == 0 )   ll_init=.TRUE.
-         !
-         IF( ln_bt_fw .OR. neuler == 0 ) THEN
+         IF( l_1st_euler )   ll_init=.TRUE.
+         !
+         IF( ln_bt_fw .OR. l_1st_euler ) THEN
             ll_fw_start =.TRUE.
             noffset     = 0
@@ -209,14 +207,17 @@
          CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
          !
-      ENDIF
-      !
-      ! If forward start at previous time step, and centered integration, 
-      ! then update averaging weights:
-      IF (.NOT.ln_bt_fw .AND.( neuler==0 .AND. kt==nit000+1 ) ) THEN
-         ll_fw_start=.FALSE.
-         CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
-      ENDIF
-      !
-                          
+      ELSEIF( kt == nit000 + 1 ) THEN           !* initialisation 2nd time-step
+         !
+         IF( .NOT.ln_bt_fw ) THEN
+            ! If we did an Euler timestep on the first timestep we need to reset ll_fw_start
+            ! and the averaging weights. We don't have an easy way of telling whether we did
+            ! an Euler timestep on the first timestep (because l_1st_euler is reset to .false.
+            ! at the end of the first timestep) so just do this in all cases. 
+            ll_fw_start = .FALSE.
+            CALL ts_wgt( ln_bt_av, ll_fw_start, icycle, wgtbtp1, wgtbtp2 )
+         ENDIF
+         !
+      ENDIF
+      !
       ! -----------------------------------------------------------------------------
       !  Phase 1 : Coupling between general trend and barotropic estimates (1st step)
@@ -302,9 +303,9 @@
       IF( ln_bt_fw ) THEN                        ! Add wind forcing
          DO_2D_00_00
-            zu_frc(ji,jj) =  zu_frc(ji,jj) + r1_rau0 * utau(ji,jj) * r1_hu(ji,jj,Kmm)
-            zv_frc(ji,jj) =  zv_frc(ji,jj) + r1_rau0 * vtau(ji,jj) * r1_hv(ji,jj,Kmm)
+            zu_frc(ji,jj) =  zu_frc(ji,jj) + r1_rho0 * utau(ji,jj) * r1_hu(ji,jj,Kmm)
+            zv_frc(ji,jj) =  zv_frc(ji,jj) + r1_rho0 * vtau(ji,jj) * r1_hv(ji,jj,Kmm)
          END_2D
       ELSE
-         zztmp = r1_rau0 * r1_2
+         zztmp = r1_rho0 * r1_2
          DO_2D_00_00
             zu_frc(ji,jj) =  zu_frc(ji,jj) + zztmp * ( utau_b(ji,jj) + utau(ji,jj) ) * r1_hu(ji,jj,Kmm)
@@ -319,7 +320,7 @@
       !                                   ! ---------------------------------------------------  !
       IF (ln_bt_fw) THEN                          ! FORWARD integration: use kt+1/2 fluxes (NOW+1/2)
-         zssh_frc(:,:) = r1_rau0 * ( emp(:,:) - rnf(:,:) + fwfisf_cav(:,:) + fwfisf_par(:,:) )
+         zssh_frc(:,:) = r1_rho0 * ( emp(:,:) - rnf(:,:) + fwfisf_cav(:,:) + fwfisf_par(:,:) )
       ELSE                                        ! CENTRED integration: use kt-1/2 + kt+1/2 fluxes (NOW)
-         zztmp = r1_rau0 * r1_2
+         zztmp = r1_rho0 * r1_2
          zssh_frc(:,:) = zztmp * (  emp(:,:)        + emp_b(:,:)                    &
                 &                 - rnf(:,:)        - rnf_b(:,:)                    &
@@ -428,5 +429,5 @@
          ! Update tide potential at the beginning of current time substep
          IF( ln_tide_pot .AND. ln_tide ) THEN
-            zt0substep = REAL(nsec_day, wp) - 0.5_wp*rdt + (jn + noffset - 1) * rdt / REAL(nn_baro, wp)
+            zt0substep = REAL(nsec_day, wp) - 0.5_wp*rn_Dt + (jn + noffset - 1) * rn_Dt / REAL(nn_e, wp)
             CALL upd_tide(zt0substep, Kmm)
          END IF
@@ -494,5 +495,5 @@
          IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) CALL agrif_dyn_ts_flux( jn, zhU, zhV )
 #endif
-         IF( ln_wd_il )   CALL wad_lmt_bt(zhU, zhV, sshn_e, zssh_frc, rdtbt)    !!gm wad_lmt_bt use of lbc_lnk on zhU, zhV
+         IF( ln_wd_il )   CALL wad_lmt_bt(zhU, zhV, sshn_e, zssh_frc, rDt_e)    !!gm wad_lmt_bt use of lbc_lnk on zhU, zhV
 
          IF( ln_wd_dl ) THEN           ! un_e and vn_e are set to zero at faces where 
@@ -509,5 +510,5 @@
          DO_2D_00_00
             zhdiv = (   zhU(ji,jj) - zhU(ji-1,jj) + zhV(ji,jj) - zhV(ji,jj-1)   ) * r1_e1e2t(ji,jj)
-            ssha_e(ji,jj) = (  sshn_e(ji,jj) - rdtbt * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
+            ssha_e(ji,jj) = (  sshn_e(ji,jj) - rDt_e * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
          END_2D
          !
@@ -599,5 +600,5 @@
             DO_2D_00_00
                ua_e(ji,jj) = (                                 un_e(ji,jj)   & 
-                         &     + rdtbt * (                   zu_spg(ji,jj)   &
+                         &     + rDt_e * (                   zu_spg(ji,jj)   &
                          &                                 + zu_trd(ji,jj)   &
                          &                                 + zu_frc(ji,jj) ) & 
@@ -605,5 +606,5 @@
 
                va_e(ji,jj) = (                                 vn_e(ji,jj)   &
-                         &     + rdtbt * (                   zv_spg(ji,jj)   &
+                         &     + rDt_e * (                   zv_spg(ji,jj)   &
                          &                                 + zv_trd(ji,jj)   &
                          &                                 + zv_frc(ji,jj) ) &
@@ -624,10 +625,10 @@
                !
                ua_e(ji,jj) = (               hu_e  (ji,jj) *   un_e (ji,jj)      & 
-                    &            + rdtbt * (  zhu_bck        * zu_spg (ji,jj)  &   !
+                    &            + rDt_e * (  zhu_bck        * zu_spg (ji,jj)  &   !
                     &                       + zhup2_e(ji,jj) * zu_trd (ji,jj)  &   !
                     &                       +  hu(ji,jj,Kmm) * zu_frc (ji,jj)  )   ) * z1_hu
                !
                va_e(ji,jj) = (               hv_e  (ji,jj) *   vn_e (ji,jj)      &
-                    &            + rdtbt * (  zhv_bck        * zv_spg (ji,jj)  &   !
+                    &            + rDt_e * (  zhv_bck        * zv_spg (ji,jj)  &   !
                     &                       + zhvp2_e(ji,jj) * zv_trd (ji,jj)  &   !
                     &                       +  hv(ji,jj,Kmm) * zv_frc (ji,jj)  )   ) * z1_hv
@@ -637,6 +638,6 @@
          IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs
             DO_2D_00_00
-                  ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rdtbt * zCdU_u(ji,jj) * hur_e(ji,jj))
-                  va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rdtbt * zCdU_v(ji,jj) * hvr_e(ji,jj))
+                  ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rDt_e * zCdU_u(ji,jj) * hur_e(ji,jj))
+                  va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rDt_e * zCdU_v(ji,jj) * hvr_e(ji,jj))
             END_2D
          ENDIF
@@ -701,14 +702,14 @@
       ! Set advection velocity correction:
       IF (ln_bt_fw) THEN
-         IF( .NOT.( kt == nit000 .AND. neuler==0 ) ) THEN
+         IF( .NOT.( kt == nit000 .AND. l_1st_euler ) ) THEN
             DO_2D_11_11
                zun_save = un_adv(ji,jj)
                zvn_save = vn_adv(ji,jj)
                !                          ! apply the previously computed correction 
-               un_adv(ji,jj) = r1_2 * ( ub2_b(ji,jj) + zun_save - atfp * un_bf(ji,jj) )
-               vn_adv(ji,jj) = r1_2 * ( vb2_b(ji,jj) + zvn_save - atfp * vn_bf(ji,jj) )
+               un_adv(ji,jj) = r1_2 * ( ub2_b(ji,jj) + zun_save - rn_atfp * un_bf(ji,jj) )
+               vn_adv(ji,jj) = r1_2 * ( vb2_b(ji,jj) + zvn_save - rn_atfp * vn_bf(ji,jj) )
                !                          ! Update corrective fluxes for next time step
-               un_bf(ji,jj)  = atfp * un_bf(ji,jj) + ( zun_save - ub2_b(ji,jj) )
-               vn_bf(ji,jj)  = atfp * vn_bf(ji,jj) + ( zvn_save - vb2_b(ji,jj) )
+               un_bf(ji,jj)  = rn_atfp * un_bf(ji,jj) + ( zun_save - ub2_b(ji,jj) )
+               vn_bf(ji,jj)  = rn_atfp * vn_bf(ji,jj) + ( zvn_save - vb2_b(ji,jj) )
                !                          ! Save integrated transport for next computation
                ub2_b(ji,jj) = zun_save
@@ -728,6 +729,6 @@
       IF( ln_dynadv_vec .OR. ln_linssh ) THEN
          DO jk=1,jpkm1
-            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) ) * r1_2dt_b
-            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) ) * r1_2dt_b
+            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) ) * r1_Dt_b
+            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) ) * r1_Dt_b
          END DO
       ELSE
@@ -744,6 +745,6 @@
          !
          DO jk=1,jpkm1
-            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + r1_hu(:,:,Kmm) * ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) * hu(:,:,Kbb) ) * r1_2dt_b
-            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + r1_hv(:,:,Kmm) * ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) * hv(:,:,Kbb) ) * r1_2dt_b
+            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + r1_hu(:,:,Kmm) * ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) * hu(:,:,Kbb) ) * r1_Dt_b
+            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + r1_hv(:,:,Kmm) * ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) * hv(:,:,Kbb) ) * r1_Dt_b
          END DO
          ! Save barotropic velocities not transport:
@@ -808,5 +809,5 @@
       LOGICAL, INTENT(in) ::   ll_fw      ! forward time splitting =.true.
       INTEGER, INTENT(inout) :: jpit      ! cycle length    
-      REAL(wp), DIMENSION(3*nn_baro), INTENT(inout) ::   zwgt1, & ! Primary weights
+      REAL(wp), DIMENSION(3*nn_e), INTENT(inout) ::   zwgt1, & ! Primary weights
                                                          zwgt2    ! Secondary weights
       
@@ -820,7 +821,7 @@
       ! Set time index when averaged value is requested
       IF (ll_fw) THEN 
-         jic = nn_baro
+         jic = nn_e
       ELSE
-         jic = 2 * nn_baro
+         jic = 2 * nn_e
       ENDIF
 
@@ -828,5 +829,5 @@
       IF (ll_av) THEN
            ! Define simple boxcar window for primary weights 
-           ! (width = nn_baro, centered around jic)     
+           ! (width = nn_e, centered around jic)     
          SELECT CASE ( nn_bt_flt )
               CASE( 0 )  ! No averaging
@@ -834,7 +835,7 @@
                  jpit = jic
 
-              CASE( 1 )  ! Boxcar, width = nn_baro
-                 DO jn = 1, 3*nn_baro
-                    za1 = ABS(float(jn-jic))/float(nn_baro) 
+              CASE( 1 )  ! Boxcar, width = nn_e
+                 DO jn = 1, 3*nn_e
+                    za1 = ABS(float(jn-jic))/float(nn_e) 
                     IF (za1 < 0.5_wp) THEN
                       zwgt1(jn) = 1._wp
@@ -843,7 +844,7 @@
                  ENDDO
 
-              CASE( 2 )  ! Boxcar, width = 2 * nn_baro
-                 DO jn = 1, 3*nn_baro
-                    za1 = ABS(float(jn-jic))/float(nn_baro) 
+              CASE( 2 )  ! Boxcar, width = 2 * nn_e
+                 DO jn = 1, 3*nn_e
+                    za1 = ABS(float(jn-jic))/float(nn_e) 
                     IF (za1 < 1._wp) THEN
                       zwgt1(jn) = 1._wp
@@ -889,5 +890,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ---------------
-         IF( ln_rstart .AND. ln_bt_fw .AND. (neuler/=0) ) THEN    !* Read the restart file
+         IF( ln_rstart .AND. ln_bt_fw .AND. (.NOT.l_1st_euler) ) THEN    !* Read the restart file
             CALL iom_get( numror, jpdom_autoglo, 'ub2_b'  , ub2_b  (:,:), ldxios = lrxios )   
             CALL iom_get( numror, jpdom_autoglo, 'vb2_b'  , vb2_b  (:,:), ldxios = lrxios ) 
@@ -975,8 +976,8 @@
 
       ! Estimate number of iterations to satisfy a max courant number= rn_bt_cmax
-      IF( ln_bt_auto )   nn_baro = CEILING( rdt / rn_bt_cmax * zcmax)
+      IF( ln_bt_auto )   nn_e = CEILING( rn_Dt / rn_bt_cmax * zcmax)
       
-      rdtbt = rdt / REAL( nn_baro , wp )
-      zcmax = zcmax * rdtbt
+      rDt_e = rn_Dt / REAL( nn_e , wp )
+      zcmax = zcmax * rDt_e
       ! Print results
       IF(lwp) WRITE(numout,*)
@@ -984,12 +985,12 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
       IF( ln_bt_auto ) THEN
-         IF(lwp) WRITE(numout,*) '     ln_ts_auto =.true. Automatically set nn_baro '
+         IF(lwp) WRITE(numout,*) '     ln_ts_auto =.true. Automatically set nn_e '
          IF(lwp) WRITE(numout,*) '     Max. courant number allowed: ', rn_bt_cmax
       ELSE
-         IF(lwp) WRITE(numout,*) '     ln_ts_auto=.false.: Use nn_baro in namelist   nn_baro = ', nn_baro
+         IF(lwp) WRITE(numout,*) '     ln_ts_auto=.false.: Use nn_e in namelist   nn_e = ', nn_e
       ENDIF
 
       IF(ln_bt_av) THEN
-         IF(lwp) WRITE(numout,*) '     ln_bt_av =.true.  ==> Time averaging over nn_baro time steps is on '
+         IF(lwp) WRITE(numout,*) '     ln_bt_av =.true.  ==> Time averaging over nn_e time steps is on '
       ELSE
          IF(lwp) WRITE(numout,*) '     ln_bt_av =.false. => No time averaging of barotropic variables '
@@ -1011,12 +1012,12 @@
       SELECT CASE ( nn_bt_flt )
          CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '           Dirac'
-         CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = nn_baro'
-         CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = 2*nn_baro' 
+         CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = nn_e'
+         CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '           Boxcar: width = 2*nn_e' 
          CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_bt_flt: should 0,1, or 2' )
       END SELECT
       !
       IF(lwp) WRITE(numout,*) ' '
-      IF(lwp) WRITE(numout,*) '     nn_baro = ', nn_baro
-      IF(lwp) WRITE(numout,*) '     Barotropic time step [s] is :', rdtbt
+      IF(lwp) WRITE(numout,*) '     nn_e = ', nn_e
+      IF(lwp) WRITE(numout,*) '     Barotropic time step [s] is :', rDt_e
       IF(lwp) WRITE(numout,*) '     Maximum Courant number is   :', zcmax
       !
@@ -1030,5 +1031,5 @@
       ENDIF
       IF( zcmax>0.9_wp ) THEN
-         CALL ctl_stop( 'dynspg_ts ERROR: Maximum Courant number is greater than 0.9: Inc. nn_baro !' )          
+         CALL ctl_stop( 'dynspg_ts ERROR: Maximum Courant number is greater than 0.9: Inc. nn_e !' )          
       ENDIF
       !
@@ -1429,5 +1430,5 @@
       !
       IF( ln_wd_il ) THEN      ! W/D : use the "clipped" bottom friction   !!gm   explain WHY, please !
-         zztmp = -1._wp / rdtbt
+         zztmp = -1._wp / rDt_e
          DO_2D_00_00
             pu_RHSi(ji,jj) = pu_RHSi(ji,jj) + zu_i(ji,jj) *  wdrampu(ji,jj) * MAX(                                 & 
