source: branches/libIGCM_MPI_OpenMP/AA_move-and-rename @ 494

Last change on this file since 494 was 436, checked in by sdipsl, 13 years ago

Some more break points ; just in case...

  • Property svn:keywords set to Revision Author Date
File size: 15.4 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14# Change SpaceName/ExperimentName/JobName names and path for a simulation during the run.
15# !! Be careful that the job is suspended before using this script !!
16# You may call this script with those four variables already defined, or modify directly
17# default values under here :
18
19# New Name Space of this experience
20NEW_SpaceName=${NEW_SpaceName:=DEVT}
21
22# New Expericence class of the run
23NEW_ExperimentName=${NEW_ExperimentName:=NEWExperimentName}
24
25# New JobName of the run
26NEW_JobName=${NEW_JobName:=NEWJobName}
27
28SUBMIT_DIR=${SUBMIT_DIR:=my_path_to_my_SUBMIT_DIR}
29
30# verbosity
31Verbosity=3
32
33########################################################################
34
35# Chemin vers MODIPSL
36MODIPSL=${MODIPSL:=::modipsl::}
37
38# Chemin vers libIGCM
39libIGCM=${libIGCM:=${MODIPSL}/libIGCM}
40# Attention : à changer si la machine de post-traitement n'est pas la frontale du serveur de calcul !
41#             voir précence de la variable MirrorlibIGCM dans votre couche systÚme.
42
43
44DEBUG_sys=false
45DEBUG_debug=false
46
47########################################################################
48
49. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ;
50. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh     #; IGCM_debug_Check
51. ${libIGCM}/libIGCM_card/libIGCM_card.ksh   #; IGCM_card_Check
52. ${libIGCM}/libIGCM_date/libIGCM_date.ksh   #; IGCM_date_Check
53. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
54
55########################################################################
56# define local functions
57
58# Function to replace OLD JobName in file
59
60function REPLACE_sed
61{
62    IGCM_debug_PushStack "REPLACE_sed"
63   
64    FILEIN=${1}
65    FILEOUT=$( basename ${FILEIN} )
66
67    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
68        ${1} > ${RUN_DIR_PATH}/${FILEOUT}
69    RET=$?
70
71    touch --reference=${1} ${RUN_DIR_PATH}/${FILEOUT}
72    IGCM_sys_Mv ${RUN_DIR_PATH}/${FILEOUT} ${2}
73    chmod --reference=${1} ${2}/${FILEOUT}
74
75    IGCM_sys_Rm -f ${1}
76
77    IGCM_debug_Print 3 "REPLACE_sed : ${1} ${2}"
78   
79    IGCM_debug_PopStack "REPLACE_sed"
80    return $RET
81}
82
83function MOVE_and_RENAME_files
84{
85    IGCM_debug_PushStack "MOVE_and_RENAME_files"
86
87    typeset VAR_files FILE_OUT
88
89    VAR_files=${1}
90    eval VAR1=\${${VAR_files[0]}}
91
92    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" )
93    IGCM_debug_Print 3 "MOVE_and_RENAME_files all : ${VAR1}"
94    IGCM_debug_Print 3 "    to     ${FILE_OUT}." 
95
96    (( ifile = 0 ))
97    for file_o in ${FILE_OUT[@]} ; do
98        eval IGCM_sys_Mv \${${VAR_files}[${ifile}]} ${file_o}
99        (( ifile = ifile + 1 ))
100    done   
101    RET=$?
102
103    IGCM_debug_PopStack "MOVE_and_RENAME_files"
104    return $RET
105}
106
107function MY_DODS_Cp
108{
109    IGCM_debug_PushStack "MY_DODS_Cp"
110
111    typeset old_JobName old_R_DODS
112    IGCM_sys_Cd ${NEW_R_SAVE}
113    old_JobName=${config_UserChoices_JobName}
114    old_R_DODS=${R_DODS}
115    old_R_SAVE=${R_SAVE}
116
117    config_UserChoices_JobName=${NEW_JobName}
118    R_DODS=${NEW_R_DODS}
119    R_SAVE=${NEW_R_SAVE}
120
121    IGCM_sys_Dods_Cp ${1}
122    IGCM_debug_Print 3 "MY_DODS_Cp : ${config_UserChoices_JobName}/${1}"
123    IGCM_sys_Cd ${RUN_DIR_PATH}
124
125    config_UserChoices_JobName=${old_JobName}
126    R_DODS=${old_R_DODS}
127    R_SAVE=${old_R_SAVE}
128
129    IGCM_debug_PopStack "MY_DODS_Cp"
130}
131
132function MY_DODS_Rm
133{
134    IGCM_debug_PushStack "MY_DODS_Rm"
135    DEBUG_debug=false
136
137    IGCM_sys_Cd ${R_SAVE}
138    IGCM_sys_Dods_Rm ${1}
139    IGCM_debug_Print 3 "MY_DODS_Rm : ${config_UserChoices_JobName}/${1}"
140    IGCM_sys_Cd ${RUN_DIR_PATH}
141
142    IGCM_debug_PopStack "MY_DODS_Rm"
143}
144########################################################################
145
146if [ ! -d ${SUBMIT_DIR} ]; then
147    IGCM_debug_Print 1 "No ${SUBMIT_DIR}, we stop here"
148    exit 1
149fi
150
151# We temporary change ${run_Configuration_PeriodState} to
152if [ -f ${SUBMIT_DIR}/run.card ] ; then
153    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
154    if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
155        old_run_Configuration_PeriodState=${run_Configuration_PeriodState}
156        IGCM_debug_PrintVariables 2 old_run_Configuration_PeriodState
157        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
158    fi
159fi
160
161IGCM_config_Initialize
162
163if [ -f ${SUBMIT_DIR}/run.card ] ; then
164    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
165    IGCM_debug_PrintVariables 2 run_Configuration_OldPrefix
166    if [ X${old_run_Configuration_PeriodState} != X"Completed" ] ; then
167        DateEnd=$( IGCM_date_ConvertFormatToGregorian $( echo ${run_Configuration_OldPrefix} | awk -F'_' '{print $2}' ) )
168    else
169        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
170    fi
171else
172    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
173fi
174
175IGCM_debug_Print 1 ""
176IGCM_debug_Print 1 "DateEnd for MoveJob_Checker : " ${DateEnd}
177IGCM_date_GetYearMonth ${DateEnd}   YearEnd   MonthEnd
178IGCM_debug_Print 1 "YearEnd MonthEnd for TimeSeries_Checker : " ${YearEnd} ${MonthEnd}
179IGCM_debug_Print 1 ""
180
181#set -vx
182
183#====================================================
184#DEFINE NEW_R_SAVE
185if [ X${config_UserChoices_SpaceName} != X ] ; then
186    NEW_SAVE=${config_UserChoices_TagName}/${NEW_SpaceName}
187else
188    NEW_SAVE=${config_UserChoices_TagName}
189fi
190if [ X${config_UserChoices_ExperimentName} != X ] ; then
191    NEW_SAVE=${NEW_SAVE}/${NEW_ExperimentName}
192fi
193
194NEW_R_SAVE=${R_OUT}/${NEW_SAVE}/${NEW_JobName}
195
196IGCM_debug_Print 1 "Move ${R_SAVE} to ${NEW_R_SAVE}"
197if [ -d ${NEW_R_SAVE} ] ; then
198    IGCM_debug_Print 1 "ERROR : ${NEW_R_SAVE} directory already exist !"
199    IGCM_debug_Print 1 "We won't try to  We stop here."
200    exit 1
201fi
202IGCM_sys_MkdirArchive ${NEW_R_SAVE}
203
204# ------------------------------------------------------------------
205# Test if all was right before proceeding further
206# ------------------------------------------------------------------
207IGCM_debug_Verif_Exit_Post
208
209#DEFINE NEW_R_DODS
210NEW_R_DODS=${NEW_SAVE}/${NEW_JobName}
211
212# Define NEW_REBUILD_DIR
213if [ -d ${REBUILD_DIR} ] ; then
214    if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
215        NEW_REBUILD_DIR=${NEW_R_SAVE}/TMP
216        IGCM_sys_MkdirArchive ${NEW_REBUILD_DIR}
217    else
218        NEW_REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${NEW_JobName}
219        IGCM_sys_MkdirWork ${NEW_REBUILD_DIR}
220    fi
221fi
222
223#====================================================
224# SAVE LOCAL WORKING DIR
225IGCM_sys_Cd ${RUN_DIR_PATH}
226
227#====================================================
228#Exe
229IGCM_debug_Print 1 "Move Exe"
230set +A listfiles -- $( find ${R_SAVE}/Exe -type f )
231
232IGCM_sys_MkdirArchive ${NEW_R_SAVE}/Exe
233MOVE_and_RENAME_files "listfiles"
234
235#====================================================
236#Out
237IGCM_debug_Print 1 "Move Out"
238OutinDir=${R_SAVE}/Out
239OutNEWDir=${NEW_R_SAVE}/Out
240IGCM_sys_MkdirArchive ${OutNEWDir}
241
242# Change JobName and copy run.card
243if [ -f ${OutinDir}/run.card ] ; then
244    REPLACE_sed ${OutinDir}/run.card ${OutNEWDir}
245fi
246
247# Just copy historical run.card
248unset listfiles
249set +A listfiles -- $( find ${OutinDir} -type f -name "run.card\.[0-9]*\.[0-9]*" )
250if [ ${#listfiles[*]} -gt 0 ] ; then
251    IGCM_sys_Cp ${listfiles[*]} ${OutNEWDir}
252    IGCM_sys_Rm -f ${listfiles[*]}
253fi
254
255# Move and Rename OLD Script_Output
256unset listfiles
257set +A listfiles -- $( find ${OutinDir} -type f -name "Script_Output_*\.[0-9]*\.[0-9]*" )
258MOVE_and_RENAME_files "listfiles"
259
260# Move and Rename OLD Executable Output
261unset listfiles
262set +A listfiles -- $( find ${OutinDir} -type f -name "*_out_${config_Executable_Name}" )
263MOVE_and_RENAME_files "listfiles"
264
265#====================================================
266IGCM_debug_Print 1 "For components"
267IGCM_debug_Print 1 "=============="
268
269#====================================================
270#Output
271# loop over components and frequencies
272IGCM_debug_Print 1 "Move Output"
273for comp in ${config_ListOfComponents[*]} ; do
274    IGCM_debug_Print 2 "------------------"
275    IGCM_debug_Print 2 "for component ${comp}"
276
277    unset FREQDIR
278    set +A FREQDIR -- $( find ${R_SAVE}/${comp}/Output -type d -not -name "*Output" )
279
280    IGCM_debug_Print 3 "List of WriteFrequencies : ${FREQDIR[*]}"
281
282    for ThisfreqDir in ${FREQDIR[*]} ; do
283        freq=$( basename ${ThisfreqDir} )
284        IGCM_debug_Print 2 "${freq}."
285
286        NEW_freqDir=${NEW_R_SAVE}/${comp}/Output/${freq}
287        IGCM_sys_MkdirArchive ${NEW_freqDir}
288
289        unset listfiles
290        set +A listfiles -- $( find ${ThisfreqDir} -type f )
291       
292        MOVE_and_RENAME_files "listfiles"
293    done
294
295    unset COMPFILES
296    set +A COMPFILES -- $( find ${R_SAVE}/${comp}/Output -type f )
297   
298    if [ ${#COMPFILES[*]} -gt 0 ] ; then
299        IGCM_debug_Print 2 "simple Output FILES : ${COMPFILES[*]}."
300
301        MOVE_and_RENAME_files "COMPFILES"
302    fi
303done
304
305#====================================================
306#Restart
307# loop over components
308IGCM_debug_Print 1 "Move Restart"
309for comp in ${config_ListOfComponents[*]} ; do
310    IGCM_debug_Print 2 "------------------"
311    IGCM_debug_Print 2 "for component ${comp}"
312
313    ThisRestDir=${R_SAVE}/${comp}/Restart
314    NEW_RestDir=${NEW_R_SAVE}/${comp}/Restart
315    IGCM_sys_MkdirArchive ${NEW_RestDir}
316
317    unset listfiles
318    set +A listfiles -- $( find ${ThisRestDir} -type f )
319   
320    MOVE_and_RENAME_files "listfiles"
321done
322
323#====================================================
324#DEBUG
325# Move and Rename OLD Executable Output
326# loop over components
327IGCM_debug_Print 1 "Move Debug"
328for comp in ${config_ListOfComponents[*]} ; do
329    IGCM_debug_Print 2 "------------------"
330    IGCM_debug_Print 2 "for component ${comp}"
331
332    ThisDebugDir=${R_SAVE}/${comp}/Debug
333    NEW_DebugDir=${NEW_R_SAVE}/${comp}/Debug
334    IGCM_sys_MkdirArchive ${NEW_DebugDir}
335
336    unset listfiles
337    set +A listfiles -- $( find ${ThisDebugDir} -type f )
338   
339    MOVE_and_RENAME_files "listfiles"
340done
341
342#====================================================
343#POST
344# loop over components and frequencies
345IGCM_debug_Print 1 "Move Analyse"
346for comp in ${config_ListOfComponents[*]} ; do
347    IGCM_debug_Print 2 "------------------"
348    IGCM_debug_Print 2 "for component ${comp}"
349   
350    if [ -d ${R_SAVE}/${comp}/Analyse ] ; then
351        unset TSDIR
352        set +A TSDIR -- $( find ${R_SAVE}/${comp}/Analyse -name "TS_*" -type d )
353       
354        for ThisTSDir in ${TSDIR[*]} ; do
355            TS_Dir=$( basename ${ThisTSDir} )
356            IGCM_debug_Print 2 "${TS_Dir}."
357           
358            NEW_TSDir=${NEW_R_SAVE}/${comp}/Analyse/${TS_Dir}
359            IGCM_sys_MkdirArchive ${NEW_TSDir}
360           
361            MY_DODS_Rm ${comp}/Analyse/${TS_Dir}
362           
363            unset listfiles
364            set +A listfiles -- $( find ${ThisTSDir} -type f )
365           
366            MOVE_and_RENAME_files "listfiles"
367           
368            MY_DODS_Cp ${comp}/Analyse/${TS_Dir}
369        done
370
371        ThisSEDir=${R_SAVE}/${comp}/Analyse/SE
372        IGCM_sys_TestDirArchive ${ThisSEDir}
373        if [ $? = 0 ] ; then
374            IGCM_debug_Print 2 "SE."
375            NEW_SEDir=${NEW_R_SAVE}/${comp}/Analyse/SE
376            IGCM_sys_MkdirArchive ${NEW_SEDir}
377           
378            MY_DODS_Rm ${comp}/Analyse/SE
379           
380            unset listfiles
381            set +A listfiles -- $( find ${ThisSEDir} -type f )
382           
383            MOVE_and_RENAME_files "listfiles"
384           
385            MY_DODS_Cp ${comp}/Analyse/SE
386        fi
387
388        MY_DODS_Rm ${comp}/Analyse
389        MY_DODS_Rm ${comp}
390    else
391        IGCM_debug_Print 2 "nothing to do without Analyse."
392    fi
393
394done
395
396#====================================================
397#GRAPHS
398IGCM_debug_Print 1 "Move ATLAS"
399R_ATLAS=ATLAS
400IGCM_sys_TestDirArchive ${R_SAVE}/${R_ATLAS}
401if [ $? = 0 ] ; then
402#    REPLACE_sed ${NEW_R_SAVE}/${R_ATLAS}/*/*/index.html ${NEW_R_SAVE}/${R_ATLAS}
403
404    MY_DODS_Rm ${R_ATLAS}
405
406    IGCM_sys_Mv ${R_SAVE}/${R_ATLAS} ${NEW_R_SAVE}/${R_ATLAS}
407
408    MY_DODS_Cp ${R_ATLAS}
409fi
410
411IGCM_debug_Print 1 "Move MONITORING"
412R_MONITORING=MONITORING
413IGCM_sys_TestDirArchive ${R_SAVE}/${R_MONITORING}
414if [ $? = 0 ] ; then
415    IGCM_sys_MkdirArchive ${NEW_R_SAVE}/${R_MONITORING}
416    REPLACE_sed ${R_SAVE}/${R_MONITORING}/index.html ${NEW_R_SAVE}/${R_MONITORING}
417    REPLACE_sed ${R_SAVE}/${R_MONITORING}/run.card ${NEW_R_SAVE}/${R_MONITORING}
418    REPLACE_sed ${R_SAVE}/${R_MONITORING}/config.card ${NEW_R_SAVE}/${R_MONITORING}
419    IGCM_sys_Cp -rp ${R_SAVE}/${R_MONITORING} ${NEW_R_SAVE}
420
421    MY_DODS_Rm ${R_MONITORING}
422    IGCM_sys_Rm -rf ${R_SAVE}/${R_MONITORING}
423
424    MY_DODS_Cp ${R_MONITORING}
425fi
426
427
428#====================================================
429#REBUILD
430
431if [ -d ${REBUILD_DIR} ] ; then
432
433    IGCM_debug_Print 1 "Move REBUILD"
434    set +A LISTREBUILDS -- $( find ${REBUILD_DIR} -type d  -not -name "*${config_UserChoices_JobName}" -a -not -name "*TMP" )
435
436    for ThisREBDir in ${LISTREBUILDS[*]} ; do
437        rebdir=$( basename ${ThisREBDir} )
438        IGCM_debug_Print 2 "${rebdir}."
439        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
440            IGCM_sys_MkdirArchive ${NEW_REBUILD_DIR}/${rebdir}
441        else
442            IGCM_sys_MkdirWork ${NEW_REBUILD_DIR}/${rebdir}
443        fi
444        REPLACE_sed ${REBUILD_DIR}/${rebdir}/rebuild.ksh ${NEW_REBUILD_DIR}/${rebdir}
445        IGCM_sys_Mv -f ${REBUILD_DIR}/${rebdir}/* ${NEW_REBUILD_DIR}/${rebdir}/
446    done
447fi
448
449#====================================================
450#List OLD R_SAVE and Ask for erase it !
451
452IGCM_debug_Print 1 "ls of SAVE DIR :"
453ls --color -lR ${R_SAVE}
454
455echo "\033[1;31mPlease verify that ALL OLD DIRECTORY LISTED IS COMPLETLY EMPTY !"
456echo "\033[1;32mIf It is NOT EMPTY, you can TRY AGAIN this script."
457echo "\033[1;31mDo you REALLY want to erase all this directory ?"
458echo -n " Your answer (y/n) : \033[m"
459if [ X${reponse} = X ] ; then
460    read reponse
461fi
462case ${reponse} in
463           
464    oui|OUI|o|y|yes|YES)
465        echo "OK. It will be erased."
466        IGCM_sys_Rm -Rf ${R_SAVE}
467        echo "done."
468        ;;
469    non|NON|n|no|NO)
470        echo "Nothing to do !"
471        ;;
472esac
473
474
475#############################################################################################################
476# Edit config.card, run.card and Job_${NewJobName}
477
478IGCM_debug_Print 1 "edit config.card"
479if [ X${config_UserChoices_SpaceName} != X ] ; then
480    IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices SpaceName ${NEW_SpaceName}
481fi
482if [ X${config_UserChoices_ExperimentName} != X ] ; then
483    IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices ExperimentName ${NEW_ExperimentName}
484fi
485IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices JobName ${NEW_JobName}
486
487if [ -f ${SUBMIT_DIR}/run.card ] ; then
488    IGCM_debug_Print 1 "edit run.card"
489    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
490        ${SUBMIT_DIR}/run.card > ${RUN_DIR_PATH}/run.card
491    IGCM_sys_Mv -f ${RUN_DIR_PATH}/run.card ${SUBMIT_DIR}/run.card
492
493    if [ X${old_run_Configuration_PeriodState} != X ] ; then
494        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState ${old_run_Configuration_PeriodState}
495    fi
496fi
497
498if [ -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ] ; then
499    IGCM_debug_Print 1 "edit Job_${NEW_JobName}"
500    sed -e "s&${R_SAVE}&${NEW_R_SAVE}&g" -e "s/${config_UserChoices_JobName}/${NEW_JobName}/g" \
501        ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} > ${SUBMIT_DIR}/Job_${NEW_JobName}
502    chmod --reference=${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${NEW_JobName}
503    ls -la ${SUBMIT_DIR}/Job_${NEW_JobName}
504fi
Note: See TracBrowser for help on using the repository browser.