Ignore:
Timestamp:
03/27/13 14:47:27 (9 years ago)
Author:
labetoulle
Message:

On Curie, ins_job sets up project id. See #98.

Default value is the first returned by ccc_myproject (different from tgcc*).
Option -p may be used to skip interactive dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modipsl/trunk/util/ins_job

    r1908 r2036  
    1414 
    1515Usage : 
    16   ${b_n} [-h] [-v] [-e] 
     16  ${b_n} [-h] [-v] [-e] [-p project] 
    1717 
    1818Options : 
    19   -h   : help 
    20   -v   : verbose mode 
    21   -e   : turn on hindcast/forecast ensemble mode 
     19  -h          : help 
     20  -v          : verbose mode 
     21  -e          : turn on hindcast/forecast ensemble mode 
     22  -p project  : add default project on curie 
    2223" 
    2324} 
     
    3738x_v='silencious'; 
    3839x_e=false; 
    39 while getopts :hve V ; do 
     40x_p=false; 
     41while getopts :hvep: V ; do 
    4042  case $V in 
    4143  (h)  ins_job_Usage; exit 0;; 
    4244  (v)  x_v='verbose';; 
    4345  (e)  x_e=true;; 
     46  (p)  x_p=true 
     47       ProjectID=${OPTARG} ;; 
    4448  (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; 
    45   exit 2;; 
     49       exit 2;; 
    4650  (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; 
    47   exit 2;; 
     51       exit 2;; 
    4852  esac 
    4953done 
     
    105109  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh 
    106110fi 
     111 
     112#- 
     113# Define Project ID to set up jobs header for Curie (TGCC) 
     114#- 
     115if ( ! ${x_p} ) ; then 
     116  if [ "X${x_t}" == "Xcurie" ] ; then 
     117    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 ) 
     118    ProjectID=${ProjectID:="gen2211"} 
     119    answer="" 
     120    print - "Hit Enter or give project ID (default is ${ProjectID}):" 
     121    read answer 
     122 
     123    if [ "X${answer}" != "X" ] ; then 
     124      ProjectID=${answer} 
     125    fi 
     126  fi 
     127else 
     128  if ( "X${x_t}" != "Xcurie" ) ; then 
     129    print - "\nOption -p invalid with this host (${x_t}): it will be ignored" 1>&2; 
     130  fi 
     131fi 
     132 
    107133#- 
    108134# Define the pattern string to substitute 
     
    116142for i in $(find ${d_n}/.. -name ${F_CFG} -print) 
    117143do 
    118  j=$(cd ${i%/*};/bin/pwd;) 
    119  n_f=${F_RCI##*/}; 
    120  
    121  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then 
    122  # Do not treat config.card if it is in sub-directory of EXPERIMENTS 
    123  # Continue to next config.card 
    124      continue 
    125  else 
    126      [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; 
    127  fi 
    128  
    129  # Find out if new structure and set .resol filename 
    130  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then 
    131      # New Structure 
    132      [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure" 
    133      new_struct=yes 
    134      resolfile=$j/.resol 
    135  else 
    136      # Old Structure 
    137      new_struct=no 
    138      resolfile=$j/../.resol 
    139  fi 
    140   
    141  # Get all variables declared in section UserChoices in config.card 
    142  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices 
    143  # Set default values 
    144  config_UserChoices_JobClass=mono 
    145  config_UserChoices_JobNumProcTot=1 
    146  config_UserChoices_ExpType="" 
    147  RESOL_ATM_3D=this_is_a_test_string 
    148  RESOL=this_is_another_test_string 
    149  typeset option 
    150  for option in ${config_UserChoices[*]} ; do 
    151      IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} 
    152  done 
    153  
    154 # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file 
    155  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then 
     144  j=$(cd ${i%/*};/bin/pwd;) 
     145  n_f=${F_RCI##*/}; 
     146 
     147  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then 
     148    # Do not treat config.card if it is in sub-directory of EXPERIMENTS 
     149    # Continue to next config.card 
     150    continue 
     151  else 
     152    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; 
     153  fi 
     154 
     155  # Find out if new structure and set .resol filename 
     156  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then 
     157    # New Structure 
     158    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure" 
     159    new_struct=yes 
     160    resolfile=$j/.resol 
     161  else 
     162    # Old Structure 
     163    new_struct=no 
     164    resolfile=$j/../.resol 
     165  fi 
     166 
     167  # Get all variables declared in section UserChoices in config.card 
     168  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices 
     169  # Set default values 
     170  config_UserChoices_JobClass=mono 
     171  config_UserChoices_JobNumProcTot=1 
     172  config_UserChoices_ExpType="" 
     173  RESOL_ATM_3D=this_is_a_test_string 
     174  RESOL=this_is_another_test_string 
     175  typeset option 
     176  for option in ${config_UserChoices[*]} ; do 
     177    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} 
     178  done 
     179 
     180  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file 
     181  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then 
    156182    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' ) 
    157183    echo TRUERESOL = $TRUERESOL 
    158184    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" ) 
    159185    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} 
    160  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then 
    161      TRUERESOL=$( head -1 $resolfile  ) 
    162      JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" ) 
    163      IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} 
    164  else 
    165      JobName=${config_UserChoices_JobName} 
    166  fi 
    167  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}" 
    168  
    169 # Add specific treatment for new type of directory structure  
     186  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then 
     187    TRUERESOL=$( head -1 $resolfile  ) 
     188    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" ) 
     189    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} 
     190  else 
     191    JobName=${config_UserChoices_JobName} 
     192  fi 
     193  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}" 
     194 
     195  # Add specific treatment for new type of directory structure  
    170196  if [ ${new_struct} == yes ] ; then 
    171197 
    172       if [ "X${config_UserChoices_ExpType}" = X ] ; then 
    173         echo "\nERROR in ${j}/config.card" 
    174         echo "ins_job stops here" 
    175         echo "=> The variable ExpType must be added in config.card in section UserChoices" 
    176         echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical" 
    177         exit 4 
    178       else 
    179         [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}" 
    180       fi 
    181  
    182       if [ -d ${j}/${JobName} ] ; then 
    183           echo "Directory ${j}/${JobName} exist already, continue next config.card" 
    184           continue 
    185       fi 
    186       echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}" 
    187       cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName} 
    188       cp -r ${j}/GENERAL/* ${j}/${JobName}/. 
    189       cp -f ${j}/${F_CFG}  ${j}/${JobName}/. 
    190       rm -f ${j}/${F_CFG} 
    191       rm -f ${j}/${F_CFG}.bak 
    192       j=${j}/${JobName} 
    193       [[ ${x_v} = 'verbose' ]] && echo new j=$j 
    194   fi 
    195 # end specific treatment for new type directory structure  
    196  
    197  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ 
    198   { 
    199    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}"; 
    200    \cp ${F_RCI} ${j}; 
    201   } 
    202  
    203  # File name for Job 
    204  n_f='Job_'${JobName}; 
    205  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } 
    206  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; 
    207  sed -e "/^${W_W} */ s///" \ 
    208      -e "/^${W_P}/d"       \ 
    209      -e "s%::modipsl::%${F_MOD}%" \ 
    210      -e "s/::Jobname::/${JobName}/" \ 
    211      -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ 
    212      -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ 
    213      ${F_JOB} > ${j}'/'${n_f} 
    214  chmod u+x ${j}'/'${n_f} 
     198    if [ "X${config_UserChoices_ExpType}" = X ] ; then 
     199      echo "\nERROR in ${j}/config.card" 
     200      echo "ins_job stops here" 
     201      echo "=> The variable ExpType must be added in config.card in section UserChoices" 
     202      echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical" 
     203      exit 4 
     204    else 
     205      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}" 
     206    fi 
     207 
     208    if [ -d ${j}/${JobName} ] ; then 
     209      echo "Directory ${j}/${JobName} exist already, continue next config.card" 
     210      continue 
     211    fi 
     212    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}" 
     213    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName} 
     214    cp -r ${j}/GENERAL/* ${j}/${JobName}/. 
     215    cp -f ${j}/${F_CFG}  ${j}/${JobName}/. 
     216    rm -f ${j}/${F_CFG} 
     217    rm -f ${j}/${F_CFG}.bak 
     218    j=${j}/${JobName} 
     219    [[ ${x_v} = 'verbose' ]] && echo new j=$j 
     220  fi 
     221  # end specific treatment for new type directory structure  
     222 
     223  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ 
     224   { 
     225    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}"; 
     226    \cp ${F_RCI} ${j}; 
     227   } 
     228 
     229  # File name for Job 
     230  n_f='Job_'${JobName}; 
     231  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } 
     232  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; 
     233  sed -e "/^${W_W} */ s///" \ 
     234      -e "/^${W_P}/d"       \ 
     235      -e "s%::modipsl::%${F_MOD}%" \ 
     236      -e "s/::Jobname::/${JobName}/" \ 
     237      -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ 
     238      -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ 
     239      -e "s/::default_project::/${ProjectID}/" \ 
     240      ${F_JOB} > ${j}'/'${n_f} 
     241  chmod u+x ${j}'/'${n_f} 
    215242done 
    216243#- 
     
    220247for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn ) 
    221248do 
    222  i_f=${i##*/}; 
    223  [[ ${i_f} = 'AA_job' ]] && { continue; } 
    224  j=${i%/*}; n_f=${i_f#AA_}'.job'; 
    225  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } 
    226  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}" 
    227  sed -e "/^${W_W} */ s///" \ 
    228      -e "s%::modipsl::%${F_MOD}%" \ 
    229      -e "/^${W_P}/d"       \ 
    230      ${i} > ${j}'/'${n_f} 
    231  chmod u+x ${j}'/'${n_f} 
     249  i_f=${i##*/}; 
     250  [[ ${i_f} = 'AA_job' ]] && { continue; } 
     251  j=${i%/*}; n_f=${i_f#AA_}'.job'; 
     252  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } 
     253  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}" 
     254  sed -e "/^${W_W} */ s///" \ 
     255      -e "s%::modipsl::%${F_MOD}%" \ 
     256      -e "/^${W_P}/d"       \ 
     257      -e "s/::default_project::/${ProjectID}/" \ 
     258      ${i} > ${j}'/'${n_f} 
     259  chmod u+x ${j}'/'${n_f} 
    232260done 
    233261#- 
Note: See TracChangeset for help on using the changeset viewer.