Index: /trunk/NEMO/OFF_SRC/daymod.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/daymod.F90	(revision 1290)
+++ /trunk/NEMO/OFF_SRC/daymod.F90	(revision 1291)
@@ -4,33 +4,56 @@
    !! Ocean        :  calendar 
    !!=====================================================================
+   !! History :        !  94-09  (M. Pontaud M. Imbard)  Original code
+   !!                  !  97-03  (O. Marti)
+   !!                  !  97-05  (G. Madec) 
+   !!                  !  97-08  (M. Imbard)
+   !!             9.0  !  03-09  (G. Madec)  F90 + nyear, nmonth, nday
+   !!                  !  04-01  (A.M. Treguier) new calculation based on adatrj
+   !!                  !  06-08  (G. Madec)  surface module major update
+   !!----------------------------------------------------------------------      
 
    !!----------------------------------------------------------------------
    !!   day        : calendar
-   !!----------------------------------------------------------------------
-   !! * Modules used
+   !!  
+   !!           -------------------------------
+   !!           ----------- WARNING -----------
+   !!
+   !!   we suppose that the time step is deviding the number of second of in a day
+   !!             ---> MOD( rday, rdttra(1) ) == 0
+   !!
+   !!           ----------- WARNING -----------
+   !!           -------------------------------
+   !!  
+   !!----------------------------------------------------------------------
    USE dom_oce         ! ocean space and time domain
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
+   USE prtctl          ! Print control
 
    IMPLICIT NONE
    PRIVATE
 
-   !! * Routine accessibility
    PUBLIC day        ! called by step.F90
-
-   !! * Shared module variables
-   INTEGER , PUBLIC ::   &  !:
-      nyear     ,   &  !: current year
-      nmonth    ,   &  !: current month
-      nday      ,   &  !: current day of the month
-      nday_year ,   &  !: curent day counted from jan 1st of the current year
-      ndastp           !: time step date in year/month/day aammjj
-
-   REAL(wp), PUBLIC ::   &  !:
-       adatrj   ,   &  !: number of elapsed days since the begining of the run
-       adatrj0         !: value of adatrj at nit000-1 (before the present run).
-       !               !  it is the accumulated duration of previous runs
-       !               !  that may have been run with different time steps.
-
+   PUBLIC day_init   ! called by istate.F90
+
+   INTEGER , PUBLIC ::   nyear       !: current year
+   INTEGER , PUBLIC ::   nmonth      !: current month
+   INTEGER , PUBLIC ::   nday        !: current day of the month
+   INTEGER , PUBLIC ::   ndastp      !: time step date in yyyymmdd format
+   INTEGER , PUBLIC ::   nday_year   !: current day counted from jan 1st of the current year
+   REAL(wp), PUBLIC ::   rsec_year   !: current time step counted in second since 00h jan 1st of the current year
+   REAL(wp), PUBLIC ::   rsec_month  !: current time step counted in second since 00h 1st day of the current month
+   REAL(wp), PUBLIC ::   rsec_day    !: current time step counted in second since 00h of the current day
+
+   REAL(wp), PUBLIC ::   adatrj      !: number of elapsed days since the begining of the run
+   !                                 !: it is the accumulated duration of previous runs
+   !                                 !: that may have been run with different time steps.
+   INTEGER , PUBLIC, DIMENSION(0:1)  ::   nyear_len    !: length in days of the previous/current year
+   INTEGER , PUBLIC, DIMENSION(0:13) ::   nmonth_len   !: length in days of the months of the current year
+   REAL(wp), PUBLIC, DIMENSION(0:13) ::   rmonth_half  !: second since the beginning of the year and the halft of the months
+   REAL(wp), PUBLIC, DIMENSION(0:13) ::   rmonth_end   !: second since the beginning of the year and the end of the months
+   REAL(wp), PUBLIC                  ::   sec1jan000   !: second since Jan. 1st 00h of nit000 year and Jan. 1st 00h of the current year
+
+   ! this two variables are wrong DO NOT USE THEM !!!
    INTEGER, PUBLIC, DIMENSION(12) ::   nbiss = (/ 31, 29, 31, 30, 31, 30,    &  !: number of days per month
       &                                           31, 31, 30, 31, 30, 31 /)     !: (leap-year)
@@ -38,11 +61,119 @@
       &                                           31, 31, 30, 31, 30, 31 /)     !: (365 days a year)
 
