Index: trunk/NEMO/OFF_SRC/DOM/domngb.F90
===================================================================
--- trunk/NEMO/OFF_SRC/DOM/domngb.F90	(revision 1749)
+++ trunk/NEMO/OFF_SRC/DOM/domngb.F90	(revision 1749)
@@ -0,0 +1,76 @@
+MODULE domngb
+   !!======================================================================
+   !!                       ***  MODULE  domngb  ***
+   !! Grid search:  find the closest grid point from a given on/lat position
+   !!======================================================================
+   !! History : 3.2  !  2009-11  (S. Masson)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_ngb       : find the closest grid point from a given on/lat position
+   !!----------------------------------------------------------------------
+   USE dom_oce         ! ocean space and time domain
+   USE lib_mpp         ! for mppsum
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dom_ngb    ! routine called in iom.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2008) 
+   !! $Id: domngb.F90 1725 2009-11-12 15:04:08Z smasson $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dom_ngb  ***
+      !!
+      !! ** Purpose :   find the closest grid point from a given on/lat position
+      !!
+      !! ** Method  :   look for minimum distance in cylindrical projection 
+      !!                -> not good if located at too high latitude...
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp)        , INTENT(in   ) ::   plon, plat   ! longitude,latitude of the point
+      INTEGER         , INTENT(  out) ::   kii, kjj     ! i-,j-index of the closes grid point
+      CHARACTER(len=1), INTENT(in   ) ::   cdgrid       ! grid name 'T', 'U', 'V', 'W'
+      !!
+      INTEGER , DIMENSION(2)        ::   iloc
+      REAL(wp), DIMENSION(jpi,jpj)  ::   zglam, zgphi, zmask, zdist
+      REAL(wp)                      ::   zlon
+      REAL(wp)                      ::   zmini
+      !!--------------------------------------------------------------------
+      
+      zmask(:,:) = 0.
+      SELECT CASE( cdgrid )
+      CASE( 'U' )  ; zglam(:,:) = glamu(:,:) ; zgphi(:,:) = gphiu(:,:) ; zmask(nldi:nlei,nldj:nlej) = umask(nldi:nlei,nldj:nlej,1)
+      CASE( 'V' )  ; zglam(:,:) = glamv(:,:) ; zgphi(:,:) = gphiv(:,:) ; zmask(nldi:nlei,nldj:nlej) = vmask(nldi:nlei,nldj:nlej,1)
+      CASE( 'F' )  ; zglam(:,:) = glamf(:,:) ; zgphi(:,:) = gphif(:,:) ; zmask(nldi:nlei,nldj:nlej) = fmask(nldi:nlei,nldj:nlej,1)
+      CASE DEFAULT ; zglam(:,:) = glamt(:,:) ; zgphi(:,:) = gphit(:,:) ; zmask(nldi:nlei,nldj:nlej) = tmask(nldi:nlei,nldj:nlej,1)
+      END SELECT
+
+      zlon       = MOD( plon       + 720., 360. )                                     ! plon between    0 and 360
+      zglam(:,:) = MOD( zglam(:,:) + 720., 360. )                                     ! glam between    0 and 360
+      IF( zlon > 270. )   zlon = zlon - 360.                                          ! zlon between  -90 and 270
+      IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
+
+      zglam(:,:) = zglam(:,:) - zlon
+      zgphi(:,:) = zgphi(:,:) - plat
+      zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
+      
+      IF( lk_mpp ) THEN  
+         CALL mpp_minloc( zdist(:,:), zmask, zmini, kii, kjj)
+      ELSE
+         iloc(:) = MINLOC( zdist(:,:), mask = zmask(:,:) == 1.e0 )
+         kii = iloc(1) + nimpp - 1
+         kjj = iloc(2) + njmpp - 1
+      ENDIF
+
+   END SUBROUTINE dom_ngb
+
+   !!======================================================================
+END MODULE domngb
Index: trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/IOM/in_out_manager.F90	(revision 1749)
@@ -77,6 +77,6 @@
    INTEGER            ::   nn_jctls     =    0    !: Start j indice for the SUM control
    INTEGER            ::   nn_jctle     =    0    !: End   j indice for the SUM control
