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

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