-   !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Id$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
+
+   !!----------------------------------------------------------------------
+   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
 
 CONTAINS
+
+   SUBROUTINE day_init
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE day_init  ***
+      !! 
+      !! ** Purpose :   Initialization of the calendar values to their values 1 time step before nit000 
+      !!                because day will be called at the beginning of step
+      !!
+      !! ** Action  : - nyear        : current year
+      !!              - nmonth       : current month of the year nyear
+      !!              - nday         : current day of the month nmonth
+      !!              - nday_year    : current day of the year nyear
+      !!              - rsec_year    : current time step counted in second since 00h jan 1st of the current year
+      !!              - rsec_month   : current time step counted in second since 00h 1st day of the current month
+      !!              - rsec_day     : current time step counted in second since 00h of the current day
+      !!              - sec1jan000   : second since Jan. 1st 00h of nit000 year and Jan. 1st 00h of the current year
+      !!              - nmonth_len, nyear_len, rmonth_half, rmonth_end through day_mth
+      !!----------------------------------------------------------------------
+
+      ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0
+      IF( MOD( rday, rdttra(1) ) /= 0 )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
+
+      ! 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 ) 
+
+      sec1jan000 = 0.e0
+      CALL day_mth
+      
+      IF ( nday == 0 ) THEN     !   for ex if ndastp = ndate0 - 1
+         nmonth = nmonth - 1  
+         nday = nmonth_len(nmonth)
+      ENDIF
+      IF ( nmonth == 0 ) THEN   ! go at the end of previous year
+         nmonth = 12
+         nyear = nyear - 1
+         sec1jan000 = sec1jan000 - rday * REAL( nyear_len(0), wp )
+         IF( nleapy == 1 )   CALL day_mth
+      ENDIF
+      
+      ! day since january 1st
+      nday_year = nday + SUM( nmonth_len(1:nmonth - 1) )
+      
+      ! number of seconds since the beginning of current year/month at the middle of the time-step
+      rsec_year  = REAL( nday_year, wp ) * rday - 0.5 * rdttra(1)   ! 1 time step before the middle of the first time step
+      rsec_month = REAL( nday     , wp ) * rday - 0.5 * rdttra(1)   ! because day will be called at the beginning of step
+      rsec_day   =                         rday - 0.5 * rdttra(1)
+
+      ! control print
+      IF(lwp) WRITE(numout,*)' ==============>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  rsec_day:', rsec_day
+      
+   END SUBROUTINE day_init
+
+
+   SUBROUTINE day_mth
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE day_init  ***
+      !! 
+      !! ** Purpose :   calendar values related to the months
+      !!
+      !! ** Action  : - nmonth_len    : length in days of the months of the current year
+      !!              - nyear_len     : length in days of the previous/current year
+      !!              - rmonth_half   : second since the beginning of the year and the halft of the months
+      !!              - rmonth_end    : second since the beginning of the year and the end of the months
+      !!----------------------------------------------------------------------
+      INTEGER  ::   jm               ! dummy loop indice
+      !!----------------------------------------------------------------------
+
+      ! length of the month of the current year (from nleapy, read in namelist)
+      IF ( nleapy < 2 ) THEN 
+         nmonth_len(:) = (/ 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 /)
+         nyear_len(:) = 365
+         IF ( nleapy == 1 ) THEN   ! we are using calandar with leap years
+            IF ( MOD(nyear-1, 4) == 0 .AND. ( MOD(nyear-1, 400) == 0 .OR. MOD(nyear-1, 100) /= 0 ) ) THEN
+               nyear_len(0) = 366
+            ENDIF
+            IF ( MOD(nyear, 4) == 0 .AND. ( MOD(nyear, 400) == 0 .OR. MOD(nyear, 100) /= 0 ) ) THEN
+               nmonth_len(2) = 29
+               nyear_len(1) = 366
+            ENDIF
+         ENDIF
+      ELSE
+         nmonth_len(:) = nleapy   ! all months with nleapy days per year
+         nyear_len(:) = 12 * nleapy
+      ENDIF
+
+      ! half month in second since the begining of the year:
+      ! time since Jan 1st   0     1     2    ...    11    12    13
+      !          ---------*--|--*--|--*--| ... |--*--|--*--|--*--|--------------------------------------
+      !                 <---> <---> <--->  ...  <---> <---> <--->        
+      ! month number      0     1     2    ...    11    12    13
+      !
+      ! rmonth_half(jm) = rday * REAL( 0.5 * nmonth_len(jm) + SUM(nmonth_len(1:jm-1)) )
+      rmonth_half(0) = - 0.5 * rday * REAL( nmonth_len(0), wp )
+      DO jm = 1, 13
+         rmonth_half(jm) = rmonth_half(jm-1) + 0.5 * rday * REAL( nmonth_len(jm-1) + nmonth_len(jm), wp )
+      END DO
+
+      rmonth_end(0) = 0.
+      DO jm = 1, 13
+         rmonth_end(jm) = rmonth_end(jm-1) + rday * REAL( nmonth_len(jm), wp )
+      END DO
+                 
+   END SUBROUTINE 
+
 
    SUBROUTINE day( kt )
