source: trunk/libIGCM/ins_job @ 1225

Last change on this file since 1225 was 1172, checked in by sdipsl, 9 years ago
  • this ins_job dont need w_i_h
  • simplify
  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 11.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Jacques Belier
5# Contact:
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13#---------------------------------------------------------------------
14#- Installation of jobs according to environment
15#---------------------------------------------------------------------
16function ins_job_Usage
17{
18print - "
19ins_job installs the jobs in the directories
20which contain a file config.card
21
22ins_job must be launched on the host
23on which the job will be submitted
24
25Usage :
26  ${b_n} [-h] [-v] [-e] [-p project]
27
28Options :
29  -h          : help
30  -v          : verbose mode
31  -e          : turn on ensemble mode (hindcast/forecast or date restart)
32  -p project  : add default project on curie
33"
34}
35function ins_job_Warning
36{
37   [[ ${x_v} = 'verbose' ]] && print - "\n############### WARNING ###############";
38   [[ ${x_v} = 'verbose' ]] && print - "File ${n_f} already exists\nin directory ${j}";
39   [[ ${x_v} = 'verbose' ]] && print - "You must delete this file to update !";
40}
41
42function ins_job_Check_JobName
43{
44  verif=${JobName##[a-zA-Z]*(?([.\-])[a-zA-Z0-9])}
45
46  if [ ${#verif} -ne 0 ] ; then
47    echo "################ ERROR ################"
48    echo "${JobName} is invalid."
49    echo "- JobName can only contain alphanumeric characters, \".\" and \"-\""
50    echo "- JobName must start with a letter"
51
52    ((NbErr=NbErr+1))
53
54    Status=1
55  else
56    Status=0
57  fi
58
59  return ${Status}
60}
61
62#-
63#     dirname     and      basename
64#-
65d_n=$(dirname ${0}); b_n=$(basename ${0});
66#-
67# Retrieving and validation of the options
68#-
69x_v='silencious';
70x_e=false;
71x_p=false;
72while getopts :hvep: V ; do
73  case $V in
74  (h)  ins_job_Usage; exit 0;;
75  (v)  x_v='verbose';;
76  (e)  x_e=true;;
77  (p)  x_p=true
78       ProjectID=${OPTARG} ;;
79  (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
80       exit 2;;
81  (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
82       exit 2;;
83  esac
84done
85[ ${x_v} = 'silencious' ] && export DEBUG_sys=false
86shift $(($OPTIND-1));
87#-
88# Define working files
89#-
90F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
91# [[ ${F_MOD##*/} != 'modipsl' ]] && \
92#  { print - "directory 'modipsl' unreachable"; exit 3; }
93W_W=${d_n}'/../libIGCM'
94[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
95libIGCM=$(cd ${W_W};/bin/pwd;)
96F_JOB=${libIGCM}'/AA_job';
97[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
98F_RCI=${libIGCM}'/run.card.init';
99[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
100#-
101# Accessing to functions (without stack)
102#-
103DEBUG_debug=false
104MirrorlibIGCM=false
105TaskType=computing
106. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
107. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
108. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
109. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
110if [ $x_e = 'true' ] ; then
111  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
112fi
113
114#-
115[[ ${x_v} = 'verbose' ]] && \
116 {
117  print - "";
118  print - '--- Host        : '${SYSTEM};
119  print - '--- modipsl     : '${F_MOD};
120  print - '--- libIGCM     : '${libIGCM};
121  print - '--- basic job   : '${F_JOB};
122  print - '--- basic card  : '${F_RCI};
123 }
124#-
125[[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${SYSTEM}'";
126#-
127
128NbErr=0
129
130#-
131# Define Project ID to set up jobs header for Curie (TGCC)
132#-
133if ( ! ${x_p} ) ; then
134  if [ X"${SYSTEM}" == "Xcurie" ] ; then
135    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )
136    ProjectID=${ProjectID:="gen2211"}
137    answer=""
138    print - "Hit Enter or give project ID (default is ${ProjectID}), possible projects are $( echo $( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | sort -u ) ) :"
139    read answer
140
141    if [ "X${answer}" != "X" ] ; then
142      ProjectID=${answer}
143    fi
144    [ "${ProjectID}" = "gencmip6" ] && ProjectNode="standard" || ProjectNode="xlarge"
145  fi
146else
147  if [ X"${SYSTEM}" != "Xcurie" ] ; then
148    print - "\nOption -p invalid with this host (${SYSTEM}): it will be ignored" 1>&2;
149  fi
150fi
151
152#-
153# Define the pattern string to substitute
154#-
155W_P='#-Q- '; W_W=${W_P}${SYSTEM};
156#-
157# Extract list of 'config.card' files
158# and create jobs with AA_job
159#-
160F_CFG='config.card';
161F_CFG_ENS='ensemble.card';
162SUBMIT_DIR_ENS=$( pwd )
163for i in $(find ${d_n}/.. -name ${F_CFG} -print)
164do
165  j=$(cd ${i%/*};/bin/pwd;)
166  n_f=${F_RCI##*/};
167
168  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
169    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
170    # Continue to next config.card
171    continue
172  else
173    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
174  fi
175
176  # Find out if new structure and set .resol filename
177  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
178    # New Structure
179    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
180    new_struct=yes
181    resolfile=$j/.resol
182  else
183    # Old Structure
184    new_struct=no
185    resolfile=$j/../.resol
186  fi
187
188  # Get all variables declared in section UserChoices in config.card
189  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
190  # Set default values
191  config_UserChoices_JobClass=mono
192  config_UserChoices_JobNumProcTot=1
193  config_UserChoices_ExpType=""
194  RESOL_ATM_3D=this_is_a_test_string
195  RESOL=this_is_another_test_string
196  typeset option
197  for option in ${config_UserChoices[*]} ; do
198    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
199  done
200
201  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
202  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
203    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
204    echo TRUERESOL = $TRUERESOL
205    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
206    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
207  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
208    TRUERESOL=$( head -1 $resolfile  )
209    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
210    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
211  else
212    JobName=${config_UserChoices_JobName}
213  fi
214
215  # Check JobName validity : only alphanumerical characters, "-" and "." are authorized
216  ins_job_Check_JobName
217  RetCode=$?
218  [[ $RetCode -gt 0 ]] && continue
219
220  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
221
222  # Add specific treatment for new type of directory structure
223  if [ ${new_struct} == yes ] ; then
224
225    if [ "X${config_UserChoices_ExpType}" = X ] ; then
226      echo "\nERROR in ${j}/config.card"
227      echo "ins_job stops here"
228      echo "=> The variable ExpType must be added in config.card in section UserChoices"
229      echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
230      exit 4
231    else
232      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
233    fi
234
235    if [ -d ${j}/${JobName} ] ; then
236      echo "Directory ${j}/${JobName} exist already, continue next config.card"
237      continue
238    fi
239    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
240    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
241    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
242    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
243    if [ -f ${F_CFG_ENS} ] ; then
244      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
245      SUBMIT_DIR_ENS=${j}/${JobName}
246    fi
247    rm -f ${j}/${F_CFG}
248    rm -f ${j}/${F_CFG_ENS}
249    rm -f ${j}/${F_CFG}.bak
250    j=${j}/${JobName}
251    [[ ${x_v} = 'verbose' ]] && echo new j=$j
252  fi
253  # end specific treatment for new type directory structure
254
255  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
256   {
257    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
258    \cp ${F_RCI} ${j};
259   }
260
261  # File name for Job
262  n_f='Job_'${JobName};
263  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
264  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
265  sed -e "/^${W_W} */ s///" \
266      -e "/^${W_P}/d"       \
267      -e "s%::modipsl::%${F_MOD}%" \
268      -e "s/::Jobname::/${JobName}/" \
269      -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
270      -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
271      -e "s/::default_project::/${ProjectID}/" \
272      ${F_JOB} > ${j}'/'${n_f}
273  chmod u+x ${j}'/'${n_f}
274done
275#-
276# Extract list of AA_* files in libIGCM
277# and create jobs (for all except AA_job)
278#-
279for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
280do
281  i_f=${i##*/};
282  [[ ${i_f} = 'AA_job' ]] && { continue; }
283  j=${i%/*}; n_f=${i_f#AA_}'.job';
284  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
285  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
286  sed -e "/^${W_W} */ s///" \
287      -e "s%::modipsl::%${F_MOD}%" \
288      -e "/^${W_P}/d"       \
289      -e "s/::default_node::/${ProjectNode}/" \
290      -e "s/::default_project::/${ProjectID}/" \
291      ${i} > ${j}'/'${n_f}
292  chmod u+x ${j}'/'${n_f}
293done
294#-
295# set default_project in libIGCM_sys_curie.ksh too.
296#-
297if [ X"${SYSTEM}" == "Xcurie" ] ; then
298  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
299  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
300fi
301#-
302# Limited to hindcast/forecast and date restart Ensemble for the time being
303if [ ${x_e} = 'true' ] ; then
304  #.. Read input data from ensemble.card ..
305  SUBMIT_DIR=${SUBMIT_DIR_ENS}
306  RUN_DIR="${WORKDIR}/ENSEMBLE"
307  #
308  # Copy initial things around and define variables (hindcast/forecast case)
309  IGCM_sys_Cd ${SUBMIT_DIR}
310  IGCM_ensemble_Init
311
312  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
313    echo "WARNING: Parametric Ensemble is not implemented yet..."
314  fi
315
316  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
317    IGCM_sys_Cd ${SUBMIT_DIR}
318    IGCM_ensemble_DateInit
319    # As it says
320    IGCM_sys_Cd ${SUBMIT_DIR}
321    IGCM_ensemble_DatePeriodicStarts
322    # As it says
323    IGCM_sys_Cd ${SUBMIT_DIR}
324    IGCM_ensemble_DateNonPeriodicStarts
325    # Clean
326    IGCM_sys_Rm -rf ${RUN_DIR}
327  fi
328
329  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
330    IGCM_sys_Cd ${SUBMIT_DIR}
331    IGCM_ensemble_CastInit
332    # As it says
333    IGCM_sys_Cd ${SUBMIT_DIR}
334    IGCM_ensemble_CastPeriodicStarts
335    # As it says
336    IGCM_sys_Cd ${SUBMIT_DIR}
337    IGCM_ensemble_CastNonPeriodicStarts
338    # As it says
339    IGCM_sys_Cd ${SUBMIT_DIR}
340    IGCM_ensemble_CastMemberList
341    # Done
342    IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
343    IGCM_sys_Cd ${SUBMIT_DIR}
344    # Clean
345    IGCM_sys_Rm -rf ${RUN_DIR}
346  fi
347fi
348#-
349[[ ${x_v} = 'verbose' ]] && print - "";
350#-
351# That's all folks
352#-
353
354if [ ${NbErr} -ne 0 ] ; then
355  echo "################ ERROR ################"
356  echo "${NbErr} invalid JobName(s) found, check the log"
357fi
358
359
360exit 0;
Note: See TracBrowser for help on using the repository browser.