-   INTEGER            ::   nn_isplt      =    1   !: number of processors following i
-   INTEGER            ::   nn_jsplt      =    1   !: number of processors following j
+   INTEGER            ::   nn_isplt     =    1    !: number of processors following i
+   INTEGER            ::   nn_jsplt     =    1    !: number of processors following j
    INTEGER            ::   nn_bench     =    0    !: benchmark parameter (0/1)
    INTEGER            ::   nn_bit_cmp   =    0    !: bit reproducibility  (0/1)
@@ -90,15 +90,10 @@
    !!                        logical units
    !!----------------------------------------------------------------------
-   INTEGER            ::   numstp                 !: logical unit for time step
+   INTEGER            ::   numstp     =   -1      !: logical unit for time step
    INTEGER            ::   numout     =    6      !: logical unit for output print
-   INTEGER            ::   numnam                 !: logical unit for namelist
-   INTEGER            ::   numnam_ice             !: logical unit for ice namelist
-   INTEGER            ::   numevo_ice             !: logical unit for ice variables (temp. evolution)
-   INTEGER            ::   numsol                 !: logical unit for solver statistics
-   INTEGER            ::   numwri                 !: logical unit for output write
-   INTEGER            ::   numgap                 !: logical unit for differences diagnostic
-   INTEGER            ::   numbol                 !: logical unit for "bol" diagnostics
-   INTEGER            ::   numptr                 !: logical unit for Poleward TRansports
-   INTEGER            ::   numflo                 !: logical unit for drifting floats
+   INTEGER            ::   numnam     =   -1      !: logical unit for namelist
+   INTEGER            ::   numnam_ice =   -1      !: logical unit for ice namelist
+   INTEGER            ::   numevo_ice =   -1      !: logical unit for ice variables (temp. evolution)
+   INTEGER            ::   numsol     =   -1      !: logical unit for solver statistics
 
    !!----------------------------------------------------------------------
@@ -149,5 +144,8 @@
          IF( PRESENT(cd10) ) WRITE(numout,*) cd10
       ENDIF
-      CALL FLUSH(numout)
+                               CALL FLUSH(numout    )
+      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
+      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
+      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
       !
    END SUBROUTINE ctl_stop
Index: trunk/NEMO/OFF_SRC/IOM/iom.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/iom.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/IOM/iom.F90	(revision 1749)
@@ -27,5 +27,9 @@
 
 #if defined key_iomput
+   USE domngb          ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE dianam          ! build name of file
    USE mod_event_client
+   USE mod_attribut
 # endif
 
@@ -34,9 +38,8 @@
    
 #if defined key_iomput
-   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.       !: iom_put flag
+   LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .TRUE.        !: iom_put flag
 #else
    LOGICAL, PUBLIC, PARAMETER ::   lk_iomput = .FALSE.       !: iom_put flag
 #endif
-
    PUBLIC iom_init, iom_open, iom_close, iom_setkt, iom_varid, iom_get, iom_gettime, iom_rstput, iom_put
 
@@ -55,5 +58,5 @@
    END INTERFACE
   INTERFACE iom_put
-     MODULE PROCEDURE iom_p2d, iom_p3d
+     MODULE PROCEDURE iom_p0d, iom_p2d, iom_p3d
   END INTERFACE
 #if defined key_iomput
@@ -71,5 +74,5 @@
 CONTAINS
 
-   SUBROUTINE iom_init( pjulian )
+   SUBROUTINE iom_init
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE   ***
@@ -78,6 +81,6 @@
       !!
       !!----------------------------------------------------------------------
-      REAL(wp), INTENT(in) ::  pjulian   !: julian day at nit000 = 0
 #if defined key_iomput
+      REAL(wp) ::   ztmp
       !!----------------------------------------------------------------------
       ! read the xml file
@@ -85,7 +88,15 @@
 
       ! calendar parameters
-      CALL event__set_time_parameters( nit000 - 1, pjulian, rdt )
+      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+      CASE ( 1)   ;   CALL event__set_calendar('gregorian')
+      CASE ( 0)   ;   CALL event__set_calendar('noleap'   )
+      CASE (30)   ;   CALL event__set_calendar('360d'     )
+      END SELECT
+      ztmp = fjulday - adatrj
+      IF( ABS(ztmp  - REAL(NINT(ztmp),wp)) < 0.1 / rday )   ztmp = REAL(NINT(ztmp),wp)   ! avoid truncation error
+      CALL event__set_time_parameters( nit000 - 1, ztmp, rdt )
 
       ! horizontal grid definition