@@ -58,108 +189,54 @@
       !!              - nday      : current day of the month nmonth
       !!              - nday_year : current day of the year nyear
-      !!              - ndastp    : =nyear*10000+nmonth*100+nday
+      !!              - ndastp    : = nyear*10000 + nmonth*100 + nday
       !!              - adatrj    : date in days since the beginning of the run
-      !!
-      !! History :
-      !!        !  94-09  (M. Pontaud M. Imbard)  Original code
-      !!        !  97-03  (O. Marti)
-      !!        !  97-05  (G. Madec) 
-      !!        !  97-08  (M. Imbard)
-      !!   9.0  !  03-09  (G. Madec)  F90 + nyear, nmonth, nday
-      !!        !  04-01  (A.M. Treguier) new calculation based on adatrj
+      !!              - rsec_year : current time of the year (in second since 00h, jan 1st)
       !!----------------------------------------------------------------------      
-      !! * Arguments
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step indices
-
-      !! * Local declarations
-      INTEGER  ::   js                   ! dummy loop indice
-      INTEGER  ::   iend, iday0, iday1   ! temporary integers
-      REAL(wp) :: zadatrjn, zadatrjb     ! adatrj at timestep kt-1 and kt-2 
-      !!----------------------------------------------------------------------
-
-      ! 0.  initialization of adatrj0 and nday, nmonth,nyear, nday_year.
-      !     ndastp has been initialized in domain.F90 or restart.F90
-      !-----------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-
-         IF( .NOT.ln_rstart )   adatrj0 = 0.e0      ! adatrj0 initialized in rst_read when restart 
-
-         adatrj  = adatrj0
-         nyear   =   ndastp / 10000
-         nmonth  = ( ndastp - (nyear * 10000) ) / 100
-         nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
-
-         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
-         nday_year =  nday
-         !                               ! accumulates days of previous months of this year
-         DO js = 1, nmonth-1
-            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
-               nday_year = nday_year + nbiss(js)
-            ELSE
-               nday_year = nday_year + nobis(js)
-            ENDIF
-         END DO
-
-      ENDIF
-
-      ! I.  calculates adatrj, zadatrjn, zadatrjb.
-      ! ------------------------------------------------------------------
-
-      adatrj    = adatrj0 + ( kt - nit000 + 1 ) * rdttra(1) / rday
-      zadatrjn  = adatrj0 + ( kt - nit000     ) * rdttra(1) / rday
-      zadatrjb  = adatrj0 + ( kt - nit000 - 1 ) * rdttra(1) / rday
-
-
-      ! II.  increment the date.  The date corresponds to 'now' variables (kt-1),
-      !      which is the time step of forcing fields. 
-      !      Do not do this at nit000  unless nrstdt= 2
-      !      In that case ndastp (read in restart) was for step nit000-2
-      ! -------------------------------------------------------------------
-
-      iday0 = INT( zadatrjb )
-      iday1 = INT( zadatrjn )
-
-      IF( iday1 - iday0 >= 1 .AND. ( kt /= nit000 .OR. nrstdt == 2 ) ) THEN
-
-         ! increase calendar
-         nyear  =   ndastp / 10000
-         nmonth = ( ndastp - (nyear * 10000) ) / 100
-         nday   =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
-         nday = nday + 1
-         IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
-            iend = nbiss(nmonth)
-         ELSEIF( nleapy > 1 ) THEN 
-            iend = nleapy
-         ELSE 
-            iend = nobis(nmonth)
-         ENDIF
-         IF( nday == iend + 1 ) THEN
-            nday  = 1
+      INTEGER, INTENT(in) ::   kt        ! ocean time-step indices
+      !
+      CHARACTER (len=25) ::   charout
+      !!----------------------------------------------------------------------
+
+      !                                                 ! New time-step
+      rsec_year  = rsec_year  + rdttra(1) 
+      rsec_month = rsec_month + rdttra(1)                 
+      rsec_day   = rsec_day   + rdttra(1)                 
+      adatrj = adatrj + rdttra(1) / rday
+      
+      IF( rsec_day > rday ) THEN                        ! NEW day
+         !
+         nday      = nday + 1
+         nday_year = nday_year + 1
+         rsec_day  = 0.5 * rdttra(1)                 
+         !
+         IF( nday == nmonth_len(nmonth) + 1 ) THEN      ! NEW month
+            nday   = 1
             nmonth = nmonth + 1
