1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Sebastien Denvil, Martial Mancip |
---|
5 | # Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr |
---|
6 | # $Date$ |
---|
7 | # $Author$ |
---|
8 | # $Revision$ |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # History: |
---|
12 | # Modification: |
---|
13 | # |
---|
14 | #************************************************************** |
---|
15 | |
---|
16 | #=================================== |
---|
17 | function IGCM_config_Initialize |
---|
18 | { |
---|
19 | IGCM_debug_PushStack "IGCM_config_Initialize" |
---|
20 | |
---|
21 | # Debug Print : |
---|
22 | echo |
---|
23 | IGCM_debug_Print 1 "IGCM_config_Initialize :" |
---|
24 | echo |
---|
25 | |
---|
26 | # Test modipsl tree existence. |
---|
27 | IGCM_sys_TestDir ${MODIPSL} |
---|
28 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
29 | IGCM_sys_TestDir ${libIGCM} |
---|
30 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
31 | IGCM_sys_TestDir ${R_EXE} |
---|
32 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
33 | IGCM_sys_TestDir ${SUBMIT_DIR} |
---|
34 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
35 | |
---|
36 | if ( $DEBUG_debug ) ; then |
---|
37 | echo "Keep trace of inital SUBMIT_DIR : " |
---|
38 | ls -lta ${SUBMIT_DIR} |
---|
39 | fi |
---|
40 | |
---|
41 | #================================== |
---|
42 | |
---|
43 | typeset option auxprint CompatibilityTag |
---|
44 | # Read libIGCM compatibility version in config.card |
---|
45 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM |
---|
46 | eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1 |
---|
47 | |
---|
48 | if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then |
---|
49 | IGCM_debug_Exit "config.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ." |
---|
50 | fi |
---|
51 | |
---|
52 | #================================== |
---|
53 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices |
---|
54 | |
---|
55 | for option in ${config_UserChoices[*]} ; do |
---|
56 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} |
---|
57 | done |
---|
58 | |
---|
59 | IGCM_debug_Print 1 "DefineArrayFromOption : config_UserChoices" |
---|
60 | IGCM_debug_PrintVariables 3 config_UserChoices_JobName |
---|
61 | if [ 3 -le ${Verbosity} ] ; then |
---|
62 | echo "--------------Debug3-->" "config_UserChoices_LongName=" |
---|
63 | echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" |
---|
64 | fi |
---|
65 | IGCM_debug_PrintVariables 3 config_UserChoices_TagName |
---|
66 | IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType |
---|
67 | IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin |
---|
68 | IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd |
---|
69 | IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength |
---|
70 | |
---|
71 | #================================== |
---|
72 | |
---|
73 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents |
---|
74 | |
---|
75 | echo |
---|
76 | IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" |
---|
77 | IGCM_debug_Print 3 ${config_ListOfComponents[*]} |
---|
78 | echo |
---|
79 | |
---|
80 | NbComponents=${#config_ListOfComponents[*]} |
---|
81 | |
---|
82 | #================================== |
---|
83 | # Define principal executable |
---|
84 | |
---|
85 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Executable |
---|
86 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name |
---|
87 | |
---|
88 | #================================== |
---|
89 | # Define Outputs Name |
---|
90 | IGCM_debug_Print 1 "Define Script_Output_Prefix and Exe_Output" |
---|
91 | eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} |
---|
92 | IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" |
---|
93 | eval Exe_Output=out_${config_Executable_Name} |
---|
94 | IGCM_debug_Print 3 "Exe_Output = ${Exe_Output}" |
---|
95 | |
---|
96 | #================================== |
---|
97 | |
---|
98 | #===================================================================# |
---|
99 | # Prepare variables available for ${COMP}.card and ${COMP}.driver # |
---|
100 | # But available to any son functions # |
---|
101 | #===================================================================# |
---|
102 | |
---|
103 | # Convert yyyy-mm-dd date to gregorian yyyymmdd |
---|
104 | DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) |
---|
105 | DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) |
---|
106 | |
---|
107 | # Period Length In Days between DateBegin and DateEnd |
---|
108 | (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} ) + 1 )) |
---|
109 | if [ ${ExperienceLengthInDays} -lt 0 ] ; then |
---|
110 | IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." |
---|
111 | IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." |
---|
112 | IGCM_debug_Verif_Exit |
---|
113 | fi |
---|
114 | |
---|
115 | # Day and Year of Initial State (Given in julian format) |
---|
116 | InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) |
---|
117 | InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) |
---|
118 | |
---|
119 | #================================== |
---|
120 | # Restarts : Gerneral rule or local for each component ? |
---|
121 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts |
---|
122 | |
---|
123 | echo |
---|
124 | IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" |
---|
125 | |
---|
126 | for option in ${config_Restarts[*]} ; do |
---|
127 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} |
---|
128 | eval auxprint=\${config_Restarts_${option}} |
---|
129 | IGCM_debug_Print 3 "${option} : ${auxprint}" |
---|
130 | done |
---|
131 | |
---|
132 | #================================================================# |
---|
133 | # Test and Prepare directories # |
---|
134 | #================================================================# |
---|
135 | |
---|
136 | # ==> 4 kinds of input files : |
---|
137 | # 1) R_INIT : Initial State Files (Etat0, carteveg) |
---|
138 | # 2) R_BC : Boundary Conditions (Forcages, lai) |
---|
139 | # 3) Parameters files (allready define through ${SUBMIT_DIR}) |
---|
140 | # 4) Restarts files (allready define in IGCM_config_Initialize) |
---|
141 | |
---|
142 | # Here we offer the possibility to redefine R_INIT, R_BC |
---|
143 | # and PeriodNb through config.card |
---|
144 | R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} |
---|
145 | echo |
---|
146 | IGCM_debug_Print 1 "(Re)Define R_INIT, R_BC and PeriodNb" |
---|
147 | IGCM_debug_Print 3 "R_INIT=${R_INIT}" |
---|
148 | R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} |
---|
149 | IGCM_debug_Print 3 "R_BC=${R_BC}" |
---|
150 | PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} |
---|
151 | IGCM_debug_Print 3 "Loop in main Job with ${PeriodNb} period(s)" |
---|
152 | |
---|
153 | # Test Archive input/output. |
---|
154 | IGCM_sys_TestDirArchive ${ARCHIVE} |
---|
155 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
156 | IGCM_sys_TestDirArchive ${R_INIT} |
---|
157 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
158 | IGCM_sys_TestDirArchive ${R_BC} |
---|
159 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
160 | |
---|
161 | #==================================================== |
---|
162 | #R_SAVE : Job output directory |
---|
163 | if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then |
---|
164 | FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) |
---|
165 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} |
---|
166 | R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} |
---|
167 | else |
---|
168 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
169 | R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
170 | fi |
---|
171 | echo MAF $R_SAVE $R_DODS |
---|
172 | |
---|
173 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
174 | IGCM_sys_MkdirArchive ${R_SAVE} |
---|
175 | else |
---|
176 | #Test state of run in run.card |
---|
177 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
178 | if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
179 | echo |
---|
180 | IGCM_debug_Print 1 "!!!! IGCM_config_Initialize Error PeriodState : " ${run_Configuration_PeriodState} "!!!!!!!!!!" |
---|
181 | echo |
---|
182 | IGCM_debug_Exit "IGCM_config_Initialize Error PeriodState : " ${run_Configuration_PeriodState} |
---|
183 | IGCM_debug_Verif_Exit |
---|
184 | fi |
---|
185 | fi |
---|
186 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
187 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
188 | |
---|
189 | #================================== |
---|
190 | # Post : |
---|
191 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post |
---|
192 | |
---|
193 | echo |
---|
194 | IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" |
---|
195 | |
---|
196 | for option in ${config_Post[*]} ; do |
---|
197 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} |
---|
198 | eval auxprint=\${config_Post_${option}} |
---|
199 | IGCM_debug_Print 3 "${option} : ${auxprint}" |
---|
200 | done |
---|
201 | |
---|
202 | #==================================================== |
---|
203 | # Define REBUILD_DIR : where we store files needing rebuild process |
---|
204 | if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then |
---|
205 | REBUILD_DIR=${R_SAVE}/TMP |
---|
206 | IGCM_sys_MkdirArchive ${REBUILD_DIR} |
---|
207 | else |
---|
208 | REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
209 | IGCM_sys_MkdirWork ${REBUILD_DIR} |
---|
210 | fi |
---|
211 | |
---|
212 | #==================================================== |
---|
213 | # Experience type : DEB(ug), DEV(elopment), RUN |
---|
214 | if [ X${JobType} != XRUN ] ; then |
---|
215 | echo |
---|
216 | echo "====================================================" |
---|
217 | echo "libIGCM JOB is NOT in RUN type mode." |
---|
218 | echo "!! OUTPUT files will NOT be PROTECTED !!" |
---|
219 | echo "Be carefull : you can ERASE the result of this job !" |
---|
220 | |
---|
221 | case ${JobType} in |
---|
222 | DEB) |
---|
223 | echo "DEBUG mode : activation of 'set -vx' mode." |
---|
224 | echo "DEBUG mode : no protection for output files." |
---|
225 | echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency." |
---|
226 | ;; |
---|
227 | DEV) |
---|
228 | echo "DEVelopment mode : no protection for output files." |
---|
229 | echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency." |
---|
230 | ;; |
---|
231 | esac |
---|
232 | |
---|
233 | if [ X${config_Post_RebuildFrequency} != XNONE ] ; then |
---|
234 | if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then |
---|
235 | echo "------------" |
---|
236 | echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency" |
---|
237 | echo " to PeriodLength : ${config_UserChoices_PeriodLength}" |
---|
238 | echo "------------" |
---|
239 | config_Post_RebuildFrequency=${config_UserChoices_PeriodLength} |
---|
240 | fi |
---|
241 | fi |
---|
242 | echo "====================================================" |
---|
243 | echo |
---|
244 | fi |
---|
245 | |
---|
246 | #==================================================== |
---|
247 | #R_OUT_KSH : Storage place for job output |
---|
248 | #R_OUT_EXE : Storage place for binary used during simulation |
---|
249 | R_OUT_KSH=${R_SAVE}/Out |
---|
250 | R_OUT_EXE=${R_SAVE}/Exe |
---|
251 | |
---|
252 | IGCM_debug_PopStack "IGCM_config_Initialize" |
---|
253 | } |
---|
254 | |
---|
255 | #=================================== |
---|
256 | function IGCM_config_Analyse_PeriodLength |
---|
257 | { |
---|
258 | IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength" |
---|
259 | |
---|
260 | typeset i |
---|
261 | |
---|
262 | # Determine number of day(s) in PeriodLength : |
---|
263 | case ${config_UserChoices_PeriodLength} in |
---|
264 | *Y|*y) |
---|
265 | PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' ) |
---|
266 | IGCM_debug_Print 1 "Number of years for PeriodLength : ${PeriodLengthInYears}" |
---|
267 | PeriodLengthInDays=0 |
---|
268 | i=0 |
---|
269 | until [ $i -ge $PeriodLengthInYears ] ; do |
---|
270 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) )) |
---|
271 | (( i=i+1 )) |
---|
272 | done |
---|
273 | ;; |
---|
274 | *M|*m) |
---|
275 | PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' ) |
---|
276 | IGCM_debug_Print 1 "Number of months for PeriodLength : ${PeriodLengthInMonths}" |
---|
277 | PeriodLengthInDays=0 |
---|
278 | i=0 |
---|
279 | until [ $i -ge $PeriodLengthInMonths ] ; do |
---|
280 | if [ $(( month + i )) -lt 13 ] ; then |
---|
281 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) |
---|
282 | else |
---|
283 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) |
---|
284 | fi |
---|
285 | (( i=i+1 )) |
---|
286 | done |
---|
287 | ;; |
---|
288 | *D|*d) |
---|
289 | PeriodLengthInMonths=0 |
---|
290 | PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );; |
---|
291 | *) |
---|
292 | IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D." |
---|
293 | IGCM_debug_Verif_Exit ;; |
---|
294 | esac |
---|
295 | |
---|
296 | IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength" |
---|
297 | |
---|
298 | } |
---|
299 | |
---|
300 | #=================================== |
---|
301 | function IGCM_config_PeriodStart |
---|
302 | { |
---|
303 | IGCM_debug_PushStack "IGCM_config_PeriodStart" |
---|
304 | |
---|
305 | echo |
---|
306 | IGCM_debug_Print 1 "IGCM_config_PeriodStart :" |
---|
307 | echo |
---|
308 | |
---|
309 | if [ ! -r ${SUBMIT_DIR}/run.card ]; then |
---|
310 | |
---|
311 | #================================================# |
---|
312 | # The file run.card doesn't exist # |
---|
313 | #================================================# |
---|
314 | |
---|
315 | eval FirstInitialize=true |
---|
316 | |
---|
317 | #copy initial run.card |
---|
318 | IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card |
---|
319 | |
---|
320 | IGCM_date_GetYearMonth $DateBegin year month |
---|
321 | year_m1=$(( year - 1 )) |
---|
322 | year_p1=$(( year + 1 )) |
---|
323 | IGCM_config_Analyse_PeriodLength |
---|
324 | |
---|
325 | eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1 |
---|
326 | PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) ) |
---|
327 | eval CumulPeriod=1 > /dev/null 2>&1 |
---|
328 | |
---|
329 | #=================================================# |
---|
330 | # Creation and write updated run.card # |
---|
331 | #=================================================# |
---|
332 | |
---|
333 | #Correct run.card Configuration for this period |
---|
334 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} |
---|
335 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} |
---|
336 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} |
---|
337 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" |
---|
338 | |
---|
339 | else |
---|
340 | #================================================# |
---|
341 | # The file run.card allready exist # |
---|
342 | #================================================# |
---|
343 | |
---|
344 | eval FirstInitialize=false |
---|
345 | |
---|
346 | #Test state of run in run.card |
---|
347 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
348 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
349 | echo |
---|
350 | IGCM_debug_Print 1 "!!!!!! IGCM_config_PeriodStart Error PeriodState : " ${run_Configuration_PeriodState} "!!!!!!!!!!" |
---|
351 | echo |
---|
352 | IGCM_debug_Exit "IGCM_config_PeriodStart Error PeriodState : " ${run_Configuration_PeriodState} |
---|
353 | IGCM_debug_Verif_Exit |
---|
354 | fi |
---|
355 | |
---|
356 | #===================================# |
---|
357 | # Read updated run.card # |
---|
358 | #===================================# |
---|
359 | |
---|
360 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix |
---|
361 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
362 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
363 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
364 | |
---|
365 | PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
366 | PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
367 | eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1 |
---|
368 | |
---|
369 | if [ ${Period} = 1 ]; then |
---|
370 | # save last Job output |
---|
371 | typeset LastPeriod iLastPeriod Last_Script_Output_Name |
---|
372 | (( LastPeriod=CumulPeriod-PeriodNb )) |
---|
373 | iLastPeriod=$( printf "%06d" ${LastPeriod} ) |
---|
374 | Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}" |
---|
375 | Last_run_card="run.card.${iLastPeriod}" |
---|
376 | #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name} |
---|
377 | #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1 |
---|
378 | IGCM_debug_Print 1 "Try to save previous ksh job output" |
---|
379 | IGCM_sys_Cd ${SUBMIT_DIR}/ |
---|
380 | IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw |
---|
381 | IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw |
---|
382 | IGCM_sys_Cd ${RUN_DIR} |
---|
383 | else |
---|
384 | unset FileToBeDeleted |
---|
385 | fi |
---|
386 | |
---|
387 | IGCM_date_GetYearMonth $PeriodDateBegin year month |
---|
388 | year_m1=$(( year - 1 )) |
---|
389 | year_p1=$(( year + 1 )) |
---|
390 | IGCM_config_Analyse_PeriodLength |
---|
391 | |
---|
392 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" |
---|
393 | |
---|
394 | fi |
---|
395 | OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd} |
---|
396 | |
---|
397 | #===================================================================# |
---|
398 | # Prepare variables available for ${COMP}.card and ${COMP}.driver # |
---|
399 | # But available to any son functions # |
---|
400 | #===================================================================# |
---|
401 | |
---|
402 | # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !) |
---|
403 | (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 )) |
---|
404 | |
---|
405 | # Debug Print : |
---|
406 | IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution" |
---|
407 | IGCM_debug_Print 3 "Year of simulation : ${year}" |
---|
408 | IGCM_debug_Print 3 "Month of simulation : ${month}" |
---|
409 | IGCM_debug_Print 3 "PeriodLengthInDays : ${PeriodLengthInDays}" |
---|
410 | IGCM_debug_Print 3 "PeriodDateBegin : ${PeriodDateBegin}" |
---|
411 | IGCM_debug_Print 3 "PeriodDateEnd : ${PeriodDateEnd}" |
---|
412 | IGCM_debug_Print 3 "SimulationLengthInDays : ${SimulationLengthInDays}" |
---|
413 | IGCM_debug_Print 3 "ExperienceLengthInDays : ${ExperienceLengthInDays}" |
---|
414 | |
---|
415 | #================================================================# |
---|
416 | # Prepare variables available for comp_finalyze # |
---|
417 | #================================================================# |
---|
418 | |
---|
419 | # Period for save files |
---|
420 | eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1 |
---|
421 | |
---|
422 | # Prefix for save files of this period |
---|
423 | eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod} > /dev/null 2>&1 |
---|
424 | |
---|
425 | # List of files that will be deleted in RUN_DIR after run |
---|
426 | [ -f stack ] && FileToBeDeleted[0]="stack" |
---|
427 | |
---|
428 | # Test if the same run as already been saved : |
---|
429 | if [ X${JobType} = XRUN ] ; then |
---|
430 | if [ ${DRYRUN} -le 0 ] ; then |
---|
431 | if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then |
---|
432 | IGCM_debug_Exit "IGCM_config_PeriodStart" "RErun an old job." |
---|
433 | IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files" |
---|
434 | IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or " |
---|
435 | IGCM_debug_Print 1 " the whole ${R_SAVE} tree." |
---|
436 | IGCM_debug_Verif_Exit |
---|
437 | fi |
---|
438 | fi |
---|
439 | else |
---|
440 | if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then |
---|
441 | IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. DEBUG of DEV mode." |
---|
442 | fi |
---|
443 | fi |
---|
444 | |
---|
445 | IGCM_debug_PopStack "IGCM_config_PeriodStart" |
---|
446 | } |
---|
447 | |
---|
448 | #=================================== |
---|
449 | function IGCM_config_PeriodEnd |
---|
450 | { |
---|
451 | IGCM_debug_PushStack "IGCM_config_PeriodEnd" |
---|
452 | |
---|
453 | echo |
---|
454 | IGCM_debug_Print 1 "IGCM_config_PeriodEnd :" |
---|
455 | echo |
---|
456 | |
---|
457 | #==================================# |
---|
458 | # Save Job output # |
---|
459 | #==================================# |
---|
460 | IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output} |
---|
461 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}" |
---|
462 | |
---|
463 | IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw |
---|
464 | |
---|
465 | typeset LS_comp LS_bin ExeDate ExeCpuLog ExeSize NextExeSize LastCompExeSize |
---|
466 | typeset comp i |
---|
467 | typeset ExeNameIn ExeNameOut |
---|
468 | |
---|
469 | #==================================# |
---|
470 | # Get last Exe Size # |
---|
471 | #==================================# |
---|
472 | |
---|
473 | (( i=0 )) |
---|
474 | if ( ${FirstInitialize} ) ; then |
---|
475 | run_Log_LastExeSize="" |
---|
476 | for comp in ${config_ListOfComponents[*]} ; do |
---|
477 | run_Log_LastExeSize[$i]=0 |
---|
478 | (( i=i+1 )) |
---|
479 | done |
---|
480 | else |
---|
481 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize |
---|
482 | fi |
---|
483 | |
---|
484 | #==================================# |
---|
485 | # And Build ExeDate # |
---|
486 | #==================================# |
---|
487 | |
---|
488 | # ExeDate = ATM_Jun_12_09:34-SRF_Jun_12_09:34-OCE_Jun_12_09:34-ICE_Jun_12_09:34-CPL_Jun_12_09:33 |
---|
489 | # Would be nice to have next line but no way to format ls output (need to ls -l --time-style "+%Y-%m-%dT%H:%M") |
---|
490 | # ExeDate = ATM_2009-06-12T09:34+SRF_2009-06-12T09:34+OCE_2009-06-12T09:34+ICE_2009-06-12T09:34+CPL_2009-06-12T09:34 |
---|
491 | ExeDate="" |
---|
492 | NextExeSize="( " |
---|
493 | (( i=0 )) |
---|
494 | |
---|
495 | for comp in ${config_ListOfComponents[*]} ; do |
---|
496 | |
---|
497 | IGCM_debug_Print 1 ${comp} |
---|
498 | |
---|
499 | eval ExeNameIn=\${config_Executable_${comp}[0]} |
---|
500 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
501 | # Only if we really have an executable for the component : |
---|
502 | if [ X${ExeNameIn} = X\"\" ] ; then |
---|
503 | # If there is no exe file for this component |
---|
504 | (( ExeSize=0 )) |
---|
505 | else |
---|
506 | eval LS_bin=${R_EXE}/${ExeNameIn} |
---|
507 | IGCM_sys_FileSize ${LS_bin} ExeSize |
---|
508 | |
---|
509 | set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} ) |
---|
510 | if [ X${ExeDate} = X ] ; then |
---|
511 | # First component exe date |
---|
512 | ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]} |
---|
513 | else |
---|
514 | ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]} |
---|
515 | fi |
---|
516 | ExeDate=${ExeDate}_${LS_comp[7]} |
---|
517 | fi |
---|
518 | |
---|
519 | if [ ${i} -eq 0 ] ; then |
---|
520 | # First component |
---|
521 | NextExeSize="( "${ExeSize} |
---|
522 | else |
---|
523 | NextExeSize=${NextExeSize}", "${ExeSize} |
---|
524 | fi |
---|
525 | eval LastCompExeSize=${run_Log_LastExeSize[$i]} |
---|
526 | (( i=i+1 )) |
---|
527 | |
---|
528 | if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then |
---|
529 | if ( ${FirstInitialize} ) ; then |
---|
530 | IGCM_debug_Print 1 "Put first ${ExeNameIn} in ${R_OUT_EXE} !" |
---|
531 | else |
---|
532 | IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !" |
---|
533 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut} |
---|
534 | fi |
---|
535 | eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw |
---|
536 | fi |
---|
537 | done |
---|
538 | |
---|
539 | if [ ${DRYRUN} -le 1 ] ; then |
---|
540 | typeset ExeCpuLog |
---|
541 | tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt |
---|
542 | ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt ) |
---|
543 | RET=$? |
---|
544 | if [ $RET -eq 0 ] ; then |
---|
545 | # ExeCpuLog variable contents 5 fields |
---|
546 | echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" | \ |
---|
547 | gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \ |
---|
548 | $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card |
---|
549 | fi |
---|
550 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt" |
---|
551 | fi |
---|
552 | |
---|
553 | NextExeSize=${NextExeSize}" )" |
---|
554 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}" |
---|
555 | |
---|
556 | # All was right ? no ? then we stop. |
---|
557 | IGCM_debug_Verif_Exit |
---|
558 | |
---|
559 | # If all was OK, we can delete all files not necessary for next Job |
---|
560 | IGCM_debug_Print 1 "Files that will be deleted before next period-run : " |
---|
561 | |
---|
562 | if [ ${DRYRUN} -le 2 ] ; then |
---|
563 | for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done |
---|
564 | else |
---|
565 | echo ${FileToBeDeleted[@]} |
---|
566 | fi |
---|
567 | |
---|
568 | #=================================================# |
---|
569 | # Modification of libIGCM behaviour # |
---|
570 | #=================================================# |
---|
571 | |
---|
572 | # To use this function, one must copy libIGCM.card from ${libIGCM} directory |
---|
573 | # and put it in ${SUBMIT_DIR} directory. Ater modifications of ${SUBMIT_DIR}/libIGCM.card, |
---|
574 | # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop. |
---|
575 | if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then |
---|
576 | echo |
---|
577 | echo "########################################################################" |
---|
578 | echo "!!! Modification of libIGCM behaviour !!!" |
---|
579 | echo |
---|
580 | |
---|
581 | IGCM_debug_Print 1 "DefineArrayFromOption : libIGCM_UserChanges in libIGCM.card" |
---|
582 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges |
---|
583 | IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]} |
---|
584 | |
---|
585 | # Special treatments for libIGCM internals |
---|
586 | for option in ${libIGCM_UserChanges[*]} ; do |
---|
587 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option} |
---|
588 | |
---|
589 | echo "We will change : ${option}." |
---|
590 | eval echo "Previous value : " \${${option}} |
---|
591 | eval echo "Change to : " \${libIGCM_UserChanges_${option}} |
---|
592 | |
---|
593 | eval ${option}=\${libIGCM_UserChanges_${option}} |
---|
594 | |
---|
595 | case ${option} in |
---|
596 | config_UserChoices_DateEnd) |
---|
597 | IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd |
---|
598 | DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) |
---|
599 | |
---|
600 | # Period Length In Days between DateBegin and DateEnd |
---|
601 | (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} ) + 1 )) |
---|
602 | if [ ${ExperienceLengthInDays} -lt 0 ] ; then |
---|
603 | IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that." |
---|
604 | IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates." |
---|
605 | IGCM_debug_Verif_Exit |
---|
606 | fi |
---|
607 | ;; |
---|
608 | config_UserChoices_PeriodLength) |
---|
609 | ;; |
---|
610 | PeriodNb) |
---|
611 | IGCM_debug_Print 3 "Loop in main Job with ${PeriodNb} period(s)" |
---|
612 | ;; |
---|
613 | config_Post_RebuildFrequency) |
---|
614 | IGCM_debug_Print 3 "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure" |
---|
615 | IGCM_post_Configure |
---|
616 | ;; |
---|
617 | config_Post_TimeSeriesFrequency) |
---|
618 | IGCM_debug_Print 3 "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize" |
---|
619 | IGCM_post_Configure |
---|
620 | ;; |
---|
621 | config_Post_SeasonalFrequency) |
---|
622 | IGCM_debug_Print 3 "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize" |
---|
623 | IGCM_post_Configure |
---|
624 | ;; |
---|
625 | esac |
---|
626 | done |
---|
627 | |
---|
628 | echo |
---|
629 | echo "########################################################################" |
---|
630 | echo |
---|
631 | fi |
---|
632 | |
---|
633 | #=================================================# |
---|
634 | # Determine next computed period # |
---|
635 | #=================================================# |
---|
636 | |
---|
637 | PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 ) |
---|
638 | IGCM_date_GetYearMonth $PeriodDateBegin year month |
---|
639 | year_m1=$(( year - 1 )) |
---|
640 | year_p1=$(( year + 1 )) |
---|
641 | IGCM_config_Analyse_PeriodLength |
---|
642 | PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) ) |
---|
643 | |
---|
644 | # Debug Print : |
---|
645 | echo |
---|
646 | IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution" |
---|
647 | IGCM_debug_Print 3 "PeriodDateBegin : ${PeriodDateBegin}" |
---|
648 | IGCM_debug_Print 3 "PeriodDateEnd : ${PeriodDateEnd}" |
---|
649 | IGCM_debug_Print 3 "PeriodLengthInDays : ${PeriodLengthInDays}" |
---|
650 | |
---|
651 | PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} ) |
---|
652 | PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} ) |
---|
653 | |
---|
654 | (( CumulPeriod = CumulPeriod + 1 )) |
---|
655 | |
---|
656 | # Debug Print : |
---|
657 | echo |
---|
658 | IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}" |
---|
659 | IGCM_debug_Print 3 "PeriodDateEnd Human : ${PeriodDateEnd}" |
---|
660 | IGCM_debug_Print 3 "CumulPeriod : ${CumulPeriod}" |
---|
661 | |
---|
662 | #=================================================# |
---|
663 | # Write updated run.card # |
---|
664 | #=================================================# |
---|
665 | |
---|
666 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix} |
---|
667 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} |
---|
668 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} |
---|
669 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} |
---|
670 | |
---|
671 | IGCM_debug_PopStack "IGCM_config_PeriodEnd" |
---|
672 | } |
---|
673 | |
---|
674 | #=================================== |
---|
675 | function IGCM_config_Finalize |
---|
676 | { |
---|
677 | IGCM_debug_PushStack "IGCM_config_Finalize" |
---|
678 | |
---|
679 | echo |
---|
680 | IGCM_debug_Print 1 "IGCM_config_Finalize :" |
---|
681 | echo |
---|
682 | |
---|
683 | if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then |
---|
684 | |
---|
685 | #==========================# |
---|
686 | # End of entire simulation # |
---|
687 | #==========================# |
---|
688 | |
---|
689 | # Mail notification |
---|
690 | IGCM_sys_SendMail |
---|
691 | |
---|
692 | # |
---|
693 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed" |
---|
694 | IGCM_debug_Print 1 "Normal End of computation." |
---|
695 | if ( $DEBUG_debug ) ; then |
---|
696 | echo |
---|
697 | IGCM_debug_Print 1 "Your files on ${R_OUT} :" |
---|
698 | IGCM_sys_Tree ${R_SAVE} |
---|
699 | fi |
---|
700 | |
---|
701 | else |
---|
702 | |
---|
703 | #=================# |
---|
704 | # Submit next job # |
---|
705 | #=================# |
---|
706 | |
---|
707 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
708 | |
---|
709 | # Name of next Ksh Script output : |
---|
710 | eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )" |
---|
711 | |
---|
712 | IGCM_debug_Print 1 "Submit next job" |
---|
713 | # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR |
---|
714 | IGCM_sys_Cd ${SUBMIT_DIR} |
---|
715 | IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} |
---|
716 | IGCM_sys_Cd - |
---|
717 | fi |
---|
718 | |
---|
719 | # Supress Non Deleted Boundary files |
---|
720 | if [ ${DRYRUN} -le 2 ] ; then |
---|
721 | IGCM_comp_DelFixeBoundaryFiles |
---|
722 | ls -la |
---|
723 | fi |
---|
724 | |
---|
725 | # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
726 | # Only for production run (No clean up in DEV or DEB mode) |
---|
727 | # and command sent from .. directory. |
---|
728 | IGCM_sys_Cd .. |
---|
729 | [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR} |
---|
730 | |
---|
731 | IGCM_debug_PopStack "IGCM_config_Finalize" |
---|
732 | } |
---|
733 | |
---|
734 | #=================================== |
---|