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