-            IF( nmonth == 13 ) THEN
-               nmonth  = 1
-               nyear = nyear + 1
+            rsec_month = 0.5 * rdttra(1)
+            IF( nmonth == 13 ) THEN                     ! NEW year
+               nyear     = nyear + 1
+               nmonth    = 1
+               nday_year = 1
+               rsec_year = 0.5 * rdttra(1)
+               sec1jan000 = sec1jan000 + rday * REAL( nyear_len(1), wp )
+               IF( nleapy == 1 )   CALL day_mth
             ENDIF
          ENDIF
-         ndastp = nyear * 10000 + nmonth * 100 + nday
-
-         ! Calculates nday_year, day since january 1st (useful to read  daily forcing fields)
-         nday_year =  nday
-         !                                ! accumulates days of previous months of this year
-         DO js = 1, nmonth-1
-            IF( nleapy == 1 .AND. MOD( nyear, 4 ) == 0 ) THEN
-               nday_year = nday_year + nbiss(js)
-            ELSE
-               nday_year = nday_year + nobis(js)
-            ENDIF
-         END DO
-
-         IF(lwp) WRITE(numout,*)' ==============>> time-step =', kt, ' New day, DATE= ',   &
-            &                   nyear, '/', nmonth, '/', nday, 'nday_year:', nday_year
-      ENDIF
-
+         !
+         ndastp = nyear * 10000 + nmonth * 100 + nday   ! NEW date
+         !
+         IF(lwp) WRITE(numout,'(a,i8,a,i4.4,a,i2.2,a,i2.2,a,i3.3)') '======>> time-step =', kt,   &
+              &   '      New day, DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, '      nday_year = ', nday_year
+         IF(lwp) WRITE(numout,'(a,F9.0,a,F9.0,a,F9.0)') '         rsec_year = ', rsec_year,   &
+              &   '   rsec_month = ', rsec_month, '   rsec_day = ', rsec_day
+      ENDIF
+      
+      IF(ln_ctl) THEN
+         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
+         CALL prt_ctl_info(charout)
+      ENDIF
+
+      !
    END SUBROUTINE day
-
    !!======================================================================
 END MODULE daymod
Index: /trunk/NEMO/OFF_SRC/dtadyn.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/dtadyn.F90	(revision 1290)
+++ /trunk/NEMO/OFF_SRC/dtadyn.F90	(revision 1291)
@@ -206,21 +206,17 @@
          flx  ! auxiliary field for 2-D surface boundary conditions
 
-
       ! 0. Initialization
       ! -----------------
 
       IF (lfirdyn) THEN
-      !
-      ! time step MUST BE nint000
-      !
-          IF (kt.ne.nit000) THEN
-              IF (lwp) THEN
-                  WRITE (numout,*) ' kt MUST BE EQUAL to nit000. kt=',kt  &
-                     ,' nit000=',nit000
-              END IF
+         ! first time step MUST BE nit000
+         IF( kt /= nit000 ) THEN
+            IF (lwp) THEN 
+               WRITE (numout,*) ' kt MUST BE EQUAL to nit000. kt=',kt ,' nit000=',nit000 
               STOP 'dtadyn'
-          END if
-      ! Initialize the parameters of the interpolation
-      CALL dta_dyn_init
+            ENDIF
+          ENDIF 
+          ! Initialize the parameters of the interpolation
+          CALL dta_dyn_init
       ENDIF
 
