Index: trunk/DataCheck/QuickLook/Step2a.sh
===================================================================
--- trunk/DataCheck/QuickLook/Step2a.sh	(revision 15399)
+++ trunk/DataCheck/QuickLook/Step2a.sh	(revision 15400)
@@ -3,10 +3,4 @@
 source `dirname $0`/../Sourcefile.sh
 printprocesslog "INFO starting $0"
-
-#root=/opt/root_svn/bin/thisroot.sh
-#source $root
-#factpath=/home/fact/FACT++.in-run-fad-loss
-
-#anapath=/loc_data/analysis
 
 if [ "$1" = "" ]
@@ -21,52 +15,108 @@
 night=`echo $datepath | sed -e 's/\///g'`
 
-sources=( 1 2 5 7 )
 numganymeds=0
 
-for source in ${sources[@]}
+# getting all image files for this night
+printprocesslog "INFO get file list for night "$datepath
+files=( `find /loc_data/analysis/star/$datepath -type f -name '*_I.root' 2>/dev/null | sort` )
+if [ ${#files[@]} -eq 0 ]
+then
+   printprocesslog "INFO no image files available for night "$datepath
+   continue
+fi
+# write data set file
+#dspath=$anapath/$source/datasets`printf %03d $min`min/$datepath
+#dspath=$anapath/$source/datasets_run/$datepath
+dspath=$anapath/datasets_run/$datepath
+makedir $dspath
+
+for (( i=1 ; i<=${#files[@]} ; i++ ))
 do 
-   ## doing first 5min datasets, i.e. one image file per dataset
-   #min=5
-   # getting all image files for this source and night
-   printprocesslog "INFO get file list for source "$source
-   files=( `find /loc_data/analysis/$source/star/$datepath -type f -name '*_I.root' 2>/dev/null | sort` )
-   if [ ${#files[@]} -eq 0 ]
-   then
-      printprocesslog "INFO no image files available for source "$source" on "$datepath
+   night=`basename ${files[$i-1]} | cut -d_ -f1`
+   echo "night: "$night
+   run=`basename ${files[$i-1]} | cut -d_ -f2`
+   echo "run: "$run
+   dsfile=$dspath"/dataset"$night"_"$run".txt"
+   echo $dsfile
+   printprocesslog "INFO writing dataset file "$dsfile
+   # write dataset only if merpp-log is available to make sure that star-file is complete
+   merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
+   stillrunning=`find $merpplog -mmin -1 2>/dev/null`
+   if [ -e $merpplog ] && [ "$stillrunning" == "" ]
+   then 
+      echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
+   else
+      echo "merpp still running - wait with file "${files[$i-1]}
       continue
    fi
-   # write data set file
-   #dspath=$anapath/$source/datasets`printf %03d $min`min/$datepath
-   dspath=$anapath/$source/datasets_run/$datepath
-   makedir $dspath
-   for (( i=1 ; i<=${#files[@]} ; i++ ))
-   do 
+   # process only if ganymedlogfiles is not yet there
+   logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
+   if ! ls $logfile >/dev/null 2>&1
+   then
       night=`basename ${files[$i-1]} | cut -d_ -f1`
+      runid=`basename ${files[$i-1]} | cut -d_ -f2 | cut -d. -f1`
       echo "night: "$night
-      run=`basename ${files[$i-1]} | cut -d_ -f2`
-      echo "run: "$run
-      dsfile=$dspath"/dataset"$night"_"$run".txt"
-      echo $dsfile
-      printprocesslog "INFO writing dataset file "$dsfile
-      # write dataset only if merpp-log is available to make sure that star-file is complete
-      merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
-      stillrunning=`find $merpplog -mmin -1 2>/dev/null`
-      if [ -e $merpplog ] && [ "$stillrunning" == "" ]
-      then 
-         echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
+      echo "runid: "$runid
+      rawfilepath=$rawdata"/"$datepath"/"
+      rawfilename=`basename ${files[$i-1]} | sed -e 's/_I.root/.fits/'`
+      echo $rawfilepath
+      echo $rawfilename
+      rawfile=`find $rawfilepath -name $rawfilename*`
+      ls $rawfile
+      drivefile=$auxdata"/"$datepath"/"`basename ${files[$i-1]} | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
+      ls $drivefile
+      tstopi=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
+      tstopf=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
+      tstop=${tstopi}${tstopf}
+      #echo "tstop: "$tstop
+      if ls $drivefile >/dev/null 2>&1
+         then
+         coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop}  2>/dev/null | tail -1 2>&1` )
+         if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
+         then
+            printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+            echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+            continue
+         fi
+         if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
+         then
+            printprocesslog "WARN coordinates "${coordinates[@]}
+            echo "WARN coordinates "${coordinates[@]}
+            continue
+         fi
       else
-         echo "merpp still running - wait with file "${files[$i-1]}
-         continue
+         printprocesslog "DEBUG coordinates "${coordinates[@]}
+         echo "DEBUG coordinates "${coordinates[@]}
+         query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
+         sourcekey=`sendquery`
+         if [ "$sourcekey" == "" ]
+         then
+            printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
+            echo "WARN sourcekey empty - coordinates"${coordinates[@]}" for "$rawfile
+            continue
+         fi
+         query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from source WHERE fSourceKey="$sourcekey
+         coordinates=( `sendquery` )
+         if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
+         then
+            printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+            echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+            continue
+         fi
+         if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
+         then
+            printprocesslog "WARN coordinates "${coordinates[@]}
+            echo "WARN coordinates "${coordinates[@]}
+            continue
+         fi
       fi
-      # process only if ganymedlogfiles is not yet there
-      logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
-      if ! ls $logfile >/dev/null 2>&1
-      then
-         echo $logfile" "${files[$i-1]}
-         echo "`dirname $0`/RunGanymed.sh $source $dsfile"
-         `dirname $0`/RunGanymed.sh $source $dsfile
-         numganymeds=`echo " $numganymeds + 1 " | bc -l`
-      fi
-   done 
+
+      echo $logfile" "${files[$i-1]}" -"${coordinates[0]}"-"${coordinates[1]}
+      echo "`dirname $0`/RunGanymed.sh $dsfile "${coordinates[0]}" "${coordinates[1]}
+      `dirname $0`/RunGanymed.sh $dsfile ${coordinates[0]} ${coordinates[1]}
+      numganymeds=`echo " $numganymeds + 1 " | bc -l`
+   fi
+done 
+echo "found "$numganymeds" ganymeds."
    
 #   # get list of 5min-dataset-files as starting point
@@ -123,5 +173,4 @@
 #   done
 
-    echo "found "$numganymeds" ganymeds."
 #   if [ $numganymeds -gt 0 ]
 #   then 
@@ -136,5 +185,5 @@
 #      numganymeds=0
 #   fi
-done
+#done
 
 finish
