source: trunk/libIGCM/AA_clean_month @ 634

Last change on this file since 634 was 634, checked in by sdipsl, 12 years ago
  • Final tweak with respect to pack flag.
  • On titane switch nco to the nco/3.9.4_netcdf4 version (with ncap2) only when running in mono classes (short term hack waiting better option)
  • Property svn:keywords set to Revision Author Date
File size: 8.5 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_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
66IGCM_debug_PrintVariables 3 config_UserChoices_JobName
67if [ 3 -le ${Verbosity} ] ; then
68        echo "--------------Debug3-->" "config_UserChoices_LongName="
69        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
70fi
71IGCM_debug_PrintVariables 3 config_UserChoices_TagName
72IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
73IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
74IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
75IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
76
77#==================================
78# Define default value to keep compatibility with previous card: means before changes due to TGCC
79if [ X${PackDefault} = Xtrue ] ; then
80  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
81else
82  config_Post_PackFrequency=NONE
83fi
84
85#==================================
86# If pack is active then PackFrequency overule the config_UserChoices_PeriodLength
87if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
88  Pack=true
89fi
90
91#====================================================
92#R_SAVE : Job output directory
93#R_BUFR : Job output buffered directory
94if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
95    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
96    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
97    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
98else
99    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
100    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
101fi
102IGCM_sys_TestDirArchive ${R_SAVE}
103[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
104
105if [ ! -f ${SUBMIT_DIR}/run.card ]; then
106    echo "You seem NOT to have a run.card in this directory !!"
107    echo "This script will fail because it doesn't know what to do without run.card available."
108    exit 1
109else
110    #===================================#
111    #        Read updated run.card      #
112    #===================================#
113    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
114    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
115    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
116    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
117    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
118
119    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
120    echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
121    set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
122    CountListFiles=${#ListFiles[@]}
123
124    if [ X${Pack} = Xtrue ] ; then
125      echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
126      set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
127      CountListFilesBuf=${#ListFilesBuf[@]}
128    else
129      CountListFilesBuf=0
130    fi
131
132    # If exist, erase REBUILD DIR
133    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
134    CountRebuildDir=0
135    if [ X${config_Post_RebuildFrequency} != X ] ; then
136        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
137            REBUILD_DIR=${R_SAVE}/TMP
138            set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " )
139        else
140            REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
141            set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
142        fi
143        CountRebuildDir=${#RebuildDir[@]}
144    fi
145
146    IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
147    if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
148        for file in ${ListFiles[@]} ; do
149            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
150        done
151        if [ X${Pack} = Xtrue ] ; then
152          for file in ${ListFilesBuf[@]} ; do
153            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
154          done
155        fi
156        echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
157        echo -n -e " Your answer (y/n) : \033[m"
158        read reponse
159        case ${reponse} in
160           
161            oui|OUI|o|y|yes|YES)
162                echo "OK. It will be erased."
163                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
164                if [ X${Pack} = Xtrue ] ; then
165                  IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
166                fi
167                echo "done."
168                ;;
169            non|NON|n|no|NO)
170                echo "Nothing to do !"
171                ;;
172        esac
173    fi
174
175    if [ ${CountRebuildDir} -gt 0 ] ; then
176        IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
177        for Dir in ${RebuildDir[@]} ; do
178            IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
179        done
180
181        echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
182        echo -n -e " Your answer (y/n) : \033[m"
183        read reponse
184        case ${reponse} in
185           
186            oui|OUI|o|y|yes|YES)
187                echo "OK. It will be erased."
188                if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
189                    IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;"
190                else
191                    find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
192                fi
193                echo "done."
194                ;;
195            non|NON|n|no|NO)
196                echo "Nothing to do !"
197                ;;
198        esac
199    fi
200   
201    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
202    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
203        echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
204        echo -n -e " Your answer (y/n) : \033[m"
205        read reponse
206        case ${reponse} in
207           
208            oui|OUI|o|y|yes|YES)
209                echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
210                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
211                ;;
212            non|NON|n|no|NO)
213                echo "Nothing to do !"
214                ;;
215        esac
216    else
217        echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
218    fi
219fi
220exit 0
Note: See TracBrowser for help on using the repository browser.