+      CALL set_scalar
       CALL set_grid( "grid_T", glamt, gphit )
       CALL set_grid( "grid_U", glamu, gphiu )
@@ -98,4 +109,7 @@
       CALL event__set_vert_axis( "depthv", gdept_0 )
       CALL event__set_vert_axis( "depthw", gdepw_0 )
+      
+      ! automatic definitions of some of the xml attributs
+      CALL set_xmlatt
 
       ! end file definition
@@ -180,5 +194,5 @@
       ! do we read the overlap 
       ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-      llnoov = (jpni * jpnj ) == jpnij 
+      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif
       ! create the file name by added, if needed, TRIM(Agrif_CFixed()) and TRIM(clsuffix)
       ! =============
@@ -525,5 +539,5 @@
       ! do we read the overlap 
       ! ugly patch SM+JMM+RB to overwrite global definition in some cases
-      llnoov = (jpni * jpnj ) == jpnij 
+      llnoov = (jpni * jpnj ) == jpnij .AND. .NOT. lk_agrif
       ! check kcount and kstart optionals parameters...
       IF( PRESENT(kcount) .AND. (.NOT. PRESENT(kstart)) ) CALL ctl_stop(trim(clinfo), 'kcount present needs kstart present')
@@ -894,6 +908,16 @@
 
    !!----------------------------------------------------------------------
-   !!                   INTERFACE iom_rstput
+   !!                   INTERFACE iom_put
    !!----------------------------------------------------------------------
+   SUBROUTINE iom_p0d( cdname, pfield0d )
+      CHARACTER(LEN=*), INTENT(in) ::   cdname
+      REAL(wp)        , INTENT(in) ::   pfield0d
+#if defined key_iomput
+      CALL event__write_field2D( cdname, RESHAPE( (/pfield0d/), (/1,1/) ) )
+#else
+      IF( .FALSE. )   WRITE(numout,*) cdname, pfield0d   ! useless test to avoid compilation warnings
+#endif
+   END SUBROUTINE iom_p0d
+
    SUBROUTINE iom_p2d( cdname, pfield2d )
       CHARACTER(LEN=*)            , INTENT(in) ::   cdname
@@ -901,4 +925,6 @@
 #if defined key_iomput
       CALL event__write_field2D( cdname, pfield2d(nldi:nlei, nldj:nlej) )
+#else
+      IF( .FALSE. )   WRITE(numout,*) cdname, pfield2d   ! useless test to avoid compilation warnings
 #endif
    END SUBROUTINE iom_p2d
@@ -909,4 +935,6 @@
 #if defined key_iomput
       CALL event__write_field3D( cdname, pfield3d(nldi:nlei, nldj:nlej, :) )
+#else
+      IF( .FALSE. )   WRITE(numout,*) cdname, pfield3d   ! useless test to avoid compilation warnings
 #endif
    END SUBROUTINE iom_p3d
@@ -920,5 +948,5 @@
       !!                     ***  ROUTINE   ***
       !!
-      !! ** Purpose :   
+      !! ** Purpose :   define horizontal grids
       !!
       !!----------------------------------------------------------------------
@@ -934,8 +962,182 @@
    END SUBROUTINE set_grid
 
