source: tags/libIGCM_v2.2/AA_clean_year

Last change on this file was 986, checked in by mafoipsl, 10 years ago

ean_year : add TimeSeriesCompleted? update after asking question to user.

  • Property svn:keywords set to Revision Date Author
File size: 11.0 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 OldPrefix
95IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
96IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
97IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
98if [ X${run_Configuration_CumulPeriod} == X ] ; then
99  ${run_Configuration_CumulPeriod} = 0
100fi
101
102
103PreviousPeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
104PreviousPeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
105
106IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth
107
108if [ $# == 1 ] ; then
109  if [ ${#1} != 4 ] ; then
110    echo "You must give a year (SSAA) as argument."
111    exit 1
112  fi
113  ReferenceYear=$1
114else
115  ReferenceYear=${PreviousPeriodYear}
116fi
117RemovedPeriods=0
118
119# Colors
120Red="\033[1;31m"
121Green="\033[1;32m"
122NoColor="\033[0m"
123
124while [ ${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
159  if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
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
190  if [ ${CountRebuildDir} -gt 0 ] ; then
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
201
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
223
224  PreviousPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} \
225                         -$( IGCM_date_DaysInMonth ${PreviousPeriodYear} ${PreviousPeriodMonth} ) )
226done
227
228if [ ${RemovedPeriods} == 0 ] ; then
229  echo "Nothing done, exit"
230  exit 0
231fi
232
233IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
234if ( [ ${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
267        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
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
289  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted
290  if [ ! X${run_PostProcessing_TimeSeriesCompleted} = X ] ; then
291
292    printf "${Green}TimeSeriesCompleted in run.card : ${run_PostProcessing_TimeSeriesCompleted}. Do we need to change it? (AAAAMMDD) ${NoColor}"
293
294    read reponse
295    case ${reponse} in
296      0*|1*|2*|3*|4*|5*|6*|7*|8*|9*)
297        #Update run.card
298        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
299        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted "${reponse}"
300        ;;
301      *)
302        echo "Nothing to do !"
303        ;;
304    esac
305  fi
306
307else
308  echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
309fi
310
311exit 0
Note: See TracBrowser for help on using the repository browser.