source: trunk/DataCheck/QuickLook/Step2a.sh@ 18066

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