Index: trunk/libIGCM/libIGCM_config/libIGCM_config.ksh
===================================================================
--- trunk/libIGCM/libIGCM_config/libIGCM_config.ksh	(revision 889)
+++ trunk/libIGCM/libIGCM_config/libIGCM_config.ksh	(revision 890)
@@ -353,7 +353,7 @@
 
 #===================================
-function IGCM_config_Analyse_PeriodLength
+function IGCM_config_DaysInPeriodLength
 {
-  IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength"
+  IGCM_debug_PushStack "IGCM_config_DaysInPeriodLength"
 
   typeset i
@@ -393,10 +393,49 @@
     IGCM_debug_Print 2 "Number of days for PeriodLength : ${PeriodLengthInDays}";;
   *)
-    IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
+    IGCM_debug_Exit "IGCM_config_DaysInPeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
     IGCM_debug_Verif_Exit ;;
   esac
 
-  IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength"
+  IGCM_debug_PopStack "IGCM_config_DaysInPeriodLength"
 }
+
+#===================================
+function IGCM_config_DateCoherency
+
+  IGCM_debug_PushStack "IGCM_config_DateCoherency"
+
+  # If one of the following modulo is not zero :
+  # we will issue an error then explain and exit in
+  # AA_job IGCM_debug_Verif_Exit call before binary submission
+
+  echo
+  IGCM_debug_Print 1 "IGCM_config_DateCoherency"
+  echo
+
+  typeset Length VerifiedPeriodDateBegin VerifiedPeriodDateEnd
+
+  # check coherency between (PeriodDateBegin, PeriodDateEnd) and (DateBegin, CumulPeriod, PeriodLength)
+  # DateBegin + CumulPeriod*PeriodLength = PeriodDateBegin
+  echo
+  
+  case ${config_UserChoices_PeriodLength} in
+  *Y|*y)
+    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInYears} ))Y )
+    ;;
+  *M|*m)
+    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInMonths} ))M )
+    ;;
+  *D|*d)
+    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInDays} ))D )
+    ;;
+  esac
+  VerifiedPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Length} )
+
+  # PeriodDateBegin + PeriodLength = PeriodDateEnd
+  VerifiedPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${VerifiedPeriodDateEnd} $(( ${PeriodLengthInDays} * -1 )) )
+
+  IGCM_debug_PopStack "IGCM_config_DateCoherency"
+}
+
 
 #===================================
@@ -456,5 +495,5 @@
   fi
 
-  #modulo (TimeSeriesFrequency and all Chunck2D) must be zero
+  # modulo (TimeSeriesFrequency and all Chunck2D) must be zero
   NbJob=${#CHUNCK2D_SIZE[@]}
   i=0
@@ -472,5 +511,5 @@
   done
 
-  #modulo (TimeSeriesFrequency and all Chunck3D) must be zero
+  # modulo (TimeSeriesFrequency and all Chunck3D) must be zero
   NbJob=${#CHUNCK3D_SIZE[@]}
   i=0
@@ -488,5 +527,5 @@
   done
 
-  #check to be sure there is enough space on temporary filesystems to run
+  # check to be sure there is enough space on temporary filesystems to run
   echo
   IGCM_debug_Print 1 "Check if there is enough space on temporary filesystem"
@@ -510,6 +549,6 @@
     #================================================#
 
-    IGCM_date_GetYearMonthDay $DateBegin year month day
-    IGCM_config_Analyse_PeriodLength
+    IGCM_date_GetYearMonthDay ${DateBegin} year month day
+    IGCM_config_DaysInPeriodLength
 
     eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1
@@ -561,10 +600,4 @@
 
     LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" )
-
-    typeset LastDate
-    set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" )
-    LastYearDateEnd=${LastDate[0]}
-    LastMonthDateEnd=${LastDate[1]}
-    LastDayDateEnd=${LastDate[2]}
 
     if [ ${Period} = 1 ]; then
@@ -596,10 +629,12 @@
     fi
 
+    # 
     IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
-    IGCM_config_Analyse_PeriodLength
+    IGCM_config_DaysInPeriodLength
 
     IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
-
-  fi
+  fi
+
+  # Save for futur use
   OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd}
 
@@ -1137,5 +1172,5 @@
   year_m1=$(( year - 1 ))
   year_p1=$(( year + 1 ))
-  IGCM_config_Analyse_PeriodLength
+  IGCM_config_DaysInPeriodLength
   PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
 
