Index: trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh
===================================================================
--- trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh	(revision 679)
+++ trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh	(revision 680)
@@ -33,4 +33,5 @@
   fi
 
+  IGCM_card_DefineVariableFromOption ${FileName} Ens_PERTURB ACTIVE
   IGCM_card_DefineVariableFromOption ${FileName} Ens_PERTURB NAME
   IGCM_card_DefineVariableFromOption ${FileName} Ens_PERTURB DEBUT_INIT
@@ -48,4 +49,5 @@
   IGCM_card_DefineArrayFromSection   config.card ListOfComponents
 
+  IGCM_debug_Print 1 "ACTIVE            = ${ensemble_Ens_PERTURB_ACTIVE}"
   IGCM_debug_Print 1 "NAME              = ${ensemble_Ens_PERTURB_NAME}"
   IGCM_debug_Print 1 "DEBUT_INIT        = ${ensemble_Ens_PERTURB_DEBUT_INIT}"
@@ -58,5 +60,5 @@
   IGCM_debug_Print 1 "PERTURB_BIN       = ${ensemble_Ens_PERTURB_PERTURB_BIN[*]}"
   IGCM_debug_Print 1 "INITFROM          = ${ensemble_Ens_PERTURB_INITFROM}"
-  IGCM_debug_Print 1 "INITFROM          = ${ensemble_Ens_PERTURB_INITPATH}"
+  IGCM_debug_Print 1 "INITPATH          = ${ensemble_Ens_PERTURB_INITPATH}"
   IGCM_debug_Print 1 "TagName           = ${config_UserChoices_TagName}"
   IGCM_debug_Print 1 "CalendarType      = ${config_UserChoices_CalendarType}"
@@ -75,104 +77,73 @@
   IGCM_debug_Print 1 "PerturbAmp  = ${PerturbAmp}"
 
-  IGCM_debug_PopStack "IGCM_ensemble_CastInit"
-}
-
-function IGCM_ensemble_CastPeriodicStarts
-{
-  IGCM_debug_PushStack "IGCM_ensemble_CastPeriodicStarts"
-
-  echo "Manage periodic starts"
-
-#.. Manage periodic starts ..
-#   ======================
-
-# ... Determine number of year(s) in PERIODICITE ...
+  # A few checks Period case:
+
+  # ... Check PERIODICITE ...
   case ${ensemble_Ens_PERTURB_PERIODICITE} in
   0)
     IGCM_debug_Print 1 "No periodic start"
+    return
     ;;
-  *Y|*y)
-    PeriodLengthInYears=$( echo ${ensemble_Ens_PERTURB_PERIODICITE} | sed -e 's/[yY]//' );;
-  *M|*m)
-    PeriodLengthInMonths=$( echo ${ensemble_Ens_PERTURB_PERIODICITE} | sed -e 's/[mM]//' );;
+  *[Yy]|*[Mm])
+    IGCM_debug_Print 1 "Periodic length : ${ensemble_Ens_PERTURB_PERIODICITE}" ;;
   *)
-    IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " \
-      ${ensemble_Ens_PERTURB_PERIODICITE} \
-      " invalid PERIODICITE : choose in *Y."
+    IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_PERIODICITE} : invalid PERIODICITE"
+    IGCM_debug_Exit "Choose a value in *Y or *M"
     IGCM_debug_Verif_Exit ;;
   esac
-# ... Determine number of year(s) in DUREE ...
+# ... Check DUREE ...
   case ${ensemble_Ens_PERTURB_DUREE} in
-  *Y|*y)
-    DureeLengthInYears=$( echo ${ensemble_Ens_PERTURB_DUREE} | sed -e 's/[yY]//' ) ;;
-  *M|*m)
-    DureeLengthInMonths=$( echo ${ensemble_Ens_PERTURB_DUREE} | sed -e 's/[mM]//' ) ;;
+  *[Yy]|*[Mm])
+    IGCM_debug_Print 1 "Periodic duration : ${ensemble_Ens_PERTURB_DUREE}" ;;
   *)
