source: tags/libIGCM_v2.2/AA_clean_month

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