source: modipsl/trunk/util/ins_job @ 1905

Last change on this file since 1905 was 1905, checked in by sdipsl, 12 years ago
  • cosmetics and cleaning. Mainly for ensemble hanfling
  • 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
99. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
100. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
101. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
102. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
103if [ $x_e = 'true' ] ; then
104  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
105fi
106#-
107# Define the pattern string to substitute
108#-
109W_P='#-Q- '; W_W=${W_P}${x_t};
110#-
111# Extract list of 'config.card' files
112# and create jobs with AA_job
113#-
114F_CFG='config.card';
115for i in $(find ${d_n}/.. -name ${F_CFG} -print)
116do
117 j=$(cd ${i%/*};/bin/pwd;)
118 n_f=${F_RCI##*/};
119
120 if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
121 # Do not treat config.card if it is in sub-directory of EXPERIMENTS
122 # Continue to next config.card
123     continue
124 else
125     [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
126 fi
127
128 # Find out if new structure and set .resol filename
129 if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
130     # New Structure
131     [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
132     new_struct=yes
133     resolfile=$j/.resol
134 else
135     # Old Structure
136     new_struct=no
137     resolfile=$j/../.resol
138 fi
139 
140 # Get all variables declared in section UserChoices in config.card
141 IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
142 # Set default values
143 config_UserChoices_JobClass=mono
144 config_UserChoices_JobNumProcTot=1
145 config_UserChoices_ExpType=""
146 RESOL_ATM_3D=this_is_a_test_string
147 RESOL=this_is_another_test_string
148 typeset option
149 for option in ${config_UserChoices[*]} ; do
150     IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
151 done
152
153# Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
154 if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
155    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
156    echo TRUERESOL = $TRUERESOL
157    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
158    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
159 elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
160     TRUERESOL=$( head -1 $resolfile  )
161     JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
162     IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
163 else
164     JobName=${config_UserChoices_JobName}
165 fi
166 [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
167
168# Add specific treatment for new type of directory structure
169  if [ ${new_struct} == yes ] ; then
170
171      if [ "X${config_UserChoices_ExpType}" = X ] ; then
172        echo "\nERROR in ${j}/config.card"
173        echo "ins_job stops here"
174        echo "=> The variable ExpType must be added in config.card in section UserChoices"
175        echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
176        exit 4
177      else
178        [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
179      fi
180
181      if [ -d ${j}/${JobName} ] ; then
182          echo "Directory ${j}/${JobName} exist already, continue next config.card"
183          continue
184      fi
185      echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
186      cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
187      cp -r ${j}/GENERAL/* ${j}/${JobName}/.
188      cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
189      rm -f ${j}/${F_CFG}
190      rm -f ${j}/${F_CFG}.bak
191      j=${j}/${JobName}
192      [[ ${x_v} = 'verbose' ]] && echo new j=$j
193  fi
194# end specific treatment for new type directory structure
195
196 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
197  {
198   [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
199   \cp ${F_RCI} ${j};
200  }
201
202 # File name for Job
203 n_f='Job_'${JobName};
204 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
205 [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
206 sed -e "/^${W_W} */ s///" \
207     -e "/^${W_P}/d"       \
208     -e "s%::modipsl::%${F_MOD}%" \
209     -e "s/::Jobname::/${JobName}/" \
210     -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
211     -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
212     ${F_JOB} > ${j}'/'${n_f}
213 chmod u+x ${j}'/'${n_f}
214done
215#-
216# Extract list of AA_* files in libIGCM
217# and create jobs (for all except AA_job)
218#-
219for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn )
220do
221 i_f=${i##*/};
222 [[ ${i_f} = 'AA_job' ]] && { continue; }
223 j=${i%/*}; n_f=${i_f#AA_}'.job';
224 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
225 [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
226 sed -e "/^${W_W} */ s///" \
227     -e "s%::modipsl::%${F_MOD}%" \
228     -e "/^${W_P}/d"       \
229     ${i} > ${j}'/'${n_f}
230 chmod u+x ${j}'/'${n_f}
231done
232#-
233# Limited to hindcast/forecast Ensemble for the time being
234if [ ${x_e} = 'true' ] ; then
235  #.. Read input data from ensemble.card ..
236  # TO BE CHANGED
237  FileName="ensemble.card"
238  SUBMIT_DIR=$( pwd )
239  RUN_DIR="${WORKDIR}/ENSEMBLE"
240  #
241  # Copy initial things around and define variables (hindcast/forecast case)
242  IGCM_ensemble_CastInit
243  # As it says
244  IGCM_sys_Cd ${SUBMIT_DIR}
245  IGCM_ensemble_CastPeriodicStarts
246  # As it says
247  IGCM_sys_Cd ${SUBMIT_DIR}
248  IGCM_ensemble_CastNonPeriodicStarts
249  # Done
250  IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${RUN_DIR}/Qsub.txt ${SUBMIT_DIR}
251  IGCM_sys_Cd ${SUBMIT_DIR}
252  # Clean
253  IGCM_sys_Rm -rf ${RUN_DIR}
254fi
255#-
256[[ ${x_v} = 'verbose' ]] && print - "";
257#-
258# That's all folks
259#-
260exit 0;
Note: See TracBrowser for help on using the repository browser.