source: modipsl/branches/newconfig/util/ins_job @ 1781

Last change on this file since 1781 was 1781, checked in by sdipsl, 12 years ago
  • Do not mirror libIGCM during the ins_job phase
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.2 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   print - "\n############### WARNING ###############";
27   print - "File ${n_f} already exists\nin directory ${j}";
28   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
50shift $(($OPTIND-1));
51#-
52# Define working files
53#-
54F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
55# [[ ${F_MOD##*/} != 'modipsl' ]] && \
56#  { print - "directory 'modipsl' unreachable"; exit 3; }
57W_W=${d_n}'/../libIGCM'
58[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
59libIGCM=$(cd ${W_W};/bin/pwd;)
60F_JOB=${libIGCM}'/AA_job';
61[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
62F_RCI=${libIGCM}'/run.card.init';
63[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
64#-
65# Host Name
66#-
67x_t=$(${d_n}/w_i_h) 2>/dev/null;
68{ [[ ${?} != 0 ]] && \
69   { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \
70  [[ ${x_t} = "Unknown" ]] && \
71   { print - "\nLocal_Host not supported\n" 1>&2; exit 1; };
72#-
73W_W=$(sed -n -e "s/^#-Q-  *\([^ ]*\).*$/\1/p" ${F_JOB} | \
74       sort -u | sed -e "/${x_t}/!d");
75[[ '\?'"${W_W}" != '\?'${x_t} ]] && \
76  {
77   print - "\nHost  "${x_t}"  not supported" 1>&2;
78   print - "'default' will be used" 1>&2;
79   x_t='default'
80  }
81#-
82[[ ${x_v} = 'verbose' ]] && \
83 {
84  print - "";
85  print - '--- Host        : '${x_t};
86  print - '--- modipsl     : '${F_MOD};
87  print - '--- libIGCM     : '${libIGCM};
88  print - '--- basic job   : '${F_JOB};
89  print - '--- basic card  : '${F_RCI};
90 }
91#-
92print - "\nInstallation of jobs for '${x_t}'";
93#-
94# Accessing to functions (without stack)
95#-
96DEBUG_debug=false
97MirrorlibIGCM=false
98. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
99. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
100. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
101. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
102. ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
103#-
104# Define the pattern string to substitute
105#-
106W_P='#-Q- '; W_W=${W_P}${x_t};
107#-
108# Extract list of 'config.card' files
109# and create jobs with AA_job
110#-
111F_CFG='config.card';
112for i in $(find ${d_n}/.. -name ${F_CFG} -print)
113do
114 j=$(cd ${i%/*};/bin/pwd;)
115 n_f=${F_RCI##*/};
116
117 if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
118 # Do not treat config.card if it is in sub-directory of EXPERIMENTS
119 # Continue to next config.card
120     continue
121 else
122     print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
123 fi
124 
125 # Get all variables declared in section UserChoices in config.card
126 IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
127 # Set default values
128 config_UserChoices_JobClass=mono
129 config_UserChoices_JobNumProcTot=1
130 config_UserChoices_ExpType=""
131 RESOL_ATM_3D=this_is_a_test_string
132 RESOL=this_is_another_test_string
133 typeset option
134 for option in ${config_UserChoices[*]} ; do
135     IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
136 done
137
138# Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
139 if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
140    TRUERESOL=$( find ../ -name ".resol" -exec tail -1 {} \; | awk "-F=" '{print $2}' )
141    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
142    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
143 elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
144     TRUERESOL=$( find ../ -name ".resol" -exec head -1 {} \; )
145     JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
146     IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
147 else
148     JobName=${config_UserChoices_JobName}
149 fi
150 echo "JobName=${JobName}"
151
152# Add specific treatment for new type of directory structure
153  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
154      echo "This is new configuration structure"
155
156      if [ "X${config_UserChoices_ExpType}" = X ] ; then
157        echo "\nERROR in ${j}/config.card"
158        echo "ins_job stops here"
159        echo "=> The variable ExpType must be added in config.card in section UserChoices"
160        echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
161        exit 4
162      else
163        echo "ExpType= ${config_UserChoices_ExpType}"
164      fi
165
166      if [ -d ${j}/${JobName} ] ; then
167          echo "Directory ${j}/${JobName} exist already, continue next config.card"
168          continue
169      fi
170      cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
171      cp -r ${j}/GENERAL/* ${j}/${JobName}/.
172      cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
173      j=${j}/${JobName}
174      echo new j=$j
175  fi
176# end specific treatment for new type directory structure
177
178 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
179  {
180   print - "\nCopying file ${F_RCI}\nin directory ${j}";
181   \cp ${F_RCI} ${j};
182  }
183
184 # File name for Job
185 n_f='Job_'${JobName};
186 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
187 print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
188 sed -e "/^${W_W} */ s///" \
189     -e "/^${W_P}/d"       \
190     -e "s%::modipsl::%${F_MOD}%" \
191     -e "s/::Jobname::/${JobName}/" \
192     -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
193     -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
194     ${F_JOB} > ${j}'/'${n_f}
195 chmod u+x ${j}'/'${n_f}
196done
197#-
198# Extract list of AA_* files in libIGCM
199# and create jobs (for all except AA_job)
200#-
201for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn )
202do
203 i_f=${i##*/};
204 [[ ${i_f} = 'AA_job' ]] && { continue; }
205 j=${i%/*}; n_f=${i_f#AA_}'.job';
206 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
207 print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
208 sed -e "/^${W_W} */ s///" \
209     -e "s%::modipsl::%${F_MOD}%" \
210     -e "/^${W_P}/d"       \
211     ${i} > ${j}'/'${n_f}
212 chmod u+x ${j}'/'${n_f}
213done
214#-
215# Limited to hindcast/forecast Ensemble for the time being
216if [ ${x_e} = 'true' ] ; then
217  #.. Read input data from ensemble.card ..
218  # TO BE CHANGED
219  FileName="ensemble.card"
220  SUBMIT_DIR=$( pwd )
221  RUN_DIR="${WORKDIR}/ENSEMBLE"
222  #
223  # Copy initial things around and define variables (hindcast/forecast case)
224  IGCM_ensemble_CastInit
225  # As it says
226  IGCM_sys_Cd ${SUBMIT_DIR}
227  IGCM_ensemble_CastPeriodicStarts
228  # As it says
229  IGCM_sys_Cd ${SUBMIT_DIR}
230  IGCM_ensemble_CastNonPeriodicStarts
231  # Done
232  IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${RUN_DIR}/Qsub.txt ${SUBMIT_DIR}
233  IGCM_sys_Cd ${SUBMIT_DIR}
234fi
235#-
236print - "";
237#-
238# That's all folks
239#-
240exit 0;
Note: See TracBrowser for help on using the repository browser.