Index: trunk/NEMO/OFF_SRC/DOM/daymod.F90
===================================================================
--- trunk/NEMO/OFF_SRC/DOM/daymod.F90	(revision 1747)
+++ trunk/NEMO/OFF_SRC/DOM/daymod.F90	(revision 1748)
@@ -4,11 +4,11 @@
    !! 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
+   !! History :  OPA  ! 1994-09  (M. Pontaud M. Imbard)  Original code
+   !!                 ! 1997-03  (O. Marti)
+   !!                 ! 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
    !!----------------------------------------------------------------------      
 
@@ -29,15 +29,17 @@
    USE phycst          ! physical constants
    USE in_out_manager  ! I/O manager
+   USE ioipsl, ONLY :   ymds2ju   ! for calendar
    USE prtctl          ! Print control
-   USE ioipsl, ONLY :   ymds2ju        ! for calendar
 
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC day        ! called by step.F90
-   PUBLIC day_init   ! called by istate.F90
-
-   !!----------------------------------------------------------------------
-   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
+   PUBLIC   day        ! called by step.F90
+   PUBLIC   day_init   ! called by istate.F90
+
+   INTEGER ::   nsecd, nsecd05, ndt, ndt05
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009) 
    !! $Id$
    !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
@@ -57,15 +59,23 @@
       !!              - 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
+      !!              - nsec_year    : current time step counted in second since 00h jan 1st of the current year
+      !!              - nsec_month   : current time step counted in second since 00h 1st day of the current month
+      !!              - nsec_day     : current time step counted in second since 00h of the current day
+      !!              - nsec1jan000  : second since Jan. 1st 00h of nit000 year and Jan. 1st 00h of the current year
+      !!              - nmonth_len, nyear_len, nmonth_half, nmonth_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' )
+      IF( MOD( rday     , rdttra(1) ) /= 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( rdttra(1), 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(      rdttra(1))
+      ndt05   = NINT(0.5 * rdttra(1))
+
 
       ! set the calandar from ndastp (read in restart file and namelist)
+
       nyear   =   ndastp / 10000
       nmonth  = ( ndastp - (nyear * 10000) ) / 100
@@ -73,8 +83,8 @@
 
       CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
+      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)
 
-
-      sec1jan000 = 0.e0
+      nsec1jan000 = 0
       CALL day_mth
       
@@ -86,5 +96,5 @@
          nmonth = 12
          nyear = nyear - 1
-         sec1jan000 = sec1jan000 - rday * REAL( nyear_len(0), wp )
+         nsec1jan000 = nsec1jan000 - nsecd * nyear_len(0)
          IF( nleapy == 1 )   CALL day_mth
       ENDIF
@@ -94,11 +104,16 @@
       
       ! 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)
+      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_day   =             nsecd - ndt05
 
       ! 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
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i6)')' ==============>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day
+
+      ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
+      ! call day to set the calendar parameters at the begining of the current simulaton. needed by iom_init
+      CALL day( nit000 )
+
       
    END SUBROUTINE day_init
@@ -113,6 +128,6 @@
       !! ** 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
+      !!              - nmonth_half   : second since the beginning of the year and the halft of the months
+      !!              - nmonth_end    : second since the beginning of the year and the end of the months
       !!----------------------------------------------------------------------
       INTEGER  ::   jm               ! dummy loop indice
@@ -143,15 +158,15 @@
       ! 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 )
+      ! nmonth_half(jm) = rday * REAL( 0.5 * nmonth_len(jm) + SUM(nmonth_len(1:jm-1)) )
+      nmonth_half(0) = - nsecd05 * nmonth_len(0)
       DO jm = 1, 13
-         rmonth_half(jm) = rmonth_half(jm-1) + 0.5 * rday * REAL( nmonth_len(jm-1) + nmonth_len(jm), wp )
+         nmonth_half(jm) = nmonth_half(jm-1) + nsecd05 * ( nmonth_len(jm-1) + nmonth_len(jm) )
       END DO
 
-      rmonth_end(0) = 0.
+      nmonth_end(0) = 0
       DO jm = 1, 13
-         rmonth_end(jm) = rmonth_end(jm-1) + rday * REAL( nmonth_len(jm), wp )
+         nmonth_end(jm) = nmonth_end(jm-1) + nsecd * nmonth_len(jm)
       END DO
-                 
+      !           
    END SUBROUTINE 
 
@@ -171,34 +186,37 @@
       !!              - ndastp    : = nyear*10000 + nmonth*100 + nday
       !!              - adatrj    : date in days since the beginning of the run
-      !!              - rsec_year : current time of the year (in second since 00h, jan 1st)
+      !!              - nsec_year : current time of the year (in second since 00h, jan 1st)
       !!----------------------------------------------------------------------      
       INTEGER, INTENT(in) ::   kt        ! ocean time-step indices
       !
       CHARACTER (len=25) ::   charout
