Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 4833)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 4887)
@@ -563,2 +563,127 @@
     return fin;
 }
+
+void MTime::AddMilliSeconds(UInt_t ms)
+{
+    fTime += ms;
+
+    fTime += 11*kHour;
+    fMjd  += (Long_t)fTime/kDay;
+    fTime  = (Long_t)fTime%kDay;
+    fTime -= 11*kHour;
+}
+/*
+MTime MTime::operator-(const MTime &tm1)
+{
+    const MTime &tm0 = *this;
+
+    MTime t0 = tm0>tm1 ? tm0 : tm1;
+    const MTime &t1 = tm0>tm1 ? tm1 : tm0;
+
+    if (t0.fNanoSec<t1.fNanoSec)
+    {
+        t0.fNanoSec += 1000000;
+        t0.fTime -= 1;
+    }
+
+    t0.fNanoSec -= t1.fNanoSec;
+    t0.fTime    -= t1.fTime;
+
+    if ((Long_t)t0.fTime<-(Long_t)kHour*11)
+    {
+        t0.fTime += kDay;
+        t0.fMjd--;
+    }
+
+    t0.fMjd -= t1.fMjd;
+
+    return t0;
+}
+
+void MTime::operator-=(const MTime &t)
+{
+    *this = *this-t;
+}
+
+MTime MTime::operator+(const MTime &t1)
+{
+    MTime t0 = *this;
+
+    t0.fNanoSec += t1.fNanoSec;
+
+    if (t0.fNanoSec>999999)
+    {
+        t0.fNanoSec -= 1000000;
+        t0.fTime += kDay;
+    }
+
+    t0.fTime += t1.fTime;
+
+    if ((Long_t)t0.fTime>=(Long_t)kHour*13)
+    {
+        t0.fTime -= kDay;
+        t0.fMjd++;
+    }
+
+    t0.fMjd += t1.fMjd;
+
+    return t0;
+}
+
+void MTime::operator+=(const MTime &t)
+{
+    *this = *this+t;
+}
+*/
+
+void MTime::SetMean(const MTime &t0, const MTime &t1)
+{
+    // This could be an operator+
+    *this = t0;
+
+    fNanoSec += t1.fNanoSec;
+
+    if (fNanoSec>999999)
+    {
+        fNanoSec -= 1000000;
+        fTime += kDay;
+    }
+
+    fTime += t1.fTime;
+
+    if ((Long_t)fTime>=(Long_t)kHour*13)
+    {
+        fTime -= kDay;
+        fMjd++;
+    }
+
+    fMjd += t1.fMjd;
+
+    // This could be an operator/
+    if ((Long_t)fTime<0)
+    {
+        fTime += kDay;
+        fMjd--;
+    }
+
+    Int_t reminder = fMjd%2;
+    fMjd /= 2;
+
+    fTime += reminder*kDay;
+    reminder = (Long_t)fTime%2;
+    fTime /= 2;
+
+    fNanoSec += reminder*1000000;
+    fNanoSec /= 2;
+
+    fTime += 11*kHour;
+    fMjd  += (Long_t)fTime/kDay;
+    fTime  = (Long_t)fTime%kDay;
+    fTime -= 11*kHour;
+}
+
+void MTime::SetMean(Double_t t0, Double_t t1)
+{
+    const Double_t mean = (t0+t1)*(500./kDay);
+    SetMjd(mean);
+}
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 4833)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 4887)
@@ -35,4 +35,5 @@
     UInt_t fNanoSec; // [ns] NanoSec part of TimeOfDay (<1000000)
 
