source: trunk/DataCheck/Processing/FillAuxMagic.sh@ 19570

Last change on this file since 19570 was 19523, checked in by Daniela Dorner, 5 years ago
removed not needed line
  • Property svn:executable set to *
File size: 9.6 KB
Line 
1#!/bin/bash
2
3# option whether to fill all row or only those where information is missing
4# $doupdate might be given as environment variable
5if [ "$doupdate" = "" ]
6then
7 doupdate="yes" # update all entries (needed when new fields have been added)
8 doupdate="no" # fill only entries which are not yet existing (default)
9fi
10
11source `dirname $0`/../Sourcefile.sh
12printprocesslog "INFO starting $0 with option doupdate="$doupdate
13
14logfile=$runlogpath"/FillAuxTemp-"$datetime".log"
15date >> $logfile
16
17# setup to use ftools
18source $HEADAS/headas-init.sh
19
20# check if software is available
21if ! ls $factpath/fitsdump >/dev/null 2>&1
22then
23 printprocesslog "ERROR "$factpath"/fitsdump is not available."
24 finish
25fi
26
27# get dates
28if [ "$certaindate" != "" ]
29then
30 getdates $certaindate
31 echo `date`": processing the following night(s): "${dates[@]}
32else
33 # get all night
34 #getdates "all"
35 # get last 6 nights
36 getdates 6
37fi
38
39
40
41printprocesslog "INFO processing the following night(s): "${dates[@]}
42echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
43
44cd $mars
45
46# do filling of aux data
47for date in ${dates[@]}
48do
49 auxdir=$auxdata/$date
50 runnumber=`echo $date | sed -e 's/\///g'`
51 if [ $runnumber -lt 20120328 ]
52 then
53 continue
54 fi
55
56 # check if aux files are available from that night
57 if ! [ -d $auxdir ]
58 then
59 printprocesslog "INFO no data available in "$auxdir
60 continue
61 else
62 printprocesslog "INFO processing files in "$auxdir
63 fi
64
65 # get file numbers from DB
66 # but only for not-corrupted files
67 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
68 if [ "$doupdate" = "no" ]
69 then
70 query=$query" AND ISNULL(fCameraTempMean) "
71 fi
72 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
73 filenumbers=( `sendquery $query` )
74 # proceed only if there are files available
75 if [ ${#filenumbers} -eq 0 ]
76 then
77 printprocesslog "INFO No files found in the DB for night "$date
78 continue
79 fi
80
81 magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
82 if ! [ -e $magicweatherfile ]
83 then
84 printprocesslog "WARN "$magicweatherfile" not found."
85 else
86 weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
87 if [ $weathernumerrors -gt 0 ]
88 then
89 printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
90 fi
91 fi
92
93 # fill auxiliary information for files
94 for filenum in ${filenumbers[@]}
95 do
96 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
97 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
98 # get information from rawfile
99 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
100 if ! [ -e $rawfile ]
101 then
102 if [ $runnumber -lt $checknight ]
103 then
104 printprocesslog "WARN "$rawfile" not found."
105 else
106 printprocesslog "INFO "$rawfile" not found."
107 fi
108 printprocesslog "INFO getting information from DB for "$rawfile
109 # get information from DB
110 query="SELECT Mjd(fRunStart)-40587 FROM RunInfo WHERE fNight="$runnumber" AND fRunID="$filenum
111 tstart=`sendquery`
112 query="SELECT Mjd(fRunStop)-40587 FROM RunInfo WHERE fNight="$runnumber" AND fRunID="$filenum
113 tstop=`sendquery`
114 query="SELECT Mjd(fRunStart)-40587-0.00011574 FROM RunInfo WHERE fNight="$runnumber" AND fRunID="$filenum
115 tstart2=`sendquery`
116 query="SELECT Mjd(fRunStop)-40587-0.00011574 FROM RunInfo WHERE fNight="$runnumber" AND fRunID="$filenum
117 tstop2=`sendquery`
118 if [ "$tstart" = "" ] || [ "$tstop" = "" ] || [ "$runtype" = "n/a" ]
119 then
120 printprocesslog "WARN: "$rawfile" not available and one of the following information empty in DB: fRunStart("$tstart"), fRunStop("$tstop"), fRunTypeKey("$runtype") "
121 continue
122 fi
123 else
124 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
125 #if [ "$checkfitsfile" == "" ]
126 #then
127 # numfitserrors=1
128 # printprocesslog "WARN: "$rawfile" probably corrupted."
129 # continue
130 #fi
131 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
132 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
133 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
134 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
135 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
136 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
137 then
138 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
139 continue
140 fi
141 # assuming that at least TSTARTI and TSTOPI are consistent
142 if [ $tstarti -gt 30000 ]
143 then
144 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
145 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
146 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
147 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
148 else
149 tstart=`echo " $tstarti + $tstartf " | bc -l`
150 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
151 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
152 tstop=`echo " $tstopi + $tstopf " | bc -l`
153 fi
154 #echo `date`": processing file number "$runnumber"_"`printf %03d $filenum`
155 fi
156
157 # build query to update runinfo in DB
158 query="UPDATE RunInfo SET "
159
160 # get information from weather: T
161 if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
162 then
163 #echo $magicweatherfile" "$tstart" "$tstop
164 printprocesslog "DEBUG root -q -b -l fact/processing/magicweather.C\("\"$magicweatherfile\""\,"$tstart"\,"$tstop"\)"
165 mtemps=( `root -q -b -l fact/processing/magicweather.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[-]?[0-9]+[.]?[0-9]*'` )
166 check1=$?
167 case $check1 in
168 0) printprocesslog "INFO got info from "$magicweatherfile
169 ;;
170 *) printprocesslog "WARN getting info from "$magicweatherfile" failed (check1="$check1")."
171 ;;
172 esac
173 #echo ${mtemps[@]}
174 if [ "${mtemps[0]}" == "" ]
175 then
176 query=$query"fOutsideTempMean=NULL"
177 else
178 query=$query"fOutsideTempMean="${mtemps[0]}
179 fi
180 if [ "${mtemps[1]}" == "" ]
181 then
182 query=$query", fOutsideTempRms=NULL"
183 else
184 query=$query", fOutsideTempRms="${mtemps[1]}
185 fi
186 if [ "${mtemps[2]}" == "" ]
187 then
188 query=$query", fHumidityMean=NULL"
189 else
190 query=$query", fHumidityMean="${mtemps[2]}
191 fi
192 if [ "${mtemps[3]}" == "" ]
193 then
194 query=$query", fHumidityRms=NULL"
195 else
196 query=$query", fHumidityRms="${mtemps[3]}
197 fi
198 if [ "${mtemps[4]}" == "" ]
199 then
200 query=$query", fAirPressureMean=NULL"
201 else
202 query=$query", fAirPressureMean="${mtemps[4]}
203 fi
204 if [ "${mtemps[5]}" == "" ]
205 then
206 query=$query", fAirPressureRms=NULL"
207 else
208 query=$query", fAirPressureRms="${mtemps[5]}
209 fi
210 if [ "${mtemps[6]}" == "" ]
211 then
212 query=$query", fDewPointMean=NULL"
213 else
214 query=$query", fDewPointMean="${mtemps[6]}
215 fi
216 if [ "${mtemps[7]}" == "" ]
217 then
218 query=$query", fDewPointRms=NULL"
219 else
220 query=$query", fDewPointRms="${mtemps[7]}
221 fi
222 if [ "${mtemps[8]}" == "" ]
223 then
224 query=$query", fWindSpeedMean=NULL"
225 else
226 query=$query", fWindSpeedMean="${mtemps[8]}
227 fi
228 if [ "${mtemps[9]}" == "" ]
229 then
230 query=$query", fWindSpeedRms=NULL"
231 else
232 query=$query", fWindSpeedRms="${mtemps[9]}
233 fi
234 if [ "${mtemps[10]}" == "" ]
235 then
236 query=$query", fWindGustMean=NULL"
237 else
238 query=$query", fWindGustMean="${mtemps[10]}
239 fi
240 if [ "${mtemps[119]}" == "" ]
241 then
242 query=$query", fWindGustRms=NULL"
243 else
244 query=$query", fWindGustRms="${mtemps[11]}
245 fi
246 else
247 query=$query"fOutsideTempMean=NULL"
248 query=$query", fOutsideTempRms=NULL"
249 query=$query", fHumidityMean=NULL"
250 query=$query", fHumidityRms=NULL"
251 query=$query", fAirPressureMean=NULL"
252 query=$query", fAirPressureRms=NULL"
253 query=$query", fDewPointMean=NULL"
254 query=$query", fDewPointRms=NULL"
255 query=$query", fWindSpeedMean=NULL"
256 query=$query", fWindSpeedRms=NULL"
257 query=$query", fWindGustMean=NULL"
258 query=$query", fWindGustRms=NULL"
259 fi
260
261 # add where condition
262 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
263
264 # send query to DB
265 sendquery >/dev/null
266 done
267done
268
269finish
270
271
Note: See TracBrowser for help on using the repository browser.