source: modipsl/trunk/util/ins_job @ 2074

Last change on this file since 2074 was 2036, checked in by labetoulle, 11 years ago

On Curie, ins_job sets up project id. See #98.

Default value is the first returned by ccc_myproject (different from tgcc*).
Option -p may be used to skip interactive dialog.

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