Collection of scripts and small programs used by the EVN Support Scientists at JIVE during the regular data processing of EVN observations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

144 lines
4.1 KiB

  1. #!/bin/bash
  2. ###### ampcal.sh
  3. ###### Jay Blanchard 2017 - bash script to do ampcal db stuff for an experiment
  4. ###### run in the directory for the experiment. Can easily be wrapped for a list of exps etc.
  5. ###### needs to pull from ccs to handle jb1/2 so needs ssh keys to be ok.
  6. function readAmpcal {
  7. #$1 is the first argument -> the source for which to get the ampcal
  8. local source=$1
  9. #echo "readAmpcal thinks source is ${source}"
  10. #check if ampcal exists for the source (exp_name will have been defined by the time this is run... scope in bash scripts eh :D)
  11. if [[ -f "${exp_name}_${source}_CALIB_AMP2.ampcal" ]]; then
  12. local amp_file="${exp_name}_${source}_CALIB_AMP2.ampcal"
  13. #else maybe we have a spectral line exp
  14. elif [[ -f "${exp_name}_1_${source}_CALIB_AMP2.ampcal" ]]; then
  15. local amp_file=${exp_name}_1_${source}_CALIB_AMP2.ampcal
  16. #else maybe Benito has named his _0 just to be difficult
  17. elif [[ -f "${exp_name}_0_${source}_CALIB_AMP2.ampcal" ]]; then
  18. local amp_file=${exp_name}_0_${source}_CALIB_AMP2.ampcal
  19. else
  20. echo "There is no ampcal file for calibrator ${source}"
  21. fi
  22. #if file was found!
  23. if [[ -f "${amp_file}" ]]; then
  24. #copy the file first then sed for JB
  25. #I think we no longer care about keeping things separate, we should worry about that when plotting!
  26. cp -puv ${amp_file} $OUT/ampcal/new/
  27. #fix JB
  28. sed -i "s/(JB)/(${jodrell})/g" "$OUT/ampcal/new/${amp_file}"
  29. #need to do ampcaldb as well as update database
  30. #need to do this in that directory because ampcaldb.pl is stupid. note: THIS BROKE EVERYTHING
  31. cd "$OUT/ampcal/new"
  32. ampcaldb.pl "${amp_file}"
  33. cat "ampcal.dat" >> "ampcal.all.dat"
  34. #insert into database:
  35. ampcal-db.py
  36. #have to return to where we were...
  37. cd "-" 1>/dev/null
  38. fi
  39. }
  40. ###### START MAIN
  41. #exp name from PWD
  42. exp_name=${PWD##*/}
  43. #getopts because eVLBI is _special_
  44. usage() { echo "Usage: ampcal.sh [-e evlbi_name]"; echo "evlbi_name is the name of the first experiment in the eVLBI session";echo "If your vex file uses non standard naming (not exp.vix) please scp and rename it yourself."; exit 1; }
  45. while getopts ":e:" opt; do
  46. case $opt in
  47. e)
  48. vexName=${OPTARG,,}
  49. echo "eVLBI mode, using vex $vexName.vix"
  50. ;;
  51. *)
  52. usage
  53. ;;
  54. esac
  55. done
  56. #we need to check we're not in $IN
  57. if [[ "${PWD}" == "${IN}/${exp_name}" ]]; then
  58. echo "You are in ${PWD}! Please run from ${OUT}/${exp_name}"
  59. exit 1
  60. fi
  61. #special handling for JB:
  62. #find out if we are using jb1 or 2
  63. #need to get vix from ccs (if it doesn't exist):
  64. if [[ ! -f "${exp_name}.vix" ]]; then
  65. #if eVLBI we need to copy the evlbi named vix file (we also rename it here so the rest of the code doesn't need changing)
  66. if [[ -n "${vexName}" ]]; then
  67. scp jops@ccs:/ccs/expr/"${vexName^^}"/"${vexName}".vix "${exp_name}".vix
  68. else
  69. scp jops@ccs:/ccs/expr/"${exp_name^^}"/"${exp_name}".vix .
  70. fi
  71. fi
  72. #check if we found it
  73. if [[ ! -f "${exp_name}.vix" ]]; then
  74. echo "Could not find vix. Are you in the experiment directory?"
  75. exit 1
  76. fi
  77. ##grep the file for "JODRELL2" if so we are jb2
  78. if [[ -z `grep JODRELL2 ${exp_name}.vix` ]]; then
  79. jodrell="J1"
  80. else
  81. jodrell="J2"
  82. fi
  83. echo "We are ${jodrell}"
  84. #we need to get the list of bandpass cals
  85. #we must cover the case of multi phase centre or spectral line
  86. #first see if $IN/expname.inp.txt exists
  87. if [[ -f "${IN}/${exp_name}/${exp_name}.inp.txt" ]]; then
  88. bpass_str=`grep -h bpass ${IN}/${exp_name}/${exp_name}.inp.txt`
  89. #else check for _1.inp.txt
  90. elif [[ -f "${IN}/${exp_name}/${exp_name}_1.inp.txt" ]]; then
  91. bpass_str=`grep -h bpass ${IN}/${exp_name}/${exp_name}_1.inp.txt`
  92. elif [[ -f "${IN}/${exp_name}/${exp_name}_0.inp.txt" ]]; then
  93. bpass_str=`grep -h bpass ${IN}/${exp_name}/${exp_name}_0.inp.txt`
  94. else
  95. echo "No input file found in ${IN}/${exp_name}! Have you run the pipeline?"
  96. exit 1
  97. fi
  98. if [[ -z bpass_str ]]; then
  99. echo "No bpass found"
  100. exit -1
  101. else
  102. IFS=', ' read -r -a bpass <<< ${bpass_str##*=}
  103. #loop through the list and get the ampcal for each
  104. for cal in "${bpass[@]}"
  105. do
  106. echo ""
  107. echo "Doing calibrator: ${cal}"
  108. readAmpcal "${cal}"
  109. done
  110. fi