Index: /trunk/libIGCM/libIGCM_config/libIGCM_config.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_config/libIGCM_config.ksh	(revision 725)
+++ /trunk/libIGCM/libIGCM_config/libIGCM_config.ksh	(revision 726)
@@ -13,45 +13,21 @@
 
 #===================================
-function IGCM_config_Initialize
+function IGCM_config_CommonConfiguration
 {
-  IGCM_debug_PushStack "IGCM_config_Initialize"
+  IGCM_debug_PushStack "IGCM_config_CommonConfiguration" $@
 
   # Debug Print :
   echo
-  IGCM_debug_Print 1 "IGCM_config_Initialize"
-
-  if [ ! -r ${SUBMIT_DIR}/run.card ]; then
-    #================================================#
-    #         The file run.card doesn't exist        #
-    #================================================#
-    FirstInitialize=true
-    #copy initial run.card
-    IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card
-    IGCM_debug_Print 2 "run.card copied from run.card.init"
-  else
-    FirstInitialize=false
-    IGCM_debug_Print 2 "run.card exists"
-  fi
-
-  # Test modipsl tree existence.
-  IGCM_sys_TestDir ${MODIPSL}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
-  IGCM_sys_TestDir ${libIGCM}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
-  IGCM_sys_TestDir ${R_EXE}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
-  IGCM_sys_TestDir ${SUBMIT_DIR}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
-
-  if ( $DEBUG_debug ) ; then
-    echo "Keep trace of inital SUBMIT_DIR : "
-    ls -lta ${SUBMIT_DIR}
-  fi
+  IGCM_debug_Print 1 "IGCM_config_CommonConfiguration" $@
+
+  # config.card path
+  configPath=$1
 
   #==================================
-
   typeset option auxprint CompatibilityTag
+
+  #==================================
   # Read libIGCM compatibility version in config.card
-  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM
+  IGCM_card_DefineVariableFromOption ${configPath} Compatibility libIGCM
   eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1
 
@@ -62,156 +38,43 @@
   #==================================
   # Read UserChoices section:
-  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
-
+  echo
+  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
+
+  IGCM_card_DefineArrayFromSection ${configPath} UserChoices
   for option in ${config_UserChoices[*]} ; do
-    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
+    IGCM_card_DefineVariableFromOption ${configPath} UserChoices ${option}
+    eval auxprint=\${config_UserChoices_${option}}
+    IGCM_debug_Print 3 "${option} : ${auxprint}"
   done
-  echo
-  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
-  # Name Space of this experience
-  if [ X${config_UserChoices_SpaceName} != X ] ; then
-    IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
-  fi
-  # Expericence class of the run
-  if [ X${config_UserChoices_ExperimentName} != X ] ; then
-    IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
-  fi
-  IGCM_debug_PrintVariables 3 config_UserChoices_JobName
-  if [ 3 -le ${Verbosity} ] ; then
-    echo "--------------Debug3-->" "config_UserChoices_LongName="
-    echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
-  fi
-  IGCM_debug_PrintVariables 3 config_UserChoices_TagName
-  IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
-  IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
-  IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
-  IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
 
   #==================================
   # Read Ensemble section:
-  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Ensemble
-
+  echo
+  IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble"
+
+  IGCM_card_DefineArrayFromSection ${configPath} Ensemble
   for option in ${config_Ensemble[*]} ; do
-    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Ensemble ${option}
+    IGCM_card_DefineVariableFromOption ${configPath} Ensemble ${option}
+    eval auxprint=\${config_Ensemble_${option}}
+    IGCM_debug_Print 3 "${option} : ${auxprint}"
   done
-
-  IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble"
-  if [ X${config_Ensemble_EnsembleRun} != X ] ; then
-    IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleRun
-  fi
-  if [ X${config_Ensemble_EnsembleName} != X ] ; then
-    IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName
-  fi
-  if [ X${config_Ensemble_EnsembleDate} != X ] ; then
-    IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate
-  fi
 
   #==================================
   # Read Post section:
-  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post
   echo
   IGCM_debug_Print 1 "DefineArrayFromOption : config_Post"
 
+  IGCM_card_DefineArrayFromSection ${configPath} Post
   for option in ${config_Post[*]} ; do
-    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option}
+    IGCM_card_DefineVariableFromOption ${configPath} Post ${option}
     eval auxprint=\${config_Post_${option}}
     IGCM_debug_Print 3 "${option} : ${auxprint}"
   done
