source: trunk/libIGCM/AA_clean_year @ 1028

Last change on this file since 1028 was 1028, checked in by sdipsl, 10 years ago

Remove OldPrefix? from run.card to ease REDO process when needed. see #168

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