1 | #!/bin/ksh |
---|
2 | #************************************************************** |
---|
3 | # Author: Martial Mancip |
---|
4 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
5 | # $Revision:: $ Revision of last commit |
---|
6 | # $Author:: $ Author of last commit |
---|
7 | # $Date:: $ Date of last commit |
---|
8 | # IPSL (2006) |
---|
9 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
10 | # |
---|
11 | #************************************************************** |
---|
12 | # ID of your genci project. Curie only : post-processing jobs need it to run properly |
---|
13 | #-Q- curie export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
14 | #-Q- irene export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
15 | #-Q- irene-amd export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
16 | |
---|
17 | #set -eu |
---|
18 | #set -vx |
---|
19 | |
---|
20 | libIGCM=::modipsl::/libIGCM |
---|
21 | |
---|
22 | #D- Task type DO NOT CHANGE (computing, post-processing or checking) |
---|
23 | TaskType=post-processing |
---|
24 | |
---|
25 | #D--------------------------------------------------------------------== |
---|
26 | #D- -1. User modification place |
---|
27 | #D--------------------------------------------------------------------== |
---|
28 | |
---|
29 | #D- Increased verbosity (1, 2, 3) |
---|
30 | Verbosity=3 |
---|
31 | |
---|
32 | #D- Low level debug : to bypass lib test checks and stack construction |
---|
33 | #D- Default=true |
---|
34 | DEBUG_debug=false |
---|
35 | |
---|
36 | #D--------------------------------------------------------------------== |
---|
37 | echo "" |
---|
38 | echo "clean_or_continue.job " |
---|
39 | |
---|
40 | # Read arguments |
---|
41 | print_help=no |
---|
42 | force_rm=no |
---|
43 | while (($# > 0)) ; do |
---|
44 | case $1 in |
---|
45 | "-h") |
---|
46 | print_help=yes ; shift ;; |
---|
47 | |
---|
48 | "-f") |
---|
49 | force_rm=yes ; shift ;; |
---|
50 | *) |
---|
51 | echo "Unknown option "$1" . Use -h for help." |
---|
52 | exit |
---|
53 | esac |
---|
54 | done |
---|
55 | |
---|
56 | |
---|
57 | if [ $print_help == yes ] ; then |
---|
58 | # Print help and exit |
---|
59 | echo "" |
---|
60 | echo "The script is called from in the your experiment directory, the so-called SUBMIT_DIR, in the following way" |
---|
61 | echo "../../../libIGCM/clean_or_continue.job : normal execution, you'll be asked before files are deleted" |
---|
62 | echo "../../../libIGCM/clean_or_continue.job -f : force normal execution to delete files without asking" |
---|
63 | echo "../../../libIGCM/clean_or_continue.job -h : print following information" |
---|
64 | echo "" |
---|
65 | echo "This script can be used for 3 cases:" |
---|
66 | echo "1- The simulation crashed and you have PeriodState=Fatal in run.card." |
---|
67 | echo "For this case, all output from the current PeriodLength set in run.card will be deleted. " |
---|
68 | echo "You need to answer yes to the questions." |
---|
69 | echo "" |
---|
70 | echo "2- The simulation stopped due to an exceeded time limit, PeriodState=Running in run.card". |
---|
71 | echo "As for case 1, all output from the current PeriodLength will be deleted and you should answer yes to questions". |
---|
72 | echo "" |
---|
73 | echo "3- The simulation is completed but you want to continue it, PeriodState=Completed in run.card." |
---|
74 | echo "For this case, you just need to change DateEnd in config.card and launch this script." |
---|
75 | echo "" |
---|
76 | echo "For all cases, the run.card is changed as needed and the number for the current period is set in the main Job_ for the Script_Output_ file" |
---|
77 | echo "" |
---|
78 | echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions." |
---|
79 | echo "" |
---|
80 | |
---|
81 | exit |
---|
82 | fi |
---|
83 | |
---|
84 | if [ $force_rm == yes ] ; then |
---|
85 | echo "" |
---|
86 | echo "Option -f to delete files without asking is set" |
---|
87 | else |
---|
88 | echo "" |
---|
89 | echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions." |
---|
90 | echo "Use ../../../libIGCM/clean_or_contine.job -h for more information" |
---|
91 | echo "" |
---|
92 | fi |
---|
93 | |
---|
94 | #D--------------------------------------------------------------------== |
---|
95 | |
---|
96 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
97 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
98 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
99 | #------- |
---|
100 | SUBMIT_DIR=$( pwd ) |
---|
101 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
102 | . ${libIGCM}/libIGCM_config/libIGCM_config.ksh |
---|
103 | #------- |
---|
104 | ( ${DEBUG_debug} ) && IGCM_debug_Check |
---|
105 | ( ${DEBUG_debug} ) && IGCM_card_Check |
---|
106 | ( ${DEBUG_debug} ) && IGCM_date_Check |
---|
107 | |
---|
108 | #================================== |
---|
109 | # First of all |
---|
110 | # |
---|
111 | # Read libIGCM compatibility version in config.card |
---|
112 | # Read UserChoices section |
---|
113 | # Read Ensemble section |
---|
114 | # Read Post section |
---|
115 | # Define all netcdf output directories |
---|
116 | #================================== |
---|
117 | IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card |
---|
118 | |
---|
119 | #================================== |
---|
120 | # Define default value to keep compatibility with previous card: means before changes due to TGCC |
---|
121 | if [ X${PackDefault} = Xtrue ] ; then |
---|
122 | [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} |
---|
123 | else |
---|
124 | config_Post_PackFrequency=NONE |
---|
125 | fi |
---|
126 | |
---|
127 | #================================== |
---|
128 | # Is the pack active |
---|
129 | if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then |
---|
130 | Pack=true |
---|
131 | fi |
---|
132 | |
---|
133 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
134 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
135 | |
---|
136 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
137 | echo "You seem NOT to have a run.card in this directory !!" |
---|
138 | echo "This script will fail because it doesn't know what to do without run.card available." |
---|
139 | exit 1 |
---|
140 | else |
---|
141 | #===================================# |
---|
142 | # Read updated run.card # |
---|
143 | #===================================# |
---|
144 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
145 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
146 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
147 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
148 | |
---|
149 | # |
---|
150 | if [ X${run_Configuration_CumulPeriod} = X ] ; then |
---|
151 | if [ $force_rm == yes ] ; then |
---|
152 | echo -e "\033[1;32mCumulPeriod is empty so run.card will be deleted to start properly. \033[m" |
---|
153 | reponse=yes |
---|
154 | else |
---|
155 | echo -e "\033[1;32mCumulPeriod is empty so we want to erase run.card to start properly. Do you want that?" |
---|
156 | echo -n -e " Your answer (y/n) : \033[m" |
---|
157 | read reponse |
---|
158 | fi |
---|
159 | case ${reponse} in |
---|
160 | |
---|
161 | oui|OUI|o|y|yes|YES) |
---|
162 | echo "Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}" |
---|
163 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
164 | ;; |
---|
165 | non|NON|n|no|NO) |
---|
166 | echo "Nothing to do !" |
---|
167 | ;; |
---|
168 | esac |
---|
169 | exit 0 |
---|
170 | fi |
---|
171 | |
---|
172 | PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
173 | echo "Search files with ${PeriodDateEnd} in ${R_SAVE}" |
---|
174 | set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " ) |
---|
175 | CountListFiles=${#ListFiles[@]} |
---|
176 | |
---|
177 | if [ X${Pack} = Xtrue ] ; then |
---|
178 | echo "Search files with ${PeriodDateEnd} in ${R_BUFR}" |
---|
179 | set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " ) |
---|
180 | CountListFilesBuf=${#ListFilesBuf[@]} |
---|
181 | else |
---|
182 | CountListFilesBuf=0 |
---|
183 | fi |
---|
184 | |
---|
185 | # If exist, erase REBUILD DIR |
---|
186 | PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
187 | CountRebuildDir=0 |
---|
188 | if [ X${config_Post_RebuildFrequency} != X ] ; then |
---|
189 | set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" ) |
---|
190 | CountRebuildDir=${#RebuildDir[@]} |
---|
191 | fi |
---|
192 | |
---|
193 | IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}." |
---|
194 | if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then |
---|
195 | for file in ${ListFiles[@]} ; do |
---|
196 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
197 | done |
---|
198 | if [ X${Pack} = Xtrue ] ; then |
---|
199 | for file in ${ListFilesBuf[@]} ; do |
---|
200 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
201 | done |
---|
202 | fi |
---|
203 | if [ $force_rm == yes ] ; then |
---|
204 | reponse=y |
---|
205 | else |
---|
206 | echo -e "\033[1;32mDo you REALLY want to erase all those files ?" |
---|
207 | echo -n -e " Your answer (y/n) : \033[m" |
---|
208 | read reponse |
---|
209 | fi |
---|
210 | case ${reponse} in |
---|
211 | |
---|
212 | oui|OUI|o|y|yes|YES) |
---|
213 | echo "The files will be erased." |
---|
214 | IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
215 | if [ X${Pack} = Xtrue ] ; then |
---|
216 | IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
217 | fi |
---|
218 | echo "done." |
---|
219 | ;; |
---|
220 | non|NON|n|no|NO) |
---|
221 | echo "Nothing to do !" |
---|
222 | ;; |
---|
223 | esac |
---|
224 | fi |
---|
225 | |
---|
226 | if [ ${CountRebuildDir} -gt 0 ] ; then |
---|
227 | IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}." |
---|
228 | for Dir in ${RebuildDir[@]} ; do |
---|
229 | IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m" |
---|
230 | done |
---|
231 | |
---|
232 | if [ $force_rm == yes ] ; then |
---|
233 | reponse=y |
---|
234 | else |
---|
235 | echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?" |
---|
236 | echo -n -e " Your answer (y/n) : \033[m" |
---|
237 | read reponse |
---|
238 | fi |
---|
239 | case ${reponse} in |
---|
240 | |
---|
241 | oui|OUI|o|y|yes|YES) |
---|
242 | echo "The files will be erased." |
---|
243 | find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \; |
---|
244 | echo "done." |
---|
245 | ;; |
---|
246 | non|NON|n|no|NO) |
---|
247 | echo "Nothing to do !" |
---|
248 | ;; |
---|
249 | esac |
---|
250 | fi |
---|
251 | |
---|
252 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
253 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
254 | |
---|
255 | if [ $force_rm == yes ] ; then |
---|
256 | echo -e "\033[1;32mPeriodState=OnQueue is set in run.card) \033[m" |
---|
257 | reponse=y |
---|
258 | else |
---|
259 | echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?" |
---|
260 | echo -n -e " Your answer (y/n) : \033[m" |
---|
261 | read reponse |
---|
262 | fi |
---|
263 | case ${reponse} in |
---|
264 | |
---|
265 | oui|OUI|o|y|yes|YES) |
---|
266 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}" |
---|
267 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
268 | ;; |
---|
269 | non|NON|n|no|NO) |
---|
270 | echo "Nothing to do !" |
---|
271 | ;; |
---|
272 | esac |
---|
273 | else |
---|
274 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}" |
---|
275 | fi |
---|
276 | |
---|
277 | if [ X${run_Configuration_CumulPeriod} = X1 ] ; then |
---|
278 | if [ $force_rm == yes ] ; then |
---|
279 | echo -e "\033[1;32mCumulPeriod=1 and therfor run.card is deleted to start properly. \033[m" |
---|
280 | reponse=y |
---|
281 | else |
---|
282 | echo -e "\033[1;32mCumulPeriod=1 so we want to erase run.card to start properly. Do you want that too?" |
---|
283 | echo -n -e " Your answer (y/n) : \033[m" |
---|
284 | read reponse |
---|
285 | fi |
---|
286 | case ${reponse} in |
---|
287 | |
---|
288 | oui|OUI|o|y|yes|YES) |
---|
289 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}" |
---|
290 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
291 | ;; |
---|
292 | non|NON|n|no|NO) |
---|
293 | echo "Nothing to do !" |
---|
294 | ;; |
---|
295 | esac |
---|
296 | else |
---|
297 | # if not first period |
---|
298 | Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} |
---|
299 | Script_Output_Job=${Script_Output_Prefix}_${config_UserChoices_JobName} |
---|
300 | Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${run_Configuration_CumulPeriod} ) |
---|
301 | |
---|
302 | if [ $force_rm == yes ] ; then |
---|
303 | echo -e "\033[1;32mThe number in the jobname in Script_Output is changed.\033[m" |
---|
304 | reponse=y |
---|
305 | else |
---|
306 | echo -e "\033[1;32mDo you want to change the number in Script_Output? (${Script_Output} into Job) ?" |
---|
307 | echo -n -e " Your answer (y/n) : \033[m" |
---|
308 | read reponse |
---|
309 | fi |
---|
310 | case ${reponse} in |
---|
311 | |
---|
312 | oui|OUI|o|y|yes|YES) |
---|
313 | cp ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$ |
---|
314 | sed -e"s/${Script_Output_Job}.[0-9][0-9][0-9][0-9][0-9][0-9]/${Script_Output}/" ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$ >${SUBMIT_DIR}/Job_${config_UserChoices_JobName} |
---|
315 | echo "Job : Job_${config_UserChoices_JobName} modified." |
---|
316 | echo "Old job saved here : Job_${config_UserChoices_JobName}_SAVED_$$" |
---|
317 | ;; |
---|
318 | non|NON|n|no|NO) |
---|
319 | echo "Nothing done in Job_${config_UserChoices_JobName} !" |
---|
320 | ;; |
---|
321 | esac |
---|
322 | |
---|
323 | fi |
---|
324 | fi |
---|
325 | exit 0 |
---|