source: tags/libIGCM_v1_5/AA_clean_month @ 1170

Last change on this file since 1170 was 225, checked in by mmaipsl, 14 years ago

Script to erase all file from the present month in R_SAVE
and change run.card PeriodState? to "Running".

File size: 4.5 KB
Line 
1#!/usr/bin/ksh
2
3# $Date: $
4# $Author: $
5# $Revision: $
6# IPSL (2006)
7#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
8
9#set -eu
10#set -vx
11
12libIGCM=::modipsl::/libIGCM
13
14#D--------------------------------------------------------------------==
15#D-                   -1. User modification place
16#D--------------------------------------------------------------------==
17
18#D- Increased verbosity (1, 2, 3)
19Verbosity=3
20
21#D- Low level debug : to bypass lib test checks and stack construction
22#D- Default=true
23DEBUG_debug=false
24
25#D--------------------------------------------------------------------==
26
27echo "clean month script :"
28echo "Script used to clean a month on SAVE directory !"
29echo "This script will erase some files !!! Be careful and read all informations !"
30echo "----"
31echo "It must be called in Experience directory (so-called SUBMIT_DIR)."
32echo "----"
33
34#D--------------------------------------------------------------------==
35
36. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
37       ( ${DEBUG_debug} ) && IGCM_debug_Check
38. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
39       ( ${DEBUG_debug} ) && IGCM_card_Check
40. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
41       ( ${DEBUG_debug} ) && IGCM_date_Check
42#-------
43SUBMIT_DIR=${pwd}
44. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
45. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
46
47
48#==================================
49IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
50
51for option in ${config_UserChoices[*]} ; do
52    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
53done
54
55IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
56IGCM_debug_PrintVariables 3 config_UserChoices_JobName
57if [ 3 -le ${Verbosity} ] ; then
58        echo "--------------Debug3-->" "config_UserChoices_LongName="
59        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
60fi
61IGCM_debug_PrintVariables 3 config_UserChoices_TagName
62IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
63IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
64IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
65IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
66
67#====================================================
68#R_SAVE : Job output directory
69R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
70IGCM_sys_TestDirArchive ${R_SAVE}
71[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
72
73if [ ! -f ${SUBMIT_DIR}/run.card ]; then
74    echo "You seem NOT to have a run.card in this directory !!"
75    echo "This script will fail because it doesn't know what to do without run.card avaible."
76    exit 1
77else
78    #===================================#
79    #        Read updated run.card      #
80    #===================================#
81    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
82    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
83    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
84    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
85    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
86
87    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
88    CountListFiles=$( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\"" | wc -l)
89    IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -ls"
90
91    echo "Number of files to be erased : ${CountListFiles}."
92    if [ ${CountListFiles} -gt 0 ] ; then
93        echo "Do you REALLY want to erase all those files ?"
94        echo -n " Your answer (y/n) : "
95        read reponse
96        case ${reponse} in
97           
98            oui|OUI|o|y|yes|YES)
99                echo "OK. It will be erased."
100                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
101                echo "done."
102                ;;
103            non|NON|n|no|NO)
104                echo "Nothing to do !"
105                ;;
106        esac
107    fi
108   
109    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
110    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
111        echo "NOW do you to run again (clean run.card) ?"
112        echo -n " Your answer (y/n) : "
113        read reponse
114        case ${reponse} in
115           
116            oui|OUI|o|y|yes|YES)
117                echo "OK. Now you can run."
118                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
119                ;;
120            non|NON|n|no|NO)
121                echo "Nothing to do !"
122                ;;
123        esac
124    else
125        echo "Job can run."
126    fi
127fi
128exit 0
Note: See TracBrowser for help on using the repository browser.