source: trunk/libIGCM/AA_clean_latestPackperiod @ 1401

Last change on this file since 1401 was 1393, checked in by sdipsl, 7 years ago
  • remove TS_MO_YE creation. XIOS can handle this much better now.
  • cosmetics
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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