+
+   SUBROUTINE set_scalar
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   define fake grids for scalar point
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(1,1) ::   zz = 1.
+      !!----------------------------------------------------------------------
+      CALL event__set_grid_dimension( 'scalarpoint', jpnij, 1)
+      CALL event__set_grid_domain   ( 'scalarpoint', 1, 1, narea, 1, zz, zz )
+      CALL event__set_grid_type_nemo( 'scalarpoint' )
+
+   END SUBROUTINE set_scalar
+
+
+   SUBROUTINE set_xmlatt
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   automatic definitions of some of the xml attributs...
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=6),DIMENSION( 8) ::   clsuff                   ! suffix name
+      CHARACTER(len=1),DIMENSION( 3) ::   clgrd                    ! suffix name
+      CHARACTER(len=50)              ::   clname                   ! file name
+      CHARACTER(len=1)               ::   cl1                      ! 1 character
+      CHARACTER(len=2)               ::   cl2                      ! 1 character
+      INTEGER                        ::   idt                      ! time-step in seconds
+      INTEGER                        ::   iddss, ihhss             ! number of seconds in 1 day, 1 hour and 1 year
+      INTEGER                        ::   iyymo                    ! number of months in 1 year
+      INTEGER                        ::   jg, jh, jd, jm, jy       ! loop counters
+      INTEGER                        ::   ix, iy                   ! i-,j- index
+      REAL(wp)        ,DIMENSION(11) ::   zlontao                  ! longitudes of tao    moorings
+      REAL(wp)        ,DIMENSION( 7) ::   zlattao                  ! latitudes  of tao    moorings
+      REAL(wp)        ,DIMENSION( 4) ::   zlonrama                 ! longitudes of rama   moorings
+      REAL(wp)        ,DIMENSION(11) ::   zlatrama                 ! latitudes  of rama   moorings
+      REAL(wp)        ,DIMENSION( 3) ::   zlonpira                 ! longitudes of pirata moorings
+      REAL(wp)        ,DIMENSION( 9) ::   zlatpira                 ! latitudes  of pirata moorings
+      !!----------------------------------------------------------------------
+      ! 
+      idt   = NINT( rdttra(1)     )
+      iddss = NINT( rday          )                                         ! number of seconds in 1 day
+      ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
+      iyymo = NINT( raamo         )                                         ! number of months in 1 year
+
+      ! frequency of the call of iom_put (attribut: freq_op)
+      CALL event__set_attribut( 'field_definition', attr( field__freq_op, idt           ) )    ! model time-step
+      
+      ! output file names (attribut: name)
+      clsuff(:) = (/ 'grid_T', 'grid_U', 'grid_V', 'grid_W', 'icemod', 'ptrc_T', 'diad_T', 'scalar' /)      
+      DO jg = 1, SIZE(clsuff)                                                                  ! grid type
+         DO jh = 1, 12                                                                         ! 1, 2, 3, 4, 6, 12 hours
+            IF( MOD(12,jh) == 0 ) THEN 
+               WRITE(cl2,'(i2)') jh 
+               CALL dia_nam( clname, jh * ihhss, clsuff(jg), ldfsec = .TRUE. )
+               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'h_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+            ENDIF
+         END DO
+         DO jd = 1, 5, 2                                                                       ! 1, 3, 5 days
+            WRITE(cl1,'(i1)') jd 
+            CALL dia_nam( clname, jd * iddss, clsuff(jg), ldfsec = .TRUE. )
+            CALL event__set_attribut( cl1//'d_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+         END DO
+         DO jm = 1, 6                                                                          ! 1, 2, 3, 4, 6 months
+            IF( MOD(6,jm) == 0 ) THEN 
+               WRITE(cl1,'(i1)') jm 
+               CALL dia_nam( clname, -jm, clsuff(jg) )
+               CALL event__set_attribut( cl1//'m_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+            ENDIF
+         END DO
+         DO jy = 1, 10                                                                         ! 1, 2, 5, 10 years  
+            IF( MOD(10,jy) == 0 ) THEN 
+               WRITE(cl2,'(i2)') jy 
+               CALL dia_nam( clname, -jy * iyymo, clsuff(jg) )
+               CALL event__set_attribut( TRIM(ADJUSTL(cl2))//'y_'//clsuff(jg), attr( file__name, TRIM(clname) ) )
+            ENDIF
+         END DO
+      END DO
+
+      ! Zooms...
+      clgrd = (/ 'T', 'U', 'W' /) 
+      DO jg = 1, SIZE(clgrd)                                                                   ! grid type
+         cl1 = clgrd(jg)
+         ! Equatorial section (attributs: jbegin, ni, name_suffix)
+         CALL dom_ngb( 0., 0., ix, iy, cl1 )
+         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__jbegin     , iy     ) )
+         CALL event__set_attribut( 'Eq'//cl1, attr( zoom__ni         , jpiglo ) )
+         CALL event__set_attribut( 'Eq'//cl1, attr( file__name_suffix, '_Eq'  ) )
+      END DO
+      ! TAO moorings (attributs: ibegin, jbegin, name_suffix)
+      zlontao = (/ 137.0, 147.0, 156.0, 165.0, -180.0, -170.0, -155.0, -140.0, -125.0, -110.0, -95.0 /)
+      zlattao = (/  -8.0,  -5.0,  -2.0,   0.0,    2.0,    5.0,    8.0 /)
+      CALL set_mooring( zlontao, zlattao )
+      ! RAMA moorings (attributs: ibegin, jbegin, name_suffix)
+      zlonrama = (/  55.0,  67.0, 80.5, 90.0 /)
+      zlatrama = (/ -16.0, -12.0, -8.0, -4.0, -1.5, 0.0, 1.5, 4.0, 8.0, 12.0, 15.0 /)
+      CALL set_mooring( zlonrama, zlatrama )
+      ! PIRATA moorings (attributs: ibegin, jbegin, name_suffix)
+      zlonpira = (/ -38.0, -23.0, -10.0 /)
+      zlatpira = (/ -19.0, -14.0,  -8.0, 0.0, 4.0, 8.0, 12.0, 15.0, 20.0 /)
+      CALL set_mooring( zlonpira, zlatpira )
+      
+   END SUBROUTINE set_xmlatt
+
+
+   SUBROUTINE set_mooring( plon, plat)
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE   ***
+      !!
+      !! ** Purpose :   automatic definitions of moorings xml attributs...
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:), INTENT(in) ::  plon, plat           ! longitudes/latitudes oft the mooring
+      !
+!!$      CHARACTER(len=1),DIMENSION(4) ::   clgrd = (/ 'T', 'U', 'V', 'W' /)   ! suffix name
+      CHARACTER(len=1),DIMENSION(1) ::   clgrd = (/ 'T' /)        ! suffix name
+      CHARACTER(len=50)             ::   clname                   ! file name
+      CHARACTER(len=1)              ::   cl1                      ! 1 character
+      CHARACTER(len=6)              ::   clon,clat                ! name of longitude, latitude
+      INTEGER                       ::   ji, jj, jg               ! loop counters
+      INTEGER                       ::   ix, iy                   ! i-,j- index
+      REAL(wp)                      ::   zlon, zlat
+      !!----------------------------------------------------------------------
+      DO jg = 1, SIZE(clgrd)
+         cl1 = clgrd(jg)
+         DO ji = 1, SIZE(plon)
+            DO jj = 1, SIZE(plat)
+               zlon = plon(ji)
+               zlat = plat(jj)
+               ! modifications for RAMA moorings
+               IF( zlon ==  67. .AND. zlat ==  15. )   zlon =  65.
+               IF( zlon ==  90. .AND. zlat <=  -4. )   zlon =  95.
+               IF( zlon ==  95. .AND. zlat ==  -4. )   zlat =  -5.
+               ! modifications for PIRATA moorings
+               IF( zlon == -38. .AND. zlat == -19. )   zlon = -34.
+               IF( zlon == -38. .AND. zlat == -14. )   zlon = -32.
+               IF( zlon == -38. .AND. zlat ==  -8. )   zlon = -30.
+               IF( zlon == -38. .AND. zlat ==   0. )   zlon = -35.
+               IF( zlon == -23. .AND. zlat ==  20. )   zlat =  21.
+               IF( zlon == -10. .AND. zlat == -14. )   zlat = -10.
+               IF( zlon == -10. .AND. zlat ==  -8. )   zlat =  -6.
+               IF( zlon == -10. .AND. zlat ==   4. ) THEN   ;   zlon = 0.   ;   zlat = 0.   ;   ENDIF
+               CALL dom_ngb( zlon, zlat, ix, iy, cl1 )
+               IF( zlon >= 0. ) THEN  
+                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT( zlon), 'e'
+                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')       zlon , 'e'
+                  ENDIF
+               ELSE             
+                  IF( zlon == REAL(NINT(zlon), wp) ) THEN   ;   WRITE(clon, '(i3,  a)') NINT(-zlon), 'w'
+                  ELSE                                      ;   WRITE(clon, '(f5.1,a)')      -zlon , 'w'
+                  ENDIF
+               ENDIF
+               IF( zlat >= 0. ) THEN  
+                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT( zlat), 'n'
+                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')       zlat , 'n'
+                  ENDIF
+               ELSE             
+                  IF( zlat == REAL(NINT(zlat), wp) ) THEN   ;   WRITE(clat, '(i2,  a)') NINT(-zlat), 's'
+                  ELSE                                      ;   WRITE(clat, '(f4.1,a)')      -zlat , 's'
+                  ENDIF
+               ENDIF
+               clname = TRIM(ADJUSTL(clat))//TRIM(ADJUSTL(clon))
+               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__ibegin     , ix                ) )
+               CALL event__set_attribut( TRIM(clname)//cl1, attr( zoom__jbegin     , iy                ) )
+               CALL event__set_attribut( TRIM(clname)//cl1, attr( file__name_suffix, '_'//TRIM(clname) ) )      
+            END DO
+         END DO
+      END DO
+      
+   END SUBROUTINE set_mooring
+
 #else
 
    SUBROUTINE iom_setkt( kt )
       INTEGER, INTENT(in   )::   kt 
+      IF( .FALSE. )   WRITE(numout,*) kt   ! useless test to avoid compilation warnings
    END SUBROUTINE iom_setkt
 
Index: trunk/NEMO/OFF_SRC/IOM/iom_ioipsl.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/IOM/iom_ioipsl.F90	(revision 1749)
@@ -48,16 +48,18 @@
       !! ** Purpose :  open an input file with IOIPSL (only fliocom module)
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid    ! ioipsl identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
-
-      CHARACTER(LEN=100) ::   clinfo     ! info character
-      INTEGER            ::   iln        ! lengths of character
-      INTEGER            ::   istop      ! temporary storage of nstop
-      INTEGER            ::   ifliodom   ! model domain identifier (see flio_dom_set)
-      INTEGER            ::   ioipslid   ! ioipsl identifier of the opened file
-      INTEGER            ::   jl         ! loop variable
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid      ! ioipsl identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo      ! info character
+      CHARACTER(LEN=10 ) ::   clstatus    ! status of opened file (REPLACE or NEW)
+      INTEGER            ::   iln         ! lengths of character
+      INTEGER            ::   istop       ! temporary storage of nstop
+      INTEGER            ::   ifliodom    ! model domain identifier (see flio_dom_set)
+      INTEGER            ::   ioipslid    ! ioipsl identifier of the opened file
+      INTEGER            ::   jl          ! loop variable
+      LOGICAL            ::   llclobber   ! local definition of ln_clobber
       !---------------------------------------------------------------------
 
@@ -65,5 +67,6 @@
       istop = nstop
       !
-      IF( ldok ) THEN      ! Open existing file...
+      llclobber = ldwrt .AND. ln_clobber
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
          !                 ! =============
          IF( ldwrt ) THEN  ! ... in write mode
@@ -78,4 +81,7 @@
          iln = INDEX( cdname, '.nc' )
          IF( ldwrt ) THEN  ! the file should be open in write mode so we create it...
+            IF( llclobber ) THEN   ;   clstatus = 'REPLACE' 
+            ELSE                   ;   clstatus = 'NEW'
+            ENDIF
             IF( jpnij > 1 ) THEN
                ! define the domain position regarding to the global domain (mainly useful in mpp)
@@ -86,9 +92,9 @@
                IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname(1:iln-1)//'... in WRITE mode'
                CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
-                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom )
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom, mode = clstatus )
             ELSE              ! the file should be open for read mode so it must exist...
                IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname//' in WRITE mode'
                CALL fliocrfd( cdname, (/'x'         , 'y'         , 'z', 't'/)   &
-                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid )
+                  &         , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid,           mode = clstatus )
             ENDIF
          ELSE              ! the file should be open for read mode so it must exist...
