source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/libIGCM/AA_clean_PeriodLength @ 6031

Last change on this file since 6031 was 5899, checked in by aclsce, 3 years ago

Modified libIGCM and configuration to run XIOS ensembles.

File size: 9.0 KB
Line 
1#!/bin/ksh
2#**************************************************************
3# Author: Martial Mancip
4# Contact: Martial.Mancip__at__ipsl.jussieu.fr
5# $Revision:: 1525                                     $ Revision of last commit
6# $Author:: cetlod                                     $ Author of last commit
7# $Date:: 2020-04-27 10:39:22 +0200 (Mon, 27 Apr 2020) $ Date of last commit
8# IPSL (2006)
9#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
10#
11#**************************************************************
12# ID of your genci project. Curie only : post-processing jobs need it to run properly
13#-Q- curie export BRIDGE_MSUB_PROJECT=::default_project::
14#-Q- irene export BRIDGE_MSUB_PROJECT=::default_project::
15#-Q- irene-amd export BRIDGE_MSUB_PROJECT=::default_project::
16
17#set -eu
18#set -vx
19
20libIGCM=::modipsl::/libIGCM
21
22#D- Task type DO NOT CHANGE (computing, post-processing or checking)
23TaskType=post-processing
24
25#D--------------------------------------------------------------------==
26#D-                   -1. User modification place
27#D--------------------------------------------------------------------==
28
29#D- Increased verbosity (1, 2, 3)
30Verbosity=3
31
32#D- Low level debug : to bypass lib test checks and stack construction
33#D- Default=true
34DEBUG_debug=false
35
36#D--------------------------------------------------------------------==
37
38echo "clean PeriodLenght script :"
39echo "Script used to clean a PeriodLength from the IGCM_OUT directory !"
40echo "This script will erase files !!! Be careful and read all informations !"
41echo "----"
42echo "It must be called in Experience directory (so-called SUBMIT_DIR)."
43echo "----"
44
45#D--------------------------------------------------------------------==
46
47. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
48. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
49. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
50#-------
51SUBMIT_DIR=$( pwd )
52. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
53. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
54#-------
55( ${DEBUG_debug} ) && IGCM_debug_Check
56( ${DEBUG_debug} ) && IGCM_card_Check
57( ${DEBUG_debug} ) && IGCM_date_Check
58
59#==================================
60# First of all
61#
62# Read libIGCM compatibility version in config.card
63# Read UserChoices section
64# Read Ensemble section
65# Read Post section
66# Define all netcdf output directories
67#==================================
68IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
69
70#==================================
71# Define default value to keep compatibility with previous card: means before changes due to TGCC
72if [ X${PackDefault} = Xtrue ] ; then
73  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
74else
75  config_Post_PackFrequency=NONE
76fi
77
78#==================================
79# Is the pack active
80if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
81  Pack=true
82fi
83
84IGCM_sys_TestDirArchive ${R_SAVE}
85[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
86
87if [ ! -f ${SUBMIT_DIR}/run.card ]; then
88  echo "You seem NOT to have a run.card in this directory !!"
89  echo "This script will fail because it doesn't know what to do without run.card available."
90  exit 1
91else
92  #===================================#
93  #        Read updated run.card      #
94  #===================================#
95  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
96  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
97  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
98  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
99
100  #
101  if [ X${run_Configuration_CumulPeriod} = X ] ; then
102    echo -e "\033[1;32mCumulPeriod is empty so we want to erase run.card to start properly. Do you want that?"
103    echo -n -e " Your answer (y/n) : \033[m"
104    read reponse
105    case ${reponse} in
106
107    oui|OUI|o|y|yes|YES)
108      echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
109      IGCM_sys_Rm ${SUBMIT_DIR}/run.card
110      ;;
111    non|NON|n|no|NO)
112      echo "Nothing to do !"
113      ;;
114    esac
115    exit 0
116  fi
117
118  PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
119  echo "Search files with ${PeriodDateEnd} in ${R_SAVE}"
120  set +A ListFiles -- $( IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" " )
121  CountListFiles=${#ListFiles[@]}
122
123  if [ X${Pack} = Xtrue ] ; then
124    echo "Search files with ${PeriodDateEnd} in ${R_BUFR}"
125    set +A ListFilesBuf -- $( IGCM_sys_RshMaster "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" " )
126    CountListFilesBuf=${#ListFilesBuf[@]}
127  else
128    CountListFilesBuf=0
129  fi
130
131  # If exist, erase REBUILD DIR
132  PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
133  CountRebuildDir=0
134  if [ X${config_Post_RebuildFrequency} != X ] ; then
135    set +A RebuildDir -- $( find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" )
136    CountRebuildDir=${#RebuildDir[@]}
137  fi
138
139  IGCM_debug_Print 1 "Number of files to be erased : ${CountListFiles}."
140  if ( [ ${CountListFiles} -gt 0 ] || [ ${CountListFilesBuf} -gt 0 ] ) ; then
141    for file in ${ListFiles[@]} ; do
142      IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
143    done
144    if [ X${Pack} = Xtrue ] ; then
145      for file in ${ListFilesBuf[@]} ; do
146        IGCM_debug_Print 2 -e "\033[1;31m ${file}\033[m"
147      done
148    fi
149    echo -e "\033[1;32mDo you REALLY want to erase all those files ?"
150    echo -n -e " Your answer (y/n) : \033[m"
151    read reponse
152    case ${reponse} in
153
154      oui|OUI|o|y|yes|YES)
155        echo "OK. It will be erased."
156        IGCM_sys_RshArchive "find ${R_SAVE} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
157        if [ X${Pack} = Xtrue ] ; then
158          IGCM_sys_RshMaster  "find ${R_BUFR} -name \"*${PeriodDateEnd}*\" -exec rm -f '{}' \;"
159        fi
160        echo "done."
161        ;;
162      non|NON|n|no|NO)
163        echo "Nothing to do !"
164        ;;
165    esac
166  fi
167
168  if [ ${CountRebuildDir} -gt 0 ] ; then
169    IGCM_debug_Print 1 "Number of REBUILD Dirs to be erased : ${CountRebuildDir}."
170    for Dir in ${RebuildDir[@]} ; do
171      IGCM_debug_Print 2 -e "\033[1;31m ${Dir}\033[m"
172    done
173
174    echo -e "\033[1;32mDo you REALLY want to erase all those Directories ?"
175    echo -n -e " Your answer (y/n) : \033[m"
176    read reponse
177    case ${reponse} in
178
179      oui|OUI|o|y|yes|YES)
180        echo "OK. It will be erased."
181        find ${REBUILD_DIR} -type d -name "*${PeriodDateBegin}*" -exec rm -Rf '{}' \;
182        echo "done."
183        ;;
184      non|NON|n|no|NO)
185        echo "Nothing to do !"
186        ;;
187    esac
188  fi
189
190  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
191  if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
192
193    echo -e "\033[1;32mNOW do you want to continue the simulation (Set PeriodState=OnQueue into run.card) ?"
194    echo -n -e " Your answer (y/n) : \033[m"
195    read reponse
196    case ${reponse} in
197
198      oui|OUI|o|y|yes|YES)
199        echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
200        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
201        ;;
202      non|NON|n|no|NO)
203        echo "Nothing to do !"
204        ;;
205    esac
206  else
207    echo "You can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
208  fi
209
210  if [ X${run_Configuration_CumulPeriod} = X1 ] ; then
211    echo -e "\033[1;32mCumulPeriod=1 so we want to erase run.card to start properly. Do you want that too?"
212    echo -n -e " Your answer (y/n) : \033[m"
213    read reponse
214    case ${reponse} in
215
216      oui|OUI|o|y|yes|YES)
217        echo "OK. Now you can submit the Job : ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}."
218        IGCM_sys_Rm ${SUBMIT_DIR}/run.card
219        ;;
220      non|NON|n|no|NO)
221        echo "Nothing to do !"
222        ;;
223    esac
224  else
225    # if not first period
226    Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
227    Script_Output_Job=${Script_Output_Prefix}_${config_UserChoices_JobName}
228    Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${run_Configuration_CumulPeriod} )
229
230    echo -e "\033[1;32mDo you want to change the number in Script_Output? (${Script_Output} into Job) ?"
231    echo -n -e " Your answer (y/n) : \033[m"
232    read reponse
233    case ${reponse} in
234
235      oui|OUI|o|y|yes|YES)
236        cp ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$
237        sed -e"s/${Script_Output_Job}.[0-9][0-9][0-9][0-9][0-9][0-9]/${Script_Output}/"  ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}_SAVED_$$  >${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
238        echo "Job : Job_${config_UserChoices_JobName} modified."
239        echo "Old job saved here : Job_${config_UserChoices_JobName}_SAVED_$$"
240        ;;
241      non|NON|n|no|NO)
242        echo "Nothing done in Job_${config_UserChoices_JobName} !"
243        ;;
244    esac
245
246  fi
247fi
248exit 0
Note: See TracBrowser for help on using the repository browser.