Changeset 2688
- Timestamp:
- 12/01/15 17:55:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modipsl/trunk/util/ins_job
r2394 r2688 4 4 #- Installation of jobs according to an environment 5 5 #--------------------------------------------------------------------- 6 function ins_job_Usage7 {8 print - "9 ins_job installs the jobs in the directories10 which contain a file config.card11 6 12 ins_job must be launched on the host 13 on which the job will be submitted 7 echo "" 8 echo "This script has been moved to libIGCM. Now please use ins_job in libIGCM directory." 9 echo "Use for example ../../libIGCM/ins_job or ../../../libIGCM/ins_job from the directory where the config.card is." 10 echo "See documentation https://forge.ipsl.jussieu.fr/igcmg_doc/wiki/DocEsetup" 11 echo "" 14 12 15 Usage :16 ${b_n} [-h] [-v] [-e] [-p project]17 18 Options :19 -h : help20 -v : verbose mode21 -e : turn on ensemble mode (hindcast/forecast or date restart)22 -p project : add default project on curie23 "24 }25 function ins_job_Warning26 {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 !";30 }31 32 function ins_job_Check_JobName33 {34 verif=${JobName##[a-zA-Z]*(?([.\-])[a-zA-Z0-9])}35 36 if [ ${#verif} -ne 0 ] ; then37 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=145 else46 Status=047 fi48 49 return ${Status}50 }51 52 #-53 # dirname and basename54 #-55 d_n=$(dirname ${0}); b_n=$(basename ${0});56 #-57 # Retrieving and validation of the options58 #-59 x_v='silencious';60 x_e=false;61 x_p=false;62 while getopts :hvep: V ; do63 case $V in64 (h) ins_job_Usage; exit 0;;65 (v) x_v='verbose';;66 (e) x_e=true;;67 (p) x_p=true68 ProjectID=${OPTARG} ;;69 (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;70 exit 2;;71 (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;72 exit 2;;73 esac74 done75 [ ${x_v} = 'silencious' ] && export DEBUG_sys=false76 shift $(($OPTIND-1));77 #-78 # Define working files79 #-80 F_MOD=$(cd ${d_n}'/..';/bin/pwd;)81 # [[ ${F_MOD##*/} != 'modipsl' ]] && \82 # { print - "directory 'modipsl' unreachable"; exit 3; }83 W_W=${d_n}'/../libIGCM'84 [[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }85 libIGCM=$(cd ${W_W};/bin/pwd;)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 Name92 #-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 #-118 [[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${x_t}'";119 #-120 # Accessing to functions (without stack)121 #-122 DEBUG_debug=false123 MirrorlibIGCM=false124 TaskType=computing125 . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh126 . ${libIGCM}/libIGCM_card/libIGCM_card.ksh127 . ${libIGCM}/libIGCM_date/libIGCM_date.ksh128 . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh129 if [ $x_e = 'true' ] ; then130 . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh131 fi132 133 NbErr=0134 135 #-136 # Define Project ID to set up jobs header for Curie (TGCC)137 #-138 if ( ! ${x_p} ) ; then139 if [ X"${x_t}" == "Xcurie" ] ; then140 ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )141 ProjectID=${ProjectID:="gen2211"}142 answer=""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 ) ) :"144 read answer145 146 if [ "X${answer}" != "X" ] ; then147 ProjectID=${answer}148 fi149 [ "${ProjectID}" = "gencmip6" ] && ProjectNode="standard" || ProjectNode="xlarge"150 fi151 else152 if [ X"${x_t}" != "Xcurie" ] ; then153 print - "\nOption -p invalid with this host (${x_t}): it will be ignored" 1>&2;154 fi155 fi156 157 #-158 # Define the pattern string to substitute159 #-160 W_P='#-Q- '; W_W=${W_P}${x_t};161 #-162 # Extract list of 'config.card' files163 # and create jobs with AA_job164 #-165 F_CFG='config.card';166 F_CFG_ENS='ensemble.card';167 SUBMIT_DIR_ENS=$( pwd )168 for i in $(find ${d_n}/.. -name ${F_CFG} -print)169 do170 j=$(cd ${i%/*};/bin/pwd;)171 n_f=${F_RCI##*/};172 173 if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then174 # Do not treat config.card if it is in sub-directory of EXPERIMENTS175 # Continue to next config.card176 continue177 else178 [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";179 fi180 181 # Find out if new structure and set .resol filename182 if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then183 # New Structure184 [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"185 new_struct=yes186 resolfile=$j/.resol187 else188 # Old Structure189 new_struct=no190 resolfile=$j/../.resol191 fi192 193 # Get all variables declared in section UserChoices in config.card194 IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices195 # Set default values196 config_UserChoices_JobClass=mono197 config_UserChoices_JobNumProcTot=1198 config_UserChoices_ExpType=""199 RESOL_ATM_3D=this_is_a_test_string200 RESOL=this_is_another_test_string201 typeset option202 for option in ${config_UserChoices[*]} ; do203 IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}204 done205 206 # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file207 if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then208 TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )209 echo TRUERESOL = $TRUERESOL210 JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )211 IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}212 elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then213 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 else217 JobName=${config_UserChoices_JobName}218 fi219 220 # Check JobName validity : only alphanumerical characters, "-" and "." are authorized221 ins_job_Check_JobName222 RetCode=$?223 [[ $RetCode -gt 0 ]] && continue224 225 [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"226 227 # Add specific treatment for new type of directory structure228 if [ ${new_struct} == yes ] ; then229 230 if [ "X${config_UserChoices_ExpType}" = X ] ; then231 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 4236 else237 [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"238 fi239 240 if [ -d ${j}/${JobName} ] ; then241 echo "Directory ${j}/${JobName} exist already, continue next config.card"242 continue243 fi244 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}/.248 if [ -f ${F_CFG_ENS} ] ; then249 cp -f ${j}/${F_CFG_ENS} ${j}/${JobName}/.250 SUBMIT_DIR_ENS=${j}/${JobName}251 fi252 rm -f ${j}/${F_CFG}253 rm -f ${j}/${F_CFG_ENS}254 rm -f ${j}/${F_CFG}.bak255 j=${j}/${JobName}256 [[ ${x_v} = 'verbose' ]] && echo new j=$j257 fi258 # end specific treatment for new type directory structure259 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 }265 266 # File name for Job267 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}279 done280 #-281 # Extract list of AA_* files in libIGCM282 # and create jobs (for all except AA_job)283 #-284 for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)285 do286 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" \294 -e "s/::default_node::/${ProjectNode}/" \295 -e "s/::default_project::/${ProjectID}/" \296 ${i} > ${j}'/'${n_f}297 chmod u+x ${j}'/'${n_f}298 done299 #-300 # set default_project in libIGCM_sys_curie.ksh too.301 #-302 if [ X"${x_t}" == "Xcurie" ] ; then303 i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh304 sed -i -e "s/::default_project::/${ProjectID}/" ${i}305 fi306 #-307 # Limited to hindcast/forecast and date restart Ensemble for the time being308 if [ ${x_e} = 'true' ] ; then309 #.. Read input data from ensemble.card ..310 SUBMIT_DIR=${SUBMIT_DIR_ENS}311 RUN_DIR="${WORKDIR}/ENSEMBLE"312 #313 # Copy initial things around and define variables (hindcast/forecast case)314 IGCM_sys_Cd ${SUBMIT_DIR}315 IGCM_ensemble_Init316 317 if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then318 echo "WARNING: Parametric Ensemble is not implemented yet..."319 fi320 321 if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then322 IGCM_sys_Cd ${SUBMIT_DIR}323 IGCM_ensemble_DateInit324 # As it says325 IGCM_sys_Cd ${SUBMIT_DIR}326 IGCM_ensemble_DatePeriodicStarts327 # As it says328 IGCM_sys_Cd ${SUBMIT_DIR}329 IGCM_ensemble_DateNonPeriodicStarts330 # Clean331 IGCM_sys_Rm -rf ${RUN_DIR}332 fi333 334 if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then335 IGCM_sys_Cd ${SUBMIT_DIR}336 IGCM_ensemble_CastInit337 # As it says338 IGCM_sys_Cd ${SUBMIT_DIR}339 IGCM_ensemble_CastPeriodicStarts340 # As it says341 IGCM_sys_Cd ${SUBMIT_DIR}342 IGCM_ensemble_CastNonPeriodicStarts343 # As it says344 IGCM_sys_Cd ${SUBMIT_DIR}345 IGCM_ensemble_CastMemberList346 # Done347 IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}348 IGCM_sys_Cd ${SUBMIT_DIR}349 # Clean350 IGCM_sys_Rm -rf ${RUN_DIR}351 fi352 fi353 #-354 [[ ${x_v} = 'verbose' ]] && print - "";355 #-356 # That's all folks357 #-358 359 if [ ${NbErr} -ne 0 ] ; then360 echo "################ ERROR ################"361 echo "${NbErr} invalid JobName(s) found, check the log"362 fi363 364 365 exit 0;
Note: See TracChangeset
for help on using the changeset viewer.