source: tags/libIGCM_v2.5/AA_clean_year @ 1456

Last change on this file since 1456 was 1059, checked in by sdipsl, 10 years ago
  • Attach the licence when it is not the case
  • 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.3 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    set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
150    CountRebuildDir=${#RebuildDir[@]}
151  fi
152
153
154  if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
155    IGCM_debug_Print 1 "Number of files to be erased from ${R_SAVE} : ${CountListFiles}."
156    for file in ${ListFiles[@]} ; do
157      IGCM_debug_Print 2 -e "${Red} ${file}${NoColor}"
158    done
159    if [ X${Pack} = Xtrue ] ; then
160      IGCM_debug_Print 1 "Number of files to be erased from ${R_BUFR} : ${CountListFilesBuf}."
161      for file in ${ListFilesBuf[@]} ; do
162        IGCM_debug_Print 2 -e "${Red} ${file}${NoColor}"
163      done
164    fi
165
166    echo -e "${Green}Do you REALLY want to erase all those files ?"
167    echo -n -e " Your answer (y/n) : ${NoColor}"
168
169    read reponse
170    case ${reponse} in
171      oui|OUI|o|y|yes|YES)
172        echo "OK. It will be erased."
173        IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
174        if [ X${Pack} = Xtrue ] ; then
175          IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
176        fi
177        echo "done."
178        ;;
179      non|NON|n|no|NO)
180        echo "Nothing to do !"
181        ;;
182    esac
183  fi
184
185  if [ ${CountRebuildDir} -gt 0 ] ; then
186    IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
187    for Dir in ${RebuildDir[@]} ; do
188      IGCM_debug_Print 2 -e "${Red} ${Dir}${NoColor}"
189    done
190
191    echo -e "${Green}Do you REALLY want to erase all those Directories ?"
192    echo -n -e " Your answer (y/n) : ${NoColor}"
193
194    read reponse
195    case ${reponse} in
196
197      oui|OUI|o|y|yes|YES)
198        echo "OK. It will be erased."       
199        find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
200        echo "done."
201        ;;
202      non|NON|n|no|NO)
203        echo "Nothing to do !"
204        ;;
205    esac
206  fi
207
208  (( RemovedPeriods = ${RemovedPeriods} + 1 ))
209
210  # Get previous period begin and end dates
211  PreviousPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} \
212                               -$( IGCM_date_DaysInMonth ${PeriodYear} ${PeriodMonth} ) )
213  IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth
214
215  PreviousPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} \
216                         -$( IGCM_date_DaysInMonth ${PreviousPeriodYear} ${PreviousPeriodMonth} ) )
217done
218
219if [ ${RemovedPeriods} == 0 ] ; then
220  echo "Nothing done, exit"
221  exit 0
222fi
223
224IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
225if ( [ ${run_Configuration_PeriodState} != "Running" ] && \
226     [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
227
228  (( NewCumulPeriod = ${run_Configuration_CumulPeriod} - ${RemovedPeriods} + 1 ))
229
230  if [ ${NewCumulPeriod} -le 1 ] ; then
231    RemoveRunCard=true
232  else
233    RemoveRunCard=false
234  fi
235
236  Suffix=$( printf '%06i' ${NewCumulPeriod} )
237
238  printf "${Green}Your run.card and Job_${config_UserChoices_JobName} will now be updated\n"
239  printf " - PeriodState = OnQueue ;\n"
240  printf " - PeriodDateBegin, PeriodDateEnd and CumulPeriod ;\n"
241  printf "   %-10s       %-10s          %6i\n" \
242         $( IGCM_date_HumanDigit ${PeriodDateBegin} ) \
243         $( IGCM_date_HumanDigit ${PeriodDateEnd} ) \
244         ${NewCumulPeriod}
245  printf " - ScriptOutput = %s" \
246         "Script_Output_${config_UserChoices_JobName}.${Suffix}"
247  printf " Are you OK ? (y/n) ${NoColor}"
248
249  read reponse
250  case ${reponse} in
251    oui|OUI|o|y|yes|YES)
252      if ( ${RemoveRunCard} ) ; then
253        echo "CumulPeriod=1 so we erase run.card to start properly."
254        IGCM_sys_Rm ${SUBMIT_DIR}/run.card
255      else
256        # Update run.card
257        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
258        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
259        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${NewCumulPeriod}
260        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin \
261                              $( IGCM_date_HumanDigit ${PeriodDateBegin} )
262        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd \
263                              $( IGCM_date_HumanDigit ${PeriodDateEnd} )
264        # Update job
265        cp Job_${config_UserChoices_JobName} Job_${config_UserChoices_JobName}.old
266        sed -e "s/\(#.*Script_Output_${config_UserChoices_JobName}\.\)\([0-9]*\)\(.*\)/\1${Suffix}\3/" \
267            Job_${config_UserChoices_JobName} > Job_${config_UserChoices_JobName}.tmp
268        mv Job_${config_UserChoices_JobName}.tmp Job_${config_UserChoices_JobName}
269      fi
270      echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
271      ;;
272    non|NON|n|no|NO)
273      echo "Nothing to do !"
274      ;;
275  esac
276
277  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted
278  if [ ! X${run_PostProcessing_TimeSeriesCompleted} = X ] ; then
279
280    printf "${Green}TimeSeriesCompleted in run.card : ${run_PostProcessing_TimeSeriesCompleted}. Do we need to change it? (AAAAMMDD) ${NoColor}"
281
282    read reponse
283    case ${reponse} in
284      0*|1*|2*|3*|4*|5*|6*|7*|8*|9*)
285        #Update run.card
286        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
287        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted "${reponse}"
288        ;;
289      *)
290        echo "Nothing to do !"
291        ;;
292    esac
293  fi
294
295else
296  echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
297fi
298
299exit 0
Note: See TracBrowser for help on using the repository browser.