| 1 | #!/bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 4 | printprocesslog "INFO starting $0"
|
|---|
| 5 |
|
|---|
| 6 | # get dates
|
|---|
| 7 | if [ "$certaindate" != "" ]
|
|---|
| 8 | then
|
|---|
| 9 | getdates $certaindate
|
|---|
| 10 | else
|
|---|
| 11 | if [ "$1" = "" ]
|
|---|
| 12 | then
|
|---|
| 13 | # get all night
|
|---|
| 14 | #getdates "all"
|
|---|
| 15 | # get last 6 nights if hour between 7 and 19h, else only current night
|
|---|
| 16 | getdates 6 7 19
|
|---|
| 17 | else
|
|---|
| 18 | getdates $1
|
|---|
| 19 | fi
|
|---|
| 20 | fi
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | for date in ${dates[@]}
|
|---|
| 25 | do
|
|---|
| 26 | printprocesslog "INFO processing "$date
|
|---|
| 27 | #echo "INFO processing "$date
|
|---|
| 28 | night=`echo $date | sed -e 's/\///g'`
|
|---|
| 29 |
|
|---|
| 30 | numganymeds=0
|
|---|
| 31 |
|
|---|
| 32 | # getting all image files for this night
|
|---|
| 33 | printprocesslog "INFO get file list for night "$date
|
|---|
| 34 | files=( `find $anapath/star/$date -type f -name '*_I.root' 2>/dev/null | sort` )
|
|---|
| 35 | if [ ${#files[@]} -eq 0 ]
|
|---|
| 36 | then
|
|---|
| 37 | printprocesslog "INFO no image files available for night "$date
|
|---|
| 38 | continue
|
|---|
| 39 | fi
|
|---|
| 40 | # write data set file
|
|---|
| 41 | #dspath=$anapath/$source/datasets`printf %03d $min`min/$date
|
|---|
| 42 | #dspath=$anapath/$source/datasets_run/$date
|
|---|
| 43 | dspath=$anapath/datasets_run/$date
|
|---|
| 44 | makedir $dspath
|
|---|
| 45 |
|
|---|
| 46 | for (( i=1 ; i<=${#files[@]} ; i++ ))
|
|---|
| 47 | do
|
|---|
| 48 | night=`basename ${files[$i-1]} | cut -d_ -f1`
|
|---|
| 49 | run=`basename ${files[$i-1]} | cut -d_ -f2`
|
|---|
| 50 | printprocesslog "DEBUG night: "$night" run: "$run
|
|---|
| 51 | dsfile=$dspath"/dataset"$night"_"$run".txt"
|
|---|
| 52 | #echo $dsfile
|
|---|
| 53 | printprocesslog "INFO writing dataset file "$dsfile
|
|---|
| 54 | # write dataset only if merpp-log is available to make sure that star-file is complete
|
|---|
| 55 | if echo $resulttable1 | grep ISDC >/dev/null 2>&1
|
|---|
| 56 | then
|
|---|
| 57 | query="SELECT LPAD(fSequenceID, 3, 0) FROM RunInfo WHERE fNight="$night" AND fRunID="$run
|
|---|
| 58 | seq=`sendquery`
|
|---|
| 59 | merpplog=`dirname ${files[$i-1]}`"/"$night"_"$seq"-merpp.log"
|
|---|
| 60 | else
|
|---|
| 61 | merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
|
|---|
| 62 | fi
|
|---|
| 63 | stillrunning=`find $merpplog -mmin -1 2>/dev/null`
|
|---|
| 64 | if [ -e $merpplog ] && [ "$stillrunning" == "" ]
|
|---|
| 65 | then
|
|---|
| 66 | echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
|
|---|
| 67 | else
|
|---|
| 68 | printprocesslog "INFO merpp still running - wait with file "${files[$i-1]}
|
|---|
| 69 | continue
|
|---|
| 70 | fi
|
|---|
| 71 | # process only if ganymedlogfiles is not yet there
|
|---|
| 72 | logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
|
|---|
| 73 | if ! ls $logfile >/dev/null 2>&1
|
|---|
| 74 | then
|
|---|
| 75 | # fixme: why is this double?
|
|---|
| 76 | night=`basename ${files[$i-1]} | cut -d_ -f1`
|
|---|
| 77 | runid=`basename ${files[$i-1]} | cut -d_ -f2 | cut -d. -f1`
|
|---|
| 78 | drivefile=$auxdata"/"$date"/"`basename ${files[$i-1]} | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
|
|---|
| 79 | rawfilepath=$rawdata"/"$date"/"
|
|---|
| 80 | rawfilename=`basename ${files[$i-1]} | sed -e 's/_I.root/.fits/'`
|
|---|
| 81 | rawfile=`find $rawfilepath -name $rawfilename* 2>/dev/null`
|
|---|
| 82 | if ! [ "$rawfile" == "" ]
|
|---|
| 83 | then
|
|---|
| 84 | printprocesslog "INFO processing "$rawfile
|
|---|
| 85 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 86 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
|
|---|
| 87 | tstop=${tstopi}${tstopf}
|
|---|
| 88 | fi
|
|---|
| 89 | #echo "tstop: "$tstop
|
|---|
| 90 | if [ ls $drivefile >/dev/null 2>&1 ] && ! [ "$tstop" == "" ]
|
|---|
| 91 | then
|
|---|
| 92 | printprocesslog "INFO getting coordinates from "$drivefile
|
|---|
| 93 | coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
|
|---|
| 94 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 95 | then
|
|---|
| 96 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 97 | #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 98 | continue
|
|---|
| 99 | fi
|
|---|
| 100 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 101 | then
|
|---|
| 102 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 103 | #echo "WARN coordinates "${coordinates[@]}
|
|---|
| 104 | continue
|
|---|
| 105 | fi
|
|---|
| 106 | else
|
|---|
| 107 | printprocesslog "INFO getting coordinates from DB."
|
|---|
| 108 | query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
|
|---|
| 109 | sourcekey=`sendquery`
|
|---|
| 110 | if [ "$sourcekey" == "" ]
|
|---|
| 111 | then
|
|---|
| 112 | printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
|
|---|
| 113 | #echo "WARN sourcekey empty - coordinates"${coordinates[@]}" for "$rawfile
|
|---|
| 114 | continue
|
|---|
| 115 | fi
|
|---|
| 116 | query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from source WHERE fSourceKey="$sourcekey
|
|---|
| 117 | coordinates=( `sendquery` )
|
|---|
| 118 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 119 | then
|
|---|
| 120 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from DB."
|
|---|
| 121 | #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 122 | continue
|
|---|
| 123 | fi
|
|---|
| 124 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 125 | then
|
|---|
| 126 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 127 | #echo "WARN coordinates "${coordinates[@]}
|
|---|
| 128 | continue
|
|---|
| 129 | fi
|
|---|
| 130 | fi
|
|---|
| 131 |
|
|---|
| 132 | printprocesslog "DEBUG "$logfile" "${files[$i-1]}" -"${coordinates[0]}"-"${coordinates[1]}
|
|---|
| 133 | printprocesslog "DEBUG `dirname $0`/RunGanymed.sh $dsfile "${coordinates[0]}" "${coordinates[1]}
|
|---|
| 134 | if [ "$qlasge" = "yes" ]
|
|---|
| 135 | then
|
|---|
| 136 | printprocesslog "$sgepath/qsub -b y -q fact_short -v AUTOMATIONSETUP=$AUTOMATIONSETUP -v dsfile=$dsfile -v ra=${coordinates[0]} -v dec=${coordinates[1]} -e bla.txt -o bla.txt `dirname $0`/RunGanymed.sh"
|
|---|
| 137 | $sgepath/qsub -b y -q fact_short -v AUTOMATIONSETUP=$AUTOMATIONSETUP -v dsfile=$dsfile -v ra=${coordinates[0]} -v dec=${coordinates[1]} -e bla.txt -o bla.txt `dirname $0`/RunGanymed.sh
|
|---|
| 138 | else
|
|---|
| 139 | `dirname $0`/RunGanymed.sh $dsfile ${coordinates[0]} ${coordinates[1]}
|
|---|
| 140 | #echo "ganymed for "$dsfile" "${coordinates[0]}" "${coordinates[1]}
|
|---|
| 141 | fi
|
|---|
| 142 | numganymeds=`echo " $numganymeds + 1 " | bc -l`
|
|---|
| 143 | fi
|
|---|
| 144 | done
|
|---|
| 145 | printprocesslog "INFO found "$numganymeds" ganymeds."
|
|---|
| 146 | done
|
|---|
| 147 |
|
|---|
| 148 | finish
|
|---|
| 149 |
|
|---|