Index: trunk/NEMO/OFF_SRC/IOM/iom_nf90.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/IOM/iom_nf90.F90	(revision 1749)
@@ -49,33 +49,40 @@
       !! ** Purpose : open an input file with NF90
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname    ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid    ! nf90 identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt     ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok      ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar   ! domain parameters: 
-
-      CHARACTER(LEN=100) ::   clinfo   ! info character
-      CHARACTER(LEN=100) ::   cltmp    ! temporary character
-      INTEGER            ::   iln      ! lengths of character
-      INTEGER            ::   istop    ! temporary storage of nstop
-      INTEGER            ::   if90id   ! nf90 identifier of the opened file
-      INTEGER            ::   idmy     ! dummy variable
-      INTEGER            ::   jl       ! loop variable
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid      ! nf90 identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
+
+      CHARACTER(LEN=100) ::   clinfo           ! info character
+      CHARACTER(LEN=100) ::   cltmp            ! temporary character
+      INTEGER            ::   iln              ! lengths of character
+      INTEGER            ::   istop            ! temporary storage of nstop
+      INTEGER            ::   if90id           ! nf90 identifier of the opened file
+      INTEGER            ::   idmy             ! dummy variable
+      INTEGER            ::   jl               ! loop variable
+      INTEGER            ::   ichunk           ! temporary storage of nn_chunksz
+      INTEGER            ::   imode            ! creation mode flag: NF90_CLOBBER or NF90_NOCLOBBER
+      LOGICAL            ::   llclobber        ! local definition of ln_clobber
       !---------------------------------------------------------------------
 
       clinfo = '                    iom_nf90_open ~~~  '
       istop = nstop   ! store the actual value of nstop
