Index: /trunk/DataCheck/Tools/get_data.sh
===================================================================
--- /trunk/DataCheck/Tools/get_data.sh	(revision 19041)
+++ /trunk/DataCheck/Tools/get_data.sh	(revision 19042)
@@ -36,6 +36,7 @@
 # ----------------
 # must-have
-# - use get_data.sh for download*.php instead of Send_Data*.sh
-#   -> add policy 
+# - fix bug for timeunit=timestamp (min-binning)
+# - add policy 
+# - add email sending and return values
 # - update function for zd/th-correction
 # - update CU for QLA
@@ -191,7 +192,27 @@
    where=$where" AND fRunTypeKey=1 "
    # zd cut
-   where=$where" AND fZenithDistanceMax < "$zdmax
+   if [ "$zdmax" != "" ]
+   then 
+      where=$where" AND fZenithDistanceMax < "$zdmax
+   fi
    # th cut
-   where=$where" AND fThresholdMedian < "$thmax
+   if [ "$thmax" != "" ]
+   then 
+      where=$where" AND "$thresh" < "$thmax
+   fi
+   # dust cut
+   if [ "$dust" != "" ] 
+   then
+      where=$where" AND fTNGDust<"$dust
+   fi
+   # light condition cut
+   if [ "$light" == "no moon" ]
+   then
+      where=$where" AND fZenithDistanceMoon>90"
+   fi
+   if [ "$light" == "dark" ]
+   then
+      where=$where" AND fMoonZenithDistance>90 AND fSunZenithDistance>108 "
+   fi
    querybase=$from$where
 
@@ -296,38 +317,4 @@
    fi
    
-   
-   fileint=$datapath"/FACT_preliminary_"$name"_internal.dat"
-   if [ "$overwrite" = "yes" ]
-   then 
-      echo "creating "$fileint" ..."
-      echo "# This file was created at "`date` > $fileint
-      echo "# The following query was used: " >> $fileint
-      echo "# "$queryint >> $fileint
-      # add policy here
-   fi
-   headerint="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
-   headerint=$headerint" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance night num_exc num_sig num_bg "
-   headerint=$headerint" zdmin zdmax thmin thmax avg(cufactor) avg(R750cor) avg(R750ref) "
-   echo $headerint >> $fileint
-   #echo "$queryint"
-   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryint" >> $fileint
-   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryint" 
-   
-   filecol=$datapath"/FACT_preliminary_"$name"_collaborators.dat"
-   if [ "$overwrite" = "yes" ]
-   then 
-      echo "creating "$filecol" ..."
-      echo "# This file was created at "`date` > $filecol
-      echo "# The following query was used: " >> $filecol
-      echo "# "$querycol >> $filecol
-      # add policy here
-   fi
-   headercol="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
-   headercol=$headercol" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance "
-   echo $headercol >> $filecol
-   #echo "$querycol"
-   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$querycol" >> $filecol
-   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$querycol
-   
    # write file for externals only for allowed binnings
    if [ $bin -eq 20 ] || [ $bin -eq -1 ]
@@ -346,5 +333,103 @@
       #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryext"
    fi
+   if [ "$mode" == "auto" ] && [ "$expert" == "no" ]
+   then
+      return
+   fi
+   
+   fileint=$datapath"/FACT_preliminary_"$name"_internal.dat"
+   if [ "$overwrite" = "yes" ]
+   then 
+      echo "creating "$fileint" ..."
+      echo "# This file was created at "`date` > $fileint
+      echo "# The following query was used: " >> $fileint
+      echo "# "$queryint >> $fileint
+      # add policy here
+   fi
+   headerint="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
+   headerint=$headerint" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance night num_exc num_sig num_bg "
+   headerint=$headerint" zdmin zdmax thmin thmax avg(cufactor) avg(R750cor) avg(R750ref) "
+   echo $headerint >> $fileint
+   #echo "$queryint"
+   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$queryint" >> $fileint
+   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$queryint" 
+   if [ "$mode"="auto" ]
+   then
+      return
+   fi
+   
+   filecol=$datapath"/FACT_preliminary_"$name"_collaborators.dat"
+   if [ "$overwrite" = "yes" ]
+   then 
+      echo "creating "$filecol" ..."
+      echo "# This file was created at "`date` > $filecol
+      echo "# The following query was used: " >> $filecol
+      echo "# "$querycol >> $filecol
+      # add policy here
+   fi
+   headercol="# "$num" time["$timeunit"] start["$timeunit"] stop["$timeunit"] excrate[evts/h] corr.excrate[evts/h] flux[CU] flux[e-11/cm2/s] delta_time["$timeunit"] ontime[min]"
+   headercol=$headercol" excrate_err[evts/h] corr.excrate_err[evts/h] flux_err[CU] flux_err[e-11/cm2/s] significance "
+   echo $headercol >> $filecol
+   #echo "$querycol"
+   mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -s -e "$querycol" >> $filecol
+   #mysql --defaults-file=$sqlpw -u factread --host=$host $dbname -e "$querycol
+   
 }
+
+# evaluation of command line options (for usage with download.php)
+
+if [ ${#@} -eq 13 ]
+then
+   #get_data.sh $start $stop $source $timebin $email $table $time $expert $dch $zd $th $light $dust
+   mode="auto"
+   # setup
+   path=`dirname $0`
+   datapath=$path"/data"
+   sqlpw=/home/$USER/.mysql.pw2 
+   host=10.0.100.21 
+   dbname=factdata 
+   nightmin=$1
+   nightmax=$2
+   source=$3
+   bin=$4
+   email=$5
+   table=$6
+   timeunit=$7
+   expert=$8
+   usedch=$9 # novalue gives same result as no 
+   if [ "${10}" != "novalue" ] && [ "${10}" != "all" ]
+   then 
+      zdmax=${10}
+   fi
+   if [ "${11}" != "novalue" ] && [ "${11}" != "all" ]
+   then 
+      thmax=${11}
+   fi
+   if [ "${12}" != "novalue" ] && [ "${12}" != "all" ]
+   then 
+      light=${12}
+   fi
+   if [ "${13}" != "novalue" ] && [ "${13}" != "all" ]
+   then 
+      dust=${13}
+   fi
+   name=`echo $email | sed -e 's/@/-at-/'`
+   get_results
+   
+   if [ "$expert" == "yes" ]
+   then 
+      echo $fileint
+   else
+      echo $fileext
+   fi
+      
+   # next: light, dust
+   # implement all options
+   # make dch swi
+   
+   exit
+fi
+
+
 
 # -------------------------------------------------------------------------------------- #
@@ -401,7 +486,4 @@
 nightmin=20111115
 nightmax=20201231
-# defaults for zd and threshold
-zdmax=90 # all data
-thmax=1500 # all data
 # overwrite dataset file? 
 # (useful to combine different binnings in one file -> set to "no")
@@ -416,4 +498,12 @@
 #   use a line like the following defining your own data quality selection cut
 #dch=" AND fR750Cor/fR750Ref BETWEEN 0.93 AND 1.3 "
+# apply additional predefined cuts
+# light conditions
+#light="no moon" # only data with no moon (but twilight allowed)
+#light="dark" # only dark night data
+# TNG dust - cut away data with calima
+#dust=1
+#dust=10
+
 
 # -------------------------------------------------------------------------------------- #
