[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##*/}; |
---|
[1618] | 110 | |
---|
[1619] | 111 | if [ ! X$( echo ${j} | grep USER_SPEC ) = X ] ; then |
---|
| 112 | # Do not treat config.card if it is in sub-directory of USER_SPEC |
---|
| 113 | # Continue to next config.card |
---|
| 114 | continue |
---|
[1644] | 115 | else |
---|
| 116 | print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
[1619] | 117 | fi |
---|
| 118 | |
---|
| 119 | # Get all variables declared in section UserChoices in config.card |
---|
| 120 | IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices |
---|
| 121 | # Set default values |
---|
| 122 | config_UserChoices_JobClass=mono |
---|
| 123 | config_UserChoices_JobNumProcTot=1 |
---|
| 124 | config_UserChoices_UserSpec="" |
---|
[1644] | 125 | RESOL_ATM_3D=this_is_a_test_string |
---|
| 126 | RESOL=this_is_another_test_string |
---|
[1619] | 127 | typeset option |
---|
| 128 | for option in ${config_UserChoices[*]} ; do |
---|
| 129 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} |
---|
| 130 | done |
---|
| 131 | |
---|
[1644] | 132 | # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file |
---|
| 133 | if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then |
---|
| 134 | TRUERESOL=$( find ../ -name ".resol" -exec tail -1 {} \; | awk "-F=" '{print $2}' ) |
---|
| 135 | JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" ) |
---|
| 136 | IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} |
---|
| 137 | elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then |
---|
| 138 | TRUERESOL=$( find ../ -name ".resol" -exec head -1 {} \; ) |
---|
| 139 | JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" ) |
---|
| 140 | IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} |
---|
| 141 | else |
---|
| 142 | JobName=${config_UserChoices_JobName} |
---|
| 143 | fi |
---|
| 144 | echo "JobName=${JobName}" |
---|
| 145 | |
---|
[1618] | 146 | # Add specific treatment for new type of directory structure |
---|
| 147 | if [ -d ${j}/USER_SPEC ] && [ -d ${j}/GENERAL ] ; then |
---|
| 148 | echo "This is new configuration structure" |
---|
[1619] | 149 | |
---|
| 150 | if [ "X${config_UserChoices_UserSpec}" = X ] ; then |
---|
| 151 | echo "\nERROR in ${j}/config.card" |
---|
| 152 | echo "ins_job stops here" |
---|
| 153 | echo "=> The variable UserSpec must be added in config.card in section UserChoices" |
---|
| 154 | echo "=> UserSpec gives the directory for the .card configurtaion files for the wanted experiement. For exemple UserSpec=IPSLCM5/historical" |
---|
| 155 | exit 4 |
---|
[1618] | 156 | else |
---|
[1619] | 157 | echo "UserSpec= ${config_UserChoices_UserSpec}" |
---|
[1618] | 158 | fi |
---|
| 159 | |
---|
[1644] | 160 | if [ -d ${j}/${JobName} ] ; then |
---|
| 161 | echo "Directory ${j}/${JobName} exist already, continue next config.card" |
---|
[1618] | 162 | continue |
---|
| 163 | fi |
---|
[1644] | 164 | cp -r ${j}/USER_SPEC/${config_UserChoices_UserSpec} ${j}/${JobName} |
---|
| 165 | cp -r ${j}/GENERAL/* ${j}/${JobName}/. |
---|
| 166 | cp -f ${j}/${F_CFG} ${j}/${JobName}/. |
---|
| 167 | j=${j}/${JobName} |
---|
[1618] | 168 | echo new j=$j |
---|
| 169 | fi |
---|
| 170 | # end specific treatment for new type directory structure |
---|
| 171 | |
---|
[96] | 172 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ |
---|
[93] | 173 | { |
---|
| 174 | print - "\nCopying file ${F_RCI}\nin directory ${j}"; |
---|
| 175 | \cp ${F_RCI} ${j}; |
---|
| 176 | } |
---|
[1644] | 177 | |
---|
[157] | 178 | # File name for Job |
---|
[1644] | 179 | n_f='Job_'${JobName}; |
---|
[93] | 180 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
| 181 | print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
| 182 | sed -e "/^${W_W} */ s///" \ |
---|
| 183 | -e "/^${W_P}/d" \ |
---|
| 184 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
[1644] | 185 | -e "s/::Jobname::/${JobName}/" \ |
---|
[131] | 186 | -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ |
---|
| 187 | -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ |
---|
[93] | 188 | ${F_JOB} > ${j}'/'${n_f} |
---|
[1053] | 189 | chmod u+x ${j}'/'${n_f} |
---|
[91] | 190 | done |
---|
| 191 | #- |
---|
| 192 | # Extract list of AA_* files in libIGCM |
---|
[92] | 193 | # and create jobs (for all except AA_job) |
---|
[91] | 194 | #- |
---|
[379] | 195 | for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn ) |
---|
[91] | 196 | do |
---|
[93] | 197 | i_f=${i##*/}; |
---|
| 198 | [[ ${i_f} = 'AA_job' ]] && { continue; } |
---|
| 199 | j=${i%/*}; n_f=${i_f#AA_}'.job'; |
---|
| 200 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
| 201 | print - "\nIn directory ${j}\n${i_f} -> ${n_f}" |
---|
| 202 | sed -e "/^${W_W} */ s///" \ |
---|
[914] | 203 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
[93] | 204 | -e "/^${W_P}/d" \ |
---|
| 205 | ${i} > ${j}'/'${n_f} |
---|
[747] | 206 | chmod u+x ${j}'/'${n_f} |
---|
[91] | 207 | done |
---|
| 208 | #- |
---|
[93] | 209 | print - ""; |
---|
| 210 | #- |
---|
[91] | 211 | # That's all folks |
---|
| 212 | #- |
---|
| 213 | exit 0; |
---|