source: modipsl/trunk/util/ins_job @ 1904

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

Removed printing in default mode. Use './ins_job -v' for verbose mode

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