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

Last change on this file since 1137 was 727, checked in by sdipsl, 12 years ago
  • use IGCM_config_CommonConfiguration
  • Property svn:keywords set to Revision Author Date
File size: 7.3 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# First of all
56#
57# Read libIGCM compatibility version in config.card
58# Read UserChoices section
59# Read Ensemble section
60# Read Post section
61# Define all netcdf output directories
62#==================================
63IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
64
65#==================================
66# Define default value to keep compatibility with previous card: means before changes due to TGCC
67if [ X${PackDefault} = Xtrue ] ; then
68  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
69else
70  config_Post_PackFrequency=NONE
71fi
72
73#==================================
74# Is the pack active
75if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
76  Pack=true
77fi
78
79IGCM_sys_TestDirArchive ${R_SAVE}
80[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
81
82if [ ! -f ${SUBMIT_DIR}/run.card ]; then
83    echo "You seem NOT to have a run.card in this directory !!"
84    echo "This script will fail because it doesn't know what to do without run.card available."
85    exit 1
86else
87    #===================================#
88    #        Read updated run.card      #
89    #===================================#
90    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
91    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
92    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
93    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
94    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
95
96    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
97    echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
98    set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
99    CountListFiles=${#ListFiles[@]}
100
101    if [ X${Pack} = Xtrue ] ; then
102      echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
103      set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
104      CountListFilesBuf=${#ListFilesBuf[@]}
105    else
106      CountListFilesBuf=0
107    fi
108
109    # If exist, erase REBUILD DIR
110    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
111    CountRebuildDir=0
112    if [ X${config_Post_RebuildFrequency} != X ] ; then
113        if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
114            REBUILD_DIR=${R_SAVE}/TMP
115            set +A RebuildDir -- $( IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" " )
116        else
117            REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
118            set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name  "*${PeriodDateBegin}*" )
119        fi
120        CountRebuildDir=${#RebuildDir[@]}
121    fi
122
123    IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
124    if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
125        for file in ${ListFiles[@]} ; do
126            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
127        done
128        if [ X${Pack} = Xtrue ] ; then
129          for file in ${ListFilesBuf[@]} ; do
130            IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
131          done
132        fi
133        echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
134        echo -n -e " Your answer (y/n) : \033[m"
135        read reponse
136        case ${reponse} in
137           
138            oui|OUI|o|y|yes|YES)
139                echo "OK. It will be erased."
140                IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
141                if [ X${Pack} = Xtrue ] ; then
142                  IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
143                fi
144                echo "done."
145                ;;
146            non|NON|n|no|NO)
147                echo "Nothing to do !"
148                ;;
149        esac
150    fi
151
152    if [ ${CountRebuildDir} -gt 0 ] ; then
153        IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
154        for Dir in ${RebuildDir[@]} ; do
155            IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
156        done
157
158        echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
159        echo -n -e " Your answer (y/n) : \033[m"
160        read reponse
161        case ${reponse} in
162           
163            oui|OUI|o|y|yes|YES)
164                echo "OK. It will be erased."
165                if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
166                    IGCM_sys_RshArchive "find ${REBUILD_DIR} -type d -name \"*${PeriodDateBegin}*\" -exec rm -Rf '{}' \;"
167                else
168                    find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
169                fi
170                echo "done."
171                ;;
172            non|NON|n|no|NO)
173                echo "Nothing to do !"
174                ;;
175        esac
176    fi
177   
178    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
179    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
180
181        echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
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. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
188                IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
189                ;;
190            non|NON|n|no|NO)
191                echo "Nothing to do !"
192                ;;
193        esac
194    else
195        echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
196    fi
197
198    if ( [ X${run_Configuration_CumulPeriod} = X ] || [ X${run_Configuration_CumulPeriod} = X1 ] ); then
199      echo "CumulPeriod=1 so we erase run.card to start properly."
200      IGCM_sys_Rm ${SUBMIT_DIR}/run.card
201    fi
202fi
203exit 0
Note: See TracBrowser for help on using the repository browser.