+
     ULong_t GetTime24() const
     {
@@ -75,4 +76,5 @@
     void Now();
 
+    // Setter functions
     Bool_t   Set(UShort_t y, Byte_t m, Byte_t d, Byte_t h=13, Byte_t min=0, Byte_t s=0, UShort_t ms=0, UInt_t ns=0);
     void     Set(const struct timeval &tv);
@@ -85,4 +87,6 @@
     Bool_t   SetMjd(UInt_t mjd, ULong_t ms, UInt_t ns=0);
     void     SetMjd(Double_t m);
+
+    // Getter functions
     Double_t GetMjd() const;
     Double_t GetGmst() const;
@@ -111,60 +115,32 @@
     UInt_t Sec() const   { Byte_t h, m, s; GetTime(h,m,s); return s; }
 
+    // I/O functions
     istream &ReadBinary(istream &fin);
 
-    operator double() const   //[s]
-    {
-        return ((Double_t)fMjd*kDay+(Long_t)fTime+fNanoSec/1e6)/1000;
-    }
-    double operator()() const //[s]
-    {
-        return operator double();
-    }
-
-    bool operator<(const MTime &t) const
-    {
-        if (fMjd<t.fMjd)
-            return true;
-        if (fMjd==t.fMjd && fTime<t.fTime)
-            return true;
-        if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec<t.fNanoSec)
-            return true;
-        return false;
-    }
-    bool operator>(const MTime &t) const
-    {
-        if (fMjd>t.fMjd)
-            return true;
-        if (fMjd==t.fMjd && fTime>t.fTime)
-            return true;
-        if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec>t.fNanoSec)
-            return true;
-        return false;
-    }
-
-    bool operator<=(const MTime &t) const
-    {
-        return !operator>(t);
-    }
-
-    bool operator>=(const MTime &t) const
-    {
-        return !operator<(t);
-    }
-
-    bool operator==(const MTime &t) const
-    {
-        return fNanoSec==t.fNanoSec && fTime==t.fTime && fMjd==t.fMjd;
-    }
-
-    bool operator!=(const MTime &t) const
-    {
-        return fNanoSec!=t.fNanoSec || fTime!=t.fTime || fMjd!=t.fMjd;
-    }
-
-    bool operator!() const
-    {
-        return fNanoSec==0 && (ULong_t)fTime==0 && fMjd==0;
-    }
+    // Conversion functions
+    operator double() const;   //[s]
+    double operator()() const; //[s]
+
+    // Calculation functions
+    void AddMilliSeconds(UInt_t ms);
+    void SetMean(const MTime &t0, const MTime &t1);
+    void SetMean(Double_t t0, Double_t t1);
+    /*
+     MTime operator-(const MTime &tm1);
+     void operator-=(const MTime &t);
+     MTime operator+(const MTime &t1);
+     void operator+=(const MTime &t);
+     */
+
+    // Base comparison operators
+    bool operator<(const MTime &t) const;
+    bool operator>(const MTime &t) const;
+
+    // Derived comparison operators
+    bool operator<=(const MTime &t) const;
+    bool operator>=(const MTime &t) const;
+    bool operator==(const MTime &t) const;
+    bool operator!=(const MTime &t) const;
+    bool operator!() const;
 
     ClassDef(MTime, 3)	//A generalized MARS time stamp
@@ -186,3 +162,60 @@
 }
 
-#endif
+inline MTime::operator double() const   //[s]
+{
+    return ((Double_t)fMjd*kDay+(Long_t)fTime+fNanoSec/1e6)/1000;
+}
+
+inline double MTime::operator()() const //[s]
+{
+    return operator double();
+}
+
+inline bool MTime::operator<(const MTime &t) const
+{
+    if (fMjd<t.fMjd)
+        return true;
+    if (fMjd==t.fMjd && fTime<t.fTime)
+        return true;
+    if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec<t.fNanoSec)
+        return true;
+    return false;
+}
+
+inline bool MTime::operator>(const MTime &t) const
+{
+    if (fMjd>t.fMjd)
+        return true;
+    if (fMjd==t.fMjd && fTime>t.fTime)
+        return true;
+    if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec>t.fNanoSec)
+        return true;
+    return false;
+}
+
+inline bool MTime::operator<=(const MTime &t) const
+{
+    return !operator>(t);
+}
+
+inline bool MTime::operator>=(const MTime &t) const
+{
+    return !operator<(t);
+}
+
+inline bool MTime::operator==(const MTime &t) const
+{
+    return fNanoSec==t.fNanoSec && fTime==t.fTime && fMjd==t.fMjd;
+}
+
+inline bool MTime::operator!=(const MTime &t) const
+{
+    return fNanoSec!=t.fNanoSec || fTime!=t.fTime || fMjd!=t.fMjd;
+}
+
+inline bool MTime::operator!() const
+{
+    return fNanoSec==0 && (ULong_t)fTime==0 && fMjd==0;
+}
+
+#endif
