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

Last change on this file since 1806 was 1806, checked in by jgipsl, 12 years ago

Added capability to have severel configurations with .resol files in same modipsl. This was not possible for the case when JobName? contains RESOL_ATM_3D variable (CREATE job).

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