Index: trunk/FACT++/src/makeplots.cc
===================================================================
--- trunk/FACT++/src/makeplots.cc	(revision 14715)
+++ trunk/FACT++/src/makeplots.cc	(revision 14716)
@@ -41,4 +41,16 @@
     return acos(arg) * 180/M_PI;
 }
+
+void CheckForGap(TCanvas &c, TGraph &g, double axis)
+{
+    if (g.GetN()==0 || axis-g.GetX()[g.GetN()-1]<450)
+        return;
+
+    c.cd();
+    ((TGraph*)g.DrawClone("C"))->SetBit(kCanDelete);
+    while (g.GetN())
+        g.RemovePoint(0);
+}
+
 
 // ========================================================================
@@ -71,4 +83,12 @@
         "makeplots - The astronomy plotter\n"
         "\n"
+        "Calculates several plots for the sources in the database\n"
+        "helpful or needed for scheduling. The Plot is always calculated\n"
+        "for the night which starts at the same so. So no matter if\n"
+        "you specify '1974-09-09 00:00:00' or '1974-09-09 21:56:00'\n"
+        "the plots will refer to the night 1974-09-09/1974-09-10.\n"
+        "The advantage is that specification of the date as in\n"
+        "1974-09-09 is enough.\n"
+        "\n"
         "Usage: makeplots sql-datetime [--ra={ra} --dec={dec}]\n";
     cout << endl;
@@ -109,15 +129,19 @@
     const double no_limits   = conf.Get<bool>("no-limits");
 
-    ln_rst_time sun_astronomical;
-    ln_get_solar_rst_horizon(time.JD(), &observer, -12, &sun_astronomical);
-
-    const double jd  = floor(time.JD());
-    const double mjd = floor(time.Mjd())+49718-0.5;
-
-    const double jd0 = fmod(sun_astronomical.set,  1);
-    const double jd1 = fmod(sun_astronomical.rise, 1);
-
-    cout << "JD0=" << jd+jd0 << endl;
-    cout << "JD1=" << jd+jd1 << endl;
+    // -12: astronomical twilight
+    ln_rst_time sun_set;   // Sun set with the same date than th provided date
+    ln_rst_time sun_rise;  // Sun rise on the following day
+    ln_get_solar_rst_horizon(time.JD()-0.5, &observer, -12, &sun_set);
+    ln_get_solar_rst_horizon(time.JD()+0.5, &observer, -12, &sun_rise);
+
+    const double jd  = floor(time.Mjd())+2400001;
+    const double mjd = floor(time.Mjd())+49718+0.5;
+
+    cout << "Time: " << time << endl;
+    cout << "Set:  " << Time(sun_set.set)   << endl;
+    cout << "Rise: " << Time(sun_rise.rise) << endl;
+
+    const double jd0 = fmod(sun_set.set,   1);   // ~0.3
+    const double jd1 = fmod(sun_rise.rise, 1);   // ~0.8
 
     const string fDatabase = conf.Get<string>("source-database");
@@ -188,4 +212,14 @@
     hframe.DrawCopy();
 
+    TCanvas c4;
+    gPad->SetLeftMargin(0.085);
+    gPad->SetRightMargin(0.01);
+    gPad->SetTopMargin(0.03);
+    gPad->SetGrid();
+    hframe.GetYaxis()->SetTitle("Distance to moon [deg]");
+    hframe.SetMinimum(0);
+    hframe.SetMaximum(180);
+    hframe.DrawCopy();
+
     Int_t color[] = { kBlack, kRed, kBlue, kGreen, kCyan, kMagenta };
     Int_t style[] = { kSolid, kDashed, kDotted };
@@ -206,17 +240,23 @@
 
         // Create graphs
-        TGraph g1, g2, g3;
+        TGraph g1, g2, g3, g4, gm;
         g1.SetName(name.data());
         g2.SetName(name.data());
         g3.SetName(name.data());
+        g4.SetName(name.data());
         g1.SetLineWidth(2);
         g2.SetLineWidth(2);
         g3.SetLineWidth(2);
