[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 | #************************************************************** |
---|
[225] | 12 | |
---|
| 13 | #set -eu |
---|
| 14 | #set -vx |
---|
| 15 | |
---|
| 16 | libIGCM=::modipsl::/libIGCM |
---|
| 17 | |
---|
| 18 | #D--------------------------------------------------------------------== |
---|
| 19 | #D- -1. User modification place |
---|
| 20 | #D--------------------------------------------------------------------== |
---|
| 21 | |
---|
| 22 | #D- Increased verbosity (1, 2, 3) |
---|
| 23 | Verbosity=3 |
---|
| 24 | |
---|
| 25 | #D- Low level debug : to bypass lib test checks and stack construction |
---|
| 26 | #D- Default=true |
---|
| 27 | DEBUG_debug=false |
---|
| 28 | |
---|
| 29 | #D--------------------------------------------------------------------== |
---|
| 30 | |
---|
| 31 | echo "clean month script :" |
---|
| 32 | echo "Script used to clean a month on SAVE directory !" |
---|
| 33 | echo "This script will erase some files !!! Be careful and read all informations !" |
---|
| 34 | echo "----" |
---|
| 35 | echo "It must be called in Experience directory (so-called SUBMIT_DIR)." |
---|
| 36 | echo "----" |
---|
| 37 | |
---|
| 38 | #D--------------------------------------------------------------------== |
---|
| 39 | |
---|
| 40 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 41 | ( ${DEBUG_debug} ) && IGCM_debug_Check |
---|
| 42 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
| 43 | ( ${DEBUG_debug} ) && IGCM_card_Check |
---|
| 44 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
| 45 | ( ${DEBUG_debug} ) && IGCM_date_Check |
---|
| 46 | #------- |
---|
[428] | 47 | SUBMIT_DIR=$( pwd ) |
---|
[225] | 48 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
| 49 | . ${libIGCM}/libIGCM_config/libIGCM_config.ksh |
---|
| 50 | |
---|
| 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 | |
---|
[403] | 59 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post |
---|
| 60 | |
---|
| 61 | for option in ${config_Post[*]} ; do |
---|
| 62 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} |
---|
| 63 | done |
---|
| 64 | |
---|
[658] | 65 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Ensemble |
---|
| 66 | |
---|
| 67 | for option in ${config_Ensemble[*]} ; do |
---|
| 68 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Ensemble ${option} |
---|
| 69 | done |
---|
| 70 | |
---|
[225] | 71 | IGCM_debug_Print 1 "DefineArrayFromOption : config_UserChoices" |
---|
| 72 | IGCM_debug_PrintVariables 3 config_UserChoices_JobName |
---|
| 73 | if [ 3 -le ${Verbosity} ] ; then |
---|
| 74 | echo "--------------Debug3-->" "config_UserChoices_LongName=" |
---|
| 75 | echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" |
---|
| 76 | fi |
---|
| 77 | IGCM_debug_PrintVariables 3 config_UserChoices_TagName |
---|
| 78 | IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType |
---|
| 79 | IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin |
---|
| 80 | IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd |
---|
| 81 | IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength |
---|
[658] | 82 | IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName |
---|
| 83 | IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate |
---|
[225] | 84 | |
---|
[634] | 85 | #================================== |
---|
| 86 | # Define default value to keep compatibility with previous card: means before changes due to TGCC |
---|
| 87 | if [ X${PackDefault} = Xtrue ] ; then |
---|
| 88 | [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} |
---|
| 89 | else |
---|
| 90 | config_Post_PackFrequency=NONE |
---|
| 91 | fi |
---|
| 92 | |
---|
| 93 | #================================== |
---|
[635] | 94 | # Is the pack active |
---|
[634] | 95 | if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then |
---|
| 96 | Pack=true |
---|
| 97 | fi |
---|
| 98 | |
---|
[225] | 99 | #==================================================== |
---|
| 100 | #R_SAVE : Job output directory |
---|
[545] | 101 | #R_BUFR : Job output buffered directory |
---|
[273] | 102 | if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then |
---|
[658] | 103 | FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) |
---|
| 104 | if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then |
---|
| 105 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName} |
---|
| 106 | R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName} |
---|
| 107 | else |
---|
[273] | 108 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} |
---|
[545] | 109 | R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} |
---|
[658] | 110 | fi |
---|
[273] | 111 | else |
---|
[658] | 112 | if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then |
---|
| 113 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName} |
---|
| 114 | R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName} |
---|
| 115 | else |
---|
[273] | 116 | R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
[545] | 117 | R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
[658] | 118 | fi |
---|
[273] | 119 | fi |
---|
[225] | 120 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
| 121 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
| 122 | |
---|
| 123 | if [ ! -f ${SUBMIT_DIR}/run.card ]; then |
---|
| 124 | echo "You seem NOT to have a run.card in this directory !!" |
---|
[545] | 125 | echo "This script will fail because it doesn't know what to do without run.card available." |
---|
[225] | 126 | exit 1 |
---|
| 127 | else |
---|
| 128 | #===================================# |
---|
| 129 | # Read updated run.card # |
---|
| 130 | #===================================# |
---|
| 131 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 132 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix |
---|
| 133 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin |
---|
| 134 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd |
---|
| 135 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod |
---|
| 136 | |
---|
| 137 | PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) |
---|
[286] | 138 | echo "Search files with ${PeriodDateEnd} in ${R_SAVE}" |
---|
| 139 | set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " ) |
---|
| 140 | CountListFiles=${#ListFiles[@]} |
---|
[225] | 141 | |
---|
[634] | 142 | if [ X${Pack} = Xtrue ] ; then |
---|
| 143 | echo "Search files with ${PeriodDateEnd} in ${R_BUFR}" |
---|
| 144 | set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " ) |
---|
| 145 | CountListFilesBuf=${#ListFilesBuf[@]} |
---|
| 146 | else |
---|
| 147 | CountListFilesBuf=0 |
---|
| 148 | fi |
---|
[545] | 149 | |
---|
[403] | 150 | # If exist, erase REBUILD DIR |
---|
| 151 | PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) |
---|
| 152 | CountRebuildDir=0 |
---|
| 153 | if [ X${config_Post_RebuildFrequency} != X ] ; then |
---|
| 154 | if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then |
---|
| 155 | REBUILD_DIR=${R_SAVE}/TMP |
---|
| 156 | set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " ) |
---|
| 157 | else |
---|
| 158 | REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} |
---|
| 159 | set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" ) |
---|
| 160 | fi |
---|
| 161 | CountRebuildDir=${#RebuildDir[@]} |
---|
| 162 | fi |
---|
| 163 | |
---|
[286] | 164 | IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}." |
---|
[627] | 165 | if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then |
---|
[286] | 166 | for file in ${ListFiles[@]} ; do |
---|
| 167 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
| 168 | done |
---|
[634] | 169 | if [ X${Pack} = Xtrue ] ; then |
---|
| 170 | for file in ${ListFilesBuf[@]} ; do |
---|
[545] | 171 | IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m" |
---|
[634] | 172 | done |
---|
| 173 | fi |
---|
[545] | 174 | echo -e "\033[1;32mDo you REALLY want to erase all those files ?" |
---|
| 175 | echo -n -e " Your answer (y/n) : \033[m" |
---|
[225] | 176 | read reponse |
---|
| 177 | case ${reponse} in |
---|
| 178 | |
---|
| 179 | oui|OUI|o|y|yes|YES) |
---|
| 180 | echo "OK. It will be erased." |
---|
| 181 | IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
[634] | 182 | if [ X${Pack} = Xtrue ] ; then |
---|
| 183 | IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;" |
---|
| 184 | fi |
---|
[225] | 185 | echo "done." |
---|
| 186 | ;; |
---|
| 187 | non|NON|n|no|NO) |
---|
| 188 | echo "Nothing to do !" |
---|
| 189 | ;; |
---|
| 190 | esac |
---|
| 191 | fi |
---|
[403] | 192 | |
---|
| 193 | if [ ${CountRebuildDir} -gt 0 ] ; then |
---|
| 194 | IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}." |
---|
| 195 | for Dir in ${RebuildDir[@]} ; do |
---|
| 196 | IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m" |
---|
| 197 | done |
---|
| 198 | |
---|
[545] | 199 | echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?" |
---|
| 200 | echo -n -e " Your answer (y/n) : \033[m" |
---|
[403] | 201 | read reponse |
---|
| 202 | case ${reponse} in |
---|
| 203 | |
---|
| 204 | oui|OUI|o|y|yes|YES) |
---|
| 205 | echo "OK. It will be erased." |
---|
| 206 | if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then |
---|
| 207 | IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;" |
---|
| 208 | else |
---|
| 209 | find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \; |
---|
| 210 | fi |
---|
| 211 | echo "done." |
---|
| 212 | ;; |
---|
| 213 | non|NON|n|no|NO) |
---|
| 214 | echo "Nothing to do !" |
---|
| 215 | ;; |
---|
| 216 | esac |
---|
| 217 | fi |
---|
[225] | 218 | |
---|
| 219 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState |
---|
| 220 | if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then |
---|
[707] | 221 | |
---|
[288] | 222 | echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?" |
---|
[286] | 223 | echo -n -e " Your answer (y/n) : \033[m" |
---|
[225] | 224 | read reponse |
---|
| 225 | case ${reponse} in |
---|
| 226 | |
---|
| 227 | oui|OUI|o|y|yes|YES) |
---|
[288] | 228 | echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
| 229 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" |
---|
[225] | 230 | ;; |
---|
| 231 | non|NON|n|no|NO) |
---|
| 232 | echo "Nothing to do !" |
---|
| 233 | ;; |
---|
| 234 | esac |
---|
| 235 | else |
---|
[303] | 236 | echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}." |
---|
[225] | 237 | fi |
---|
[707] | 238 | |
---|
| 239 | if ( [ X${run_Configuration_CumulPeriod} = X ] || [ X${run_Configuration_CumulPeriod} = X1 ] ); then |
---|
| 240 | echo "CumulPeriod=1 so we erase run.card to start properly." |
---|
| 241 | IGCM_sys_Rm ${SUBMIT_DIR}/run.card |
---|
| 242 | fi |
---|
[225] | 243 | fi |
---|
| 244 | exit 0 |
---|