meta_launch_cca.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash -e
  2. #---------------------------------------------------------------------------
  3. # With PBSpro (qsub) you cannot pass arguments to a script at the command line,
  4. # like this:
  5. #
  6. # qsub <qsub_options> script arg1 arg2
  7. #
  8. # Only this is posiible:
  9. #
  10. # qsub <qsub_options> script
  11. #
  12. # So we rely on a template, which is parsed here to create a script that can
  13. # be submitted and has all the options we want.
  14. #
  15. #---------------------------------------------------------------------------
  16. # HOW-TO
  17. # you have to first "cd <location of barakuda package>/platform" and
  18. # then:
  19. #
  20. # ./meta_launch_cca.sh -C ......
  21. #
  22. #---------------------------------------------------------------------------
  23. # OPTIONAL SETTING
  24. #
  25. # - you can overwrite the default hpc account for running barakuda with (in
  26. # your ~/.user_bashrc or ~/.bashrc):
  27. #
  28. # export ECE3_POSTPROC_ACCOUNT=<hpc account to use>
  29. #
  30. # If not set, your default ECMWF account is used (i.e. 1st one in the list
  31. # you get with "account -l $USER" on ecgate). Note that you can also
  32. # specify an account at the command line when calling the script with the
  33. # -a option.
  34. #
  35. #---------------------------------------------------------------------------
  36. # P. Le Sager, June/July 2017
  37. #---------------------------------------------------------------------------
  38. usage() {
  39. echo
  40. echo "USAGE: ${0} -C <config> -R <experiment> (options)"
  41. echo
  42. echo " Available configs are:"
  43. for cc in ${list_conf}; do
  44. echo " * ${cc}"
  45. done
  46. echo
  47. echo "Options are:"
  48. echo
  49. echo " -a ACCOUNT : specify a different special project for accounting (default: \$ECE3_POSTPROC_ACCOUNT)"
  50. echo " -i YEAR_START : first year to build climatolgy. Climatology is built if set."
  51. echo " -e YEAR_END : last year to build climatolgy. Climatology is built if set."
  52. echo
  53. exit
  54. }
  55. # -------- Checks before submitting
  56. [[ -z $ECE3_BARAKUDA_TOPDIR ]] && cd .. && ECE3_BARAKUDA_TOPDIR=$PWD
  57. cd $ECE3_BARAKUDA_TOPDIR
  58. # Available configs:
  59. list_conf=$(\ls ${ECE3_BARAKUDA_TOPDIR}/configs/config_*.sh | sed -e "s|${ECE3_BARAKUDA_TOPDIR}/configs\/config_||g" -e s/'.sh'/''/g)
  60. # User configs, potentially in the directory from which barakuda.sh is called:
  61. list_conf+=" $(\ls ./config_*.sh 2>/dev/null | sed -e "s|.\/config_||g" -e s/'.sh'/''/g)"
  62. # -------- Options
  63. account=$ECE3_POSTPROC_ACCOUNT # default account if exists
  64. climato=0
  65. while getopts C:R:a:i:e: option ; do
  66. case $option in
  67. C) conf=${OPTARG} ;;
  68. R) exp=${OPTARG} ;;
  69. a) account=$OPTARG ;;
  70. i) y1=${OPTARG} ;;
  71. e) y2=${OPTARG} ;;
  72. *) usage ;;
  73. esac
  74. done
  75. shift $((OPTIND-1))
  76. [[ -n $y1 && -n $y2 ]] && climato=1 # generate climato, and compare with it
  77. [[ -z $conf ]] && usage
  78. [[ ! ${list_conf} =~ ${conf} ]] && { echo ; echo "!!!! UNKNOWN CONF: $conf !!!!!"; usage;}
  79. [[ -z $exp ]] && usage
  80. # -- Scratch dir (location of submit script and its log)
  81. OUT=$SCRATCH/tmp_barakuda
  82. mkdir -p $OUT
  83. # -------- Create diagnostics
  84. cmd="./barakuda.sh -C ${conf} -R ${exp}"
  85. tgt_script=$OUT/b_${exp}_diag.job
  86. sed "s/<EXPID>/$exp/" < platform/cca.job.tmpl > $tgt_script
  87. [[ -n $account ]] && \
  88. sed -i "s/<ACCOUNT>/$account/" $tgt_script || \
  89. sed -i "/<ACCOUNT>/ d" $tgt_script
  90. sed -i "s|<BARAKUDA_TOPDIR>|${ECE3_BARAKUDA_TOPDIR}|" $tgt_script
  91. sed -i "s|<DIAG>|diag|" $tgt_script
  92. sed -i "s|<OUT>|$OUT|" $tgt_script
  93. sed -i "s|<CMD>|${cmd}|" $tgt_script
  94. diagid=$(qsub $tgt_script)
  95. echo $diagid
  96. # -------- Create climatologies
  97. if (( $climato ))
  98. then
  99. cmd="./build_clim.sh -C ${conf} -R ${exp} -i $y1 -e $y2"
  100. tgt_script=$OUT/b_${exp}_climato.job
  101. sed "s/<EXPID>/$exp/" < platform/cca.job.tmpl > $tgt_script
  102. [[ -n $account ]] && \
  103. sed -i "s/<ACCOUNT>/$account/" $tgt_script || \
  104. sed -i "/<ACCOUNT>/ d" $tgt_script
  105. sed -i "s|<BARAKUDA_TOPDIR>|${ECE3_BARAKUDA_TOPDIR}|" $tgt_script
  106. sed -i "s|<DIAG>|clim|" $tgt_script
  107. sed -i "s|<OUT>|$OUT|" $tgt_script
  108. sed -i "s|<CMD>|${cmd}|" $tgt_script
  109. climid=$(qsub $tgt_script)
  110. echo $climid
  111. fi
  112. # -------- Create figures
  113. if (( $climato ))
  114. then
  115. cmd="./barakuda.sh -C ${conf} -R ${exp} -E"
  116. else
  117. cmd="./barakuda.sh -C ${conf} -R ${exp} -e"
  118. fi
  119. tgt_script=$OUT/b_${exp}_fig.job
  120. sed "s/<EXPID>/$exp/" < platform/cca.job.tmpl > $tgt_script
  121. [[ -n $account ]] && \
  122. sed -i "s/<ACCOUNT>/$account/" $tgt_script || \
  123. sed -i "/<ACCOUNT>/ d" $tgt_script
  124. sed -i "s|<BARAKUDA_TOPDIR>|${ECE3_BARAKUDA_TOPDIR}|" $tgt_script
  125. sed -i "s|<DIAG>|fig|" $tgt_script
  126. sed -i "s|<OUT>|$OUT|" $tgt_script
  127. sed -i "s|<CMD>|${cmd}|" $tgt_script
  128. if (( $climato ))
  129. then
  130. qsub -W depend=afterok:$diagid:$climid $tgt_script
  131. else
  132. qsub -W depend=afterok:$diagid $tgt_script
  133. fi
  134. # --------- info
  135. qstat -wu $USER