+        g4.SetLineWidth(2);
+        gm.SetLineWidth(1);
         g1.SetLineStyle(style[cnt/6]);
         g2.SetLineStyle(style[cnt/6]);
         g3.SetLineStyle(style[cnt/6]);
+        g4.SetLineStyle(style[cnt/6]);
         g1.SetLineColor(color[cnt%6]);
         g2.SetLineColor(color[cnt%6]);
         g3.SetLineColor(color[cnt%6]);
+        g4.SetLineColor(color[cnt%6]);
+        gm.SetLineColor(kYellow);
 
         // Loop over 24 hours
@@ -254,27 +294,9 @@
 
             // If there is a gap of more than one bin, start a new curve
-            if (g1.GetN()>0 && axis-g1.GetX()[g1.GetN()-1]>450)
-            {
-                c1.cd();
-                ((TGraph*)g1.DrawClone("C"))->SetBit(kCanDelete);
-                while (g1.GetN())
-                    g1.RemovePoint(0);
-            }
-
-            if (g2.GetN()>0 && axis-g2.GetX()[g2.GetN()-1]>450)
-            {
-                c2.cd();
-                ((TGraph*)g2.DrawClone("C"))->SetBit(kCanDelete);
-                while (g2.GetN())
-                    g2.RemovePoint(0);
-            }
-
-            if (g3.GetN()>0 && axis-g3.GetX()[g3.GetN()-1]>450)
-            {
-                c3.cd();
-                ((TGraph*)g3.DrawClone("C"))->SetBit(kCanDelete);
-                while (g3.GetN())
-                    g3.RemovePoint(0);
-            }
+            CheckForGap(c1, g1, axis);
+            CheckForGap(c1, gm, axis);
+            CheckForGap(c2, g2, axis);
+            CheckForGap(c3, g3, axis);
+            CheckForGap(c4, g4, axis);
 
             // Add data
@@ -287,19 +309,30 @@
             if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
                 g3.SetPoint(g3.GetN(), axis, ratio*cur/7.7);
+
+            if (no_limits || (cur<max_current && 90-hrz.alt<max_zd))
+                g4.SetPoint(g4.GetN(), axis, angle);
+
+            if (cnt==0)
+                gm.SetPoint(gm.GetN(), axis, hrzm.alt);
         }
 
         // Add graphs to canvases and add corresponding entry to legend
-        TGraph *g = 0;
-
         c1.cd();
-        g = (TGraph*)g1.DrawClone("C");
-        g->SetBit(kCanDelete);
+        if (cnt==0)
+        {
+            TGraph *g = (TGraph*)gm.DrawClone("C");
+            g->SetBit(kCanDelete);
+            leg.AddEntry(g, "Moon", "l");
+        }
+        ((TGraph*)g1.DrawClone("C"))->SetBit(kCanDelete);
 
         c2.cd();
-        g = (TGraph*)g2.DrawClone("C");
-        g->SetBit(kCanDelete);
+        ((TGraph*)g2.DrawClone("C"))->SetBit(kCanDelete);
 
         c3.cd();
-        g = (TGraph*)g3.DrawClone("C");
+        ((TGraph*)g3.DrawClone("C"))->SetBit(kCanDelete);
+
+        c4.cd();
+        TGraph *g = (TGraph*)g4.DrawClone("C");
         g->SetBit(kCanDelete);
 
@@ -307,6 +340,7 @@
     }
 
+
     // Save three plots
-    TCanvas c4;
+    TCanvas c5;
     leg.Draw();
 
@@ -314,9 +348,11 @@
     c2.SaveAs("test2.eps");
     c3.SaveAs("test3.eps");
-    c4.SaveAs("legend.eps");
+    c4.SaveAs("test4.eps");
+    c5.SaveAs("legend.eps");
 
     c1.SaveAs("test1.root");
     c2.SaveAs("test2.root");
     c3.SaveAs("test3.root");
+    c4.SaveAs("test4.root");
 
     return 0;
