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