Index: trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh
===================================================================
--- trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh	(revision 829)
+++ trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh	(revision 864)
@@ -87,5 +87,4 @@
     IGCM_debug_Print 1 "periodic start not active"
     CastPeriodicStart=false
-    return
     ;;
   *[Yy]|*[Mm])
@@ -116,5 +115,4 @@
       IGCM_debug_Print 1 "non-periodic start not active"
       CastNonPeriodicStart=false
-      return
       ;;
     *[Yy]|*[Mm])
@@ -129,4 +127,20 @@
     (( DateNum = DateNum + 1 ))
   done
+
+  # Need to know all the restart filename of the component we will apply the noise to
+  IGCM_card_DefineArrayFromOption config.card ListOfComponents ${PerturbComp}
+  eval compname=\${config_ListOfComponents_${PerturbComp}[0]} > /dev/null 2>&1
+
+  # Target the component's card we apply the noise to
+  card=${SUBMIT_DIR}/COMP/${compname}.card
+
+  # Read the restart file list. To be used later
+  IGCM_card_DefineArrayFromOption ${card} RestartFiles List
+  ListFilesName=${compname}_RestartFiles_List
+  eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
+  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
+
+  # Check
+  IGCM_debug_Print 1 "Nb Restart Files  = ${NbFiles}"
 
   IGCM_debug_PopStack "IGCM_ensemble_CastInit"
@@ -415,4 +429,6 @@
   IGCM_debug_PushStack "IGCM_ensemble_CastPerturbFile"
 
+  typeset i i_ j j4 file_out file_out_
+
   #.. Debug Print ..
   echo
@@ -433,7 +449,6 @@
 
   FileOut="${MemberDir}_${RestartDate}_${PerturbFile}"
+  IGCM_debug_Print 1 "FileIn  = ${DirIn}/${FileIn}"
   IGCM_debug_Print 1 "FileOut = ${DirOut}/${FileOut}.nc"
-
-  #IGCM_debug_Print 1 "FileIn  = ${DirIn}/${FileIn}"
 
   IGCM_sys_TestFileArchive ${DirOut}/${FileOut}.nc
@@ -442,4 +457,31 @@
 
     # * Look for the restart file we apply the noise to
+
+    # restart file list pertaining to the component we apply the noise to
+    # but not being the precise restart file we will apply the noise to
+    unset OtherFileInList
+    # generic restart filename list (like flxat, sstoc, restart, ...)
+    unset OtherGenericList
+
+    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
+      (( i=0 ))
+      until [ $i -ge ${NbFiles} ]; do
+
+        (( i_ = i+1 ))
+        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
+        eval file_out=${file_out_}
+
+        generic_restart_file_name_out=$( basename ${file_out} .nc )
+
+        if [ ! ${generic_restart_file_name_out} = ${PerturbFile} ] ; then
+          set +A OtherFileInList ${OtherFileInList[*]} ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic_restart_file_name_out}\*.nc
+          set +A OtherGenericList ${OtherGenericList[*]} ${generic_restart_file_name_out}
+        fi
+
+        (( i=i+3 ))
+      done
+    fi
+    # How many restart files other than the one we will apply the noise to
+    NbOtherFiles=${#OtherGenericList[*]}
 
     ##########################
@@ -464,30 +506,48 @@
       Archived=false
       Tared=true
+
       # Look for the tar file we want if we did not found it already
-      #if [ X${IsMatching} = X ] ; then
-        for PotentialTarFile in $( find ${ensemble_Ens_PERTURB_INITPATH}/${ensemble_Ens_PERTURB_INITFROM}/RESTART -name "${ensemble_Ens_PERTURB_INITFROM}_*_restart.tar" -print ) ; do
-          IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:^${ensemble_Ens_PERTURB_INITFROM}_::" | sed "s:\.restart\.tar$::" | gawk -F_ -v restartdate=${RestartDate} '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
-          if [ ! X${IsMatching} = X ] ; then
-            TarFileFound=${PotentialTarFile}
-            break
-          fi
-        done
-      #fi
-      # already specialized for CPL sstoc and flxat!
-      IGCM_debug_Print 1 "tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_flxat.nc"
-      tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_flxat.nc
+      for PotentialTarFile in $( find ${ensemble_Ens_PERTURB_INITPATH}/${ensemble_Ens_PERTURB_INITFROM}/RESTART -name "${ensemble_Ens_PERTURB_INITFROM}_*_restart.tar" -print ) ; do
+        IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:^${ensemble_Ens_PERTURB_INITFROM}_::" | sed "s:\.restart\.tar$::" | gawk -F_ -v restartdate=${RestartDate} '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
+        if [ ! X${IsMatching} = X ] ; then
+          TarFileFound=${PotentialTarFile}
+          break
+        fi
+      done
+
+      # Extract relevant restart files
+      IGCM_debug_Print 1 "tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${OtherFileInList[*]}"
+      tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${OtherFileInList[*]}
       nb_restart_file=$( IGCM_sys_CountFileBuffer ${PerturbComp}_${FileIn}_????.nc )
     fi
 
+    # Move around and perturb restart files so as to be able to start hindcast/forecast simulation members
     if [ ${nb_restart_file} -gt 1 ] ; then
       j=0
-      until [ $j -ge $nb_restart_file ]; do
+      until [ $j -ge ${nb_restart_file} ]; do
         j4=${j}
         if [ X${Buffered} = Xtrue ] ; then
           IGCM_sys_GetBuffer ${DirIn}/${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
+
+          cd ${DirOut}
+          for generic in ${OtherGenericList[*]} ; do
+            ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}_${j4}.nc
+          done
+          cd -
+
         elif [ X${Archived} = Xtrue ] ; then
           IGCM_sys_Get ${DirIn}/${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
+
+          for generic in ${OtherGenericList[*]} ; do
+            IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}_${j4}.nc"
+          done
+
         elif [ X${Tared} = Xtrue ] ; then
           IGCM_sys_Mv ${PerturbComp}_${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
+
+          for generic in ${OtherGenericList[*]} ; do
+            IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${DirOut}/${MemberDir}_${RestartDate}_${generic}_${j4}.nc
+          done
+
         fi
         (( j=j+1 ))
@@ -496,14 +556,25 @@
       if [ X${Buffered} = Xtrue ] ; then
         IGCM_sys_GetBuffer ${DirIn}/${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
-        # already specialized for CPL sstoc and flxat!
-        IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_flxat.nc ${MemberDir}_${RestartDate}_flxat.nc"
+
+        cd ${DirOut}
+        for generic in ${OtherGenericList[*]} ; do
+          ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}.nc
+        done
+        cd -
+
       elif [ X${Archived} = Xtrue ] ; then
         IGCM_sys_Get ${DirIn}/${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
-        # already specialized for CPL sstoc and flxat!
-        IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_flxat.nc ${MemberDir}_${RestartDate}_flxat.nc"
+
+        for generic in ${OtherGenericList[*]} ; do
+          IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}.nc"
+        done
+
       elif [ X${Tared} = Xtrue ] ; then
         IGCM_sys_Mv ${PerturbComp}_${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
-        # already specialized for CPL sstoc and flxat!
-        IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_flxat.nc ${DirOut}/${MemberDir}_${RestartDate}_flxat.nc
+
+        for generic in ${OtherGenericList[*]} ; do
+          IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${DirOut}/${MemberDir}_${RestartDate}_${generic}.nc
+        done
+
       fi
     fi
