source: trunk/libIGCM/AA_clean_latestPackperiod @ 1517

Last change on this file since 1517 was 1464, checked in by mafoipsl, 6 years ago

Remove previous commit done for Irene.

  • 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.6 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
104PreviousPeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
105PreviousPeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
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 ${PeriodDateBegin} -1 )
214  Length=$( IGCM_date_DaysInPreviousPeriod ${PreviousPeriodDateEnd} ${config_UserChoices_PeriodLength} )
215  echo "PreviousPeriodDateEnd, Length : $Length $PreviousPeriodDateEnd"
216  PreviousPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PreviousPeriodDateEnd} -$(( Length - 1 )) )
217  echo "PreviousPeriodDateBegin PreviousPeriodDateEnd :" $PreviousPeriodDateBegin $PreviousPeriodDateEnd
218  IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth
219
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 initialize it? (y/n) ${NoColor}"
284   
285    read reponse
286    case ${reponse} in
287    oui|OUI|o|y|yes|YES)
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 ""
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.