1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # option
|
---|
4 | doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
5 | #doupdate="no" # fill only entries which are not yet existing (default)
|
---|
6 |
|
---|
7 | source `dirname $0`/../Sourcefile.sh
|
---|
8 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
9 |
|
---|
10 | logfile=$runlogpath"/FillTemp-"$datetime".log"
|
---|
11 | date >> $logfile
|
---|
12 |
|
---|
13 | # setup to use ftools
|
---|
14 | source $HEADAS/headas-init.sh
|
---|
15 |
|
---|
16 | # check if software is available
|
---|
17 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
18 | then
|
---|
19 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
20 | finish
|
---|
21 | fi
|
---|
22 |
|
---|
23 |
|
---|
24 | # get last 3, 6 or 9 nights
|
---|
25 | dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
|
---|
26 | # `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
|
---|
27 | # `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
|
---|
28 | )
|
---|
29 | dates=( `find -L $ziprawdata -mindepth 3 -type d | sort | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
|
---|
30 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
31 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
32 |
|
---|
33 | echo ${dates[@]}
|
---|
34 |
|
---|
35 | cd $mars
|
---|
36 |
|
---|
37 | # do filling of aux data
|
---|
38 | for date in ${dates[@]}
|
---|
39 | do
|
---|
40 | auxdir=$auxdata/$date
|
---|
41 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
42 | if [ $runnumber -lt 20120328 ]
|
---|
43 | then
|
---|
44 | continue
|
---|
45 | fi
|
---|
46 |
|
---|
47 | # check if aux files are available from that night
|
---|
48 | if ! [ -d $auxdir ]
|
---|
49 | then
|
---|
50 | printprocesslog "INFO no data available in "$auxdir
|
---|
51 | continue
|
---|
52 | else
|
---|
53 | printprocesslog "INFO processing files in "$auxdir
|
---|
54 | fi
|
---|
55 |
|
---|
56 | # get file numbers from DB
|
---|
57 | # but only for not-corrupted files
|
---|
58 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
59 | if [ "$doupdate" = "no" ]
|
---|
60 | then
|
---|
61 | query=$query" AND ISNULL(fCameraTempMean) "
|
---|
62 | fi
|
---|
63 |
|
---|
64 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
65 | filenumbers=( `sendquery $query` )
|
---|
66 | if [ ${#filenumbers} -eq 0 ]
|
---|
67 | then
|
---|
68 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
69 | continue
|
---|
70 | fi
|
---|
71 |
|
---|
72 | magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
|
---|
73 | if ! [ -e $magicweatherfile ]
|
---|
74 | then
|
---|
75 | printprocesslog "WARN "$magicweatherfile" not found."
|
---|
76 | echo "WARN "$magicweatherfile" not found."
|
---|
77 | else
|
---|
78 | weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
79 | if [ $weathernumerrors -gt 0 ]
|
---|
80 | then
|
---|
81 | printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
|
---|
82 | fi
|
---|
83 | fi
|
---|
84 |
|
---|
85 | fsctempfile=$auxdir/$runnumber.FSC_CONTROL_TEMPERATURE.fits
|
---|
86 | if ! [ -e $fsctempfile ]
|
---|
87 | then
|
---|
88 | printprocesslog "WARN "$fsctempfile" not found."
|
---|
89 | echo "WARN "$fsctempfile" not found."
|
---|
90 | else
|
---|
91 | tempnumerrors=`fverify $fsctempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
92 | if [ $tempnumerrors -gt 0 ]
|
---|
93 | then
|
---|
94 | printprocesslog "WARN for $fsctempfile fverify returned "$tempnumerrors" error(s)."
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 |
|
---|
98 | # fill auxiliary information for files
|
---|
99 | for filenum in ${filenumbers[@]}
|
---|
100 | do
|
---|
101 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
102 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
103 | # get information from rawfile
|
---|
104 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
|
---|
105 | if ! [ -e $rawfile ]
|
---|
106 | then
|
---|
107 | printprocesslog "ERROR: "$rawfile" not found."
|
---|
108 | continue
|
---|
109 | fi
|
---|
110 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
---|
111 | #if [ "$checkfitsfile" == "" ]
|
---|
112 | #then
|
---|
113 | # numfitserrors=1
|
---|
114 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
---|
115 | # continue
|
---|
116 | #fi
|
---|
117 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
118 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
119 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
120 | tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
121 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
122 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
---|
123 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
124 | then
|
---|
125 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
126 | continue
|
---|
127 | fi
|
---|
128 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
129 | #echo $rawfile
|
---|
130 | #echo $tstarti
|
---|
131 | #echo $tstopi
|
---|
132 | #echo $tstartf
|
---|
133 | #echo $tstopf
|
---|
134 | if [ $tstarti -gt 30000 ]
|
---|
135 | then
|
---|
136 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
137 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
138 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
139 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
140 | else
|
---|
141 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
142 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
143 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
144 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
145 | fi
|
---|
146 |
|
---|
147 | # build query to update runinfo in DB
|
---|
148 | query="UPDATE RunInfo SET "
|
---|
149 |
|
---|
150 | # get information from fsc: T[31]
|
---|
151 | if [ -e $fsctempfile ] && [ $tempnumerrors -eq 0 ]
|
---|
152 | then
|
---|
153 | fsctemps=( `root -q -b -l fact/camtemp.C\("\"$fsctempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
154 | echo ${fsctemps[@]}
|
---|
155 | if [ "${fsctemps[0]}" == "" ]
|
---|
156 | then
|
---|
157 | query=$query"fCameraTempMean=NULL"
|
---|
158 | else
|
---|
159 | query=$query"fCameraTempMean="${fsctemps[0]}
|
---|
160 | fi
|
---|
161 | if [ "${fsctemps[1]}" == "" ]
|
---|
162 | then
|
---|
163 | query=$query", fCameraTempRms=NULL"
|
---|
164 | else
|
---|
165 | query=$query", fCameraTempRms="${fsctemps[1]}
|
---|
166 | fi
|
---|
167 | if [ "${fsctemps[2]}" == "" ]
|
---|
168 | then
|
---|
169 | query=$query", fCameraTempRmsMean=NULL"
|
---|
170 | else
|
---|
171 | query=$query", fCameraTempRmsMean="${fsctemps[2]}
|
---|
172 | fi
|
---|
173 | else
|
---|
174 | query=$query" fCameraTempMean=NULL"
|
---|
175 | query=$query", fCameraTempRms=NULL"
|
---|
176 | query=$query", fCameraTempRmsMean=NULL"
|
---|
177 | fi
|
---|
178 | #fCameraTempMeanRms: mean of rms of single sensors
|
---|
179 |
|
---|
180 | # get information from weather: T
|
---|
181 | if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
|
---|
182 | then
|
---|
183 | mtemps=( `root -q -b -l fact/magictemp.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
184 | if [ "${mtemps[0]}" == "" ]
|
---|
185 | then
|
---|
186 | query=$query", fOutsideTempMean=NULL"
|
---|
187 | else
|
---|
188 | query=$query", fOutsideTempMean="${mtemps[0]}
|
---|
189 | fi
|
---|
190 | if [ "${mtemps[1]}" == "" ]
|
---|
191 | then
|
---|
192 | query=$query", fOutsideTempRms=NULL"
|
---|
193 | else
|
---|
194 | query=$query", fOutsideTempRms="${mtemps[1]}
|
---|
195 | fi
|
---|
196 | else
|
---|
197 | query=$query", fOutsideTempMean=NULL"
|
---|
198 | query=$query", fOutsideTempRms=NULL"
|
---|
199 | fi
|
---|
200 |
|
---|
201 | # add where condition
|
---|
202 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
203 |
|
---|
204 | echo $query
|
---|
205 | # send query to DB
|
---|
206 | sendquery >/dev/null
|
---|
207 | done
|
---|
208 | done
|
---|
209 |
|
---|
210 | finish
|
---|
211 |
|
---|
212 |
|
---|