source: trunk/libIGCM/AA_clean_latestPackperiod @ 1438

Last change on this file since 1438 was 1437, checked in by jgipsl, 6 years ago

For Irene:

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