[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 : |
---|
[1828] | 16 | ${b_n} [-h] [-v] [-e] |
---|
[91] | 17 | |
---|
| 18 | Options : |
---|
| 19 | -h : help |
---|
| 20 | -v : verbose mode |
---|
[1828] | 21 | -e : turn on hindcast/forecast ensemble mode |
---|
[91] | 22 | " |
---|
| 23 | } |
---|
[93] | 24 | function ins_job_Warning |
---|
| 25 | { |
---|
[1877] | 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 !"; |
---|
[93] | 29 | } |
---|
[91] | 30 | #- |
---|
[293] | 31 | # dirname and basename |
---|
[91] | 32 | #- |
---|
[293] | 33 | d_n=$(dirname ${0}); b_n=$(basename ${0}); |
---|
[91] | 34 | #- |
---|
| 35 | # Retrieving and validation of the options |
---|
| 36 | #- |
---|
| 37 | x_v='silencious'; |
---|
[1828] | 38 | x_e=false; |
---|
| 39 | while 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 |
---|
| 49 | done |
---|
[91] | 50 | shift $(($OPTIND-1)); |
---|
| 51 | #- |
---|
| 52 | # Define working files |
---|
| 53 | #- |
---|
[108] | 54 | F_MOD=$(cd ${d_n}'/..';/bin/pwd;) |
---|
[208] | 55 | # [[ ${F_MOD##*/} != 'modipsl' ]] && \ |
---|
| 56 | # { print - "directory 'modipsl' unreachable"; exit 3; } |
---|
[91] | 57 | W_W=${d_n}'/../libIGCM' |
---|
| 58 | [[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; } |
---|
[108] | 59 | libIGCM=$(cd ${W_W};/bin/pwd;) |
---|
[91] | 60 | F_JOB=${libIGCM}'/AA_job'; |
---|
| 61 | [[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; } |
---|
| 62 | F_RCI=${libIGCM}'/run.card.init'; |
---|
| 63 | [[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; } |
---|
| 64 | #- |
---|
| 65 | # Host Name |
---|
| 66 | #- |
---|
| 67 | x_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 | #- |
---|
| 73 | W_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 | #- |
---|
[1877] | 92 | [[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${x_t}'"; |
---|
[91] | 93 | #- |
---|
| 94 | # Accessing to functions (without stack) |
---|
| 95 | #- |
---|
| 96 | DEBUG_debug=false |
---|
[1828] | 97 | MirrorlibIGCM=false |
---|
[91] | 98 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 99 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
[1828] | 100 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
| 101 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
| 102 | if [ $x_e = 'true' ] ; then |
---|
| 103 | . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh |
---|
| 104 | fi |
---|
[91] | 105 | #- |
---|
[93] | 106 | # Define the pattern string to substitute |
---|
| 107 | #- |
---|
| 108 | W_P='#-Q- '; W_W=${W_P}${x_t}; |
---|
| 109 | #- |
---|
[91] | 110 | # Extract list of 'config.card' files |
---|
| 111 | # and create jobs with AA_job |
---|
| 112 | #- |
---|
| 113 | F_CFG='config.card'; |
---|
[96] | 114 | for i in $(find ${d_n}/.. -name ${F_CFG} -print) |
---|
[91] | 115 | do |
---|
[108] | 116 | j=$(cd ${i%/*};/bin/pwd;) |
---|
[93] | 117 | n_f=${F_RCI##*/}; |
---|
[1618] | 118 | |
---|
[1828] | 119 | if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then |
---|
| 120 | # Do not treat config.card if it is in sub-directory of EXPERIMENTS |
---|
[1619] | 121 | # Continue to next config.card |
---|
| 122 | continue |
---|
[1644] | 123 | else |
---|
[1877] | 124 | [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
[1619] | 125 | fi |
---|
[1828] | 126 | |
---|
| 127 | # Find out if new structure and set .resol filename |
---|
| 128 | if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then |
---|
| 129 | # New Structure |
---|
[1877] | 130 | [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure" |
---|
[1828] | 131 | new_struct=yes |
---|
| 132 | resolfile=$j/.resol |
---|
| 133 | else |
---|
| 134 | # Old Structure |
---|
| 135 | new_struct=no |
---|
| 136 | resolfile=$j/../.resol |
---|
| 137 | fi |
---|
[1619] | 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 |
---|
[1828] | 144 | config_UserChoices_ExpType="" |
---|
[1644] | 145 | RESOL_ATM_3D=this_is_a_test_string |
---|
| 146 | RESOL=this_is_another_test_string |
---|
[1619] | 147 | typeset option |
---|
| 148 | for option in ${config_UserChoices[*]} ; do |
---|
| 149 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} |
---|
| 150 | done |
---|
| 151 | |
---|
[1644] | 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 |
---|
[1828] | 154 | TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' ) |
---|
| 155 | echo TRUERESOL = $TRUERESOL |
---|
[1644] | 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 |
---|
[1828] | 159 | TRUERESOL=$( head -1 $resolfile ) |
---|
[1644] | 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 |
---|
[1877] | 165 | [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}" |
---|
[1644] | 166 | |
---|
[1618] | 167 | # Add specific treatment for new type of directory structure |
---|
[1828] | 168 | if [ ${new_struct} == yes ] ; then |
---|
[1619] | 169 | |
---|
[1828] | 170 | if [ "X${config_UserChoices_ExpType}" = X ] ; then |
---|
[1619] | 171 | echo "\nERROR in ${j}/config.card" |
---|
| 172 | echo "ins_job stops here" |
---|
[1828] | 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" |
---|
[1619] | 175 | exit 4 |
---|
[1618] | 176 | else |
---|
[1877] | 177 | [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}" |
---|
[1618] | 178 | fi |
---|
| 179 | |
---|
[1644] | 180 | if [ -d ${j}/${JobName} ] ; then |
---|
| 181 | echo "Directory ${j}/${JobName} exist already, continue next config.card" |
---|
[1618] | 182 | continue |
---|
| 183 | fi |
---|
[1877] | 184 | echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}" |
---|
[1828] | 185 | cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName} |
---|
[1644] | 186 | cp -r ${j}/GENERAL/* ${j}/${JobName}/. |
---|
| 187 | cp -f ${j}/${F_CFG} ${j}/${JobName}/. |
---|
[1831] | 188 | rm -f ${j}/${F_CFG} |
---|
| 189 | rm -f ${j}/${F_CFG}.bak |
---|
[1644] | 190 | j=${j}/${JobName} |
---|
[1877] | 191 | [[ ${x_v} = 'verbose' ]] && echo new j=$j |
---|
[1618] | 192 | fi |
---|
| 193 | # end specific treatment for new type directory structure |
---|
| 194 | |
---|
[96] | 195 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ |
---|
[93] | 196 | { |
---|
[1877] | 197 | [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}"; |
---|
[93] | 198 | \cp ${F_RCI} ${j}; |
---|
| 199 | } |
---|
[1644] | 200 | |
---|
[157] | 201 | # File name for Job |
---|
[1644] | 202 | n_f='Job_'${JobName}; |
---|
[93] | 203 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
[1877] | 204 | [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
[93] | 205 | sed -e "/^${W_W} */ s///" \ |
---|
| 206 | -e "/^${W_P}/d" \ |
---|
| 207 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
[1644] | 208 | -e "s/::Jobname::/${JobName}/" \ |
---|
[131] | 209 | -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ |
---|
| 210 | -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ |
---|
[93] | 211 | ${F_JOB} > ${j}'/'${n_f} |
---|
[1053] | 212 | chmod u+x ${j}'/'${n_f} |
---|
[91] | 213 | done |
---|
| 214 | #- |
---|
| 215 | # Extract list of AA_* files in libIGCM |
---|
[92] | 216 | # and create jobs (for all except AA_job) |
---|
[91] | 217 | #- |
---|
[379] | 218 | for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn ) |
---|
[91] | 219 | do |
---|
[93] | 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; } |
---|
[1877] | 224 | [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}" |
---|
[93] | 225 | sed -e "/^${W_W} */ s///" \ |
---|
[914] | 226 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
[93] | 227 | -e "/^${W_P}/d" \ |
---|
| 228 | ${i} > ${j}'/'${n_f} |
---|
[747] | 229 | chmod u+x ${j}'/'${n_f} |
---|
[91] | 230 | done |
---|
| 231 | #- |
---|
[1828] | 232 | # Limited to hindcast/forecast Ensemble for the time being |
---|
| 233 | if [ ${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} |
---|
| 251 | fi |
---|
| 252 | #- |
---|
[1877] | 253 | [[ ${x_v} = 'verbose' ]] && print - ""; |
---|
[93] | 254 | #- |
---|
[91] | 255 | # That's all folks |
---|
| 256 | #- |
---|
| 257 | exit 0; |
---|