@@ -234,5 +230,5 @@
       zweighm1 = 1. - zweigh
 
-      IF (lperdyn) THEN
+      IF( lperdyn ) THEN
          iperm1 = MOD(INT(zt),ndtadyn)
       ELSE
@@ -240,16 +236,12 @@
       ENDIF
       iper = iperm1 + 1
-      IF (iperm1 == 0) THEN
-          IF (lperdyn) THEN
+      IF( iperm1 == 0 ) THEN
+          IF( lperdyn ) THEN
               iperm1 = ndtadyn
           ELSE 
-              IF (lfirdyn) THEN
-                  IF (lwp) THEN 
-                      WRITE (numout,*) ' dynamic file is not periodic '
-                      WRITE (numout,*) ' with or without interpolation, '
-                      WRITE (numout,*) ' we take the first value'
-                      WRITE (numout,*) ' for the previous period '
-                      WRITE (numout,*) ' iperm1 = 0  '
-                  END IF 
+              IF( lfirdyn ) THEN 
+                  IF (lwp) WRITE (numout,*) & 
+                      &   ' dynamic file is not periodic with or without interpolation  &
+                      &   we take the first value for the previous period iperm1 = 0  '
               END IF
           END IF 
Index: /trunk/NEMO/OFF_SRC/opa.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/opa.F90	(revision 1290)
+++ /trunk/NEMO/OFF_SRC/opa.F90	(revision 1291)
@@ -20,5 +20,4 @@
    USE istate          ! initial state setting          (istate_init routine)
    USE eosbn2          ! equation of state            (eos bn2 routine)
-   USE zpshde          ! partial step: hor. derivative (zps_hde routine)
 
    ! ocean physics
@@ -130,5 +129,4 @@
       ENDIF
 
-
       !                                     ! ============================== !
       !                                     !  Model general initialization  !
@@ -138,5 +136,5 @@
 
                                             ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN
+      IF( jpni * jpnj == jpnij ) THEN
          CALL mpp_init                          ! standard cutting out
       ELSE
@@ -147,29 +145,14 @@
 
       CALL dom_cfg                          ! Domain configuration
-      
+
       CALL dom_init                         ! Domain
 
-      CALL day( nit000 )                    ! Calendar
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
 
-      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
-!!add
-                       CALL eos( tn, sn, rhd, rhop )        ! before potential and in situ densities
+      CALL trc_ini                           ! Passive tracers
 
-                       CALL bn2( tn, sn, rn2 )              ! before Brunt-Vaisala frequency
+      CALL day_init                          ! Calendar
 
-      IF( ln_zps    )   CALL zps_hde( nit000, tn, sn, rhd,  &  ! Partial steps: before Horizontal DErivative
-                                          gtu, gsu, gru, &  ! of t, s, rd at the bottom ocean level
-                                          gtv, gsv, grv )
-
-!!add
-
-      ! Initialization for the dynamics
-      !
-      CALL dta_dyn(nit000)     
-
-#if defined key_top
-      CALL trc_ini                           ! Passive tracers
-#endif
-
+      CALL dta_dyn( nit000 )                 ! Initialization for the dynamics
       !                                     ! Ocean physics
       CALL tra_qsr_init                         ! Solar radiation penetration
@@ -178,7 +161,4 @@
       CALL ldf_tra_init                         ! Lateral ocean tracer physics
 #endif 
-
-      !                                     ! Ocean trends
-
       !                                     ! =============== !
       !                                     !  time stepping  !
Index: /trunk/NEMO/OFF_SRC/step.F90
===================================================================
--- /trunk/NEMO/OFF_SRC/step.F90	(revision 1290)
+++ /trunk/NEMO/OFF_SRC/step.F90	(revision 1291)
@@ -81,15 +81,6 @@
       CALL dta_dyn( kstp )          ! Interpolation of the dynamical fields
 
-#if defined key_top
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Passive Tracer Model
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      ! N.B. ua, va, ta, sa arrays are used as workspace in this section
-      !-----------------------------------------------------------------------
+      CALL trc_stp( kstp, indic)           ! time-stepping
 
-                             CALL trc_stp( kstp, indic)           ! time-stepping
-
-
-#endif
 
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -97,5 +88,5 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       !                                            ! Time loop: control and print
-                       CALL stp_ctl( kstp )
+       CALL stp_ctl( kstp )
 
 
