[91] | 1 | #!/bin/ksh |
---|
| 2 | # $Id$ |
---|
| 3 | #--------------------------------------------------------------------- |
---|
| 4 | #- Installation of jobs according to an environment |
---|
| 5 | #--------------------------------------------------------------------- |
---|
| 6 | function ins_job_Usage |
---|
| 7 | { |
---|
| 8 | echo " |
---|
| 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 | } |
---|
| 23 | #- |
---|
| 24 | # dirname and basename |
---|
| 25 | #- |
---|
| 26 | d_n=${0%/*}; b_n=${0##*/}; |
---|
| 27 | #- |
---|
| 28 | # Retrieving and validation of the options |
---|
| 29 | #- |
---|
| 30 | x_v='silencious'; |
---|
| 31 | while getopts :hv V |
---|
| 32 | do |
---|
| 33 | case $V in |
---|
| 34 | (h) ins_job_Usage; exit 0;; |
---|
| 35 | (v) x_v='verbose';; |
---|
| 36 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
| 37 | exit 2;; |
---|
| 38 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
| 39 | exit 2;; |
---|
| 40 | esac |
---|
| 41 | done |
---|
| 42 | shift $(($OPTIND-1)); |
---|
| 43 | #- |
---|
| 44 | # Define working files |
---|
| 45 | #- |
---|
| 46 | F_MOD=$(cd ${d_n}'/..';pwd) |
---|
| 47 | [[ ${F_MOD##*/} != 'modipsl' ]] && \ |
---|
| 48 | { print - "directory 'modipsl' unreachable"; exit 3; } |
---|
| 49 | W_W=${d_n}'/../libIGCM' |
---|
| 50 | [[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; } |
---|
| 51 | libIGCM=$(cd ${W_W};pwd) |
---|
| 52 | F_JOB=${libIGCM}'/AA_job'; |
---|
| 53 | [[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; } |
---|
| 54 | F_RCI=${libIGCM}'/run.card.init'; |
---|
| 55 | [[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; } |
---|
| 56 | #- |
---|
| 57 | # Host Name |
---|
| 58 | #- |
---|
| 59 | x_t=$(${d_n}/w_i_h) 2>/dev/null; |
---|
| 60 | { [[ ${?} != 0 ]] && \ |
---|
| 61 | { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \ |
---|
| 62 | [[ ${x_t} = "Unknown" ]] && \ |
---|
| 63 | { print - "\nLocal_Host not supported\n" 1>&2; exit 1; }; |
---|
| 64 | #- |
---|
| 65 | W_W=$(sed -n -e "s/^#-Q- *\([^ ]*\).*$/\1/p" ${F_JOB} | \ |
---|
| 66 | sort -u | sed -e "/${x_t}/!d"); |
---|
| 67 | [[ '\?'"${W_W}" != '\?'${x_t} ]] && \ |
---|
| 68 | { |
---|
| 69 | print - "\nHost "${x_t}" not supported" 1>&2; |
---|
| 70 | print - "'default' will be used" 1>&2; |
---|
| 71 | x_t='default' |
---|
| 72 | } |
---|
| 73 | #- |
---|
| 74 | [[ ${x_v} = 'verbose' ]] && \ |
---|
| 75 | { |
---|
| 76 | print - ""; |
---|
| 77 | print - '--- Host : '${x_t}; |
---|
| 78 | print - '--- modipsl : '${F_MOD}; |
---|
| 79 | print - '--- libIGCM : '${libIGCM}; |
---|
| 80 | print - '--- basic job : '${F_JOB}; |
---|
| 81 | print - '--- basic card : '${F_RCI}; |
---|
| 82 | } |
---|
| 83 | #- |
---|
| 84 | print - "\nInstallation of jobs for '${x_t}'"; |
---|
| 85 | #- |
---|
| 86 | # Accessing to functions (without stack) |
---|
| 87 | #- |
---|
| 88 | DEBUG_debug=false |
---|
| 89 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 90 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
| 91 | #- |
---|
| 92 | # Extract list of 'config.card' files |
---|
| 93 | # and create jobs with AA_job |
---|
| 94 | #- |
---|
| 95 | F_CFG='config.card'; |
---|
| 96 | l_cfg=$(find ${d_n}/.. -name ${F_CFG} -print) |
---|
| 97 | for i in ${l_cfg} |
---|
| 98 | do |
---|
| 99 | j=$(cd ${i%/*};pwd) |
---|
| 100 | \cp ${F_RCI} ${j} |
---|
| 101 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices JobName |
---|
| 102 | print - "\nWorking with file ${F_CFG}"; |
---|
| 103 | print - "in directory ${j}"; |
---|
| 104 | print - "for Job_${config_UserChoices_JobName}" |
---|
| 105 | W_P='#-Q- '; W_W=${W_P}${x_t}; |
---|
| 106 | sed -e "/^${W_W} */ s///" \ |
---|
| 107 | -e "/^${W_P}/d" \ |
---|
| 108 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
| 109 | -e "s/::Jobname::/${config_UserChoices_JobName}/" \ |
---|
| 110 | ${F_JOB} > ${j}'/Job_'${config_UserChoices_JobName} |
---|
| 111 | done |
---|
| 112 | #- |
---|
| 113 | # Extract list of AA_* files in libIGCM |
---|
[92] | 114 | # and create jobs (for all except AA_job) |
---|
[91] | 115 | #- |
---|
| 116 | l_cfg=$(find ${libIGCM} -name "AA_*" -print) |
---|
| 117 | for i in ${l_cfg} |
---|
| 118 | do |
---|
| 119 | i_f=${i##*/}; |
---|
| 120 | [[ ${i_f} = 'AA_job' ]] && continue |
---|
| 121 | i_d=${i%/*}; n_f=${i_f#AA_}'.job'; |
---|
| 122 | print - "\nIn directory ${i_d}\n${i_f} -> ${n_f}" |
---|
| 123 | sed -e "/^${W_W} */ s///" \ |
---|
| 124 | -e "/^${W_P}/d" \ |
---|
| 125 | ${i} > ${i_d}'/'${n_f} |
---|
| 126 | done |
---|
| 127 | #- |
---|
| 128 | # That's all folks |
---|
| 129 | #- |
---|
| 130 | exit 0; |
---|