Index: trunk/DataCheck/Processing/FillAuxData.sh
===================================================================
--- trunk/DataCheck/Processing/FillAuxData.sh	(revision 17094)
+++ trunk/DataCheck/Processing/FillAuxData.sh	(revision 17095)
@@ -20,12 +20,16 @@
 # trigger rate has as first value -1, but with using the median it should be fine
 
-# option 
-doupdate="yes" # update all entries (needed when new fields have been added)
-doupdate="no" # fill only entries which are not yet existing (default)
+# option whether to fill all row or only those where information is missing
+# $doupdate might be given as environment variable
+if [ "$doupdate" = "" ]
+then
+   doupdate="yes" # update all entries (needed when new fields have been added)
+   doupdate="no" # fill only entries which are not yet existing (default)
+fi
 
 source `dirname $0`/../Sourcefile.sh
 printprocesslog "INFO starting $0 with option doupdate="$doupdate
 
-logfile=$runlogpath"/FillAuxLP-"$datetime".log"
+logfile=$runlogpath"/FillAuxData-"$datetime".log"
 date >> $logfile
 
@@ -71,5 +75,6 @@
       printprocesslog "WARN couldn't get statistics from file $1 for run $date $file"
       rm $tmpfile
-      finish
+      continue
+      #finish
    fi
    #echo "good: "$good
@@ -91,20 +96,14 @@
 fi
 
-
-# get current hour
-hour=`date +%k`
-if [ $hour -le 7 ] || [ $hour -ge 19 ]
+# get dates
+if [ "$certaindate" != "" ]
 then
-   dates=( `date +%Y/%m/%d --date="-12hour"` )
+   getdates $certaindate
 else
-   # get last 3, 6 or 9 nights
-   dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
-           `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
-#           `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
-           )
+   # get all night
+   #getdates "all"
+   # get last 6 nights if time between 7 and 19h
+   getdates 6 7 19
 fi
-#dates=( `find $ziprawdata -mindepth 3 -type d | sort | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
-
-#dates=( "2013/06/13")
 
 printprocesslog "INFO processing the following night(s): "${dates[@]}
@@ -160,4 +159,13 @@
          printprocesslog "WARN for $sourceposfile fverify returned "$sourceposnumerrors" error(s)."
       fi
+      sourceposfiletstarti=`$factpath/fitsdump -h $sourceposfile  2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
+      sourceposfiletstartf=`$factpath/fitsdump -h $sourceposfile  2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
+      if [ $sourceposfiletstarti -gt 30000 ]
+      then 
+         sourceposfiletstart=`echo " $sourceposfiletstarti + $sourceposfiletstartf - 40587 " | bc -l`
+      else
+         sourceposfiletstart=`echo " $sourceposfiletstarti + $sourceposfiletstartf " | bc -l`
+      fi
+      #echo "tstart: "$sourceposfiletstart
    fi
    
@@ -257,9 +265,11 @@
 
       # get information from source_pos file
+      #echo $sourceposfile
       if [ -e $sourceposfile ] && [ $sourceposnumerrors -eq 0 ]
       then 
          #sourcename=`${factpath}/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}  2>/dev/null | tail -1 2>&1 | grep -o -E "['][a-zA-Z0-9\ ]+[']" | sed -e "s/'//g"`
          #sourcename=`/home/fact/FACT++.dbg/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}  2>/dev/null | tail -1 2>&1 | grep -o -E "['][a-zA-Z0-9\+\-\ ]+[']" | sed -e "s/'//g"`
-         sourcename=`/home/fact/FACT++.dbg/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}  2>/dev/null | tail -1 2>&1 | grep -o -E "['][a-zA-Z0-9\ \.\+\-]+[']" | sed -e "s/'//g"`
+         sourcename=`$factpath/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}' && [1]>'${sourceposfiletstart}  2>/dev/null | tail -1 2>&1 | grep -o -E "['][a-zA-Z0-9\ \.\+\-]+[']" | sed -e "s/'//g"`
+         #echo "$factpath/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop} --filter='[1]>'${sourceposfiletstart}  2>/dev/null | tail -1 2>&1 | grep -o -E \"['][a-zA-Z0-9\ \.\+\-]+[']\" | sed -e \"s/'//g\""
          #echo $sourcename
          if [ "$sourcename" == "" ]
@@ -268,4 +278,5 @@
          else 
             query="SELECT fSourceKey FROM Source WHERE fSourceName='"$sourcename"'"
+            #echo $query
             sourcekey=`sendquery`
             if [ "$sourcename" == "" ]
@@ -283,4 +294,6 @@
       then
          query=$query" fSourceKey="$sourcekey", "
+      else
+         query=$query" fSourceKey=NULL, "
       fi
       
