source: branches/libIGCM_MPI_OpenMP/AA_clean_month @ 593

Last change on this file since 593 was 571, checked in by mafoipsl, 12 years ago

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

  • Property svn:keywords set to Revision Author Date
File size: 7.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
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#R_SAVE : Job output directory
79#R_BUFR : Job output buffered directory
80if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
81    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
82    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
83    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
84else
85    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
86    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
87fi
88IGCM_sys_TestDirArchive ${R_SAVE}
89[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
90
91if [ ! -f ${SUBMIT_DIR}/run.card ]; then
92    echo "You seem NOT to have a run.card in this directory !!"
93    echo "This script will fail because it doesn't know what to do without run.card available."
94    exit 1
95else
96    #===================================#
97    #        Read updated run.card      #
98    #===================================#
99    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
100    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
101    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
102    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
103    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
104
105    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
106    echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
107    set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
108    CountListFiles=${#ListFiles[@]}
109
110    echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
111    set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
112    CountListFilesBuf=${#ListFilesBuf[@]}
113
114    # If exist, erase REBUILD DIR
115    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
116    CountRebuildDir=0
117    if [ X${config_Post_RebuildFrequency} != X ] ; then
118        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
119            REBUILD_DIR=${R_SAVE}/TMP
120            set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " )
121        else
122            REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
123            set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
124        fi
125        CountRebuildDir=${#RebuildDir[@]}
126    fi
127
128    IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
129    if [ ${CountListFiles} -gt 0 ] ; then
130        for file in ${ListFiles[@]} ; do
131            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
132        done
133        for file in ${ListFilesBuf[@]} ; do
134            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
135        done
136
137        echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
138        echo -n -e " Your answer (y/n) : \033[m"
139        read reponse
140        case ${reponse} in
141           
142            oui|OUI|o|y|yes|YES)
143                echo "OK. It will be erased."
144                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
145                IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
146                echo "done."
147                ;;
148            non|NON|n|no|NO)
149                echo "Nothing to do !"
150                ;;
151        esac
152    fi
153
154    if [ ${CountRebuildDir} -gt 0 ] ; then
155        IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
156        for Dir in ${RebuildDir[@]} ; do
157            IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
158        done
159
160        echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
161        echo -n -e " Your answer (y/n) : \033[m"
162        read reponse
163        case ${reponse} in
164           
165            oui|OUI|o|y|yes|YES)
166                echo "OK. It will be erased."
167                if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
168                    IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;"
169                else
170                    find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
171                fi
172                echo "done."
173                ;;
174            non|NON|n|no|NO)
175                echo "Nothing to do !"
176                ;;
177        esac
178    fi
179   
180    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
181    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
182        echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
183        echo -n -e " Your answer (y/n) : \033[m"
184        read reponse
185        case ${reponse} in
186           
187            oui|OUI|o|y|yes|YES)
188                echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
189                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
190                ;;
191            non|NON|n|no|NO)
192                echo "Nothing to do !"
193                ;;
194        esac
195    else
196        echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
197    fi
198fi
199exit 0
Note: See TracBrowser for help on using the repository browser.