source: tags/libIGCM_v2.0_beta3/AA_clean_month @ 1137

Last change on this file since 1137 was 658, checked in by labetoulle, 12 years ago

Add Ensemble functionality to libIGCM - First step :
modify output directories according to an option in section [Ensemble]
in config.card (modification of config.card yet to be done).

  • Property svn:keywords set to Revision Author Date
File size: 9.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
13#set -eu
14#set -vx
15
16libIGCM=::modipsl::/libIGCM
17
18#D--------------------------------------------------------------------==
19#D-                   -1. User modification place
20#D--------------------------------------------------------------------==
21
22#D- Increased verbosity (1, 2, 3)
23Verbosity=3
24
25#D- Low level debug : to bypass lib test checks and stack construction
26#D- Default=true
27DEBUG_debug=false
28
29#D--------------------------------------------------------------------==
30
31echo "clean month script :"
32echo "Script used to clean a month on SAVE directory !"
33echo "This script will erase some files !!! Be careful and read all informations !"
34echo "----"
35echo "It must be called in Experience directory (so-called SUBMIT_DIR)."
36echo "----"
37
38#D--------------------------------------------------------------------==
39
40. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
41       ( ${DEBUG_debug} ) && IGCM_debug_Check
42. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
43       ( ${DEBUG_debug} ) && IGCM_card_Check
44. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
45       ( ${DEBUG_debug} ) && IGCM_date_Check
46#-------
47SUBMIT_DIR=$( pwd )
48. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
49. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
50
51
52#==================================
53IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
54
55for option in ${config_UserChoices[*]} ; do
56    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
57done
58
59IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post
60
61for option in ${config_Post[*]} ; do
62    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option}
63done
64
65IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Ensemble
66
67for option in ${config_Ensemble[*]} ; do
68    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Ensemble ${option}
69done
70
71IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
72IGCM_debug_PrintVariables 3 config_UserChoices_JobName
73if [ 3 -le ${Verbosity} ] ; then
74        echo "--------------Debug3-->" "config_UserChoices_LongName="
75        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
76fi
77IGCM_debug_PrintVariables 3 config_UserChoices_TagName
78IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
79IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
80IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
81IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
82IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName
83IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate
84
85#==================================
86# Define default value to keep compatibility with previous card: means before changes due to TGCC
87if [ X${PackDefault} = Xtrue ] ; then
88  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
89else
90  config_Post_PackFrequency=NONE
91fi
92
93#==================================
94# Is the pack active
95if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
96  Pack=true
97fi
98
99#====================================================
100#R_SAVE : Job output directory
101#R_BUFR : Job output buffered directory
102if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
103  FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
104  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
105    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
106    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
107  else
108    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
109    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
110  fi
111else
112  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
113    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
114    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
115  else
116    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
117    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
118  fi
119fi
120IGCM_sys_TestDirArchive ${R_SAVE}
121[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
122
123if [ ! -f ${SUBMIT_DIR}/run.card ]; then
124    echo "You seem NOT to have a run.card in this directory !!"
125    echo "This script will fail because it doesn't know what to do without run.card available."
126    exit 1
127else
128    #===================================#
129    #        Read updated run.card      #
130    #===================================#
131    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
132    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
133    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
134    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
135    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
136
137    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
138    echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
139    set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
140    CountListFiles=${#ListFiles[@]}
141
142    if [ X${Pack} = Xtrue ] ; then
143      echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
144      set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
145      CountListFilesBuf=${#ListFilesBuf[@]}
146    else
147      CountListFilesBuf=0
148    fi
149
150    # If exist, erase REBUILD DIR
151    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
152    CountRebuildDir=0
153    if [ X${config_Post_RebuildFrequency} != X ] ; then
154        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
155            REBUILD_DIR=${R_SAVE}/TMP
156            set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " )
157        else
158            REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
159            set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
160        fi
161        CountRebuildDir=${#RebuildDir[@]}
162    fi
163
164    IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
165    if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
166        for file in ${ListFiles[@]} ; do
167            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
168        done
169        if [ X${Pack} = Xtrue ] ; then
170          for file in ${ListFilesBuf[@]} ; do
171            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
172          done
173        fi
174        echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
175        echo -n -e " Your answer (y/n) : \033[m"
176        read reponse
177        case ${reponse} in
178           
179            oui|OUI|o|y|yes|YES)
180                echo "OK. It will be erased."
181                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
182                if [ X${Pack} = Xtrue ] ; then
183                  IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
184                fi
185                echo "done."
186                ;;
187            non|NON|n|no|NO)
188                echo "Nothing to do !"
189                ;;
190        esac
191    fi
192
193    if [ ${CountRebuildDir} -gt 0 ] ; then
194        IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
195        for Dir in ${RebuildDir[@]} ; do
196            IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
197        done
198
199        echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
200        echo -n -e " Your answer (y/n) : \033[m"
201        read reponse
202        case ${reponse} in
203           
204            oui|OUI|o|y|yes|YES)
205                echo "OK. It will be erased."
206                if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
207                    IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;"
208                else
209                    find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
210                fi
211                echo "done."
212                ;;
213            non|NON|n|no|NO)
214                echo "Nothing to do !"
215                ;;
216        esac
217    fi
218   
219    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
220    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
221        echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
222        echo -n -e " Your answer (y/n) : \033[m"
223        read reponse
224        case ${reponse} in
225           
226            oui|OUI|o|y|yes|YES)
227                echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
228                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
229                ;;
230            non|NON|n|no|NO)
231                echo "Nothing to do !"
232                ;;
233        esac
234    else
235        echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
236    fi
237fi
238exit 0
Note: See TracBrowser for help on using the repository browser.