[373] | 1 | #!/bin/ksh |
---|
| 2 | #************************************************************** |
---|
| 3 | # Author: Martial Mancip |
---|
[403] | 4 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
[373] | 5 | # $Revision:: $ Revision of last commit |
---|
| 6 | # $Author:: $ Author of last commit |
---|
| 7 | # $Date:: $ Date of last commit |
---|
[225] | 8 | # IPSL (2006) |
---|
| 9 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
[373] | 10 | # |
---|
| 11 | #************************************************************** |
---|
[1330] | 12 | # ID of your genci project. Curie only : post-processing jobs need it to run properly |
---|
| 13 | #-Q- curie export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
[1437] | 14 | #-Q- irene export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
[1525] | 15 | #-Q- irene-amd export BRIDGE_MSUB_PROJECT=::default_project:: |
---|
[225] | 16 | |
---|
| 17 | #set -eu |
---|
| 18 | #set -vx |
---|
| 19 | |
---|
| 20 | libIGCM=::modipsl::/libIGCM |
---|
| 21 | |
---|
[1356] | 22 | #D- Task type DO NOT CHANGE (computing, post-processing or checking) |
---|
[712] | 23 | TaskType=post-processing |
---|
| 24 | |
---|
[225] | 25 | #D--------------------------------------------------------------------== |
---|
| 26 | #D- -1. User modification place |
---|
| 27 | #D--------------------------------------------------------------------== |
---|
| 28 | |
---|
| 29 | #D- Increased verbosity (1, 2, 3) |
---|
| 30 | Verbosity=3 |
---|
| 31 | |
---|
| 32 | #D- Low level debug : to bypass lib test checks and stack construction |
---|
| 33 | #D- Default=true |
---|
| 34 | DEBUG_debug=false |
---|
| 35 | |
---|
| 36 | #D--------------------------------------------------------------------== |
---|
[1575] | 37 | echo "" |
---|
| 38 | echo "clean_or_continue.job " |
---|
| 39 | if [ $# -gt 0 ] ; then |
---|
| 40 | # Print help and exit |
---|
| 41 | echo "" |
---|
| 42 | echo "The script is called from in the your experiment directory, the so-called SUBMIT_DIR, in the following way" |
---|
| 43 | echo "../../../libIGCM/clean_or_continue.job -h : to print following information" |
---|
| 44 | echo "../../../libIGCM/clean_or_continue.job : normal execution" |
---|
| 45 | echo "" |
---|
| 46 | echo "This script can be used for 3 cases:" |
---|
| 47 | echo "1- The simulation crashed and you have PeriodState=Fatal in run.card." |
---|
| 48 | echo "For this case, all output from the current PeriodLength set in run.card will be deleted. " |
---|
| 49 | echo "You need to answer yes to the questions." |
---|
| 50 | echo "" |
---|
| 51 | echo "2- The simulation stopped due to an exceeded time limit, PeriodState=Running in run.card". |
---|
| 52 | echo "As for case 1, all output from the current PeriodLength will be deleted and you should answer yes to questions". |
---|
| 53 | echo "" |
---|
| 54 | echo "3- The simulation is completed but you want to continue it, PeriodState=Completed in run.card." |
---|
| 55 | echo "For this case, you just need to change DateEnd in config.card and launch this script." |
---|
| 56 | echo "" |
---|
| 57 | echo "For all cases, the run.card is changed as needed and the number for the current period is set in the main Job_ for the Script_Output_ file" |
---|
| 58 | echo "" |
---|
| 59 | echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions." |
---|
| 60 | echo "" |
---|
[225] | 61 | |
---|
[1575] | 62 | exit |
---|
| 63 | fi |
---|
| 64 | echo "" |
---|
| 65 | echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions." |
---|
| 66 | echo "Use ../../../libIGCM/clean_or_contine.job -h for more information" |
---|
| 67 | echo "" |
---|
[225] | 68 | |
---|
| 69 | #D--------------------------------------------------------------------== |
---|
| 70 | |
---|
| 71 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 72 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
| 73 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
| 74 | #------- |
---|
[428] | 75 | SUBMIT_DIR=$( pwd ) |
---|
[225] | 76 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
| 77 | . ${libIGCM}/libIGCM_config/libIGCM_config.ksh |
---|
[832] | 78 | #------- |
---|
| 79 | ( ${DEBUG_debug} ) && IGCM_debug_Check |
---|
| 80 | ( ${DEBUG_debug} ) && IGCM_card_Check |
---|
| 81 | ( ${DEBUG_debug} ) && IGCM_date_Check |
---|
[225] | 82 | |
---|
| 83 | #================================== |
---|
[727] | 84 | # First of all |
---|
| 85 | # |
---|
| 86 | # Read libIGCM compatibility version in config.card |
---|
| 87 | # Read UserChoices section |
---|
| 88 | # Read Ensemble section |
---|
| 89 | # Read Post section |
---|
| 90 | # Define all netcdf output directories |
---|
| 91 | #================================== |
---|
| 92 | IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card |
---|
[225] | 93 | |
---|
[634] | 94 | #================================== |
---|
| 95 | # Define default value to keep compatibility with previous card: means before changes due to TGCC |
---|
| 96 | if [ X${PackDefault} = Xtrue ] ; then |
---|
| 97 | [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} |
---|
| 98 | else |
---|
| 99 | config_Post_PackFrequency=NONE |
---|
| 100 | fi |
---|
| 101 | |
---|
| 102 | #================================== |
---|
[906] | 103 | # Is the pack active |
---|
[634] | 104 | if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then |
---|
| 105 | Pack=true |
---|
| 106 | fi |
---|
| 107 | |
---|
[225] | 108 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
| 109 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
| 110 | |
---|
[906] | 111 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
[785] | 112 | echo "You seem NOT to have a run.card in this directory !!" |
---|
| 113 | echo "This script will fail because it doesn't know what to do without run.card available." |
---|
| 114 | exit 1 |
---|
[225] | 115 | else |
---|
[785] | 116 | #===================================# |
---|
| 117 | # Read updated run.card # |
---|
| 118 | #===================================# |
---|
| 119 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 120 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
| 121 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
| 122 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
[225] | 123 | |
---|
[1185] | 124 | # |
---|
| 125 | if [ X${run_Configuration_CumulPeriod} = X ] ; then |
---|
| 126 | echo -e "\033[1;32mCumulPeriod is empty so we want to erase run.card to start properly. Do you want that?" |
---|
| 127 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 128 | read reponse |
---|
| 129 | case ${reponse} in |
---|
| 130 | |
---|
| 131 | oui|OUI|o|y|yes|YES) |
---|
| 132 | echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
| 133 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
| 134 | ;; |
---|
| 135 | non|NON|n|no|NO) |
---|
| 136 | echo "Nothing to do !" |
---|
| 137 | ;; |
---|
| 138 | esac |
---|
| 139 | exit 0 |
---|
| 140 | fi |
---|
| 141 | |
---|
[785] | 142 | PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
| 143 | echo "Search files with ${PeriodDateEnd} in ${R_SAVE}" |
---|
| 144 | set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " ) |
---|
| 145 | CountListFiles=${#ListFiles[@]} |
---|
[225] | 146 | |
---|
[785] | 147 | if [ X${Pack} = Xtrue ] ; then |
---|
| 148 | echo "Search files with ${PeriodDateEnd} in ${R_BUFR}" |
---|
| 149 | set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " ) |
---|
| 150 | CountListFilesBuf=${#ListFilesBuf[@]} |
---|
| 151 | else |
---|
| 152 | CountListFilesBuf=0 |
---|
| 153 | fi |
---|
| 154 | |
---|
| 155 | # If exist, erase REBUILD DIR |
---|
| 156 | PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
| 157 | CountRebuildDir=0 |
---|
| 158 | if [ X${config_Post_RebuildFrequency} != X ] ; then |
---|
[1031] | 159 | set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" ) |
---|
[785] | 160 | CountRebuildDir=${#RebuildDir[@]} |
---|
| 161 | fi |
---|
[545] | 162 | |
---|
[785] | 163 | IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}." |
---|
[906] | 164 | if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then |
---|
[785] | 165 | for file in ${ListFiles[@]} ; do |
---|
| 166 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
| 167 | done |
---|
| 168 | if [ X${Pack} = Xtrue ] ; then |
---|
| 169 | for file in ${ListFilesBuf[@]} ; do |
---|
| 170 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
| 171 | done |
---|
[403] | 172 | fi |
---|
[785] | 173 | echo -e "\033[1;32mDo you REALLY want to erase all those files ?" |
---|
| 174 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 175 | read reponse |
---|
| 176 | case ${reponse} in |
---|
[403] | 177 | |
---|
[785] | 178 | oui|OUI|o|y|yes|YES) |
---|
| 179 | echo "OK. It will be erased." |
---|
| 180 | IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
[634] | 181 | if [ X${Pack} = Xtrue ] ; then |
---|
[785] | 182 | IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
[634] | 183 | fi |
---|
[785] | 184 | echo "done." |
---|
| 185 | ;; |
---|
| 186 | non|NON|n|no|NO) |
---|
| 187 | echo "Nothing to do !" |
---|
| 188 | ;; |
---|
| 189 | esac |
---|
| 190 | fi |
---|
[403] | 191 | |
---|
[906] | 192 | if [ ${CountRebuildDir} -gt 0 ] ; then |
---|
[785] | 193 | IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}." |
---|
| 194 | for Dir in ${RebuildDir[@]} ; do |
---|
| 195 | IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m" |
---|
| 196 | done |
---|
[403] | 197 | |
---|
[785] | 198 | echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?" |
---|
| 199 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 200 | read reponse |
---|
| 201 | case ${reponse} in |
---|
[707] | 202 | |
---|
[785] | 203 | oui|OUI|o|y|yes|YES) |
---|
| 204 | echo "OK. It will be erased." |
---|
[1031] | 205 | find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \; |
---|
[785] | 206 | echo "done." |
---|
| 207 | ;; |
---|
| 208 | non|NON|n|no|NO) |
---|
| 209 | echo "Nothing to do !" |
---|
| 210 | ;; |
---|
| 211 | esac |
---|
| 212 | fi |
---|
[707] | 213 | |
---|
[785] | 214 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 215 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
| 216 | |
---|
| 217 | echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?" |
---|
| 218 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 219 | read reponse |
---|
| 220 | case ${reponse} in |
---|
| 221 | |
---|
| 222 | oui|OUI|o|y|yes|YES) |
---|
| 223 | echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
| 224 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
| 225 | ;; |
---|
| 226 | non|NON|n|no|NO) |
---|
| 227 | echo "Nothing to do !" |
---|
| 228 | ;; |
---|
| 229 | esac |
---|
| 230 | else |
---|
| 231 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
| 232 | fi |
---|
| 233 | |
---|
[1185] | 234 | if [ X${run_Configuration_CumulPeriod} = X1 ] ; then |
---|
[896] | 235 | echo -e "\033[1;32mCumulPeriod=1 so we want to erase run.card to start properly. Do you want that too?" |
---|
| 236 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 237 | read reponse |
---|
| 238 | case ${reponse} in |
---|
| 239 | |
---|
| 240 | oui|OUI|o|y|yes|YES) |
---|
| 241 | echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
| 242 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
| 243 | ;; |
---|
| 244 | non|NON|n|no|NO) |
---|
| 245 | echo "Nothing to do !" |
---|
| 246 | ;; |
---|
| 247 | esac |
---|
[1383] | 248 | else |
---|
| 249 | # if not first period |
---|
| 250 | Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} |
---|
| 251 | Script_Output_Job=${Script_Output_Prefix}_${config_UserChoices_JobName} |
---|
| 252 | Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${run_Configuration_CumulPeriod} ) |
---|
| 253 | |
---|
| 254 | echo -e "\033[1;32mDo you want to change the number in Script_Output? (${Script_Output} into Job) ?" |
---|
| 255 | echo -n -e " Your answer (y/n) : \033[m" |
---|
| 256 | read reponse |
---|
| 257 | case ${reponse} in |
---|
| 258 | |
---|
| 259 | oui|OUI|o|y|yes|YES) |
---|
| 260 | cp ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$ |
---|
| 261 | sed -e"s/${Script_Output_Job}.[0-9][0-9][0-9][0-9][0-9][0-9]/${Script_Output}/" ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$ >${SUBMIT_DIR}/Job_${config_UserChoices_JobName} |
---|
| 262 | echo "Job : Job_${config_UserChoices_JobName} modified." |
---|
| 263 | echo "Old job saved here : Job_${config_UserChoices_JobName}_SAVED_$$" |
---|
| 264 | ;; |
---|
| 265 | non|NON|n|no|NO) |
---|
| 266 | echo "Nothing done in Job_${config_UserChoices_JobName} !" |
---|
| 267 | ;; |
---|
| 268 | esac |
---|
| 269 | |
---|
[785] | 270 | fi |
---|
[225] | 271 | fi |
---|
| 272 | exit 0 |
---|