source: branches/libIGCM_CESMEP/AA_clean_latestPackperiod

Last change on this file was 1525, checked in by cetlod, 4 years ago

Update Scripts for Post-processing on Irene-Rome

  • 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.7 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#-Q- irene-amd export BRIDGE_MSUB_PROJECT=::default_project::
16
17#set -eu
18#set -vx
19
20libIGCM=::modipsl::/libIGCM
21
22#D- Task type DO NOT CHANGE (computing, post-processing or checking)
23TaskType=post-processing
24
25#D--------------------------------------------------------------------==
26#D-                   -1. User modification place
27#D--------------------------------------------------------------------==
28
29#D- Increased verbosity (1, 2, 3)
30Verbosity=3
31
32#D- Low level debug : to bypass lib test checks and stack construction
33#D- Default=true
34DEBUG_debug=false
35
36#D--------------------------------------------------------------------==
37
38echo "clean latest PackPeriod script :"
39echo "Script used to clean a Pack Period from the IGCM_OUT directory !"
40echo "This script will erase files !!! Be careful and read all informations !"
41echo "----"
42echo "It must be called in Experience directory (so-called SUBMIT_DIR)."
43echo "----"
44
45#D--------------------------------------------------------------------==
46
47. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
48. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
49. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
50#-------
51SUBMIT_DIR=$( pwd )
52. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
53. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
54#-------
55( ${DEBUG_debug} ) && IGCM_debug_Check
56( ${DEBUG_debug} ) && IGCM_card_Check
57( ${DEBUG_debug} ) && IGCM_date_Check
58
59#==================================
60# First of all
61#
62# Read libIGCM compatibility version in config.card
63# Read UserChoices section
64# Read Ensemble section
65# Read Post section
66# Define all netcdf output directories
67#==================================
68IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
69
70#==================================
71# Define default value to keep compatibility with previous card: means before changes due to TGCC
72if [ X${PackDefault} = Xtrue ] ; then
73  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
74else
75  config_Post_PackFrequency=NONE
76fi
77
78#==================================
79# Is the pack active
80if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \
81     [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
82  Pack=true
83fi
84
85IGCM_sys_TestDirArchive ${R_SAVE}
86[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
87
88if [ ! -f ${SUBMIT_DIR}/run.card ]; then
89    echo "You seem NOT to have a run.card in this directory !!"
90    echo "This script will fail because it doesn't know what to do without run.card available."
91    exit 1
92fi
93
94#===================================#
95#        Read updated run.card      #
96#===================================#
97IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
98IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
99IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
100IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
101if [ X${run_Configuration_CumulPeriod} == X ] ; then
102  ${run_Configuration_CumulPeriod} = 0
103fi
104
105PreviousPeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
106PreviousPeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
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 ${PeriodDateBegin} -1 )
215  Length=$( IGCM_date_DaysInPreviousPeriod ${PreviousPeriodDateEnd} ${config_UserChoices_PeriodLength} )
216  echo "PreviousPeriodDateEnd, Length : $Length $PreviousPeriodDateEnd"
217  PreviousPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PreviousPeriodDateEnd} -$(( Length - 1 )) )
218  echo "PreviousPeriodDateBegin PreviousPeriodDateEnd :" $PreviousPeriodDateBegin $PreviousPeriodDateEnd
219  IGCM_date_GetYearMonth ${PreviousPeriodDateEnd} PreviousPeriodYear PreviousPeriodMonth
220
221done
222
223if [ ${RemovedPeriods} == 0 ] ; then
224  echo "Nothing done, exit"
225  exit 0
226fi
227
228IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
229if ( [ ${run_Configuration_PeriodState} != "Running" ] && \
230     [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
231
232  (( NewCumulPeriod = ${run_Configuration_CumulPeriod} - ${RemovedPeriods} + 1 ))
233
234  if [ ${NewCumulPeriod} -le 1 ] ; then
235    RemoveRunCard=true
236  else
237    RemoveRunCard=false
238  fi
239
240  Suffix=$( printf '%06i' ${NewCumulPeriod} )
241
242  printf "${Green}Your run.card and Job_${config_UserChoices_JobName} will now be updated\n"
243  printf " - PeriodState = OnQueue ;\n"
244  printf " - PeriodDateBegin, PeriodDateEnd and CumulPeriod ;\n"
245  printf "   %-10s       %-10s          %6i\n" \
246         $( IGCM_date_HumanDigit ${PeriodDateBegin} ) \
247         $( IGCM_date_HumanDigit ${PeriodDateEnd} ) \
248         ${NewCumulPeriod}
249  printf " - ScriptOutput = %s" \
250         "Script_Output_${config_UserChoices_JobName}.${Suffix}"
251  printf " Are you OK ? (y/n) ${NoColor}"
252
253  read reponse
254  case ${reponse} in
255    oui|OUI|o|y|yes|YES)
256      if ( ${RemoveRunCard} ) ; then
257        echo "CumulPeriod=1 so we erase run.card to start properly."
258        IGCM_sys_Rm ${SUBMIT_DIR}/run.card
259      else
260        # Update run.card
261        cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
262        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
263        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${NewCumulPeriod}
264        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin \
265                              $( IGCM_date_HumanDigit ${PeriodDateBegin} )
266        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd \
267                              $( IGCM_date_HumanDigit ${PeriodDateEnd} )
268        # Update job
269        cp Job_${config_UserChoices_JobName} Job_${config_UserChoices_JobName}.old
270        sed -e "s/\(#.*Script_Output_${config_UserChoices_JobName}\.\)\([0-9]*\)\(.*\)/\1${Suffix}\3/" \
271            Job_${config_UserChoices_JobName} > Job_${config_UserChoices_JobName}.tmp
272        mv Job_${config_UserChoices_JobName}.tmp Job_${config_UserChoices_JobName}
273      fi
274      echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
275      ;;
276    non|NON|n|no|NO)
277      echo "Nothing to do !"
278      ;;
279  esac
280
281  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted
282  if [ ! X${run_PostProcessing_TimeSeriesCompleted} = X ] ; then
283
284    printf "${Green}TimeSeriesCompleted in run.card : ${run_PostProcessing_TimeSeriesCompleted}. Do we need to initialize it? (y/n) ${NoColor}"
285   
286    read reponse
287    case ${reponse} in
288    oui|OUI|o|y|yes|YES)
289      #Update run.card
290      cp ${SUBMIT_DIR}/run.card ${SUBMIT_DIR}/run.card.old
291      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card PostProcessing TimeSeriesCompleted ""
292      ;;
293    *)
294      echo "Nothing to do !"
295      ;;
296    esac
297  fi
298
299else
300  echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
301fi
302
303exit 0
Note: See TracBrowser for help on using the repository browser.