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 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
40 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
41 |
|
---|
42 | cd $mars
|
---|
43 |
|
---|
44 | # do filling of aux data
|
---|
45 | for date in ${dates[@]}
|
---|
46 | do
|
---|
47 | auxdir=$auxdata/$date
|
---|
48 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
49 | if [ $runnumber -lt 20120328 ]
|
---|
50 | then
|
---|
51 | continue
|
---|
52 | fi
|
---|
53 |
|
---|
54 | # check if aux files are available from that night
|
---|
55 | if ! [ -d $auxdir ]
|
---|
56 | then
|
---|
57 | printprocesslog "INFO no data available in "$auxdir
|
---|
58 | continue
|
---|
59 | else
|
---|
60 | printprocesslog "INFO processing files in "$auxdir
|
---|
61 | fi
|
---|
62 |
|
---|
63 | # get file numbers from DB
|
---|
64 | # but only for not-corrupted files
|
---|
65 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
66 | if [ "$doupdate" = "no" ]
|
---|
67 | then
|
---|
68 | query=$query" AND ISNULL(fCamHumidityMean) "
|
---|
69 | fi
|
---|
70 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
71 | filenumbers=( `sendquery $query` )
|
---|
72 | # proceed only if there are files available
|
---|
73 | if [ ${#filenumbers} -eq 0 ]
|
---|
74 | then
|
---|
75 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
76 | continue
|
---|
77 | fi
|
---|
78 |
|
---|
79 | fschumfile=$auxdir/$runnumber.FSC_CONTROL_HUMIDITY.fits
|
---|
80 | if ! [ -e $fschumfile ]
|
---|
81 | then
|
---|
82 | printprocesslog "WARN "$fschumfile" not found."
|
---|
83 | else
|
---|
84 | humnumerrors=`fverify $fschumfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
85 | if [ $humnumerrors -gt 0 ]
|
---|
86 | then
|
---|
87 | printprocesslog "WARN for "$fschumfile" fverify returned "$humnumerrors" error(s)."
|
---|
88 | fi
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # fill auxiliary information for files
|
---|
92 | for filenum in ${filenumbers[@]}
|
---|
93 | do
|
---|
94 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
95 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
96 | # get information from rawfile
|
---|
97 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
|
---|
98 | if ! [ -e $rawfile ]
|
---|
99 | then
|
---|
100 | printprocesslog "ERROR: "$rawfile" not found."
|
---|
101 | continue
|
---|
102 | fi
|
---|
103 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
---|
104 | #if [ "$checkfitsfile" == "" ]
|
---|
105 | #then
|
---|
106 | # numfitserrors=1
|
---|
107 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
---|
108 | # continue
|
---|
109 | #fi
|
---|
110 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
111 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
112 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
113 | tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
114 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
115 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
---|
116 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
117 | then
|
---|
118 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
119 | continue
|
---|
120 | fi
|
---|
121 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
122 | if [ $tstarti -gt 30000 ]
|
---|
123 | then
|
---|
124 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
125 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
126 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
127 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
128 | else
|
---|
129 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
130 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
131 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
132 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
133 | fi
|
---|
134 |
|
---|
135 | # build query to update runinfo in DB
|
---|
136 | query="UPDATE RunInfo SET "
|
---|
137 |
|
---|
138 | # get information from fsc: T[31]
|
---|
139 | if [ -e $fschumfile ] && [ $humnumerrors -eq 0 ]
|
---|
140 | then
|
---|
141 | hums=( `root -q -b -l fact/processing/camhum.C\("\"$fschumfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
142 | if [ "${hums[0]}" == "" ]
|
---|
143 | then
|
---|
144 | query=$query"fCamHumidityMean=NULL"
|
---|
145 | else
|
---|
146 | query=$query"fCamHumidityMean="${hums[0]}
|
---|
147 | fi
|
---|
148 | else
|
---|
149 | query=$query" fCamHumidityMean=NULL"
|
---|
150 | fi
|
---|
151 | #fCameraTempMeanRms: mean of rms of single sensors
|
---|
152 |
|
---|
153 | # add where condition
|
---|
154 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
155 |
|
---|
156 | # send query to DB
|
---|
157 | sendquery >/dev/null
|
---|
158 | done
|
---|
159 | done
|
---|
160 |
|
---|
161 | finish
|
---|
162 |
|
---|
163 |
|
---|