source: modipsl/trunk/util/ins_job @ 2008

Last change on this file since 2008 was 1908, checked in by sdipsl, 12 years ago
  • little adjustement for ensemble handling
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1#!/bin/ksh
2# $Id$
3#---------------------------------------------------------------------
4#- Installation of jobs according to an environment
5#---------------------------------------------------------------------
6function ins_job_Usage
7{
8print - "
9ins_job installs the jobs in the directories
10which contain a file config.card
11
12ins_job must be launched on the host
13on which the job will be submitted
14
15Usage :
16  ${b_n} [-h] [-v] [-e]
17
18Options :
19  -h   : help
20  -v   : verbose mode
21  -e   : turn on hindcast/forecast ensemble mode
22"
23}
24function ins_job_Warning
25{
26   [[ ${x_v} = 'verbose' ]] && print - "\n############### WARNING ###############";
27   [[ ${x_v} = 'verbose' ]] && print - "File ${n_f} already exists\nin directory ${j}";
28   [[ ${x_v} = 'verbose' ]] && print - "You must delete this file to update !";
29}
30#-
31#     dirname     and      basename
32#-
33d_n=$(dirname ${0}); b_n=$(basename ${0});
34#-
35# Retrieving and validation of the options
36#-
37x_v='silencious';
38x_e=false;
39while getopts :hve V ; do
40  case $V in
41  (h)  ins_job_Usage; exit 0;;
42  (v)  x_v='verbose';;
43  (e)  x_e=true;;
44  (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
45  exit 2;;
46  (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
47  exit 2;;
48  esac
49done
50[ ${x_v} = 'silencious' ] && export DEBUG_sys=false
51shift $(($OPTIND-1));
52#-
53# Define working files
54#-
55F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
56# [[ ${F_MOD##*/} != 'modipsl' ]] && \
57#  { print - "directory 'modipsl' unreachable"; exit 3; }
58W_W=${d_n}'/../libIGCM'
59[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
60libIGCM=$(cd ${W_W};/bin/pwd;)
61F_JOB=${libIGCM}'/AA_job';
62[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
63F_RCI=${libIGCM}'/run.card.init';
64[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
65#-
66# Host Name
67#-
68x_t=$(${d_n}/w_i_h) 2>/dev/null;
69{ [[ ${?} != 0 ]] && \
70   { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \
71  [[ ${x_t} = "Unknown" ]] && \
72   { print - "\nLocal_Host not supported\n" 1>&2; exit 1; };
73#-
74W_W=$(sed -n -e "s/^#-Q-  *\([^ ]*\).*$/\1/p" ${F_JOB} | \
75       sort -u | sed -e "/${x_t}/!d");
76[[ '\?'"${W_W}" != '\?'${x_t} ]] && \
77  {
78   print - "\nHost  "${x_t}"  not supported" 1>&2;
79   print - "'default' will be used" 1>&2;
80   x_t='default'
81  }
82#-
83[[ ${x_v} = 'verbose' ]] && \
84 {
85  print - "";
86  print - '--- Host        : '${x_t};
87  print - '--- modipsl     : '${F_MOD};
88  print - '--- libIGCM     : '${libIGCM};
89  print - '--- basic job   : '${F_JOB};
90  print - '--- basic card  : '${F_RCI};
91 }
92#-
93[[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${x_t}'";
94#-
95# Accessing to functions (without stack)
96#-
97DEBUG_debug=false
98MirrorlibIGCM=false
99TaskType=computing
100. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
101. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
102. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
103. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
104if [ $x_e = 'true' ] ; then
105  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
106fi
107#-
108# Define the pattern string to substitute
109#-
110W_P='#-Q- '; W_W=${W_P}${x_t};
111#-
112# Extract list of 'config.card' files
113# and create jobs with AA_job
114#-
115F_CFG='config.card';
116for i in $(find ${d_n}/.. -name ${F_CFG} -print)
117do
118 j=$(cd ${i%/*};/bin/pwd;)
119 n_f=${F_RCI##*/};
120
121 if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
122 # Do not treat config.card if it is in sub-directory of EXPERIMENTS
123 # Continue to next config.card
124     continue
125 else
126     [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
127 fi
128
129 # Find out if new structure and set .resol filename
130 if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
131     # New Structure
132     [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
133     new_struct=yes
134     resolfile=$j/.resol
135 else
136     # Old Structure
137     new_struct=no
138     resolfile=$j/../.resol
139 fi
140 
141 # Get all variables declared in section UserChoices in config.card
142 IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
143 # Set default values
144 config_UserChoices_JobClass=mono
145 config_UserChoices_JobNumProcTot=1
146 config_UserChoices_ExpType=""
147 RESOL_ATM_3D=this_is_a_test_string
148 RESOL=this_is_another_test_string
149 typeset option
150 for option in ${config_UserChoices[*]} ; do
151     IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
152 done
153
154# Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
155 if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
156    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
157    echo TRUERESOL = $TRUERESOL
158    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
159    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
160 elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
161     TRUERESOL=$( head -1 $resolfile  )
162     JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
163     IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
164 else
165     JobName=${config_UserChoices_JobName}
166 fi
167 [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
168
169# Add specific treatment for new type of directory structure
170  if [ ${new_struct} == yes ] ; then
171
172      if [ "X${config_UserChoices_ExpType}" = X ] ; then
173        echo "\nERROR in ${j}/config.card"
174        echo "ins_job stops here"
175        echo "=> The variable ExpType must be added in config.card in section UserChoices"
176        echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
177        exit 4
178      else
179        [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
180      fi
181
182      if [ -d ${j}/${JobName} ] ; then
183          echo "Directory ${j}/${JobName} exist already, continue next config.card"
184          continue
185      fi
186      echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
187      cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
188      cp -r ${j}/GENERAL/* ${j}/${JobName}/.
189      cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
190      rm -f ${j}/${F_CFG}
191      rm -f ${j}/${F_CFG}.bak
192      j=${j}/${JobName}
193      [[ ${x_v} = 'verbose' ]] && echo new j=$j
194  fi
195# end specific treatment for new type directory structure
196
197 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
198  {
199   [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
200   \cp ${F_RCI} ${j};
201  }
202
203 # File name for Job
204 n_f='Job_'${JobName};
205 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
206 [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
207 sed -e "/^${W_W} */ s///" \
208     -e "/^${W_P}/d"       \
209     -e "s%::modipsl::%${F_MOD}%" \
210     -e "s/::Jobname::/${JobName}/" \
211     -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
212     -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
213     ${F_JOB} > ${j}'/'${n_f}
214 chmod u+x ${j}'/'${n_f}
215done
216#-
217# Extract list of AA_* files in libIGCM
218# and create jobs (for all except AA_job)
219#-
220for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn )
221do
222 i_f=${i##*/};
223 [[ ${i_f} = 'AA_job' ]] && { continue; }
224 j=${i%/*}; n_f=${i_f#AA_}'.job';
225 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
226 [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
227 sed -e "/^${W_W} */ s///" \
228     -e "s%::modipsl::%${F_MOD}%" \
229     -e "/^${W_P}/d"       \
230     ${i} > ${j}'/'${n_f}
231 chmod u+x ${j}'/'${n_f}
232done
233#-
234# Limited to hindcast/forecast Ensemble for the time being
235if [ ${x_e} = 'true' ] ; then
236  #.. Read input data from ensemble.card ..
237  # TO BE CHANGED
238  FileName="ensemble.card"
239  SUBMIT_DIR=$( pwd )
240  RUN_DIR="${WORKDIR}/ENSEMBLE"
241  #
242  # Copy initial things around and define variables (hindcast/forecast case)
243  IGCM_ensemble_CastInit
244  # As it says
245  IGCM_sys_Cd ${SUBMIT_DIR}
246  IGCM_ensemble_CastPeriodicStarts
247  # As it says
248  IGCM_sys_Cd ${SUBMIT_DIR}
249  IGCM_ensemble_CastNonPeriodicStarts
250  # Done
251  IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
252  IGCM_sys_Cd ${SUBMIT_DIR}
253  # Clean
254  IGCM_sys_Rm -rf ${RUN_DIR}
255fi
256#-
257[[ ${x_v} = 'verbose' ]] && print - "";
258#-
259# That's all folks
260#-
261exit 0;
Note: See TracBrowser for help on using the repository browser.