-
-  #==================================
-  # Define default value to keep compatibility with previous card: means before changes due to TGCC
-  if [ X${PackDefault} = Xtrue ] ; then
-    [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
-  else
-    config_Post_PackFrequency=NONE
-  fi
-
-  #==================================
-  # Read ListOfComponents section:
-  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
-  for comp in ${config_ListOfComponents[*]} ; do
-    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
-  done
-
-  echo
-  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
-  IGCM_debug_Print 3 ${config_ListOfComponents[*]}
-
-  NbComponents=${#config_ListOfComponents[*]}
-
-  #==================================
-  # Define principal executable
-  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
-
-  #==================================
-  # Define Outputs Name
-  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
-  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
-  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
-  eval Exe_Output=out_execution
-  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
-
-  #===================================================================#
-  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
-  #             But available to any son functions                    #
-  #===================================================================#
-
-  # Convert yyyy-mm-dd date to gregorian yyyymmdd
-  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
-  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   )
-
-  # Period Length In Days between DateBegin and DateEnd
-  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
-  if [ ${ExperienceLengthInDays} -lt 0 ] ; then
-    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
-    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
-    IGCM_debug_Verif_Exit
-  fi
-
-  # Day and Year of Initial State (Given in julian format)
-  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
-  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
-
-  #==================================
-  # Restarts : Gerneral rule or local for each component ?
-  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
-
-  echo
-  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
-
-  for option in ${config_Restarts[*]} ; do
-    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
-    eval auxprint=\${config_Restarts_${option}}
-    IGCM_debug_Print 3 "${option} : ${auxprint}"
-  done
-
-  #================================================================#
-  #                  Test and Prepare directories                  #
-  #================================================================#
-
-  # ==> 4 kinds of input files :
-  #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
-  #     2) R_BC    : Boundary Conditions   (Forcages, lai)
-  #     3) Parameters files (allready define through ${SUBMIT_DIR})
-  #     4) Restarts files   (allready define in IGCM_config_Initialize)
-
-  # Here we offer the possibility to redefine R_INIT, R_BC
-  # and PeriodNb through config.card
-  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
-  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
-  IGCM_debug_Print 3 "R_INIT=${R_INIT}"
-  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
-  IGCM_debug_Print 3  "R_BC=${R_BC}"
-  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
-  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
-
-  # Test Archive input/output.
-  IGCM_sys_TestDirArchive ${ARCHIVE}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
-  IGCM_sys_TestDirArchive ${R_IN}
-  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
+  echo
 
   #====================================================
-  #R_SAVE : Job output directory
+  # R_SAVE : Job output directory
+  # R_BUFR : Job output buffered directory
+
   if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
     FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
@@ -241,7 +104,162 @@
   fi
 
+  IGCM_debug_PopStack "IGCM_config_CommonConfiguration"
+}
+
+#===================================
+function IGCM_config_Initialize
+{
+  IGCM_debug_PushStack "IGCM_config_Initialize"
+
+  # Debug Print :
+  echo
+  IGCM_debug_Print 1 "IGCM_config_Initialize"
+
+  if [ ! -r ${SUBMIT_DIR}/run.card ]; then
+    #================================================#
+    #         The file run.card doesn't exist        #
+    #================================================#
+    FirstInitialize=true
+    #copy initial run.card
+    IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card
+    IGCM_debug_Print 2 "run.card copied from run.card.init"
+  else
+    FirstInitialize=false
+    IGCM_debug_Print 2 "run.card exists"
+  fi
+
+  # Test modipsl tree existence.
+  IGCM_sys_TestDir ${MODIPSL}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
+  IGCM_sys_TestDir ${libIGCM}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
+  IGCM_sys_TestDir ${R_EXE}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
+  IGCM_sys_TestDir ${SUBMIT_DIR}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
+
+  if ( $DEBUG_debug ) ; then
+    echo "Keep trace of inital SUBMIT_DIR : "
+    ls -lta ${SUBMIT_DIR}
+  fi
+
+  #==================================
+  # Read libIGCM compatibility version in config.card
+  # Read UserChoices section
+  # Read Ensemble section
+  # Read Post section
+  # Define all netcdf output directories
+  #==================================
+  IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
+
+  #==================================
+  # Define default value to keep compatibility with previous card: means before changes due to TGCC
+  if [ X${PackDefault} = Xtrue ] ; then
+    # If we DO apply pack in this computing center
+    IGCM_debug_Print 1 "Due to pack policy OVERRULE RebuildFromArchive to NONE"
+    config_Post_RebuildFromArchive=NONE
+    if [ X${config_UserChoices_SpaceName} = XTEST ]; then
+      # TEST simulations will not be packed and will stay on SCRATCHDIR filesystem
+      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE PackFrequency to NONE"
+      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE destination path directories"
+      config_Post_PackFrequency=NONE
+      IGCM_sys_ChangeArchive
+    else
+      # Default to RebuildFrequency if nothing has been set up related to PackFrequency
+      [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
+    fi
+  else
+    # If we DO NOT apply pack in this computing center
+    config_Post_PackFrequency=NONE
+  fi
+
+  #==================================
+  # Read ListOfComponents section:
+  echo
+  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
+
+  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
+  for comp in ${config_ListOfComponents[*]} ; do
+    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
+  done
+  IGCM_debug_Print 3 ${config_ListOfComponents[*]}
+
+  #==================================
+  # Read Executable section:
+  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
+
+  #==================================
+  # Read Restarts section:
+  # Restarts : Gerneral rule or local for each component.
+  echo
+  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
+
+  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
+  for option in ${config_Restarts[*]} ; do
+    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
+    eval auxprint=\${config_Restarts_${option}}
+    IGCM_debug_Print 3 "${option} : ${auxprint}"
+  done
+
+  #==================================
+  # Define Job Outputs Name
+  echo
+  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
+  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
+  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
+  eval Exe_Output=out_execution
+  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
+
+  #===================================================================#
+  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
+  #             But available to any son functions                    #
+  #===================================================================#
+
+  # Convert yyyy-mm-dd date to gregorian yyyymmdd
+  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
+  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   )
+
+  # Period Length In Days between DateBegin and DateEnd
+  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
+  if [ ${ExperienceLengthInDays} -lt 0 ] ; then
+    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
+    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
+    IGCM_debug_Verif_Exit
+  fi
+
+  # Day and Year of Initial State (Given in julian format)
+  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
+  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
+
+  #================================================================#
+  #                  Test and Prepare directories                  #
+  #================================================================#
+
+  # ==> 4 kinds of input files :
+  #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
+  #     2) R_BC    : Boundary Conditions   (Forcages, lai)
+  #     3) Parameters files (allready define through ${SUBMIT_DIR})
+  #     4) Restarts files   (allready define in IGCM_config_Initialize)
+
+  # Here we offer the possibility to redefine R_INIT, R_BC
+  # and PeriodNb through config.card
+  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
+  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
+  IGCM_debug_Print 3 "R_INIT=${R_INIT}"
+  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
+  IGCM_debug_Print 3  "R_BC=${R_BC}"
+  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
+  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
+
+  # Test Archive input/output.
+  echo
+  IGCM_sys_TestDirArchive ${ARCHIVE}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
+  IGCM_sys_TestDirArchive ${R_IN}
+  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
+
   if ( ${FirstInitialize} ) ; then
-    IGCM_sys_MkdirArchive ${R_SAVE}
-    IGCM_sys_Mkdir        ${R_BUFR}
+    IGCM_sys_MkdirArchive   ${R_SAVE}
+    IGCM_sys_Mkdir          ${R_BUFR}
   else
     IGCM_sys_TestDirArchive ${R_SAVE}
