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"/FillAuxDust-"$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(fTNGDust) "
|
---|
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 | dustfile=$auxdir/$runnumber.TNG_WEATHER_DUST.fits
|
---|
81 | if ! [ -e $dustfile ]
|
---|
82 | then
|
---|
83 | printprocesslog "WARN "$dustfile" not found."
|
---|
84 | else
|
---|
85 | dustnumerrors=`fverify $dustfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
86 | if [ $dustnumerrors -gt 0 ]
|
---|
87 | then
|
---|
88 | printprocesslog "WARN for "$dustfile" fverify returned "$dustnumerrors" error(s)."
|
---|
89 | fi
|
---|
90 | fi
|
---|
91 |
|
---|
92 | # fill auxiliary information for files
|
---|
93 | for filenum in ${filenumbers[@]}
|
---|
94 | do
|
---|
95 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
96 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
97 | # get information from rawfile
|
---|
98 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
|
---|
99 | if ! [ -e $rawfile ]
|
---|
100 | then
|
---|
101 | if [ $runnumber -lt $checknight ]
|
---|
102 | then
|
---|
103 | printprocesslog "WARN "$rawfile" not found."
|
---|
104 | else
|
---|
105 | printprocesslog "INFO "$rawfile" not found."
|
---|
106 | fi
|
---|
107 | continue
|
---|
108 | fi
|
---|
109 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
---|
110 | #if [ "$checkfitsfile" == "" ]
|
---|
111 | #then
|
---|
112 | # numfitserrors=1
|
---|
113 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
---|
114 | # continue
|
---|
115 | #fi
|
---|
116 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
117 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
118 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
119 | 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\\^/'`
|
---|
120 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
121 | 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\\^/'`
|
---|
122 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
123 | then
|
---|
124 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
125 | continue
|
---|
126 | fi
|
---|
127 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
128 | if [ $tstarti -gt 30000 ]
|
---|
129 | then
|
---|
130 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
131 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
132 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
133 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
134 | else
|
---|
135 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
136 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
137 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
138 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
139 | fi
|
---|
140 |
|
---|
141 | # build query to update runinfo in DB
|
---|
142 | query="UPDATE RunInfo SET "
|
---|
143 |
|
---|
144 | # get information from tng dust file
|
---|
145 | if [ -e $dustfile ] && [ $dustnumerrors -eq 0 ]
|
---|
146 | then
|
---|
147 | dust=( `root -q -b -l fact/processing/dust.C\("\"$dustfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
148 | if [ "${dust[0]}" == "" ]
|
---|
149 | then
|
---|
150 | query=$query"fTNGDust=NULL"
|
---|
151 | else
|
---|
152 | query=$query"fTNGDust="${dust[0]}
|
---|
153 | fi
|
---|
154 | else
|
---|
155 | query=$query" fTNGDust=NULL"
|
---|
156 | fi
|
---|
157 | #fCameraTempMeanRms: mean of rms of single sensors
|
---|
158 |
|
---|
159 | # add where condition
|
---|
160 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
161 |
|
---|
162 | # send query to DB
|
---|
163 | sendquery >/dev/null
|
---|
164 | done
|
---|
165 | done
|
---|
166 |
|
---|
167 | finish
|
---|
168 |
|
---|
169 |
|
---|