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