source: tags/libIGCM_v2.0_rc3/AA_clean_year @ 1170

Last change on this file since 1170 was 785, checked in by labetoulle, 11 years ago

Cosmetics :

  • Convert tabs into space for better lisibility with different editors.
File size: 10.4 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       ( ${DEBUG_debug} ) && IGCM_debug_Check
45. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
46       ( ${DEBUG_debug} ) && IGCM_card_Check
47. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
48       ( ${DEBUG_debug} ) && IGCM_date_Check
49#-------
50SUBMIT_DIR=$( pwd )
51. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
52. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
53
54#==================================
55# First of all
56#
57# Read libIGCM compatibility version in config.card
58# Read UserChoices section
59# Read Ensemble section
60# Read Post section
61# Define all netcdf output directories
62#==================================
63IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
64
65#==================================
66# Define default value to keep compatibility with previous card: means before changes due to TGCC
67if [ X${PackDefault} = Xtrue ] ; then
68  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
69else
70  config_Post_PackFrequency=NONE
71fi
72
73#==================================
74# Is the pack active
75if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \
76     [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
77  Pack=true
78fi
79
80IGCM_sys_TestDirArchive ${R_SAVE}
81[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
82
83if [ ! -f ${SUBMIT_DIR}/run.card ]; then
84    echo "You seem NOT to have a run.card in this directory !!"
85    echo "This script will fail because it doesn't know what to do without run.card available."
86    exit 1
87fi
88
89#===================================#
90#        Read updated run.card      #
91#===================================#
92IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
93IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
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, CumulPeriod and OldPrefix ;\n"
249  printf "   %-10s       %-10s          %6i     %s\n" \
250         $( IGCM_date_HumanDigit ${PeriodDateBegin} ) \
251         $( IGCM_date_HumanDigit ${PeriodDateEnd} ) \
252         ${NewCumulPeriod} \
253         ${config_UserChoices_JobName}_${PreviousPeriodDateEnd}
254  printf " - ScriptOutput = %s" \
255         "Script_Output_${config_UserChoices_JobName}.${Suffix}"
256  printf " Are you OK ? (y/n) ${NoColor}"
257
258  read reponse
259  case ${reponse} in
260    oui|OUI|o|y|yes|YES)
261      if ( ${RemoveRunCard} ) ; then
262        echo "CumulPeriod=1 so we erase run.card to start properly."
263        IGCM_sys_Rm ${SUBMIT_DIR}/run.card
264      else
265        # Update run.card
266        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
267        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
268        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${NewCumulPeriod}
269        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin \
270                              $( IGCM_date_HumanDigit ${PeriodDateBegin} )
271        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd \
272                              $( IGCM_date_HumanDigit ${PeriodDateEnd} )
273        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix \
274                              ${config_UserChoices_JobName}_${PreviousPeriodDateEnd}
275        # Update job
276        cp Job_${config_UserChoices_JobName} Job_${config_UserChoices_JobName}.old
277        sed -e "s/\(#.*Script_Output_${config_UserChoices_JobName}\.\)\([0-9]*\)\(.*\)/\1${Suffix}\3/" \
278            Job_${config_UserChoices_JobName} > Job_${config_UserChoices_JobName}.tmp
279        mv Job_${config_UserChoices_JobName}.tmp Job_${config_UserChoices_JobName}
280      fi
281      echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
282      ;;
283    non|NON|n|no|NO)
284      echo "Nothing to do !"
285      ;;
286  esac
287else
288  echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
289fi
290
291exit 0
Note: See TracBrowser for help on using the repository browser.