-    IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " \
-      ${ensemble_Ens_PERTURB_DUREE} \
-      " invalid DUREE : choose in *Y."
+    IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_DUREE} invalid DUREE"
+    IGCM_debug_Exit "Choose a value in choose in *Y or *M"
     IGCM_debug_Verif_Exit ;;
   esac
 
+  # A few checks Non-Period case:
+  DateNum=0
+  while [ $DateNum -lt ${#ensemble_Ens_PERTURB_NONPERIODIC[*]} ] ; do
+
+    # - Check DUREE_NONPERIODIC
+    case ${ensemble_Ens_PERTURB_DUREE_NONPERIODIC[$DateNum]} in
+    0)
+      IGCM_debug_Print 1 "No non-periodic start"
+      return
+      ;;
+    *[Yy]|*[Mm])
+      IGCM_debug_Print 1 "Non-periodic duration : ${ensemble_Ens_PERTURB_DUREE_NONPERIODIC[$DateNum]}"
+      ;;
+    *)
+      IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_DUREE_NONPERIODIC[$DateNum]} : invalid DUREE"
+      IGCM_debug_Exit "choose in *Y or *M"
+      IGCM_debug_Verif_Exit ;;
+    esac
+    (( DateNum = DateNum + 1 ))
+  done
+
+  IGCM_debug_PopStack "IGCM_ensemble_CastInit"
+}
+
+function IGCM_ensemble_CastPeriodicStarts
+{
+  IGCM_debug_PushStack "IGCM_ensemble_CastPeriodicStarts"
+
+  echo "Manage periodic starts"
+
+#.. Manage periodic starts ..
+#   ======================
+
 # ... Loop over DateBegin ...
   eval DateBegin=\${ensemble_Ens_PERTURB_DEBUT_INIT}
 
-  while [ ${DateBegin} -le ${ensemble_Ens_PERTURB_FIN_INIT}  ] ; do
+  while [ ${DateBegin} -le ${ensemble_Ens_PERTURB_FIN_INIT} ] ; do
     IGCM_date_GetYearMonth ${DateBegin} year month
 
   # - Determine number of day(s) in PERIODICITE
-    PeriodLengthInDays=0
-    case ${ensemble_Ens_PERTURB_PERIODICITE} in
-    *Y|*y)
-      i=0
-      until [ $i -ge ${PeriodLengthInYears} ] ; do
-        (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
-        (( i = i + 1 ))
-      done
-      ;;
-    *M|*m)
-      i=0
-      year_wrk=$year
-      month_wrk=$month
-      until [ $i -ge ${PeriodLengthInMonths} ] ; do
-        (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year_wrk $month_wrk ) ))
-        if [ $month_wrk -lt 12 ] ; then
-          (( month_wrk = month_wrk + 1 ))
-        else
-          (( year_wrk  = year_wrk + 1 ))
-          (( month_wrk = 1 ))
-        fi
-        (( i = i + 1 ))
-      done
-      ;;
-    esac
+    PeriodLengthInDays=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_PERTURB_PERIODICITE} )
+
   # - Determine number of day(s) in DUREE
-    DureeLengthInDays=0
-    case ${ensemble_Ens_PERTURB_DUREE} in
-    *Y|*y)
-      i=0
-      until [ $i -ge ${DureeLengthInYears} ] ; do
-        (( DureeLengthInDays = DureeLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
-        (( i = i + 1 ))
-      done
-      ;;
-    *M|*m)
-      i=0
-      year_wrk=$year
-      month_wrk=$month
-      until [ $i -ge ${DureeLengthInMonths} ] ; do
-        (( DureeLengthInDays = DureeLengthInDays + $( IGCM_date_DaysInMonth $year_wrk $month_wrk ) ))
-        if [ $month_wrk -lt 12 ] ; then
-          (( month_wrk = month_wrk + 1 ))
-        else
-          (( year_wrk  = year_wrk + 1 ))
-          (( month_wrk = 1 ))
-        fi
-        (( i = i + 1 ))
-      done
-      ;;
-    esac
-
-    (( DureeLengthInDays = DureeLengthInDays - 1 ))
+    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_PERTURB_DUREE} ) - 1 ))
 
   # - Determine DateEnd