-      !
-      IF( ldok ) THEN      ! Open existing file...
+      IF( nn_chunksz > 0 ) THEN   ;   ichunk = nn_chunksz
+      ELSE                        ;   ichunk = NF90_SIZEHINT_DEFAULT
+      ENDIF
+      !
+      llclobber = ldwrt .AND. ln_clobber
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
          !                 ! =============
          IF( ldwrt ) THEN  ! ... in write mode
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
-            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_WRITE  , if90id), clinfo)
-            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy    ), clinfo)
+            CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_WRITE  , if90id, chunksize = ichunk ), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                          ), clinfo)
          ELSE              ! ... in read mode
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
-            CALL iom_nf90_check(NF90_OPEN(TRIM(cdname), NF90_NOWRITE, if90id), clinfo)
-         ENDIF
-      ELSE                 ! the file does not exist
+            CALL iom_nf90_check(NF90_OPEN( TRIM(cdname), NF90_NOWRITE, if90id, chunksize = ichunk ), clinfo)
+         ENDIF
+      ELSE                                       ! the file does not exist (or we overwrite it)
          !                 ! =============
          iln = INDEX( cdname, '.nc' )
@@ -86,6 +93,10 @@
             ENDIF
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in WRITE mode'
-            CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), NF90_NOCLOBBER, if90id ), clinfo)
-            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy          ), clinfo)
+
+            IF( llclobber ) THEN   ;   imode = NF90_CLOBBER 
+            ELSE                   ;   imode = NF90_NOCLOBBER 
+            ENDIF
+            CALL iom_nf90_check(NF90_CREATE( TRIM(cdname), imode, if90id, chunksize = ichunk ), clinfo)
+            CALL iom_nf90_check(NF90_SET_FILL( if90id, NF90_NOFILL, idmy                     ), clinfo)
             ! define dimensions
             CALL iom_nf90_check(NF90_DEF_DIM( if90id, 'x', kdompar(1,1)  , idmy ), clinfo)
