source: trunk/libIGCM/AA_clean_month @ 712

Last change on this file since 712 was 712, checked in by aclsce, 12 years ago
  • Added TaskType? variable in jobs to specify the type of the job (computing or post-processing).
  • Added the use of TaskType? variable in Curie libsys to source the appropriate .atlas_env* configuration file.
  • Property svn:keywords set to Revision Author Date
File size: 9.9 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 month script :"
35echo "Script used to clean a month 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       ( ${DEBUG_debug} ) && IGCM_debug_Check
45. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
46       ( ${DEBUG_debug} ) && IGCM_card_Check
47. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
48       ( ${DEBUG_debug} ) && IGCM_date_Check
49#-------
50SUBMIT_DIR=$( pwd )
51. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
52. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
53
54
55#==================================
56IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
57
58for option in ${config_UserChoices[*]} ; do
59    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
60done
61
62IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post
63
64for option in ${config_Post[*]} ; do
65    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option}
66done
67
68IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Ensemble
69
70for option in ${config_Ensemble[*]} ; do
71    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Ensemble ${option}
72done
73
74IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
75IGCM_debug_PrintVariables 3 config_UserChoices_JobName
76if [ 3 -le ${Verbosity} ] ; then
77        echo "--------------Debug3-->" "config_UserChoices_LongName="
78        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
79fi
80IGCM_debug_PrintVariables 3 config_UserChoices_TagName
81IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
82IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
83IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
84IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
85IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName
86IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate
87
88#==================================
89# Define default value to keep compatibility with previous card: means before changes due to TGCC
90if [ X${PackDefault} = Xtrue ] ; then
91  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
92else
93  config_Post_PackFrequency=NONE
94fi
95
96#==================================
97# Is the pack active
98if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
99  Pack=true
100fi
101
102#====================================================
103#R_SAVE : Job output directory
104#R_BUFR : Job output buffered directory
105if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
106  FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
107  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
108    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
109    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
110  else
111    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
112    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
113  fi
114else
115  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
116    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
117    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
118  else
119    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
120    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
121  fi
122fi
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 OldPrefix
136    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
137    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
138    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
139
140    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
141    echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
142    set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
143    CountListFiles=${#ListFiles[@]}
144
145    if [ X${Pack} = Xtrue ] ; then
146      echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
147      set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
148      CountListFilesBuf=${#ListFilesBuf[@]}
149    else
150      CountListFilesBuf=0
151    fi
152
153    # If exist, erase REBUILD DIR
154    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
155    CountRebuildDir=0
156    if [ X${config_Post_RebuildFrequency} != X ] ; then
157        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
158            REBUILD_DIR=${R_SAVE}/TMP
159            set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " )
160        else
161            REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
162            set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
163        fi
164        CountRebuildDir=${#RebuildDir[@]}
165    fi
166
167    IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
168    if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
169        for file in ${ListFiles[@]} ; do
170            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
171        done
172        if [ X${Pack} = Xtrue ] ; then
173          for file in ${ListFilesBuf[@]} ; do
174            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
175          done
176        fi
177        echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
178        echo -n -e " Your answer (y/n) : \033[m"
179        read reponse
180        case ${reponse} in
181           
182            oui|OUI|o|y|yes|YES)
183                echo "OK. It will be erased."
184                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
185                if [ X${Pack} = Xtrue ] ; then
186                  IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
187                fi
188                echo "done."
189                ;;
190            non|NON|n|no|NO)
191                echo "Nothing to do !"
192                ;;
193        esac
194    fi
195
196    if [ ${CountRebuildDir} -gt 0 ] ; then
197        IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
198        for Dir in ${RebuildDir[@]} ; do
199            IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
200        done
201
202        echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
203        echo -n -e " Your answer (y/n) : \033[m"
204        read reponse
205        case ${reponse} in
206           
207            oui|OUI|o|y|yes|YES)
208                echo "OK. It will be erased."
209                if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
210                    IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;"
211                else
212                    find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
213                fi
214                echo "done."
215                ;;
216            non|NON|n|no|NO)
217                echo "Nothing to do !"
218                ;;
219        esac
220    fi
221   
222    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
223    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
224
225        echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
226        echo -n -e " Your answer (y/n) : \033[m"
227        read reponse
228        case ${reponse} in
229           
230            oui|OUI|o|y|yes|YES)
231                echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
232                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
233                ;;
234            non|NON|n|no|NO)
235                echo "Nothing to do !"
236                ;;
237        esac
238    else
239        echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
240    fi
241
242    if ( [ X${run_Configuration_CumulPeriod} = X ] || [ X${run_Configuration_CumulPeriod} = X1 ] ); then
243      echo "CumulPeriod=1 so we erase run.card to start properly."
244      IGCM_sys_Rm ${SUBMIT_DIR}/run.card
245    fi
246fi
247exit 0
Note: See TracBrowser for help on using the repository browser.