source: trunk/DataCheck/Processing/FillAuxCamHum.sh@ 18009

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