Index: trunk/NEMO/OFF_SRC/IOM/iom_rstdimg.F90
===================================================================
--- trunk/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/IOM/iom_rstdimg.F90	(revision 1749)
@@ -48,12 +48,13 @@
       !! ** Purpose :  open an input file read only (return 0 if not found)
       !!---------------------------------------------------------------------
-      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name
-      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file
-      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file?
-      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence 
-      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters: 
+      CHARACTER(len=*)       , INTENT(inout)           ::   cdname      ! File name
+      INTEGER                , INTENT(  out)           ::   kiomid      ! iom identifier of the opened file
+      LOGICAL                , INTENT(in   )           ::   ldwrt       ! read or write the file?
+      LOGICAL                , INTENT(in   )           ::   ldok        ! check the existence 
+      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar     ! domain parameters: 
 
       CHARACTER(LEN=100)                      ::   clinfo                     ! info character
       CHARACTER(LEN=100)                      ::   cltmp                      ! temporary character
+      CHARACTER(LEN=10 )                      ::   clstatus                   ! status of opened file (REPLACE or NEW)
       INTEGER                                 ::   jv                         ! loop counter
       INTEGER                                 ::   istop                      ! temporary storage of nstop
@@ -70,7 +71,8 @@
       INTEGER                                 ::   iiglo, ijglo               ! domain global size 
       INTEGER                                 ::   jl                         ! loop variable
