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