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