[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 : |
---|
| 16 | ${b_n} [-h] [-v] |
---|
| 17 | |
---|
| 18 | Options : |
---|
| 19 | -h : help |
---|
| 20 | -v : verbose mode |
---|
| 21 | " |
---|
| 22 | } |
---|
[93] | 23 | function ins_job_Warning |
---|
| 24 | { |
---|
| 25 | print - "\n############### WARNING ###############"; |
---|
| 26 | print - "File ${n_f} already exists\nin directory ${j}"; |
---|
| 27 | print - "You must delete this file to update !"; |
---|
| 28 | } |
---|
[91] | 29 | #- |
---|
[293] | 30 | # dirname and basename |
---|
[91] | 31 | #- |
---|
[293] | 32 | d_n=$(dirname ${0}); b_n=$(basename ${0}); |
---|
[91] | 33 | #- |
---|
| 34 | # Retrieving and validation of the options |
---|
| 35 | #- |
---|
| 36 | x_v='silencious'; |
---|
| 37 | while getopts :hv V |
---|
| 38 | do |
---|
| 39 | case $V in |
---|
| 40 | (h) ins_job_Usage; exit 0;; |
---|
| 41 | (v) x_v='verbose';; |
---|
| 42 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
| 43 | exit 2;; |
---|
| 44 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
| 45 | exit 2;; |
---|
| 46 | esac |
---|
| 47 | done |
---|
| 48 | shift $(($OPTIND-1)); |
---|
| 49 | #- |
---|
| 50 | # Define working files |
---|
| 51 | #- |
---|
[108] | 52 | F_MOD=$(cd ${d_n}'/..';/bin/pwd;) |
---|
[208] | 53 | # [[ ${F_MOD##*/} != 'modipsl' ]] && \ |
---|
| 54 | # { print - "directory 'modipsl' unreachable"; exit 3; } |
---|
[91] | 55 | W_W=${d_n}'/../libIGCM' |
---|
| 56 | [[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; } |
---|
[108] | 57 | libIGCM=$(cd ${W_W};/bin/pwd;) |
---|
[91] | 58 | F_JOB=${libIGCM}'/AA_job'; |
---|
| 59 | [[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; } |
---|
| 60 | F_RCI=${libIGCM}'/run.card.init'; |
---|
| 61 | [[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; } |
---|
| 62 | #- |
---|
| 63 | # Host Name |
---|
| 64 | #- |
---|
| 65 | x_t=$(${d_n}/w_i_h) 2>/dev/null; |
---|
| 66 | { [[ ${?} != 0 ]] && \ |
---|
| 67 | { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \ |
---|
| 68 | [[ ${x_t} = "Unknown" ]] && \ |
---|
| 69 | { print - "\nLocal_Host not supported\n" 1>&2; exit 1; }; |
---|
| 70 | #- |
---|
| 71 | W_W=$(sed -n -e "s/^#-Q- *\([^ ]*\).*$/\1/p" ${F_JOB} | \ |
---|
| 72 | sort -u | sed -e "/${x_t}/!d"); |
---|
| 73 | [[ '\?'"${W_W}" != '\?'${x_t} ]] && \ |
---|
| 74 | { |
---|
| 75 | print - "\nHost "${x_t}" not supported" 1>&2; |
---|
| 76 | print - "'default' will be used" 1>&2; |
---|
| 77 | x_t='default' |
---|
| 78 | } |
---|
| 79 | #- |
---|
| 80 | [[ ${x_v} = 'verbose' ]] && \ |
---|
| 81 | { |
---|
| 82 | print - ""; |
---|
| 83 | print - '--- Host : '${x_t}; |
---|
| 84 | print - '--- modipsl : '${F_MOD}; |
---|
| 85 | print - '--- libIGCM : '${libIGCM}; |
---|
| 86 | print - '--- basic job : '${F_JOB}; |
---|
| 87 | print - '--- basic card : '${F_RCI}; |
---|
| 88 | } |
---|
| 89 | #- |
---|
| 90 | print - "\nInstallation of jobs for '${x_t}'"; |
---|
| 91 | #- |
---|
| 92 | # Accessing to functions (without stack) |
---|
| 93 | #- |
---|
| 94 | DEBUG_debug=false |
---|
| 95 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 96 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
| 97 | #- |
---|
[93] | 98 | # Define the pattern string to substitute |
---|
| 99 | #- |
---|
| 100 | W_P='#-Q- '; W_W=${W_P}${x_t}; |
---|
| 101 | #- |
---|
[91] | 102 | # Extract list of 'config.card' files |
---|
| 103 | # and create jobs with AA_job |
---|
| 104 | #- |
---|
| 105 | F_CFG='config.card'; |
---|
[96] | 106 | for i in $(find ${d_n}/.. -name ${F_CFG} -print) |
---|
[91] | 107 | do |
---|
[108] | 108 | j=$(cd ${i%/*};/bin/pwd;) |
---|
[93] | 109 | n_f=${F_RCI##*/}; |
---|
[96] | 110 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ |
---|
[93] | 111 | { |
---|
| 112 | print - "\nCopying file ${F_RCI}\nin directory ${j}"; |
---|
| 113 | \cp ${F_RCI} ${j}; |
---|
| 114 | } |
---|
[157] | 115 | # We keep explicitly JobName because it is not optionnal. |
---|
[331] | 116 | RESOL=this_is_a_test_string |
---|
[93] | 117 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices JobName |
---|
[331] | 118 | if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then |
---|
| 119 | TRUERESOL=$( find ../ -name ".resol" -exec cat {} \; ) |
---|
| 120 | config_UserChoices_JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" ) |
---|
| 121 | IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${config_UserChoices_JobName} |
---|
| 122 | fi |
---|
| 123 | |
---|
[157] | 124 | # Other options are not always needed |
---|
| 125 | IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices |
---|
[221] | 126 | # Default values |
---|
[222] | 127 | config_UserChoices_JobClass=mono |
---|
| 128 | config_UserChoices_JobNumProcTot=1 |
---|
[221] | 129 | # config.card optionnal values |
---|
[157] | 130 | typeset option |
---|
| 131 | for option in ${config_UserChoices[*]} ; do |
---|
| 132 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} |
---|
| 133 | done |
---|
| 134 | # File name for Job |
---|
[93] | 135 | n_f='Job_'${config_UserChoices_JobName}; |
---|
| 136 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
| 137 | print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
| 138 | sed -e "/^${W_W} */ s///" \ |
---|
| 139 | -e "/^${W_P}/d" \ |
---|
| 140 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
| 141 | -e "s/::Jobname::/${config_UserChoices_JobName}/" \ |
---|
[131] | 142 | -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ |
---|
| 143 | -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ |
---|
[93] | 144 | ${F_JOB} > ${j}'/'${n_f} |
---|
[91] | 145 | done |
---|
| 146 | #- |
---|
| 147 | # Extract list of AA_* files in libIGCM |
---|
[92] | 148 | # and create jobs (for all except AA_job) |
---|
[91] | 149 | #- |
---|
[96] | 150 | for i in $(find ${libIGCM} -name "AA_*" -print) |
---|
[91] | 151 | do |
---|
[93] | 152 | i_f=${i##*/}; |
---|
| 153 | [[ ${i_f} = 'AA_job' ]] && { continue; } |
---|
| 154 | j=${i%/*}; n_f=${i_f#AA_}'.job'; |
---|
| 155 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
| 156 | print - "\nIn directory ${j}\n${i_f} -> ${n_f}" |
---|
| 157 | sed -e "/^${W_W} */ s///" \ |
---|
| 158 | -e "/^${W_P}/d" \ |
---|
| 159 | ${i} > ${j}'/'${n_f} |
---|
[199] | 160 | chmod u+X ${j}'/'${n_f} |
---|
[91] | 161 | done |
---|
| 162 | #- |
---|
[93] | 163 | print - ""; |
---|
| 164 | #- |
---|
[91] | 165 | # That's all folks |
---|
| 166 | #- |
---|
| 167 | exit 0; |
---|