-      !!----------------------------------------------------------------------
-
+      REAL(wp)           ::   zprec      ! fraction of day corresponding to 0.1 second
+      !!----------------------------------------------------------------------
+      zprec = 0.1 / rday
       !                                                 ! 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
+      nsec_year  = nsec_year  + ndt 
+      nsec_month = nsec_month + ndt                 
+      nsec_day   = nsec_day   + ndt                
+      adatrj  = adatrj  + rdttra(1) / rday
       fjulday = fjulday + rdttra(1) / rday
-   
-      IF( rsec_day > rday ) THEN                        ! NEW day
+      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
          !
          nday      = nday + 1
          nday_year = nday_year + 1
-         rsec_day  = 0.5 * rdttra(1)                 
+         nsec_day  = ndt05
          !
          IF( nday == nmonth_len(nmonth) + 1 ) THEN      ! NEW month
             nday   = 1
             nmonth = nmonth + 1
-            rsec_month = 0.5 * rdttra(1)
+            nsec_month = ndt05
             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 )
+               nsec_year = ndt05
+               nsec1jan000 = nsec1jan000 + nsecd * nyear_len(1)
                IF( nleapy == 1 )   CALL day_mth
             ENDIF
@@ -209,6 +227,6 @@
          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
+         IF(lwp) WRITE(numout,'(a,i8,a,i7,a,i5)') '         nsec_year = ', nsec_year,   &
+              &   '   nsec_month = ', nsec_month, '   nsec_day = ', nsec_day
       ENDIF
       
@@ -218,6 +236,6 @@
       ENDIF
 
-      !
    END SUBROUTINE day
+
    !!======================================================================
 END MODULE daymod
Index: trunk/NEMO/OFF_SRC/DOM/dom_oce.F90
===================================================================
--- trunk/NEMO/OFF_SRC/DOM/dom_oce.F90	(revision 1747)
+++ trunk/NEMO/OFF_SRC/DOM/dom_oce.F90	(revision 1748)
@@ -190,4 +190,5 @@
       n_cla                    !: flag (0/1) for cross land advection to
       !                        ! parameterize exchanges through straits
+
    !!----------------------------------------------------------------------
    !! calendar variables
@@ -198,16 +199,24 @@
    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
+   INTEGER , PUBLIC ::   nsec_year   !: current time step counted in second since 00h jan 1st of the current year
+   INTEGER , PUBLIC ::   nsec_month  !: current time step counted in second since 00h 1st day of the current month
+   INTEGER , PUBLIC ::   nsec_day    !: current time step counted in second since 00h of the current day
    REAL(wp), PUBLIC ::   fjulday     !: julian day 
    REAL(wp), PUBLIC ::   adatrj      !: number of elapsed days since the begining of the whole simulation
    !                                 !: (cumulative duration of previous runs that may have used different time-step size)
-   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 Jan 1st 0h of the current year and the half of the months
-   REAL(wp), PUBLIC, DIMENSION(0:13) ::   rmonth_end   !: second since Jan 1st 0h of the current year and the end of the months
-   REAL(wp), PUBLIC                  ::   sec1jan000   !: second since Jan 1st 0h of nit000 year and Jan 1st 0h the current year
-
+   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
+   INTEGER , PUBLIC, DIMENSION(0:13) ::   nmonth_half   !: second since Jan 1st 0h of the current year and the half of the months
+   INTEGER , PUBLIC, DIMENSION(0:13) ::   nmonth_end    !: second since Jan 1st 0h of the current year and the end of the months
+   INTEGER , PUBLIC                  ::   nsec1jan000   !: second since Jan 1st 0h of nit000 year and Jan 1st 0h the current year
+
+   !!----------------------------------------------------------------------
+   !! agrif domain
+   !!----------------------------------------------------------------------
+#if defined key_agrif
+   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .TRUE.    !: agrif flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .FALSE.   !: agrif flag
+#endif
 
 #if defined key_off_degrad
Index: trunk/NEMO/OFF_SRC/DOM/domain.F90
===================================================================
--- trunk/NEMO/OFF_SRC/DOM/domain.F90	(revision 1747)
+++ trunk/NEMO/OFF_SRC/DOM/domain.F90	(revision 1748)
@@ -152,4 +152,16 @@
       ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
       adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
+      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+
+      CASE (  1 )
+         CALL ioconf_calendar('gregorian')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "gregorian", i.e. leap year'
+      CASE (  0 )
+         CALL ioconf_calendar('noleap')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "noleap", i.e. no leap year'
+      CASE ( 30 )
+         CALL ioconf_calendar('360d')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "360d", i.e. 360 days in a year'
+      END SELECT
 
      ! Namelist namctl : print control
