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