Index: /trunk/NEMO/LIM_SRC/limrst.F90
===================================================================
--- /trunk/NEMO/LIM_SRC/limrst.F90	(revision 782)
+++ /trunk/NEMO/LIM_SRC/limrst.F90	(revision 783)
@@ -54,18 +54,28 @@
       !!----------------------------------------------------------------------
       !
-      IF( kt == nit000 )   lrst_ice = .FALSE.
-      
-      IF( kt == nitrst - 2*nfice + 1 .OR.  nitend - nit000 + 1 <= nfice ) THEN
-         ! beware if model runs less than nfice + 1 time step
-         ! beware of the format used to write kt (default is i8.8, that should be large enough)
-         IF( nitrst > 1.0e9 ) THEN   
-            WRITE(clkt,*) nitrst
-         ELSE
-            WRITE(clkt,'(i8.8)') nitrst
+      IF( kt == nit000 )   lrst_ice = .FALSE.   ! default definition
+      
+      ! to get better performances with NetCDF format:
+      ! we open and define the ice restart file one ice time step before writing the data (-> at nitrst - 2*nfice + 1)
+      ! except if we write ice restart files every ice time step or if an ice restart file was writen at nitend - 2*nfice + 1
+      IF( kt == nitrst - 2*nfice + 1 .OR. nstock == nfice .OR. ( kt == nitend - nfice + 1 .AND. .NOT. lrst_ice ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+         IF( nitrst > 99999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+         ELSE                           ;   WRITE(clkt, '(i8.8)') nitrst
          ENDIF
          ! create the file
-         IF(lwp) WRITE(numout,*)
          clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_ice"
-         IF(lwp) WRITE(numout,*) '             open ice restart.output NetCDF file: '//clname
+         IF(lwp) THEN
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ice restart binary file: '//clname
+            CASE DEFAULT         ;   WRITE(numout,*) '             open ice restart NetCDF file: '//clname
+            END SELECT
+            IF( kt == nitrst - 2*nfice + 1 ) THEN   
+               WRITE(numout,*)         '             kt = nitrst - 2*nfice + 1 = ', kt,' date= ', ndastp
+            ELSE   ;   WRITE(numout,*) '             kt = '                       , kt,' date= ', ndastp
+            ENDIF
+         ENDIF
+
          CALL iom_open( clname, numriw, ldwrt = .TRUE., kiolib = jprstlib )
          lrst_ice = .TRUE.
@@ -85,9 +95,9 @@
       !!----------------------------------------------------------------------
 
-      iter = kt + nfice -1
+      iter = kt + nfice - 1   ! ice restarts are written at kt == nitrst - nfice + 1
 
       IF( iter == nitrst ) THEN
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'lim_rst_write : write ice restart.output NetCDF file  kt =', kt
+         IF(lwp) WRITE(numout,*) 'lim_rst_write : write ice restart file  kt =', kt
          IF(lwp) WRITE(numout,*) '~~~~~~~'         
       ENDIF
@@ -97,5 +107,5 @@
       !                                                                     ! calendar control
       CALL iom_rstput( iter, nitrst, numriw, 'nfice' , REAL( nfice, wp) )      ! time-step 
-      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice', REAL( iter, wp) )      ! date
+      CALL iom_rstput( iter, nitrst, numriw, 'kt_ice', REAL( iter , wp) )      ! date
       
       CALL iom_rstput( iter, nitrst, numriw, 'hicif' , hicif (:,:)   )      ! prognostic variables 
Index: /trunk/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domain.F90	(revision 782)
+++ /trunk/NEMO/OPA_SRC/DOM/domain.F90	(revision 783)
@@ -181,16 +181,14 @@
       ndastp = ndate0                ! Assign initial date to current date
 
-! ... Control of output frequency
-      IF ( nstock == 0 ) THEN
-          IF(lwp)WRITE(numout,cform_war)
-          IF(lwp)WRITE(numout,*) '           nstock = ', nstock, ' it is forced to ', nitend
-          nstock = nitend
-          nwarn = nwarn + 1
+      ! ... Control of output frequency
+      IF ( nstock == 0 .OR. nstock > nitend - nit000 + 1 ) THEN
+         WRITE(ctmp1,*) '           nstock = ', nstock, ' it is forced to ', nitend - nit000 + 1
+         CALL ctl_warn( ctmp1 )
+         nstock = nitend - nit000 + 1
       ENDIF
       IF ( nwrite == 0 ) THEN
-          IF(lwp)WRITE(numout,cform_war)
-          IF(lwp)WRITE(numout,*) '           nwrite = ', nwrite, ' it is forced to ', nitend
-          nwrite = nitend
-          nwarn = nwarn + 1
+         WRITE(ctmp1,*) '           nwrite = ', nwrite, ' it is forced to ', nitend
+         CALL ctl_warn( ctmp1 )
+         nwrite = nitend
       ENDIF
 
@@ -261,10 +259,14 @@
       IF( lk_ice_lim ) THEN
          IF(lwp) WRITE(numout,*) '           ice model coupling frequency      nfice  = ', nfice
+         IF( MOD( nitend - nit000 + 1, nfice) /= 0 ) THEN 
+            WRITE(ctmp1,*) 'experiment length (', nitend - nit000 + 1, ') is NOT a multiple of nfice (', nfice, ')'
+            CALL ctl_stop( ctmp1, 'Impossible to do proper restart files' )
+         ENDIF
+         IF( MOD( nstock             , nfice) /= 0 ) THEN 
+            WRITE(ctmp1,*) 'nstock ('           , nstock             , ') is NOT a multiple of nfice (', nfice, ')'
+            CALL ctl_stop( ctmp1, 'Impossible to do proper restart files' )
+         ENDIF
          nfbulk = nfice
-         IF( MOD( rday, nfice*rdt ) /= 0 ) THEN 
-            IF(lwp) WRITE(numout,*) ' '
-            IF(lwp) WRITE(numout,*) 'W A R N I N G :  nfice is NOT a multiple of the number of time steps in a day'
-            IF(lwp) WRITE(numout,*) ' '
-         ENDIF
+         IF( MOD( rday, nfice*rdt ) /= 0 )   CALL ctl_warn( 'nfice is NOT a multiple of the number of time steps in a day' )
          IF(lwp) WRITE(numout,*) '           bulk computation frequency       nfbulk  = ', nfbulk, ' = nfice if ice model used'
          IF(lwp) WRITE(numout,*) '           flag closed sea or not           nclosea = ', nclosea
Index: /trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 782)
+++ /trunk/NEMO/OPA_SRC/TRD/trdmld_rst.F90	(revision 783)
@@ -46,12 +46,25 @@
       !!--------------------------------------------------------------------------------
 
-      IF( kt == nitrst-1 ) THEN
-         IF( nitrst > 1.0e9 ) THEN   
-            WRITE(clkt,*) nitrst
-         ELSE
-            WRITE(clkt,'(i8.8)') nitrst
+      ! to get better performances with NetCDF format:
+      ! we open and define the ocean restart_mld file one time step before writing the data (-> at nitrst - 1)
+      ! except if we write ocean restart_mld files every time step or if an ocean restart_mld file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. MOD( nitend - 1, nstock ) == 0 ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
          ENDIF
+         ! create the file
          clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_restart_mld"
-         IF(lwp) WRITE(numout,*) '             open ocean restart_mld NetCDF file: '//clname
+         IF(lwp) THEN
+            WRITE(numout,*)
+            SELECT CASE ( jprstlib )
+            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart_mld binary file: '//clname
+            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart_mld NetCDF file: '//clname
+            END SELECT
+            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
+            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
+            ENDIF
+         ENDIF
+
          CALL iom_open( clname, nummldw, ldwrt = .TRUE., kiolib = jprstlib )
       ENDIF
@@ -59,5 +72,5 @@
       IF( kt == nitrst .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'trdmld_rst: output for ML diags. restart, with trd_mld_rst_write routine'
+         WRITE(numout,*) 'trdmld_rst: output for ML diags. restart, with trd_mld_rst_write routine kt =', kt
          WRITE(numout,*) '~~~~~~~~~~'
          WRITE(numout,*)
@@ -81,8 +94,6 @@
          CALL iom_rstput( kt, nitrst, nummldw, 'tml_sumb'        , tml_sumb        )
          DO jk = 1, jpltrd
-            IF( jk < 10 )   THEN
-               WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
-            ELSE
-               WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I1)") jk
+            ELSE                 ;   WRITE(charout,FMT="('tmltrd_csum_ub_', I2)") jk
             ENDIF
             CALL iom_rstput( kt, nitrst, nummldw, charout,  tmltrd_csum_ub(:,:,jk) )
@@ -94,8 +105,6 @@
          CALL iom_rstput( kt, nitrst, nummldw, 'sml_sumb'        , sml_sumb        )
          DO jk = 1, jpltrd
-            IF( jk < 10 )   THEN
-               WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
-            ELSE
-               WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
+            IF( jk < 10 ) THEN   ;   WRITE(charout,FMT="('smltrd_csum_ub_', I1)") jk
+            ELSE                 ;   WRITE(charout,FMT="('smltrd_csum_ub_', I2)") jk
             ENDIF
             CALL iom_rstput( kt, nitrst, nummldw, charout , smltrd_csum_ub(:,:,jk) )
Index: /trunk/NEMO/OPA_SRC/restart.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/restart.F90	(revision 782)
+++ /trunk/NEMO/OPA_SRC/restart.F90	(revision 783)
@@ -65,19 +65,21 @@
       !!----------------------------------------------------------------------
       !
-      IF( kt == nit000 ) THEN   ! default initialization, to do: should be read in the namelist...
-         nitrst = nitend        ! to do: should be read in the namelist in a cleaver way...
-         lrst_oce = .FALSE.
-      ENDIF
-
-      IF    ( kt == nitrst-1 .AND. lrst_oce         ) THEN
-         CALL ctl_stop( 'rst_opn: we cannot create an ocean restart at every time step',    &
-            &           'if the run has more than one time step!!!' )
-         numrow = 0
-      ELSEIF( kt == nitrst-1 .OR.  nitend == nit000 ) THEN   ! beware if model runs only one time step
-         ! beware of the format used to write kt (default is i8.8, that should be large enough)
-         IF( nitrst > 1.0e9 ) THEN   
-            WRITE(clkt,*) nitrst
-         ELSE
-            WRITE(clkt,'(i8.8)') nitrst
+      IF( kt == nit000 ) THEN   ! default definitions
+         lrst_oce = .FALSE.   
+         nitrst = nitend
+      ENDIF
+      IF( MOD( kt - 1, nstock ) == 0 ) THEN   
+         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
+         nitrst = kt + nstock - 1                  ! define the next value of nitrst for restart writing
+         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
+      ENDIF
+
+      ! to get better performances with NetCDF format:
+      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
+      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
+         ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+         IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+         ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
          ENDIF
          ! create the file
@@ -86,13 +88,9 @@
             WRITE(numout,*)
             SELECT CASE ( jprstlib )
-            CASE ( jpnf90 )
-               WRITE(numout,*) '             open ocean restart.output NetCDF file: '//clname
-            CASE ( jprstdimg )
-               WRITE(numout,*) '             open ocean restart.output binary file: '//clname
+            CASE ( jprstdimg )   ;   WRITE(numout,*) '             open ocean restart binary file: '//clname
+            CASE DEFAULT         ;   WRITE(numout,*) '             open ocean restart NetCDF file: '//clname
             END SELECT
-            IF( kt == nitrst-1 ) THEN
-               WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
-            ELSE
-               WRITE(numout,*) '             kt = ', kt,' date= ', ndastp
+            IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt,' date= ', ndastp
+            ELSE                          ;   WRITE(numout,*) '             kt = '             , kt,' date= ', ndastp
             ENDIF
          ENDIF
@@ -116,4 +114,10 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time-step
       !!----------------------------------------------------------------------
+
+      IF( kt == nitrst ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'rst_write : write oce restart file  kt =', kt
+         IF(lwp) WRITE(numout,*) '~~~~~~~'         
+      ENDIF
 
       ! calendar control
