source: branches/libIGCM_CESMEP/AA_clean_or_continue

Last change on this file was 1585, checked in by ssenesi, 11 months ago

merge branch libIGCM_CESMEP with trunk that handles RedHat8 on Irene

File size: 10.7 KB
Line 
1#!/bin/ksh
2#**************************************************************
3# Author: Martial Mancip
4# Contact: Martial.Mancip__at__ipsl.jussieu.fr
5# $Revision:: 1575                                     $ Revision of last commit
6# $Author:: jgipsl                                     $ Author of last commit
7# $Date:: 2023-02-16 11:56:52 +0100 (Thu, 16 Feb 2023) $ 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--------------------------------------------------------------------==
37echo ""
38echo "clean_or_continue.job "
39if  [ $# -gt 0 ] ; then
40    # Print help and exit
41    echo ""
42    echo "The script is called from in the your experiment directory, the so-called SUBMIT_DIR, in the following way"
43    echo "../../../libIGCM/clean_or_continue.job -h      : to print following information"
44    echo "../../../libIGCM/clean_or_continue.job         : normal execution"
45    echo ""
46    echo "This script can be used for 3 cases:"
47    echo "1- The simulation crashed and you have PeriodState=Fatal in run.card."
48    echo "For this case, all output from the current PeriodLength set in run.card will be deleted. "
49    echo "You need to answer yes to the questions."
50    echo ""
51    echo "2- The simulation stopped due to an exceeded time limit, PeriodState=Running in run.card".
52    echo "As for case 1, all output from the current PeriodLength will be deleted and you should answer yes to questions".
53    echo ""
54    echo "3- The simulation is completed but you want to continue it, PeriodState=Completed in run.card."
55    echo "For this case, you just need to change DateEnd in config.card and launch this script."
56    echo ""
57    echo "For all cases, the run.card is changed as needed and the number for the current period is set in the main Job_ for the Script_Output_ file"
58    echo ""
59    echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions."
60    echo ""
61
62    exit
63fi
64echo ""
65echo "This script needs to delete files to work correctly. Therefore you should answer yes to the questions."
66echo "Use ../../../libIGCM/clean_or_contine.job -h  for more information"
67echo ""
68
69#D--------------------------------------------------------------------==
70
71. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
72. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
73. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
74#-------
75SUBMIT_DIR=$( pwd )
76. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
77. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
78#-------
79( ${DEBUG_debug} ) && IGCM_debug_Check
80( ${DEBUG_debug} ) && IGCM_card_Check
81( ${DEBUG_debug} ) && IGCM_date_Check
82
83clean_CESMEP()
84{
85    IGCM_card_DefineVariableFromOption ${prefix}config.card Post Cesmep
86    if [ ${config_Post_Cesmep} != FALSE ]; then
87        echo -e "\033[1;32mDo you want to erase the CESMEP atlas and dedicated CliMAF cache) ?"
88        echo -n -e " Your answer (y/n) : \033[m"
89        read reponse
90        case ${reponse} in
91            oui|OUI|o|y|yes|YES)
92                $SUBMIT_DIR/cesmep_lite/libIGCM_clean.sh
93                ;;
94        esac 
95    fi
96}
97
98#==================================
99# First of all
100#
101# Read libIGCM compatibility version in config.card
102# Read UserChoices section
103# Read Ensemble section
104# Read Post section
105# Define all netcdf output directories
106#==================================
107IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
108
109#==================================
110# Define default value to keep compatibility with previous card: means before changes due to TGCC
111if [ X${PackDefault} = Xtrue ] ; then
112  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
113else
114  config_Post_PackFrequency=NONE
115fi
116
117#==================================
118# Is the pack active
119if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
120  Pack=true
121fi
122
123IGCM_sys_TestDirArchive ${R_SAVE}
124[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
125
126if [ ! -f ${SUBMIT_DIR}/run.card ]; then
127  echo "You seem NOT to have a run.card in this directory !!"
128  echo "This script will fail because it doesn't know what to do without run.card available."
129  exit 1
130else
131  #===================================#
132  #        Read updated run.card      #
133  #===================================#
134  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
135  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
136  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
137  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
138
139  #
140  if [ X${run_Configuration_CumulPeriod} = X ] ; then
141    echo -e "\033[1;32mCumulPeriod is empty so we want to erase run.card to start properly. Do you want that?"
142    echo -n -e " Your answer (y/n) : \033[m"
143    read reponse
144    case ${reponse} in
145
146    oui|OUI|o|y|yes|YES)
147      echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
148      IGCM_sys_Rm ${SUBMIT_DIR}/run.card
149      ;;
150    non|NON|n|no|NO)
151      echo "Nothing to do !"
152      ;;
153    esac
154    clean_CESMEP
155    exit 0
156  fi
157
158  PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
159  echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
160  set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
161  CountListFiles=${#ListFiles[@]}
162
163  if [ X${Pack} = Xtrue ] ; then
164    echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
165    set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
166    CountListFilesBuf=${#ListFilesBuf[@]}
167  else
168    CountListFilesBuf=0
169  fi
170
171  # If exist, erase REBUILD DIR
172  PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
173  CountRebuildDir=0
174  if [ X${config_Post_RebuildFrequency} != X ] ; then
175    set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" )
176    CountRebuildDir=${#RebuildDir[@]}
177  fi
178
179  IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
180  if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
181    for file in ${ListFiles[@]} ; do
182      IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
183    done
184    if [ X${Pack} = Xtrue ] ; then
185      for file in ${ListFilesBuf[@]} ; do
186        IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
187      done
188    fi
189    echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
190    echo -n -e " Your answer (y/n) : \033[m"
191    read reponse
192    case ${reponse} in
193
194      oui|OUI|o|y|yes|YES)
195        echo "OK. It will be erased."
196        IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
197        if [ X${Pack} = Xtrue ] ; then
198          IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
199        fi
200        echo "done."
201        ;;
202      non|NON|n|no|NO)
203        echo "Nothing to do !"
204        ;;
205    esac
206  fi
207
208  if [ ${CountRebuildDir} -gt 0 ] ; then
209    IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
210    for Dir in ${RebuildDir[@]} ; do
211      IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
212    done
213
214    echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
215    echo -n -e " Your answer (y/n) : \033[m"
216    read reponse
217    case ${reponse} in
218
219      oui|OUI|o|y|yes|YES)
220        echo "OK. It will be erased."
221        find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
222        echo "done."
223        ;;
224      non|NON|n|no|NO)
225        echo "Nothing to do !"
226        ;;
227    esac
228  fi
229
230  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
231  if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
232
233    echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
234    echo -n -e " Your answer (y/n) : \033[m"
235    read reponse
236    case ${reponse} in
237
238      oui|OUI|o|y|yes|YES)
239        echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
240        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
241        ;;
242      non|NON|n|no|NO)
243        echo "Nothing to do !"
244        ;;
245    esac
246  else
247    echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
248  fi
249
250  if [ X${run_Configuration_CumulPeriod} = X1 ] ; then
251    echo -e "\033[1;32mCumulPeriod=1 so we want to erase run.card to start properly. Do you want that too?"
252    echo -n -e " Your answer (y/n) : \033[m"
253    read reponse
254    case ${reponse} in
255
256      oui|OUI|o|y|yes|YES)
257        echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
258        IGCM_sys_Rm ${SUBMIT_DIR}/run.card
259        ;;
260      non|NON|n|no|NO)
261        echo "Nothing to do !"
262        ;;
263    esac
264  else
265    # if not first period
266    Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
267    Script_Output_Job=${Script_Output_Prefix}_${config_UserChoices_JobName}
268    Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${run_Configuration_CumulPeriod} )
269
270    echo -e "\033[1;32mDo you want to change the number in Script_Output? (${Script_Output} into Job) ?"
271    echo -n -e " Your answer (y/n) : \033[m"
272    read reponse
273    case ${reponse} in
274
275      oui|OUI|o|y|yes|YES)
276        cp ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$
277        sed -e"s/${Script_Output_Job}.[0-9][0-9][0-9][0-9][0-9][0-9]/${Script_Output}/"  ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$  >${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
278        echo "Job : Job_${config_UserChoices_JobName} modified."
279        echo "Old job saved here : Job_${config_UserChoices_JobName}_SAVED_$$"
280        ;;
281      non|NON|n|no|NO)
282        echo "Nothing done in Job_${config_UserChoices_JobName} !"
283        ;;
284    esac
285
286  fi
287fi
288exit 0
Note: See TracBrowser for help on using the repository browser.