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

Last change on this file since 18341 was 18321, checked in by Daniela Dorner, 9 years ago
removed check of certaindate-variable (now done in getdate())
  • Property svn:executable set to *
File size: 5.4 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 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
38
39printprocesslog "INFO processing the following night(s): "${dates[@]}
40echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
41
42cd $mars
43
44# do filling of aux data
45for date in ${dates[@]}
46do
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
159done
160
161finish
162
163
Note: See TracBrowser for help on using the repository browser.