Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 9155)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 9156)
@@ -18,4 +18,21 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2008/11/12 Thomas Bretz
+
+   * datacenter/macros/plotstat.C:
+     - added descriptions for the tabs
+     - added legend to all tabs
+     - added beginning and end of period to all tabs
+
+   * mastro/MAstro.[h,cc]:
+     - added new member function GetMoonPeriodMjd
+     - added new member function GetMagicPeriodStart
+
+   * mbase/MTime.[h,cc]:
+     - added new member function SetMoonPeriod
+     - added new member function SetMagicPeriodStart
+
+
 
  2008/11/11 Thomas Bretz
Index: /trunk/MagicSoft/Mars/mastro/MAstro.cc
===================================================================
--- /trunk/MagicSoft/Mars/mastro/MAstro.cc	(revision 9155)
+++ /trunk/MagicSoft/Mars/mastro/MAstro.cc	(revision 9156)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -46,4 +46,7 @@
 
 ClassImp(MAstro);
+
+const Double_t MAstro::kSynMonth = 29.53058868; // synodic month (new Moon to new Moon)
+const Double_t MAstro::kEpoch0   = 44240.37917; // First full moon after 1980/1/1
 
 Double_t MAstro::RadToHor()
@@ -616,9 +619,18 @@
 Double_t MAstro::GetMoonPeriod(Double_t mjd)
 {
-    const Double_t synmonth = 29.53058868; // synodic month (new Moon to new Moon)
-    const Double_t epoch0   = 44240.37917; // First full moon after 1980/1/1
-
-    const Double_t et = mjd-epoch0; // Ellapsed time
-    return et/synmonth;
+    const Double_t et = mjd-kEpoch0; // Elapsed time
+    return et/kSynMonth;
+}
+
+// --------------------------------------------------------------------------
+//
+// Convert a moon period back to a mjd
+//
+// See also
+//   MAstro::GetMoonPeriod
+//
+Double_t MAstro::GetMoonPeriodMjd(Double_t p)
+{
+    return p*kSynMonth+kEpoch0;
 }
 
@@ -629,5 +641,5 @@
 //   53257.8 --> 53258
 //   53258.3 --> 53258
-// Which is the time between 13h and 12:59h of the following day. To
+// Which is the time between 12h and 11:59h of the following day. To
 // this day-period we assign the moon-period at midnight. To get
 // the MAGIC definition we now substract 284.
@@ -653,4 +665,16 @@
 
     return (Int_t)TMath::Floor(period)-284;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the start time (12h noon) of the MAGIC period p.
+//
+// See also
+//   MAstro::GetMagicPeriod
+//
+Double_t MAstro::GetMagicPeriodStart(Int_t p)
+{
+    return TMath::Floor(GetMoonPeriodMjd(p+284))+0.5;
 }
 
Index: /trunk/MagicSoft/Mars/mastro/MAstro.h
===================================================================
--- /trunk/MagicSoft/Mars/mastro/MAstro.h	(revision 9155)
+++ /trunk/MagicSoft/Mars/mastro/MAstro.h	(revision 9156)
@@ -16,4 +16,7 @@
 {
 private:
+    static const Double_t kSynMonth; // synodic month (new Moon to new Moon)
+    static const Double_t kEpoch0;   // First full moon after 1980/1/1
+
     static Double_t Round(Double_t val);
     static Double_t Trunc(Double_t val);
@@ -87,5 +90,7 @@
     static Double_t GetMoonPhase(Double_t mjd);
     static Double_t GetMoonPeriod(Double_t mjd);
+    static Double_t GetMoonPeriodMjd(Double_t p);
     static Int_t    GetMagicPeriod(Double_t mjd);
+    static Double_t GetMagicPeriodStart(Int_t p);
 
     static Double_t EstimateCulminationTime(Double_t mjd, Double_t longit, Double_t ra);
Index: /trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9155)
+++ /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9156)
@@ -179,4 +179,15 @@
 // --------------------------------------------------------------------------
 //
+// Set the time corresponding to the moon period.
+//
+//   see MTime::GetMoonPeriod and MAstro::GetMoonPeriod
+//
+void MTime::SetMoonPeriod(Double_t p)
+{
+    SetMjd(MAstro::GetMoonPeriodMjd(p));
+}
+
+// --------------------------------------------------------------------------
+//
 // To get the moon period as defined for MAGIC observation we take the
 // nearest integer mjd, eg:
@@ -208,4 +219,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Set the start time (noon) of a MAGIC period
+//
+//   see MTime::GetMagicPeriod and MAstro::GetMagicPeriod
+//
+void MTime::SetMagicPeriodStart(Int_t p)
+{
+    SetMjd(MAstro::GetMagicPeriodStart(p));
+}
 
 // --------------------------------------------------------------------------
Index: /trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 9155)
+++ /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 9156)
@@ -104,4 +104,6 @@
     void     SetMjd(Double_t m);
     void     SetAxisTime(Double_t time);
+    void     SetMoonPeriod(Double_t p);
+    void     SetMagicPeriodStart(Int_t p);
     void     SetUnixTime(Long64_t sec, ULong64_t usec=0);
     void     SetEaster(Short_t year=0);
