Index: trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F
===================================================================
--- trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F	(revision 1703)
+++ trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F	(revision 1824)
@@ -19,5 +19,5 @@
      &                       dissip_period,offline,ip_ebil_dyn,
      &                       ok_dynzon,periodav,ok_dyn_ave,iecri,
-     &                       ok_dyn_ins,output_grads_dyn
+     &                       ok_dyn_ins,output_grads_dyn,ecritstart
       use exner_hyb_m, only: exner_hyb
       use exner_milieu_m, only: exner_milieu
@@ -31,5 +31,5 @@
      .			statcl,conser,apdiss,purmats,tidal,ok_strato
       USE temps_mod, ONLY: jD_ref,jH_ref,itaufin,day_ini,day_ref,
-     .			start_time,dt
+     .			start_time,dt,hour_ini
 
       IMPLICIT NONE
@@ -131,4 +131,5 @@
 c   variables pour le fichier histoire
 !      REAL dtav      ! intervalle de temps elementaire
+      LOGICAL lrestart
 
       REAL tppn(iim),tpps(iim),tpn,tps
@@ -289,4 +290,12 @@
 c   ----------------------------------
 
+c     RMBY: check that hour_ini and start_time are not both non-zero
+      if ((hour_ini.ne.0.0).and.(start_time.ne.0.0)) then
+        write(*,*) "ERROR: hour_ini = ", hour_ini, 
+     &             "start_time = ", start_time
+        abort_message = 'hour_ini and start_time both nonzero'
+        call abort_gcm(modname,abort_message,1)
+      endif
+
    1  CONTINUE ! Matsuno Forward step begins here
 
@@ -296,6 +305,11 @@
       jD_cur = jD_ref + day_ini - day_ref +                             &
      &          (itau+1)/day_step 
-      jH_cur = jH_ref + start_time +                                    &
-     &          mod(itau+1,day_step)/float(day_step) 
+      IF (planet_type .eq. "mars") THEN
+        jH_cur = jH_ref + hour_ini +                                    &
+     &           mod(itau+1,day_step)/float(day_step) 
+      ELSE
+        jH_cur = jH_ref + start_time +                                  &
+     &           mod(itau+1,day_step)/float(day_step)
+      ENDIF
       jD_cur = jD_cur + int(jH_cur)
       jH_cur = jH_cur - int(jH_cur)
@@ -351,6 +365,11 @@
         jD_cur = jD_ref + day_ini - day_ref +
      &            (itau+1)/day_step
-        jH_cur = jH_ref + start_time +
-     &            mod(itau+1,day_step)/float(day_step) 
+        IF (planet_type .eq. "mars") THEN
+          jH_cur = jH_ref + hour_ini + 
+     &             mod(itau+1,day_step)/float(day_step) 
+        ELSE
+          jH_cur = jH_ref + start_time +
+     &             mod(itau+1,day_step)/float(day_step)
+        ENDIF
         jD_cur = jD_cur + int(jH_cur)
         jH_cur = jH_cur - int(jH_cur)
@@ -529,10 +548,13 @@
            ENDIF
 
-           jH_cur = jH_ref + start_time +                               &
-     &          mod(itau+1,day_step)/float(day_step) 
-           IF ((planet_type .eq."generic").or.
-     &         (planet_type .eq."mars")) THEN
+           IF (planet_type .eq. "mars") THEN
+             jH_cur = jH_ref + hour_ini +                                 &
+     &                mod(itau,day_step)/float(day_step)
+           ELSE IF (planet_type .eq. "generic") THEN
              jH_cur = jH_ref + start_time +                               &
-     &          mod(itau,day_step)/float(day_step)
+     &                mod(itau,day_step)/float(day_step)
+           ELSE
+             jH_cur = jH_ref + start_time +                               &
+     &                mod(itau+1,day_step)/float(day_step)
            ENDIF
            jD_cur = jD_cur + int(jH_cur)
@@ -861,6 +883,16 @@
             ENDIF ! of IF(MOD(itau,iecri).EQ.0)
 
-            IF(itau.EQ.itaufin) THEN
-
+c           Determine whether to write to the restart.nc file
+c           Decision can't be made in one IF statement as if
+c           ecritstart==0 there will be a divide-by-zero error
+            lrestart = .false.
+            IF (itau.EQ.itaufin) THEN
+              lrestart = .true.
+            ELSE IF (ecritstart.GT.0) THEN
+              IF (MOD(itau,ecritstart).EQ.0) lrestart  = .true.
+            ENDIF
+
+c           Write to the restart.nc file
+            IF (lrestart) THEN
               if (planet_type=="mars") then
                 CALL dynredem1("restart.nc",REAL(itau)/REAL(day_step),
@@ -872,5 +904,5 @@
               CLOSE(99)
               !!! Ehouarn: Why not stop here and now?
-            ENDIF ! of IF (itau.EQ.itaufin)
+            ENDIF ! of IF (lrestart)
 
 c-----------------------------------------------------------------------
@@ -992,5 +1024,16 @@
               ENDIF ! of IF(MOD(itau,iecri         ).EQ.0) 
 
-              IF(itau.EQ.itaufin) THEN
+c             Determine whether to write to the restart.nc file
+c             Decision can't be made in one IF statement as if
+c             ecritstart==0 there will be a divide-by-zero error
+              lrestart = .false.
+              IF (itau.EQ.itaufin) THEN
+                lrestart = .true.
+              ELSE IF (ecritstart.GT.0) THEN
+                IF (MOD(itau,ecritstart).EQ.0) lrestart = .true.
+              ENDIF
+
+c             Write to the restart.nc file
+              IF (lrestart) THEN
                 if (planet_type=="mars") then
                   CALL dynredem1("restart.nc",REAL(itau)/REAL(day_step),
@@ -1000,5 +1043,5 @@
      &                         vcov,ucov,teta,q,masse,ps)
                 endif
-              ENDIF ! of IF(itau.EQ.itaufin)
+              ENDIF ! of IF (lrestart)
 
               forward = .TRUE.
