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 | |
---|
15 | #set -eu |
---|
16 | #set -vx |
---|
17 | |
---|
18 | libIGCM=::modipsl::/libIGCM |
---|
19 | |
---|
20 | #D- Task type DO NOT CHANGE (computing, post-processing or checking) |
---|
21 | TaskType=post-processing |
---|
22 | |
---|
23 | #D--------------------------------------------------------------------== |
---|
24 | #D- -1. User modification place |
---|
25 | #D--------------------------------------------------------------------== |
---|
26 | |
---|
27 | #D- Increased verbosity (1, 2, 3) |
---|
28 | Verbosity=3 |
---|
29 | |
---|
30 | #D- Low level debug : to bypass lib test checks and stack construction |
---|
31 | #D- Default=true |
---|
32 | DEBUG_debug=false |
---|
33 | |
---|
34 | #D--------------------------------------------------------------------== |
---|
35 | |
---|
36 | echo "clean latest PackPeriod script :" |
---|
37 | echo "Script used to clean a Pack Period from the IGCM_OUT directory !" |
---|
38 | echo "This script will erase files !!! Be careful and read all informations !" |
---|
39 | echo "----" |
---|
40 | echo "It must be called in Experience directory (so-called SUBMIT_DIR)." |
---|
41 | echo "----" |
---|
42 | |
---|
43 | #D--------------------------------------------------------------------== |
---|
44 | |
---|
45 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
46 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
47 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
48 | #------- |
---|
49 | SUBMIT_DIR=$( pwd ) |
---|
50 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
51 | . ${libIGCM}/libIGCM_config/libIGCM_config.ksh |
---|
52 | #------- |
---|
53 | ( ${DEBUG_debug} ) && IGCM_debug_Check |
---|
54 | ( ${DEBUG_debug} ) && IGCM_card_Check |
---|
55 | ( ${DEBUG_debug} ) && IGCM_date_Check |
---|
56 | |
---|
57 | #================================== |
---|
58 | # First of all |
---|
59 | # |
---|
60 | # Read libIGCM compatibility version in config.card |
---|
61 | # Read UserChoices section |
---|
62 | # Read Ensemble section |
---|
63 | # Read Post section |
---|
64 | # Define all netcdf output directories |
---|
65 | #================================== |
---|
66 | IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card |
---|
67 | |
---|
68 | #================================== |
---|
69 | # Define default value to keep compatibility with previous card: means before changes due to TGCC |
---|
70 | if [ X${PackDefault} = Xtrue ] ; then |
---|
71 | [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} |
---|
72 | else |
---|
73 | config_Post_PackFrequency=NONE |
---|
74 | fi |
---|
75 | |
---|
76 | #================================== |
---|
77 | # Is the pack active |
---|
78 | if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \ |
---|
79 | [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then |
---|
80 | Pack=true |
---|
81 | fi |
---|
82 | |
---|
83 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
84 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
85 | |
---|
86 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
87 | echo "You seem NOT to have a run.card in this directory !!" |
---|
88 | echo "This script will fail because it doesn't know what to do without run.card available." |
---|
89 | exit 1 |
---|
90 | fi |
---|
91 | |
---|
92 | #===================================# |
---|
93 | # Read updated run.card # |
---|
94 | #===================================# |
---|
95 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
96 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
97 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
98 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
99 | if [ X${run_Configuration_CumulPeriod} == X ] ; then |
---|
100 | ${run_Configuration_CumulPeriod} = 0 |
---|
101 | fi |
---|
102 | |
---|
103 | |
---|
104 | PreviousPeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
105 | PreviousPeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
106 | |
---|
107 | IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth |
---|
108 | |
---|
109 | if [ $# == 1 ] ; then |
---|
110 | if [ ${#1} != 4 ] ; then |
---|
111 | echo "You must give a year (SSAA) as argument." |
---|
112 | exit 1 |
---|
113 | fi |
---|
114 | ReferenceYear=$1 |
---|
115 | else |
---|
116 | ReferenceYear=${PreviousPeriodYear} |
---|
117 | fi |
---|
118 | RemovedPeriods=0 |
---|
119 | |
---|
120 | # Colors |
---|
121 | Red="\033[1;31m" |
---|
122 | Green="\033[1;32m" |
---|
123 | NoColor="\033[0m" |
---|
124 | |
---|
125 | while [ ${PreviousPeriodYear} -ge ${ReferenceYear} ] ; do |
---|
126 | |
---|
127 | PeriodDateEnd=${PreviousPeriodDateEnd} |
---|
128 | PeriodDateBegin=${PreviousPeriodDateBegin} |
---|
129 | PeriodYear=${PreviousPeriodYear} |
---|
130 | PeriodMonth=${PreviousPeriodMonth} |
---|
131 | |
---|
132 | echo "Search files with ${PeriodDateEnd} in ${R_SAVE}" |
---|
133 | unset ListFiles |
---|
134 | set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " ) |
---|
135 | CountListFiles=${#ListFiles[@]} |
---|
136 | |
---|
137 | if [ X${Pack} = Xtrue ] ; then |
---|
138 | echo "Search files with ${PeriodDateEnd} in ${R_BUFR}" |
---|
139 | unset ListFilesBuf |
---|
140 | set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " ) |
---|
141 | CountListFilesBuf=${#ListFilesBuf[@]} |
---|
142 | else |
---|
143 | CountListFilesBuf=0 |
---|
144 | fi |
---|
145 | |
---|
146 | # If exist, erase REBUILD DIR |
---|
147 | CountRebuildDir=0 |
---|
148 | if [ X${config_Post_RebuildFrequency} != X ] ; then |
---|
149 | echo "Search directories with ${PeriodDateBegin} in REBUILD_DIR" |
---|
150 | unset RebuildDir |
---|
151 | set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" ) |
---|
152 | CountRebuildDir=${#RebuildDir[@]} |
---|
153 | fi |
---|
154 | |
---|
155 | |
---|
156 | if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then |
---|
157 | IGCM_debug_Print 1 "Number of files to be erased from ${R_SAVE} : ${CountListFiles}." |
---|
158 | for file in ${ListFiles[@]} ; do |
---|
159 | IGCM_debug_Print 2 -e "${Red} ${file}${NoColor}" |
---|
160 | done |
---|
161 | if [ X${Pack} = Xtrue ] ; then |
---|
162 | IGCM_debug_Print 1 "Number of files to be erased from ${R_BUFR} : ${CountListFilesBuf}." |
---|
163 | for file in ${ListFilesBuf[@]} ; do |
---|
164 | IGCM_debug_Print 2 -e "${Red} ${file}${NoColor}" |
---|
165 | done |
---|
166 | fi |
---|
167 | |
---|
168 | echo -e "${Green}Do you REALLY want to erase all those files ?" |
---|
169 | echo -n -e " Your answer (y/n) : ${NoColor}" |
---|
170 | |
---|
171 | read reponse |
---|
172 | case ${reponse} in |
---|
173 | oui|OUI|o|y|yes|YES) |
---|
174 | echo "OK. It will be erased." |
---|
175 | IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
176 | if [ X${Pack} = Xtrue ] ; then |
---|
177 | IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
178 | fi |
---|
179 | echo "done." |
---|
180 | ;; |
---|
181 | non|NON|n|no|NO) |
---|
182 | echo "Nothing to do !" |
---|
183 | ;; |
---|
184 | esac |
---|
185 | fi |
---|
186 | |
---|
187 | if [ ${CountRebuildDir} -gt 0 ] ; then |
---|
188 | IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}." |
---|
189 | for Dir in ${RebuildDir[@]} ; do |
---|
190 | IGCM_debug_Print 2 -e "${Red} ${Dir}${NoColor}" |
---|
191 | done |
---|
192 | |
---|
193 | echo -e "${Green}Do you REALLY want to erase all those Directories ?" |
---|
194 | echo -n -e " Your answer (y/n) : ${NoColor}" |
---|
195 | |
---|
196 | read reponse |
---|
197 | case ${reponse} in |
---|
198 | |
---|
199 | oui|OUI|o|y|yes|YES) |
---|
200 | echo "OK. It will be erased." |
---|
201 | find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \; |
---|
202 | echo "done." |
---|
203 | ;; |
---|
204 | non|NON|n|no|NO) |
---|
205 | echo "Nothing to do !" |
---|
206 | ;; |
---|
207 | esac |
---|
208 | fi |
---|
209 | |
---|
210 | (( RemovedPeriods = ${RemovedPeriods} + 1 )) |
---|
211 | |
---|
212 | # Get previous period begin and end dates |
---|
213 | PreviousPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} \ |
---|
214 | -$( IGCM_date_DaysInMonth ${PeriodYear} ${PeriodMonth} ) ) |
---|
215 | IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth |
---|
216 | |
---|
217 | PreviousPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} \ |
---|
218 | -$( IGCM_date_DaysInMonth ${PreviousPeriodYear} ${PreviousPeriodMonth} ) ) |
---|
219 | done |
---|
220 | |
---|
221 | if [ ${RemovedPeriods} == 0 ] ; then |
---|
222 | echo "Nothing done, exit" |
---|
223 | exit 0 |
---|
224 | fi |
---|
225 | |
---|
226 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
227 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && \ |
---|
228 | [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
229 | |
---|
230 | (( NewCumulPeriod = ${run_Configuration_CumulPeriod} - ${RemovedPeriods} + 1 )) |
---|
231 | |
---|
232 | if [ ${NewCumulPeriod} -le 1 ] ; then |
---|
233 | RemoveRunCard=true |
---|
234 | else |
---|
235 | RemoveRunCard=false |
---|
236 | fi |
---|
237 | |
---|
238 | Suffix=$( printf '%06i' ${NewCumulPeriod} ) |
---|
239 | |
---|
240 | printf "${Green}Your run.card and Job_${config_UserChoices_JobName} will now be updated\n" |
---|
241 | printf " - PeriodState = OnQueue ;\n" |
---|
242 | printf " - PeriodDateBegin, PeriodDateEnd and CumulPeriod ;\n" |
---|
243 | printf " %-10s %-10s %6i\n" \ |
---|
244 | $( IGCM_date_HumanDigit ${PeriodDateBegin} ) \ |
---|
245 | $( IGCM_date_HumanDigit ${PeriodDateEnd} ) \ |
---|
246 | ${NewCumulPeriod} |
---|
247 | printf " - ScriptOutput = %s" \ |
---|
248 | "Script_Output_${config_UserChoices_JobName}.${Suffix}" |
---|
249 | printf " Are you OK ? (y/n) ${NoColor}" |
---|
250 | |
---|
251 | read reponse |
---|
252 | case ${reponse} in |
---|
253 | oui|OUI|o|y|yes|YES) |
---|
254 | if ( ${RemoveRunCard} ) ; then |
---|
255 | echo "CumulPeriod=1 so we erase run.card to start properly." |
---|
256 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
257 | else |
---|
258 | #Â Update run.card |
---|
259 | cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old |
---|
260 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
261 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${NewCumulPeriod} |
---|
262 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin \ |
---|
263 | $( IGCM_date_HumanDigit ${PeriodDateBegin} ) |
---|
264 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd \ |
---|
265 | $( IGCM_date_HumanDigit ${PeriodDateEnd} ) |
---|
266 | #Â Update job |
---|
267 | cp Job_${config_UserChoices_JobName} Job_${config_UserChoices_JobName}.old |
---|
268 | sed -e "s/\(#.*Script_Output_${config_UserChoices_JobName}\.\)\([0-9]*\)\(.*\)/\1${Suffix}\3/" \ |
---|
269 | Job_${config_UserChoices_JobName} > Job_${config_UserChoices_JobName}.tmp |
---|
270 | mv Job_${config_UserChoices_JobName}.tmp Job_${config_UserChoices_JobName} |
---|
271 | fi |
---|
272 | echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
273 | ;; |
---|
274 | non|NON|n|no|NO) |
---|
275 | echo "Nothing to do !" |
---|
276 | ;; |
---|
277 | esac |
---|
278 | |
---|
279 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted |
---|
280 | if [ ! X${run_PostProcessing_TimeSeriesCompleted} = X ] ; then |
---|
281 | |
---|
282 | printf "${Green}TimeSeriesCompleted in run.card : ${run_PostProcessing_TimeSeriesCompleted}. Do we need to change it? (AAAAMMDD) ${NoColor}" |
---|
283 | |
---|
284 | read reponse |
---|
285 | case ${reponse} in |
---|
286 | 0*|1*|2*|3*|4*|5*|6*|7*|8*|9*) |
---|
287 | #Update run.card |
---|
288 | cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old |
---|
289 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted "${reponse}" |
---|
290 | ;; |
---|
291 | *) |
---|
292 | echo "Nothing to do !" |
---|
293 | ;; |
---|
294 | esac |
---|
295 | fi |
---|
296 | |
---|
297 | else |
---|
298 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
299 | fi |
---|
300 | |
---|
301 | exit 0 |
---|