[2] | 1 | #!/bin/ksh |
---|
| 2 | |
---|
| 3 | #************************************************************** |
---|
| 4 | # Author: Sebastien Denvil, Martial Mancip |
---|
| 5 | # Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr |
---|
[4] | 6 | # $Date$ |
---|
[5] | 7 | # $Author$ |
---|
| 8 | # $Revision$ |
---|
[2] | 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} |
---|
[67] | 28 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 29 | IGCM_sys_TestDir ${libIGCM} |
---|
[67] | 30 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 31 | IGCM_sys_TestDir ${R_EXE} |
---|
[67] | 32 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 33 | IGCM_sys_TestDir ${SUBMIT_DIR} |
---|
[67] | 34 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 35 | |
---|
[144] | 36 | if ( $DEBUG_debug ) ; then |
---|
| 37 | echo "Keep trace of inital SUBMIT_DIR : " |
---|
| 38 | ls -lta ${SUBMIT_DIR} |
---|
| 39 | fi |
---|
| 40 | |
---|
[2] | 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 |
---|
[144] | 61 | if [ 3 -le ${Verbosity} ] ; then |
---|
| 62 | echo "--------------Debug3-->" "config_UserChoices_LongName=" |
---|
| 63 | echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" |
---|
| 64 | fi |
---|
[2] | 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) |
---|
[146] | 116 | InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) |
---|
| 117 | InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) |
---|
[2] | 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} |
---|
[67] | 155 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 156 | IGCM_sys_TestDirArchive ${R_INIT} |
---|
[67] | 157 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 158 | IGCM_sys_TestDirArchive ${R_BC} |
---|
[67] | 159 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 160 | |
---|
| 161 | #==================================================== |
---|
| 162 | #R_SAVE : Job output directory |
---|
| 163 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
| 164 | |
---|
| 165 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
| 166 | IGCM_sys_MkdirArchive ${R_SAVE} |
---|
| 167 | else |
---|
| 168 | #Test state of run in run.card |
---|
| 169 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 170 | if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
| 171 | echo |
---|
| 172 | IGCM_debug_Print 1 "!!!! IGCM_config_Initialize Error PeriodState : " ${run_Configuration_PeriodState} "!!!!!!!!!!" |
---|
| 173 | echo |
---|
| 174 | IGCM_debug_Exit "IGCM_config_Initialize Error PeriodState : " ${run_Configuration_PeriodState} |
---|
| 175 | IGCM_debug_Verif_Exit |
---|
| 176 | fi |
---|
| 177 | fi |
---|
| 178 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
[67] | 179 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
[2] | 180 | |
---|
[146] | 181 | #================================== |
---|
| 182 | # Post : |
---|
| 183 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post |
---|
| 184 | |
---|
| 185 | echo |
---|
| 186 | IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" |
---|
| 187 | |
---|
| 188 | for option in ${config_Post[*]} ; do |
---|
| 189 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} |
---|
| 190 | eval auxprint=\${config_Post_${option}} |
---|
| 191 | IGCM_debug_Print 3 "${option} : ${auxprint}" |
---|
| 192 | done |
---|
| 193 | |
---|
| 194 | # Define REBUILD_DIR : where we store files needing rebuild process |
---|
| 195 | if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then |
---|
| 196 | REBUILD_DIR=${R_SAVE}/TMP |
---|
| 197 | IGCM_sys_MkdirArchive ${REBUILD_DIR} |
---|
| 198 | else |
---|
[157] | 199 | REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
| 200 | IGCM_sys_MkdirWork ${REBUILD_DIR} |
---|
[146] | 201 | fi |
---|
| 202 | |
---|
[2] | 203 | #==================================================== |
---|
| 204 | #R_OUT_KSH : Storage place for job output |
---|
| 205 | #R_OUT_EXE : Storage place for binary used during simulation |
---|
| 206 | R_OUT_KSH=${R_SAVE}/Out |
---|
| 207 | R_OUT_EXE=${R_SAVE}/Exe |
---|
| 208 | |
---|
[128] | 209 | #==================================================== |
---|
| 210 | # Experience type : DEB(ug), DEV(elopment), RUN |
---|
| 211 | if [ X${JobType} != XRUN ] ; then |
---|
| 212 | echo |
---|
| 213 | echo "====================================================" |
---|
| 214 | echo "libIGCM JOB is NOT in RUN type mode." |
---|
| 215 | echo "!! OUTPUT files will NOT be PROTECTED !!" |
---|
| 216 | echo "Be carefull : you can ERASE the result of this job !" |
---|
| 217 | |
---|
| 218 | case ${JobType} in |
---|
| 219 | DEB) |
---|
| 220 | echo "DEBUG mode : activation of 'set -vx' mode.";; |
---|
| 221 | DEV) |
---|
| 222 | echo "DEVelopment mode : no protection for output files." |
---|
| 223 | ;; |
---|
| 224 | esac |
---|
| 225 | echo "====================================================" |
---|
| 226 | echo |
---|
| 227 | fi |
---|
| 228 | |
---|
[2] | 229 | IGCM_debug_PopStack "IGCM_config_Initialize" |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | #=================================== |
---|
[118] | 233 | function IGCM_config_Analyse_PeriodLength |
---|
| 234 | { |
---|
| 235 | IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength" |
---|
| 236 | |
---|
[124] | 237 | typeset i |
---|
| 238 | |
---|
[118] | 239 | # Determine number of day(s) in PeriodLength : |
---|
| 240 | case ${config_UserChoices_PeriodLength} in |
---|
| 241 | *Y|*y) |
---|
[128] | 242 | PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' ) |
---|
[118] | 243 | IGCM_debug_Print 1 "Number of years for PeriodLength : ${PeriodLengthInYears}" |
---|
| 244 | PeriodLengthInDays=0 |
---|
| 245 | i=0 |
---|
| 246 | until [ $i -ge $PeriodLengthInYears ] ; do |
---|
| 247 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) )) |
---|
| 248 | (( i=i+1 )) |
---|
| 249 | done |
---|
| 250 | ;; |
---|
| 251 | *M|*m) |
---|
[128] | 252 | PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' ) |
---|
[118] | 253 | IGCM_debug_Print 1 "Number of months for PeriodLength : ${PeriodLengthInMonths}" |
---|
| 254 | PeriodLengthInDays=0 |
---|
| 255 | i=0 |
---|
| 256 | until [ $i -ge $PeriodLengthInMonths ] ; do |
---|
| 257 | if [ $(( month + i )) -lt 13 ] ; then |
---|
| 258 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) |
---|
| 259 | else |
---|
| 260 | (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) |
---|
| 261 | fi |
---|
| 262 | (( i=i+1 )) |
---|
| 263 | done |
---|
| 264 | ;; |
---|
| 265 | *D|*d) |
---|
[128] | 266 | PeriodLengthInMonths=0 |
---|
| 267 | PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );; |
---|
[118] | 268 | *) |
---|
| 269 | IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D." |
---|
| 270 | IGCM_debug_Verif_Exit ;; |
---|
| 271 | esac |
---|
| 272 | |
---|
| 273 | IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength" |
---|
| 274 | |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | #=================================== |
---|
[2] | 278 | function IGCM_config_PeriodStart |
---|
| 279 | { |
---|
| 280 | IGCM_debug_PushStack "IGCM_config_PeriodStart" |
---|
| 281 | |
---|
| 282 | echo |
---|
| 283 | IGCM_debug_Print 1 "IGCM_config_PeriodStart :" |
---|
| 284 | echo |
---|
| 285 | |
---|
| 286 | if [ ! -r ${SUBMIT_DIR}/run.card ]; then |
---|
| 287 | |
---|
| 288 | #================================================# |
---|
| 289 | # The file run.card doesn't exist # |
---|
| 290 | #================================================# |
---|
| 291 | |
---|
| 292 | eval FirstInitialize=true |
---|
| 293 | |
---|
| 294 | #copy initial run.card |
---|
| 295 | IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card |
---|
| 296 | |
---|
| 297 | IGCM_date_GetYearMonth $DateBegin year month |
---|
[124] | 298 | IGCM_config_Analyse_PeriodLength |
---|
[2] | 299 | |
---|
| 300 | eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1 |
---|
[146] | 301 | PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) ) |
---|
[2] | 302 | eval CumulPeriod=1 > /dev/null 2>&1 |
---|
| 303 | |
---|
| 304 | #=================================================# |
---|
| 305 | # Creation and write updated run.card # |
---|
| 306 | #=================================================# |
---|
| 307 | |
---|
| 308 | #Correct run.card Configuration for this period |
---|
| 309 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} |
---|
| 310 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} |
---|
| 311 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} |
---|
| 312 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" |
---|
| 313 | |
---|
| 314 | else |
---|
| 315 | #================================================# |
---|
| 316 | # The file run.card allready exist # |
---|
| 317 | #================================================# |
---|
| 318 | |
---|
| 319 | eval FirstInitialize=false |
---|
| 320 | |
---|
| 321 | #Test state of run in run.card |
---|
| 322 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 323 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
| 324 | echo |
---|
| 325 | IGCM_debug_Print 1 "!!!!!! IGCM_config_PeriodStart Error PeriodState : " ${run_Configuration_PeriodState} "!!!!!!!!!!" |
---|
| 326 | echo |
---|
| 327 | IGCM_debug_Exit "IGCM_config_PeriodStart Error PeriodState : " ${run_Configuration_PeriodState} |
---|
| 328 | IGCM_debug_Verif_Exit |
---|
| 329 | fi |
---|
| 330 | |
---|
| 331 | #===================================# |
---|
| 332 | # Read updated run.card # |
---|
| 333 | #===================================# |
---|
| 334 | |
---|
| 335 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix |
---|
| 336 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
| 337 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
| 338 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
| 339 | |
---|
| 340 | PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
| 341 | PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
| 342 | eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1 |
---|
| 343 | |
---|
| 344 | if [ ${Period} = 1 ]; then |
---|
| 345 | # save last Job output |
---|
| 346 | typeset LastPeriod Last_Script_Output_Name |
---|
| 347 | (( LastPeriod=CumulPeriod-PeriodNb )) |
---|
[57] | 348 | Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${LastPeriod} )" |
---|
[2] | 349 | #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name} |
---|
| 350 | #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1 |
---|
| 351 | IGCM_debug_Print 1 "Try to save previous ksh job output" |
---|
| 352 | IGCM_sys_Cd ${SUBMIT_DIR}/ |
---|
[118] | 353 | IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ |
---|
[2] | 354 | IGCM_sys_Cd ${RUN_DIR} |
---|
| 355 | else |
---|
| 356 | unset FileToBeDeleted |
---|
| 357 | fi |
---|
| 358 | |
---|
| 359 | IGCM_date_GetYearMonth $PeriodDateBegin year month |
---|
[124] | 360 | IGCM_config_Analyse_PeriodLength |
---|
[2] | 361 | |
---|
| 362 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" |
---|
| 363 | |
---|
| 364 | fi |
---|
| 365 | OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd} |
---|
| 366 | |
---|
| 367 | #===================================================================# |
---|
| 368 | # Prepare variables available for ${COMP}.card and ${COMP}.driver # |
---|
| 369 | # But available to any son functions # |
---|
| 370 | #===================================================================# |
---|
| 371 | |
---|
| 372 | # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !) |
---|
| 373 | (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 )) |
---|
| 374 | |
---|
| 375 | # Debug Print : |
---|
| 376 | IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution" |
---|
| 377 | IGCM_debug_Print 3 "Year of simulation : ${year}" |
---|
| 378 | IGCM_debug_Print 3 "Month of simulation : ${month}" |
---|
| 379 | IGCM_debug_Print 3 "PeriodLengthInDays : ${PeriodLengthInDays}" |
---|
| 380 | IGCM_debug_Print 3 "PeriodDateBegin : ${PeriodDateBegin}" |
---|
| 381 | IGCM_debug_Print 3 "PeriodDateEnd : ${PeriodDateEnd}" |
---|
| 382 | IGCM_debug_Print 3 "SimulationLengthInDays : ${SimulationLengthInDays}" |
---|
| 383 | IGCM_debug_Print 3 "ExperienceLengthInDays : ${ExperienceLengthInDays}" |
---|
| 384 | |
---|
| 385 | #================================================================# |
---|
| 386 | # Prepare variables available for comp_finalyze # |
---|
| 387 | #================================================================# |
---|
| 388 | |
---|
| 389 | # Period for save files |
---|
| 390 | eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1 |
---|
| 391 | |
---|
| 392 | # Prefix for save files of this period |
---|
| 393 | eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod} > /dev/null 2>&1 |
---|
| 394 | |
---|
| 395 | # List of files that will be deleted in RUN_DIR after run |
---|
[52] | 396 | [ -f stack ] && FileToBeDeleted[0]="stack" |
---|
[2] | 397 | |
---|
| 398 | # Test if the same run as already been saved : |
---|
[128] | 399 | if [ X${JobType} = XRUN ] ; then |
---|
| 400 | if [ ${DRYRUN} -le 0 ] ; then |
---|
| 401 | if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then |
---|
| 402 | IGCM_debug_Exit "IGCM_config_PeriodStart" "RErun an old job." |
---|
| 403 | IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files" |
---|
| 404 | IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or " |
---|
| 405 | IGCM_debug_Print 1 " the whole ${R_SAVE} tree." |
---|
| 406 | IGCM_debug_Verif_Exit |
---|
| 407 | fi |
---|
| 408 | fi |
---|
| 409 | else |
---|
[2] | 410 | if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then |
---|
[128] | 411 | IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. DEBUG of DEV mode." |
---|
[2] | 412 | fi |
---|
| 413 | fi |
---|
[128] | 414 | |
---|
[2] | 415 | IGCM_debug_PopStack "IGCM_config_PeriodStart" |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | #=================================== |
---|
| 419 | function IGCM_config_PeriodEnd |
---|
| 420 | { |
---|
| 421 | IGCM_debug_PushStack "IGCM_config_PeriodEnd" |
---|
| 422 | |
---|
| 423 | echo |
---|
| 424 | IGCM_debug_Print 1 "IGCM_config_PeriodEnd :" |
---|
| 425 | echo |
---|
| 426 | |
---|
| 427 | #==================================# |
---|
| 428 | # Save Job output # |
---|
| 429 | #==================================# |
---|
| 430 | IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output} |
---|
| 431 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}" |
---|
| 432 | |
---|
| 433 | typeset LS_comp LS_bin ExeDate ExeCpuLog ExeSize NextExeSize LastCompExeSize |
---|
| 434 | typeset comp i |
---|
| 435 | typeset ExeNameIn ExeNameOut |
---|
| 436 | |
---|
| 437 | #==================================# |
---|
| 438 | # Get last Exe Size # |
---|
| 439 | #==================================# |
---|
| 440 | |
---|
| 441 | (( i=0 )) |
---|
| 442 | if ( ${FirstInitialize} ) ; then |
---|
| 443 | run_Log_LastExeSize="" |
---|
| 444 | for comp in ${config_ListOfComponents[*]} ; do |
---|
| 445 | run_Log_LastExeSize[$i]=0 |
---|
| 446 | (( i=i+1 )) |
---|
| 447 | done |
---|
| 448 | else |
---|
| 449 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize |
---|
| 450 | fi |
---|
| 451 | |
---|
| 452 | #==================================# |
---|
| 453 | # And Build ExeDate # |
---|
| 454 | #==================================# |
---|
| 455 | |
---|
| 456 | # 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 |
---|
[57] | 457 | # 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") |
---|
| 458 | # 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 |
---|
[2] | 459 | ExeDate="" |
---|
| 460 | NextExeSize="( " |
---|
| 461 | (( i=0 )) |
---|
| 462 | |
---|
| 463 | for comp in ${config_ListOfComponents[*]} ; do |
---|
| 464 | |
---|
| 465 | IGCM_debug_Print 1 ${comp} |
---|
| 466 | |
---|
| 467 | eval ExeNameIn=\${config_Executable_${comp}[0]} |
---|
| 468 | eval ExeNameOut=\${config_Executable_${comp}[1]} |
---|
[124] | 469 | # Only if we really have an executable for the component : |
---|
[2] | 470 | if [ X${ExeNameIn} = X\"\" ] ; then |
---|
| 471 | # If there is no exe file for this component |
---|
| 472 | (( ExeSize=0 )) |
---|
| 473 | else |
---|
| 474 | eval LS_bin=${R_EXE}/${ExeNameIn} |
---|
| 475 | IGCM_sys_FileSize ${LS_bin} ExeSize |
---|
| 476 | |
---|
[57] | 477 | set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} ) |
---|
[2] | 478 | if [ X${ExeDate} = X ] ; then |
---|
| 479 | # First component exe date |
---|
| 480 | ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]} |
---|
| 481 | else |
---|
| 482 | ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]} |
---|
| 483 | fi |
---|
| 484 | ExeDate=${ExeDate}_${LS_comp[7]} |
---|
| 485 | fi |
---|
| 486 | |
---|
| 487 | if [ ${i} -eq 0 ] ; then |
---|
| 488 | # First component |
---|
| 489 | NextExeSize="( "${ExeSize} |
---|
| 490 | else |
---|
| 491 | NextExeSize=${NextExeSize}", "${ExeSize} |
---|
| 492 | fi |
---|
| 493 | eval LastCompExeSize=${run_Log_LastExeSize[$i]} |
---|
| 494 | (( i=i+1 )) |
---|
| 495 | |
---|
[151] | 496 | if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then |
---|
[2] | 497 | if ( ${FirstInitialize} ) ; then |
---|
| 498 | IGCM_debug_Print 1 "Put first ${ExeNameIn} in ${R_OUT_EXE} !" |
---|
| 499 | else |
---|
| 500 | IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !" |
---|
[151] | 501 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut} |
---|
[2] | 502 | fi |
---|
| 503 | eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} |
---|
[151] | 504 | IGCM_sys_Chmod u+xw ${ExeNameOut} |
---|
[2] | 505 | fi |
---|
| 506 | done |
---|
| 507 | |
---|
| 508 | if [ ${DRYRUN} -le 1 ] ; then |
---|
| 509 | typeset ExeCpuLog |
---|
| 510 | tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt |
---|
| 511 | ExeCpuLog=$( ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt ) |
---|
| 512 | RET=$? |
---|
[57] | 513 | if [ $RET -eq 0 ] ; then |
---|
| 514 | # ExeCpuLog variable contents 5 fields |
---|
[92] | 515 | echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" | \ |
---|
[109] | 516 | gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \ |
---|
[57] | 517 | $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card |
---|
[2] | 518 | fi |
---|
| 519 | eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt" |
---|
| 520 | fi |
---|
| 521 | |
---|
| 522 | NextExeSize=${NextExeSize}" )" |
---|
| 523 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}" |
---|
| 524 | |
---|
| 525 | # All was right ? no ? then we stop. |
---|
| 526 | IGCM_debug_Verif_Exit |
---|
| 527 | |
---|
| 528 | # If all was OK, we can delete all files not necessary for next Job |
---|
[92] | 529 | IGCM_debug_Print 1 "Files that will be deleted before next period-run : " |
---|
[2] | 530 | |
---|
| 531 | if [ ${DRYRUN} -le 2 ] ; then |
---|
[139] | 532 | for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done |
---|
[2] | 533 | else |
---|
| 534 | echo ${FileToBeDeleted[@]} |
---|
| 535 | fi |
---|
| 536 | |
---|
| 537 | #=================================================# |
---|
[119] | 538 | # Modification of libIGCM behaviour # |
---|
| 539 | #=================================================# |
---|
| 540 | |
---|
[146] | 541 | # To use this function, one must copy libIGCM.card from ${libIGCM} directory |
---|
[119] | 542 | # and put it in ${SUBMIT_DIR} directory. Ater modifications of ${SUBMIT_DIR}/libIGCM.card, |
---|
[146] | 543 | # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop. |
---|
[119] | 544 | if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then |
---|
| 545 | echo |
---|
| 546 | echo "########################################################################" |
---|
| 547 | echo "!!! Modification of libIGCM behaviour !!!" |
---|
| 548 | echo |
---|
| 549 | |
---|
| 550 | IGCM_debug_Print 1 "DefineArrayFromOption : libIGCM_UserChanges in libIGCM.card" |
---|
| 551 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges |
---|
| 552 | IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]} |
---|
| 553 | |
---|
| 554 | # Special treatments for libIGCM internals |
---|
| 555 | for option in ${libIGCM_UserChanges[*]} ; do |
---|
| 556 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option} |
---|
| 557 | |
---|
| 558 | echo "We will change : ${option}." |
---|
| 559 | eval echo "Previous value : " \${${option}} |
---|
| 560 | eval echo "Change to : " \${libIGCM_UserChanges_${option}} |
---|
| 561 | |
---|
| 562 | eval ${option}=\${libIGCM_UserChanges_${option}} |
---|
| 563 | |
---|
| 564 | case ${option} in |
---|
| 565 | config_UserChoices_DateEnd) |
---|
| 566 | IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd |
---|
| 567 | DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) |
---|
| 568 | |
---|
| 569 | # Period Length In Days between DateBegin and DateEnd |
---|
| 570 | (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} ) + 1 )) |
---|
| 571 | if [ ${ExperienceLengthInDays} -lt 0 ] ; then |
---|
| 572 | IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that." |
---|
| 573 | IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates." |
---|
| 574 | IGCM_debug_Verif_Exit |
---|
| 575 | fi |
---|
| 576 | ;; |
---|
| 577 | config_UserChoices_PeriodLength) |
---|
| 578 | ;; |
---|
| 579 | PeriodNb) |
---|
| 580 | IGCM_debug_Print 3 "Loop in main Job with ${PeriodNb} period(s)" |
---|
| 581 | ;; |
---|
| 582 | config_Post_RebuildFrequency) |
---|
| 583 | IGCM_debug_Print 3 "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure" |
---|
| 584 | IGCM_post_Configure |
---|
| 585 | ;; |
---|
| 586 | config_Post_TimeSeriesFrequency) |
---|
| 587 | IGCM_debug_Print 3 "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize" |
---|
[121] | 588 | IGCM_post_Configure |
---|
[119] | 589 | ;; |
---|
| 590 | config_Post_SeasonalFrequency) |
---|
| 591 | IGCM_debug_Print 3 "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize" |
---|
[121] | 592 | IGCM_post_Configure |
---|
[119] | 593 | ;; |
---|
| 594 | esac |
---|
| 595 | done |
---|
| 596 | |
---|
| 597 | echo |
---|
| 598 | echo "########################################################################" |
---|
| 599 | echo |
---|
| 600 | fi |
---|
| 601 | |
---|
| 602 | #=================================================# |
---|
[2] | 603 | # Determine next computed period # |
---|
| 604 | #=================================================# |
---|
| 605 | |
---|
| 606 | PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 ) |
---|
| 607 | IGCM_date_GetYearMonth $PeriodDateBegin year month |
---|
| 608 | |
---|
[124] | 609 | IGCM_config_Analyse_PeriodLength |
---|
[146] | 610 | PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) ) |
---|
[2] | 611 | |
---|
| 612 | # Debug Print : |
---|
| 613 | echo |
---|
| 614 | IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution" |
---|
| 615 | IGCM_debug_Print 3 "PeriodDateBegin : ${PeriodDateBegin}" |
---|
| 616 | IGCM_debug_Print 3 "PeriodDateEnd : ${PeriodDateEnd}" |
---|
| 617 | IGCM_debug_Print 3 "PeriodLengthInDays : ${PeriodLengthInDays}" |
---|
| 618 | |
---|
| 619 | PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} ) |
---|
| 620 | PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} ) |
---|
| 621 | |
---|
| 622 | (( CumulPeriod = CumulPeriod + 1 )) |
---|
| 623 | |
---|
| 624 | # Debug Print : |
---|
| 625 | echo |
---|
| 626 | IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}" |
---|
| 627 | IGCM_debug_Print 3 "PeriodDateEnd Human : ${PeriodDateEnd}" |
---|
| 628 | IGCM_debug_Print 3 "CumulPeriod : ${CumulPeriod}" |
---|
| 629 | |
---|
| 630 | #=================================================# |
---|
| 631 | # Write updated run.card # |
---|
| 632 | #=================================================# |
---|
| 633 | |
---|
| 634 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix} |
---|
| 635 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} |
---|
| 636 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} |
---|
| 637 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} |
---|
| 638 | |
---|
| 639 | IGCM_debug_PopStack "IGCM_config_PeriodEnd" |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | #=================================== |
---|
| 643 | function IGCM_config_Finalize |
---|
| 644 | { |
---|
| 645 | IGCM_debug_PushStack "IGCM_config_Finalize" |
---|
| 646 | |
---|
| 647 | echo |
---|
| 648 | IGCM_debug_Print 1 "IGCM_config_Finalize :" |
---|
| 649 | echo |
---|
| 650 | |
---|
| 651 | if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then |
---|
| 652 | |
---|
| 653 | #==========================# |
---|
| 654 | # End of entire simulation # |
---|
| 655 | #==========================# |
---|
| 656 | |
---|
[154] | 657 | # Mail notification |
---|
| 658 | IGCM_sys_SendMail |
---|
[2] | 659 | |
---|
[154] | 660 | # |
---|
[2] | 661 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed" |
---|
| 662 | IGCM_debug_Print 1 "Normal End of computation." |
---|
| 663 | if ( $DEBUG_debug ) ; then |
---|
| 664 | echo |
---|
| 665 | IGCM_debug_Print 1 "Your files on ${R_OUT} :" |
---|
| 666 | IGCM_sys_Tree ${R_SAVE} |
---|
| 667 | fi |
---|
[154] | 668 | |
---|
[2] | 669 | else |
---|
| 670 | |
---|
| 671 | #=================# |
---|
| 672 | # Submit next job # |
---|
| 673 | #=================# |
---|
| 674 | |
---|
| 675 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
| 676 | |
---|
| 677 | # Name of next Ksh Script output : |
---|
[57] | 678 | eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )" |
---|
[2] | 679 | |
---|
| 680 | IGCM_debug_Print 1 "Submit next job" |
---|
[154] | 681 | # SUBMIT NEXT JOB |
---|
[2] | 682 | IGCM_sys_Cd ${SUBMIT_DIR} |
---|
| 683 | IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} |
---|
| 684 | fi |
---|
| 685 | |
---|
[154] | 686 | # Supress Non Deleted Boundary files |
---|
| 687 | if [ ${DRYRUN} -le 2 ] ; then |
---|
| 688 | IGCM_comp_DelFixeBoundaryFiles |
---|
| 689 | ls -la |
---|
| 690 | fi |
---|
| 691 | |
---|
| 692 | # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
| 693 | # Only for production run (No clean up in DEV or DEB mode) |
---|
| 694 | [ X${JobType} = X${RUN} ] && IGCM_sys_Rm -rf ${RUN_DIR} |
---|
| 695 | |
---|
[2] | 696 | IGCM_debug_PopStack "IGCM_config_Finalize" |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | #=================================== |
---|