Index: trunk/DataCheck/Processing/FillMoonInfo.sh
===================================================================
--- trunk/DataCheck/Processing/FillMoonInfo.sh	(revision 14195)
+++ trunk/DataCheck/Processing/FillMoonInfo.sh	(revision 14195)
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# option 
+doupdate="yes" # update all entries (needed when new fields have been added)
+#doupdate="no" # fill only entries which are not yet existing (default)
+
+source `dirname $0`/../Sourcefile.sh
+printprocesslog "INFO starting $0 with option doupdate="$doupdate
+
+logfile=$runlogpath"/FillMoonInfo-"$datetime".log"
+date >> $logfile
+
+# 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"` \
+        )
+dates=( `find $auxdata -mindepth 3 -type d | sort -r | sed "s/\${auxdata_for_sed}//g" | sed -e 's/^\///'` )
+echo ${dates[@]}
+printprocesslog "INFO processing the following night(s): "${dates[@]}
+echo  `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
+
+# do filling of aux data 
+for date in ${dates[@]}
+do 
+   runnumber=`echo $date | sed -e 's/\///g'`
+   if [ $runnumber -lt 20111115 ]
+   then
+      continue
+   fi
+   echo "processing date "$date
+
+   # get file numbers from DB
+   #   but only for not-corrupted files
+   query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND NOT ISNULL(fRightAscension) AND NOT ISNULL(fDeclination) "
+   #query=$query" AND fRunTypeKEY=6 "
+   if [ "$doupdate" = "no" ]
+   then
+      query=$query" AND ISNULL(fMoonDisk) "
+   fi
+   printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
+   filenumbers=( `sendquery` )
+   if [ ${#filenumbers} -eq 0 ]
+   then
+      printprocesslog "INFO No files found in the DB for night "$date
+      continue
+   fi
+
+   # fill auxiliary information for files
+   for filenum in ${filenumbers[@]}
+   do
+      printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
+      echo  `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
+      
+      # get input info from DB 
+      query="SELECT fRightAscension, fDeclination, fRunStart from RunInfo "
+      query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
+      info=( `sendquery` )
+      echo ${info[@]}
+      #echo "/home/fact/FACT++.db/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null"
+      lightinfo=( `/home/fact/FACT++.db/moon "${info[2]} ${info[3]}" --ra=${info[0]} --dec=${info[1]} 2>/dev/null` )
+      echo ${lightinfo[@]}
+      
+      # build query to update runinfo in DB
+      query="UPDATE RunInfo SET fSunZenithDistance="${lightinfo[2]}", fMoonDisk="${lightinfo[4]}", fMoonZenithDistance="${lightinfo[5]}", fAngleToMoon="${lightinfo[6]}
+      # add where condition
+      query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
+      echo $query
+      
+      # send query to DB
+      sendquery >/dev/null
+   done
+done
+
+finish
+
+