+      LOGICAL                                 ::   llclobber                  ! local definition of ln_clobber
       CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables
-      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
-      !                                                                               ! position for 1/2/3D variables
+      REAL(wp),             DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record
+      !                                                                                   ! position for 1/2/3D variables
       !---------------------------------------------------------------------
       clinfo = '                    iom_rstdimg_open ~~~  '
@@ -78,4 +80,5 @@
       ios = 0            ! default definition
       kiomid = 0         ! default definition
+      llclobber = ldwrt .AND. ln_clobber
       ! get a free unit
       idrst = getunit()  ! get a free logical unit for the restart file
@@ -85,5 +88,5 @@
       ! Open the file...
       ! =============
-      IF( ldok ) THEN      ! Open existing file...
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! Open existing file...
          ! find the record length
          OPEN( idrst, FILE = TRIM(cdname), FORM = 'unformatted', ACCESS = 'direct'   &
@@ -101,5 +104,5 @@
                &       , RECL = irecl8, STATUS = 'old', ACTION = 'read'     , IOSTAT = ios, ERR = 987 )
          ENDIF
-      ELSE                 ! the file does not exist
+      ELSE                                       ! the file does not exist (or we overwrite it)
          iln = INDEX( cdname, '.dimg' )
          IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it...
@@ -110,6 +113,10 @@
             ENDIF
             IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//TRIM(cdname)//' in READWRITE mode'
+            
+            IF( llclobber ) THEN   ;   clstatus = 'REPLACE' 
+            ELSE                   ;   clstatus = 'NEW'
+            ENDIF
             OPEN( idrst, FILE = TRIM(cdname), FORM = 'UNFORMATTED', ACCESS = 'DIRECT'   &
-               &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
+               &       , RECL = irecl8, STATUS = TRIM(clstatus), ACTION = 'readwrite', IOSTAT = ios, ERR = 987 )
          ELSE              ! the file should be open for read mode so it must exist...
             CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
@@ -118,5 +125,5 @@
       ! Performs checks on the file
       ! =============
-      IF( ldok ) THEN      ! old file
+      IF( ldok .AND. .NOT. llclobber ) THEN      ! old file
          READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              &
               &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   &
Index: trunk/NEMO/OFF_SRC/opa.F90
===================================================================
--- trunk/NEMO/OFF_SRC/opa.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/opa.F90	(revision 1749)
@@ -216,26 +216,15 @@
       
       CALL phy_cst                          ! Physical constants
-
       CALL eos_init                         ! Equation of state
-
       CALL dom_cfg                          ! Domain configuration
-
       CALL dom_init                         ! Domain
-
       CALL istate_init                      ! ocean initial state (Dynamics and tracers)
-      
+      CALL trc_ini                           ! Passive tracers
       CALL dta_dyn( nit000 )                 ! Initialization for the dynamics
-      
-      CALL trc_ini                           ! Passive tracers
-      !                                     ! Ocean physics
       CALL tra_qsr_init                         ! Solar radiation penetration
-
 #if ! defined key_off_degrad
       CALL ldf_tra_init                         ! Lateral ocean tracer physics
 #endif 
-      CALL iom_init( fjulday - adatrj )     ! iom_put initialization
-      !                                     ! =============== !
-      !                                     !  time stepping  !
-      !                                     ! =============== !
+      CALL iom_init                         ! iom_put initialization
 
       IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
Index: trunk/NEMO/OFF_SRC/step.F90
===================================================================
--- trunk/NEMO/OFF_SRC/step.F90	(revision 1748)
+++ trunk/NEMO/OFF_SRC/step.F90	(revision 1749)
@@ -73,5 +73,5 @@
       !! ---------------------------------------------------------------------
 
-      CALL day( kstp )             ! Calendar
+      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
 
       IF( lk_iomput ) CALL iom_setkt( kstp )       ! say to iom that we are at time step kstp
