source: tags/libIGCM_v2.2/AA_move-and-rename

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