Index: /trunk/libIGCM/AA_move-and-rename
===================================================================
--- /trunk/libIGCM/AA_move-and-rename	(revision 342)
+++ /trunk/libIGCM/AA_move-and-rename	(revision 342)
@@ -0,0 +1,568 @@
+#-Q- cesium #!/bin/ksh
+#-Q- cesium ######################
+#-Q- cesium ## CESIUM   CEA ##
+#-Q- cesium ######################
+#-Q- cesium #MSUB -r MoveJob             # Nom du job                
+#-Q- cesium #MSUB -N 1              # Reservation du noeud
+#-Q- cesium #MSUB -n 1              # Reservation du processus
+#-Q- cesium #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- cesium #MSUB -E "-j o"
+#-Q- cesium #MSUB -E "-S /bin/ksh"
+#-Q- platine #!/usr/bin/ksh
+#-Q- platine ###################
+#-Q- platine ## PLATINE   CEA ##
+#-Q- platine ###################
+#-Q- platine #BSUB -J MoveJob                     # Nom du job
+#-Q- platine #BSUB -N                        # message a la fin du job
+#-Q- platine #BSUB -n 1                      # reservation des processeurs pour le job
+#-Q- platine #BSUB -W 1:00                   # Limite temps
+#-Q- platine #BSUB -q post                   # Passage en queue post
+#-Q- sx8brodie #!/bin/ksh
+#-Q- sx8brodie #######################
+#-Q- sx8brodie ## SX8BRODIE   IDRIS ##
+#-Q- sx8brodie #######################
+#-Q- sx8brodie # Temps Elapsed max. d'une requete hh:mm:ss
+#-Q- sx8brodie # @ wall_clock_limit = 20:00:00
+#-Q- sx8brodie # Nom du travail LoadLeveler
+#-Q- sx8brodie # @ job_name   = MoveJob
+#-Q- sx8brodie # Fichier de sortie standard du travail       
+#-Q- sx8brodie # @ output     = $(job_name).$(jobid)
+#-Q- sx8brodie # Fichier de sortie d'erreur du travail
+#-Q- sx8brodie # @ error      =  $(job_name).$(jobid)
+#-Q- sx8brodie # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
+#-Q- sx8brodie # @ notification = error
+#-Q- sx8brodie # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $REBUILD_DIR ; $RebuildFromArchive ; $POST_DIR ; $MASTER ; $RebuildFrequency ; $StandAlone
+#-Q- aix6 #!/bin/ksh
+#-Q- aix6 #######################
+#-Q- aix6 ##   VARGAS   IDRIS  ##
+#-Q- aix6 #######################
+#-Q- aix6 # Temps Elapsed max. d'une requete hh:mm:ss
+#-Q- aix6 # @ wall_clock_limit = 20:00:00
+#-Q- aix6 # Nom du travail LoadLeveler
+#-Q- aix6 # @ job_name   = MoveJob
+#-Q- aix6 # Fichier de sortie standard du travail
+#-Q- aix6 # @ output     = $(job_name).$(jobid)
+#-Q- aix6 # Fichier de sortie d'erreur du travail
+#-Q- aix6 # @ error      =  $(job_name).$(jobid)
+#-Q- aix6 # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
+#-Q- aix6 # @ notification = error
+#-Q- aix6 # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $REBUILD_DIR ; $RebuildFromArchive ; $MASTER ; $RebuildFrequency ; $StandAlone 
+#-Q- aix6 # @ queue
+#-Q- sx8brodie # @ queue
+#-Q- sx8mercure #!/bin/ksh
+#-Q- sx8mercure ######################
+#-Q- sx8mercure ## SX8MERCURE   CEA ##
+#-Q- sx8mercure ######################
+#-Q- sx8mercure #PBS -N MoveJob                   # Nom du job
+#-Q- sx8mercure #PBS -j o                    # regroupement des stdout et stderr
+#-Q- sx8mercure #PBS -S /usr/bin/ksh         # shell de soumission
+#-Q- sx8mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
+#-Q- sx8mercure #PBS -l cputim_job=24:00:00   # Limite temps a 2 heures
+#-Q- sx8mercure #PBS -q scalaire
+#-Q- sx9mercure #!/bin/ksh
+#-Q- sx9mercure #########################
+#-Q- sx9mercure ## CESIUM FOR SX9  CEA ##
+#-Q- sx9mercure #########################
+#-Q- sx9mercure #MSUB -r MoveJob             # Nom du job                
+#-Q- sx9mercure #MSUB -N 1              # Reservation du noeud
+#-Q- sx9mercure #MSUB -n 1              # Reservation du processus
+#-Q- sx9mercure #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- sx9mercure #MSUB -E "-j o"
+#-Q- sx9mercure #MSUB -E "-S /bin/ksh"
+#-Q- titane #!/bin/ksh
+#-Q- titane ######################
+#-Q- titane ## TITANE   CEA ##
+#-Q- titane ######################
+#-Q- titane #MSUB -r MoveJob             # Nom du job                
+#-Q- titane #MSUB -N 1              # Reservation du noeud
+#-Q- titane #MSUB -n 1              # Reservation du processus
+#-Q- titane #MSUB -T 86400          # Limite de temps elapsed du job
+#-Q- titane #MSUB -E "-j o"
+#-Q- titane #MSUB -E "-S /bin/ksh"
+#-Q- titane ##MSUB -e nco.out        # Sortie standard
+#-Q- titane ##MSUB -o nco.out        # Sortie standard
+#-Q- lxiv8 ######################
+#-Q- lxiv8 ## OBELIX      LSCE ##
+#-Q- lxiv8 ######################
+#-Q- lxiv8 #PBS -N MoveJob
+#-Q- lxiv8 #PBS -m a
+#-Q- lxiv8 #PBS -j oe
+#-Q- lxiv8 #PBS -q medium
+#-Q- lxiv8 #PBS -o MoveJob.$$
+#-Q- lxiv8 #PBS -S /bin/ksh
+#-Q- default #!/bin/ksh
+#-Q- default ##################
+#-Q- default ## DEFAULT HOST ##
+#-Q- default ##################
+
+#**************************************************************
+# Author: Sebastien Denvil
+# Contact: Sebastien.Denvil@ipsl.jussieu.fr
+# $Date: $
+# $Author: $
+# $Revision: $
+# IPSL (2006)
+#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
+# History:
+# Modification:
+#
+#**************************************************************
+
+# Change SpaceName/ExperimentName/JobName names and path for a simulation during the run.
+# !! Be careful that the job is suspended before using this script !!
+# You may call this script with those four variables already defined, or modify directly 
+# default values under here :
+
+# New Name Space of this experience 
+NEW_SpaceName=${NEW_SpaceName:=DEVT}
+
+# New Expericence class of the run
+NEW_ExperimentName=${NEW_ExperimentName:=NEWExperimentName}
+
+# New JobName of the run
+NEW_JobName=${NEW_JobName:=NEWJobName}
+
+SUBMIT_DIR=${SUBMIT_DIR:=my_path_to_my_SUBMIT_DIR}
+
+# verbosity
+Verbosity=3
+
+########################################################################
+
+# Chemin vers MODIPSL
+MODIPSL=${MODIPSL:=::modipsl::}
+
+# Chemin vers libIGCM
+libIGCM=${libIGCM:=${MODIPSL}/libIGCM}
+# Attention : Ã  changer si la machine de post-traitement n'est pas la frontale du serveur de calcul !
+#             voir prÃ©cence de la variable MirrorlibIGCM dans votre couche systÃšme.
+
+
+DEBUG_sys=false
+DEBUG_debug=false
+
+########################################################################
+
+. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ;
+. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh     #; IGCM_debug_Check
+. ${libIGCM}/libIGCM_card/libIGCM_card.ksh   #; IGCM_card_Check
+. ${libIGCM}/libIGCM_date/libIGCM_date.ksh   #; IGCM_date_Check
+. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
+
+########################################################################
+# define local functions
+
+# Function to replace OLD JobName in file
+
+function REPLACE_sed
+{
+    IGCM_debug_PushStack "REPLACE_sed"
+    
+    FILEIN=${1}
+    FILEOUT=$( basename ${FILEIN} )
+
+    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
+	${1} > ${RUN_DIR_PATH}/${FILEOUT}
+    RET=$?
+
+    touch --reference=${1} ${RUN_DIR_PATH}/${FILEOUT}
+    IGCM_sys_Mv ${RUN_DIR_PATH}/${FILEOUT} ${2}
+    chmod --reference=${1} ${2}/${FILEOUT}
+
+    IGCM_sys_Rm -f ${1}
+
+    IGCM_debug_Print 3 "REPLACE_sed : ${1} ${2}"
+    
+    IGCM_debug_PopStack "REPLACE_sed"
+    return $RET
+}
+
+function MOVE_and_RENAME_files
+{
+    IGCM_debug_PushStack "MOVE_and_RENAME_files"
+
+    typeset VAR_files FILE_OUT
+
+    VAR_files=${1}
+    eval VAR1=\${${VAR_files[0]}}
+
+    set +A FILE_OUT -- $( eval echo \${${VAR_files}[*]} | sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" )
+    IGCM_debug_Print 3 "MOVE_and_RENAME_files all : ${VAR1}"
+    IGCM_debug_Print 3 "    to     ${FILE_OUT}." 
+
+    (( ifile = 0 ))
+    for file_o in ${FILE_OUT[@]} ; do
+	eval IGCM_sys_Mv \${${VAR_files}[${ifile}]} ${file_o}
+	(( ifile = ifile + 1 ))
+    done    
+    RET=$?
+
+    IGCM_debug_PopStack "MOVE_and_RENAME_files"
+    return $RET
+}
+
+function MY_DODS_Cp
+{
+    IGCM_debug_PushStack "MY_DODS_Cp"
+
+    IGCM_sys_Cd ${NEW_R_SAVE}
+    old_JobName=${config_UserChoices_JobName}
+    config_UserChoices_JobName=${NEW_JobName}
+    IGCM_sys_Dods_Cp ${1}
+    IGCM_debug_Print 3 "MY_DODS_Cp : ${config_UserChoices_JobName}/${1}"
+    IGCM_sys_Cd ${RUN_DIR_PATH}
+    config_UserChoices_JobName=${old_JobName}
+
+    IGCM_debug_PopStack "MY_DODS_Cp"
+}
+
+function MY_DODS_Rm
+{
+    IGCM_debug_PushStack "MY_DODS_Rm"
+    DEBUG_debug=false
+
+    IGCM_sys_Cd ${R_SAVE}
+    IGCM_sys_Dods_Rm ${1}
+    IGCM_debug_Print 3 "MY_DODS_Rm : ${config_UserChoices_JobName}/${1}"
+    IGCM_sys_Cd ${RUN_DIR_PATH}
+
+    IGCM_debug_PopStack "MY_DODS_Rm"
+}
+########################################################################
+
+
+if [ ! -d ${SUBMIT_DIR} ]; then
+    IGCM_debug_Print 0 "No ${SUBMIT_DIR}, we stop here"
+    exit 1
+fi
+
+# We temporary change ${run_Configuration_PeriodState} to 
+if [ -f ${SUBMIT_DIR}/run.card ] ; then
+    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
+    if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
+	old_run_Configuration_PeriodState=${run_Configuration_PeriodState}
+	IGCM_debug_PrintVariables 2 old_run_Configuration_PeriodState
+	IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
+    fi
+fi
+
+IGCM_config_Initialize
+
+if [ -f ${SUBMIT_DIR}/run.card ] ; then
+    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
+    IGCM_debug_PrintVariables 2 run_Configuration_OldPrefix
+    if [ X${old_run_Configuration_PeriodState} != X"Completed" ] ; then
+	DateEnd=$( IGCM_date_ConvertFormatToGregorian $( echo ${run_Configuration_OldPrefix} | awk -F'_' '{print $2}' ) )
+    else
+	DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
+    fi
+else
+    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
+fi
+
+IGCM_debug_Print 1 ""
+IGCM_debug_Print 1 "DateEnd for MoveJob_Checker : " ${DateEnd}
+IGCM_date_GetYearMonth ${DateEnd}   YearEnd   MonthEnd
+IGCM_debug_Print 1 "YearEnd MonthEnd for TimeSeries_Checker : " ${YearEnd} ${MonthEnd}
+IGCM_debug_Print 1 ""
+
+#set -vx
+
+#====================================================
+#DEFINE NEW_R_SAVE
+if [ X${config_UserChoices_SpaceName} != X ] ; then
+    NEW_SAVE=${config_UserChoices_TagName}/${NEW_SpaceName}
+else
+    NEW_SAVE=${config_UserChoices_TagName}
+fi
+if [ X${config_UserChoices_ExperimentName} != X ] ; then
+    NEW_SAVE=${NEW_SAVE}/${NEW_ExperimentName}
+fi
+
+NEW_R_SAVE=${R_OUT}/${NEW_SAVE}/${NEW_JobName}
+
+IGCM_debug_Print 1 "Move ${R_SAVE} to ${NEW_R_SAVE}"
+if [ -d ${NEW_R_SAVE} ] ; then
+    IGCM_debug_Print 0 "ERROR : ${NEW_R_SAVE} directory already exist !"
+    IGCM_debug_Print 0 "We won't try to  We stop here."
+    exit 1
+fi
+IGCM_sys_MkdirArchive ${NEW_R_SAVE}
+
+#DEFINE NEW_R_DODS
+if [ -d ${R_DODS} ] ; then
+    NEW_R_DODS=${NEW_SAVE}
+fi
+
+# Define NEW_REBUILD_DIR
+if [ -d ${REBUILD_DIR} ] ; then
+    if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
+	NEW_REBUILD_DIR=${NEW_R_SAVE}/TMP
+	IGCM_sys_MkdirArchive ${NEW_REBUILD_DIR}
+    else
+	NEW_REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${NEW_JobName}
+	IGCM_sys_MkdirWork ${NEW_REBUILD_DIR}
+    fi
+fi
+
+#====================================================
+# SAVE LOCAL WORKING DIR
+IGCM_sys_Cd ${RUN_DIR_PATH}
+
+#====================================================
+#Exe
+IGCM_debug_Print 1 "Move Exe"
+set +A listfiles -- $( find ${R_SAVE}/Exe -type f )
+
+IGCM_sys_MkdirArchive ${NEW_R_SAVE}/Exe
+MOVE_and_RENAME_files "listfiles"
+
+#====================================================
+#Out
+IGCM_debug_Print 1 "Move Out"
+OutinDir=${R_SAVE}/Out
+OutNEWDir=${NEW_R_SAVE}/Out
+IGCM_sys_MkdirArchive ${OutNEWDir}
+
+# Change JobName and copy run.card
+REPLACE_sed ${OutinDir}/run.card ${OutNEWDir}
+
+# Just copy historical run.card
+unset listfiles
+set +A listfiles -- $( find ${OutinDir} -type f -name "run.card\.[0-9]*\.[0-9]*" )
+IGCM_sys_Cp ${listfiles[*]} ${OutNEWDir}
+IGCM_sys_Rm -f ${listfiles[*]}
+
+# Move and Rename OLD Script_Output
+unset listfiles
+set +A listfiles -- $( find ${OutinDir} -type f -name "Script_Output_*\.[0-9]*\.[0-9]*" )
+MOVE_and_RENAME_files "listfiles"
+
+# Move and Rename OLD Executable Output
+unset listfiles
+set +A listfiles -- $( find ${OutinDir} -type f -name "*_out_${config_Executable_Name}" )
+MOVE_and_RENAME_files "listfiles"
+
+#====================================================
+IGCM_debug_Print 1 "For components"
+IGCM_debug_Print 1 "=============="
+
+#====================================================
+#Output
+# loop over components and frequencies
+IGCM_debug_Print 1 "Move Output"
+for comp in ${config_ListOfComponents[*]} ; do
+    IGCM_debug_Print 2 "------------------"
+    IGCM_debug_Print 2 "for component ${comp}"
+
+    unset FREQDIR
+    set +A FREQDIR -- $( find ${R_SAVE}/${comp}/Output -type d -not -name "*Output" )
+
+    IGCM_debug_Print 3 "List of WriteFrequencies : ${FREQDIR[*]}"
+
+    for ThisfreqDir in ${FREQDIR[*]} ; do
+	freq=$( basename ${ThisfreqDir} )
+	IGCM_debug_Print 2 "${freq}."
+
+	NEW_freqDir=${NEW_R_SAVE}/${comp}/Output/${freq}
+	IGCM_sys_MkdirArchive ${NEW_freqDir}
+
+	unset listfiles
+	set +A listfiles -- $( find ${ThisfreqDir} -type f )
+	
+	MOVE_and_RENAME_files "listfiles"
+    done
+done
+
+#====================================================
+#Restart
+# loop over components
+IGCM_debug_Print 1 "Move Restart"
+for comp in ${config_ListOfComponents[*]} ; do
+    IGCM_debug_Print 2 "------------------"
+    IGCM_debug_Print 2 "for component ${comp}"
+
+    ThisRestDir=${R_SAVE}/${comp}/Restart
+    NEW_RestDir=${NEW_R_SAVE}/${comp}/Restart
+    IGCM_sys_MkdirArchive ${NEW_RestDir}
+
+    unset listfiles
+    set +A listfiles -- $( find ${ThisRestDir} -type f )
+    
+    MOVE_and_RENAME_files "listfiles"
+done
+
+#====================================================
+#DEBUG
+# Move and Rename OLD Executable Output
+# loop over components
+IGCM_debug_Print 1 "Move Debug"
+for comp in ${config_ListOfComponents[*]} ; do
+    IGCM_debug_Print 2 "------------------"
+    IGCM_debug_Print 2 "for component ${comp}"
+
+    ThisDebugDir=${R_SAVE}/${comp}/Debug
+    NEW_DebugDir=${NEW_R_SAVE}/${comp}/Debug
+    IGCM_sys_MkdirArchive ${NEW_DebugDir}
+
+    unset listfiles
+    set +A listfiles -- $( find ${ThisDebugDir} -type f )
+    
+    MOVE_and_RENAME_files "listfiles"
+done
+
+#====================================================
+#POST
+# loop over components and frequencies
+IGCM_debug_Print 1 "Move Analyse"
+for comp in ${config_ListOfComponents[*]} ; do
+    IGCM_debug_Print 2 "------------------"
+    IGCM_debug_Print 2 "for component ${comp}"
+    
+    if [ -d ${R_SAVE}/${comp}/Analyse ] ; then
+	unset TSDIR
+	set +A TSDIR -- $( find ${R_SAVE}/${comp}/Analyse -name "TS_*" -type d )
+	
+	for ThisTSDir in ${TSDIR[*]} ; do
+	    TS_Dir=$( basename ${ThisTSDir} )
+	    IGCM_debug_Print 2 "${TS_Dir}."
+	    
+	    NEW_TSDir=${NEW_R_SAVE}/${comp}/Analyse/${TS_Dir}
+	    IGCM_sys_MkdirArchive ${NEW_TSDir}
+	    
+	    MY_DODS_Rm ${comp}/Analyse/${TS_Dir}
+	    
+	    unset listfiles
+	    set +A listfiles -- $( find ${ThisTSDir} -type f )
+	    
+	    MOVE_and_RENAME_files "listfiles"
+	    
+	    MY_DODS_Cp ${comp}/Analyse/${TS_Dir}
+	done
+
+	ThisSEDir=${R_SAVE}/${comp}/Analyse/SE
+	IGCM_sys_TestDirArchive ${ThisSEDir}
+	if [ $? = 0 ] ; then
+	    IGCM_debug_Print 2 "SE."
+	    NEW_SEDir=${NEW_R_SAVE}/${comp}/Analyse/SE
+	    IGCM_sys_MkdirArchive ${NEW_SEDir}
+	    
+	    MY_DODS_Rm ${comp}/Analyse/SE
+	    
+	    unset listfiles
+	    set +A listfiles -- $( find ${ThisSEDir} -type f )
+	    
+	    MOVE_and_RENAME_files "listfiles"
+	    
+	    MY_DODS_Cp ${comp}/Analyse/SE
+	fi
+    else
+	IGCM_debug_Print 2 "nothing to do without Analyse."
+    fi
+
+    MY_DODS_Rm ${comp}/Analyse
+    MY_DODS_Rm ${comp}
+done
+
+#====================================================
+#GRAPHS
+IGCM_debug_Print 1 "Move ATLAS"
+R_ATLAS=ATLAS
+IGCM_sys_TestDirArchive ${R_SAVE}/${R_ATLAS}
+if [ $? = 0 ] ; then
+    IGCM_sys_Mv ${R_SAVE}/${R_ATLAS} ${NEW_R_SAVE}/${R_ATLAS}
+#    REPLACE_sed ${NEW_R_SAVE}/${R_ATLAS}/*/*/index.html ${NEW_R_SAVE}/${R_ATLAS}
+
+    MY_DODS_Rm ${R_ATLAS}
+
+    MY_DODS_Cp ${R_ATLAS}
+fi
+
+IGCM_debug_Print 1 "Move MONITORING"
+R_MONITORING=MONITORING
+IGCM_sys_TestDirArchive ${R_SAVE}/${R_MONITORING}
+if [ $? = 0 ] ; then
+    IGCM_sys_MkdirArchive ${NEW_R_SAVE}/${R_MONITORING}
+    REPLACE_sed ${R_SAVE}/${R_MONITORING}/index.html ${NEW_R_SAVE}/${R_MONITORING}
+    IGCM_sys_Mv ${R_SAVE}/${R_MONITORING} ${NEW_R_SAVE}
+
+    MY_DODS_Rm ${R_MONITORING}
+
+    MY_DODS_Cp ${R_MONITORING}
+fi
+
+
+#====================================================
+#REBUILD
+
+if [ -d ${REBUILD_DIR} ] ; then
+
+    IGCM_debug_Print 1 "Move REBUILD"
+    set +A LISTREBUILDS -- $( find ${REBUILD_DIR} -type d  -not -name "*${config_UserChoices_JobName}" )
+
+    for rebdir in ${LISTREBUILDS[*]} ; do
+	IGCM_debug_Print 2 "${rebdir}."
+	if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
+	    IGCM_sys_MkdirArchive ${NEW_REBUILD_DIR}/${rebdir}
+	else
+	    IGCM_sys_MkdirWork ${NEW_REBUILD_DIR}/${rebdir}
+	fi
+	REPLACE_sed ${REBUILD_DIR}/${rebdir}/rebuild.ksh ${NEW_REBUILD_DIR}/${rebdir}
+	IGCM_sys_Mv -f ${REBUILD_DIR}/${rebdir} ${NEW_REBUILD_DIR}
+    done
+fi
+
+#====================================================
+#List OLD R_SAVE and Ask for erase it !
+
+IGCM_debug_Print 1 "ls of SAVE DIR :"
+ls --color -lR ${R_SAVE}
+
+echo "\033[1;31mPlease verify that ALL OLD DIRECTORY LISTED IS COMPLETLY EMPTY !"
+echo "\033[1;32mIf It is NOT EMPTY, you can TRY AGAIN this script."
+echo "\033[1;31mDo you REALLY want to erase all this directory ?"
+echo -n " Your answer (y/n) : \033[m"
+read reponse
+case ${reponse} in
+	    
+    oui|OUI|o|y|yes|YES)
+	echo "OK. It will be erased."
+	IGCM_sys_Rm -Rf ${R_SAVE}
+	echo "done."
+	;;
+    non|NON|n|no|NO)
+	echo "Nothing to do !"
+	;;
+esac
+
+
+#############################################################################################################
+# Edit config.card, run.card and Job_${NewJobName}
+
+IGCM_debug_Print 1 "edit config.card"
+if [ X${config_UserChoices_SpaceName} != X ] ; then
+    IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices SpaceName ${NEW_SpaceName}
+fi
+if [ X${config_UserChoices_ExperimentName} != X ] ; then
+    IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices ExperimentName ${NEW_ExperimentName}
+fi
+IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices JobName ${NEW_JobName}
+
+if [ -f ${SUBMIT_DIR}/run.card ] ; then
+    IGCM_debug_Print 1 "edit run.card"
+    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
+	${SUBMIT_DIR}/run.card > ${RUN_DIR_PATH}/run.card
+    IGCM_sys_Mv -f ${RUN_DIR_PATH}/run.card ${SUBMIT_DIR}/run.card
+
+    if [ X${old_run_Configuration_PeriodState} != X ] ; then
+	IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState ${old_run_Configuration_PeriodState}
+    fi
+fi
+
+if [ -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ] ; then
+    IGCM_debug_Print 1 "edit Job_${NEW_JobName}"
+    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
+	${SUBMIT_DIR}/Job_${config_UserChoices_JobName} > ${SUBMIT_DIR}/Job_${NEW_JobName}
+    chmod --reference=${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${NEW_JobName}
+    ls -la ${SUBMIT_DIR}/Job_${NEW_JobName}
+fi