@@ -200,7 +171,5 @@
   # - Create directory in which to store new restart files
     RestartDir=$ARCHIVE/IGCM_IN/${config_UserChoices_TagName}/${StartDir}
-    if [ ! -d  ${RestartDir} ] ; then
-      IGCM_sys_MkdirArchive ${RestartDir}
-    fi
+    IGCM_sys_MkdirArchive ${RestartDir}
 
   # - Loop over members
@@ -218,5 +187,5 @@
       if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
         IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
-#      IGCM_sys_Cp -r COMP/ PARAM/ ${StartDir}/${MemberDir}
+        #IGCM_sys_Cp -r COMP/ PARAM/ ${StartDir}/${MemberDir}
         IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
         ln -s ../../COMP
@@ -245,5 +214,5 @@
     echo "$DateBegin  $PeriodLengthInDays"
     case ${ensemble_Ens_PERTURB_PERIODICITE} in
-    *Y|*y|*M|*m)
+    *[Yy]|*[Mm])
       (( DateBegin = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${PeriodLengthInDays} ) ))
       ;;
@@ -254,16 +223,4 @@
   IGCM_debug_PopStack "IGCM_ensemble_CastPeriodicStarts"
 }
-
-
-
-
-
-
-
-
-
-
-
-
 
 function IGCM_ensemble_CastNonPeriodicStarts
@@ -285,40 +242,8 @@
     echo ">${DateBegin}<"
     echo ">${Duree}<"
-  # - Determine number of year(s) in DUREE_NONPERIODIC
-    case ${Duree} in
-    0)
-      IGCM_debug_Print 1 "No non-periodic start"
-      exit
-      ;;
-    *Y|*y)
-      DureeLengthInYears=$( echo ${Duree} | sed -e 's/[yY]//' )
-      ;;
-    *M|*m)
-      DureeLengthInMonths=$( echo ${Duree} | sed -e 's/[mM]//' )
-      ;;
-    *)
-      IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${Duree} " invalid DUREE : choose in *Y."
-      IGCM_debug_Verif_Exit ;;
-    esac
+
   # - Determine number of day(s) in DUREE_NONPERIODIC
     IGCM_date_GetYearMonth ${DateBegin} year month
-    DureeLengthInDays=0
-    case ${Duree} in
-    *Y|*y)
-      i=0
-      until [ $i -ge ${DureeLengthInYears} ] ; do
-        (( DureeLengthInDays = DureeLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
-        (( i = i + 1 ))
-      done
-      ;;
-    *M|*m)
-      i=0
-      until [ $i -ge ${DureeLengthInMonths} ] ; do
-        (( DureeLengthInDays = DureeLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) ))
-        (( i = i + 1 ))
-      done
-      ;;
-    esac
-    (( DureeLengthInDays = DureeLengthInDays - 1 ))
+    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${Duree} ) - 1 ))
 
   # - Build directory name
@@ -330,5 +255,4 @@
     (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
     echo ">${DateEnd}<"
-
     echo "tout va bien 1"
 
@@ -354,7 +278,5 @@
   # - Create directory in which to store new restart files if it does'nt already exist
     RestartDir=$DMFDIR/IGCM_IN/${config_UserChoices_TagName}/${StartDir}
-    if [ ! -d  ${RestartDir} ] ; then
-      IGCM_sys_MkdirArchive ${RestartDir}
-    fi
+    IGCM_sys_MkdirArchive ${RestartDir}
 
   # - Loop over members
@@ -457,6 +379,4 @@
   year=$3
   month=$4
-
-  set -A AlphaMonth a b c d e f g h i j k l
 
   # - Build directory name
@@ -521,5 +441,5 @@
     if [ $? -ne 0 ] ; then
       echo "Abend $( basename ${PerturbExe} )"
-      exit
+      return
     fi
 
