Index: trunk/MagicSoft/Mars/mbase/MEnv.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEnv.cc	(revision 7449)
+++ trunk/MagicSoft/Mars/mbase/MEnv.cc	(revision 7450)
@@ -39,6 +39,4 @@
 #include <TPave.h>
 #include <TAttText.h>
-//#include <TAttFill.h>
-//#include <TAttLine.h>
 #include <TAttMarker.h>
 
@@ -50,4 +48,22 @@
 using namespace std;
 
+//---------------------------------------------------------------------------
+//
+// Compile str+post and make sure that in between there is a unique dot.
+//
+TString MEnv::Compile(TString str, const char *post) const
+{
+    if (!str.IsNull() && !str.EndsWith("."))
+        str += ".";
+
+    str += post;
+
+    return str;
+}
+
+//---------------------------------------------------------------------------
+//
+// Get the value from the table and remember the value as checked 
+//
 Int_t MEnv::GetValue(const char *name, Int_t dflt)
 {
@@ -57,4 +73,8 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the value from the table and remember the value as checked 
+//
 Double_t MEnv::GetValue(const char *name, Double_t dflt)
 {
@@ -64,4 +84,8 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the value from the table and remember the value as checked 
+//
 const char *MEnv::GetValue(const char *name, const char *dflt)
 {
@@ -71,4 +95,22 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// TEnv doen't have a streamer --> cannot be cloned
+//   --> we have to clone it ourself
+//
+TObject *MEnv::Clone(const char *newname) const
+{
+    MEnv *env = new MEnv("/dev/null");
+    env->fName = fName;
+    env->AddEnv(*this);
+    return env;
+}
+
+//---------------------------------------------------------------------------
+//
+// Interprete fill style: Hollow, Solid, Hatch, 0%-100%
+// If no text style is detected the value is converted to an integer.
+//
 Int_t MEnv::GetFillStyle(const char *name, Int_t dftl)
 {
@@ -90,8 +132,12 @@
 }
 
-Int_t MEnv::GetColor(const char *name, Int_t dftl)
+//---------------------------------------------------------------------------
+//
+// Interprete line style: Solid, Dashed, Dotted, DashDotted
+// If no line style is detected the value is converted to an integer.
+//
+Int_t MEnv::GetLineStyle(const char *name, Int_t dftl)
 {
     TString str = GetValue(name, "");
-
     str = str.Strip(TString::kBoth);
     if (str.IsNull())
@@ -102,12 +148,119 @@
     switch (str.Hash())
     {
-    case (unsigned)-1926423925/*2368543371*/: return kWhite;
-    case 1814927399: return kBlack;
-    case 7496964:    return kRed;
-    case (unsigned)-1397860222/*2897107074*/: return kGreen;
-    case 1702194402: return kBlue;
-    case (unsigned)-1920149414/* 2374817882*/: return kYellow;
-    case (unsigned)-1400748595/*2894218701*/: return kMagenta;
-    case 1851881955: return kCyan;
+    case 764279305:  return kSolid;
+    case 241979881:  return kDashed;
+    case (unsigned)-1903324694: return kDotted;
+    case 1124931659: return kDashDotted;
+    }
+
+    return str.Atoi();
+}
+
+//---------------------------------------------------------------------------
+//
+// Interprete alignment: Top, Right, Left, Bottom, Center, tr, cc, bl, ...
+// If no text align is detected the value is converted to an integer.
+//
+//  eg.
+//    Top Right
+//    Bottom Center
+//    Center
+//    tr
+//    br
+//    cr
+//
+Int_t MEnv::GetAlign(const char *name, Int_t dftl)
+{
+    TString str = GetValue(name, "");
+    str = str.Strip(TString::kBoth);
+    if (str.IsNull())
+        return dftl;
+
+    str.ToLower();
+
+    switch (str.Hash())
+    {
+    case 29746: return 33; // tr
+    case 25379: return 22; // cc
+    case 25132: return 11; // bl
+
+    case 25388: return 12; // cl
+    case 25394: return 32; // cr
+
+    case 29731: return 23; // tc
+    case 25123: return 32; // bc
+
+    case 29740: return 13; // tl
+    case 25138: return 13; // br
+    }
+
+    Int_t align = 0;
+    if (str.Contains("right", TString::kIgnoreCase))
+        align += 3;
+    if (str.Contains("left", TString::kIgnoreCase))
+        align += 1;
+    if (str.Contains("bottom", TString::kIgnoreCase))
+        align += 10;
+    if (str.Contains("top", TString::kIgnoreCase))
+        align += 30;
+
+    if (str.Contains("center", TString::kIgnoreCase))
+    {
+        if (align==0)
+            return 22;
+        if (align/10==0)
+            return align+20;
+        if (align%10==0)
+            return align+2;
+    }
+
+    return align>0 ? align : str.Atoi();
+}
+
+//---------------------------------------------------------------------------
+//
+// Interprete color: Black, White, Red, Green, Blue, Yellow, Magenta,
+// Cyan, Gray1-5, Grey1-5.
+// If no text color is detected the value is converted to an integer.
+//
+//  eg.
+//    Red
+//    Light Red
+//    Dark Red
+//
+Int_t MEnv::GetColor(const char *name, Int_t dftl)
+{
+    TString str = GetValue(name, "");
+
+    str = str.Strip(TString::kBoth);
+    if (str.IsNull())
+        return dftl;
+
+    str.ToLower();
+
+    Int_t offset=0;
+    if (str.Contains("dark"))
+    {
+        str.ReplaceAll("dark", "");
+        str = str.Strip(TString::kBoth);
+        offset = 100;
+    }
+    if (str.Contains("light"))
+    {
+        str.ReplaceAll("light", "");
+        str = str.Strip(TString::kBoth);
+        offset = 150;
+    }
+
+    switch (str.Hash())
+    {
+    case (unsigned)-1926423925/*2368543371*/: return kWhite+offset;
+    case 1814927399: return kBlack+offset;
+    case 7496964:    return kRed+offset;
+    case (unsigned)-1397860222/*2897107074*/: return kGreen+offset;
+    case 1702194402: return kBlue+offset;
+    case (unsigned)-1920149414/* 2374817882*/: return kYellow+offset;
+    case (unsigned)-1400748595/*2894218701*/: return kMagenta+offset;
+    case 1851881955: return kCyan+offset;
     case 749623518: return 18; // grey1
     case 749623517: return 17; // grey2
@@ -124,14 +277,170 @@
 }
 
-TString MEnv::Compile(TString str, const char *post) const
-{
-    if (!str.IsNull() && !str.EndsWith("."))
-        str += ".";
-
-    str += post;
-
-    return str;
-}
-
+//---------------------------------------------------------------------------
+//
+// As possible convert the color col into a text string which can be
+// interpreted by GetColor before setting the resource value
+//
+void MEnv::SetColor(const char *name, Int_t col)
+{
+    TString val;
+
+    if (col>99 && col<101+kCyan)
+    {
+        val = "Dark ";
+        col -= 100;
+    }
+    if (col>150 && col<151+kCyan)
+    {
+        val = "Light ";
+        col -= 150;
+    }
+
+    switch (col)
+    {
+    case kWhite:   val += "White";   break;
+    case kBlack:   val += "Black";   break;
+    case kRed:     val += "Red";     break;
+    case kGreen:   val += "Green";   break;
+    case kBlue:    val += "Blue";    break;
+    case kYellow:  val += "Yellow";  break;
+    case kMagenta: val += "Magenta"; break;
+    case kCyan:    val += "Cyan";    break;
+    case 18:       val += "White";   break;
+    case 17:       val += "White";   break;
+    case 16:       val += "White";   break;
+    case 15:       val += "White";   break;
+    case 14:       val += "White";   break;
+    }
+
+    if (val.IsNull())
+        val += col;
+
+    SetValue(name, val);
+}
+
+//---------------------------------------------------------------------------
+//
+// As possible convert the alignment align into a text string which can be
+// interpreted by GetAlign before setting the resource value
+//
+void MEnv::SetAlign(const char *name, Int_t align)
+{
+    TString val;
+    if (align==22)
+    {
+        SetValue(name, "Center");
+        return;
+    }
+
+    switch (align%10)
+    {
+    case 1: val += "Left";   break;
+    case 2: val += "Center"; break;
+    case 3: val += "Right";  break;
+    }
+
+    switch (align/10)
+    {
+    case 1: val += "Bottom"; break;
+    case 2: val += "Center"; break;
+    case 3: val += "Top";    break;
+    }
+
+    SetValue(name, val);
+}
+
+//---------------------------------------------------------------------------
+//
+// As possible convert the fill style style into a text string which can be
+// interpreted by GetFillStyle before setting the resource value
+//
+void MEnv::SetFillStyle(const char *name, Int_t style)
+{
+    TString val;
+
+    if (style>3999 && style<4101)
+        val = Form("%d%%", style-4000);
+
+    switch (style)
+    {
+    case 0:    val = "Hollow"; break;
+    case 1001: val = "Solid";  break;
+    case 2001: val = "Hatch";  break;
+    }
+
+    if (val.IsNull())
+        val += style;
+
+    SetValue(name, val);
+}
+
+//---------------------------------------------------------------------------
+//
+// As possible convert the line style style into a text string which can be
+// interpreted by GetLineStyle before setting the resource value
+//
+void MEnv::SetLineStyle(const char *name, Int_t style)
+{
+    TString val;
+    switch (style)
+    {
+    case kSolid:      val = "Solid";       break;
+    case kDashed:     val = "Dashed";      break;
+    case kDotted:     val = "Dotted";      break;
+    case kDashDotted: val = "DashDotted";  break;
+    }
+
+    if (val.IsNull())
+        val += style;
+
+    SetValue(name, val);
+}
+
+//---------------------------------------------------------------------------
+//
+// As possible convert the marker style style into a text string which can be
+// interpreted by GetLineStyle before setting the resource value
+//
+void MEnv::SetMarkerStyle(const char *name, Int_t style)
+{
+    TString val;
+    switch (style)
+    {
+    case kDot:              val = "dot";
+    case kPlus:             val = "plus";
+    case kCircle:           val = "circle";
+    case kMultiply:         val = "multiply";
+    case kFullDotSmall:     val = "fulldotsmall";
+    case kFullDotMedium:    val = "fulldotmedium";
+    case kFullDotLarge:     val = "fulldotlarge";
+    case kOpenTriangleDown: val = "opentriangledown";
+    case kFullCross:        val = "fullcross";
+    case kFullCircle:       val = "fullcircle";
+    case kFullSquare:       val = "fullsquare";
+    case kFullTriangleDown: val = "fulltriangledown";
+    case kOpenCircle:       val = "opencircle";
+    case kOpenSquare:       val = "opensquare";
+    case kOpenTriangleUp:   val = "opentriangleup";
+    case kOpenDiamond:      val = "opendiamond";
+    case kOpenCross:        val = "opencross";
+    case kFullStar:         val = "fullstar";
+    case kOpenStar:         val = "openstar";
+    }
+
+    if (val.IsNull())
+        val += style;
+
+    SetValue(name, val);
+}
+
+//---------------------------------------------------------------------------
+//
+// Get the attributed from a TAttLine (if dftl is given use it as default)
+//   name.LineColor  <see also GetColor>
+//   name.LineStyle
+//   name.LineWidth
+// For more details on the meaning see TAttLine
+//
 void MEnv::GetAttLine(const char *name, TAttLine &line, TAttLine *dftl)
 {
@@ -144,5 +453,5 @@
 
     const Color_t col = GetColor(color, dftl->GetLineColor());
-    const Style_t sty = GetValue(style, dftl->GetLineStyle());
+    const Style_t sty = GetLineStyle(style, dftl->GetLineStyle());
     const Style_t wid = GetValue(width, dftl->GetLineWidth());
 
@@ -152,4 +461,14 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the attributed from a TAttText (if dftl is given use it as default)
+//   name.TextColor  <see also GetColor>
+//   name.TextAlign  <see also GetAlign>
+//   name.TextAngle
+//   name.TextFont
+//   name.TextSize
+// For more details on the meaning see TAttText
+//
 void MEnv::GetAttText(const char *name, TAttText &text, TAttText *dftl)
 {
@@ -164,5 +483,5 @@
 
     const Color_t col = GetColor(color, dftl->GetTextColor());
-    const Short_t ali = GetValue(align, dftl->GetTextAlign());
+    const Short_t ali = GetAlign(align, dftl->GetTextAlign());
     const Float_t ang = GetValue(angle, dftl->GetTextAngle());
     const Font_t  fon = GetValue(font,  dftl->GetTextFont());
@@ -176,4 +495,11 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the attributed from a TAttFill (if dftl is given use it as default)
+//   name.FillColor  <see also GetColor>
+//   name.FillStyle  <see also GetFillStyle>
+// For more details on the meaning see TAttFill
+//
 void MEnv::GetAttFill(const char *name, TAttFill &fill, TAttFill *dftl)
 {
@@ -191,4 +517,12 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the attributed from a TAttMarker (if dftl is given use it as default)
+//   name.MarkerColor  <see also GetColor>
+//   name.MarkerStyle
+//   name.MarkerSize
+// For more details on the meaning see TAttMarker
+//
 void MEnv::GetAttMarker(const char *name, TAttMarker &marker, TAttMarker *dftl)
 {
@@ -209,4 +543,18 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the attributed from a TPave (if dftl is given use it as default)
+//   name.CornerRadius
+//   name.BorderSize
+//   name.Option
+// Also all resources from TAttLine and TAttFill are supported.
+//
+// For your conveinience: If the CornerRadius is greater than 0 "arc" is
+// added to the options. If it is equal or less than 0 "arc" is removed
+// from the options.
+//
+// For more details on the meaning see TPave
+//
 void MEnv::GetAttPave(const char *str, TPave &pave, TPave *dftl)
 {
@@ -248,4 +596,16 @@
 }
 
+//---------------------------------------------------------------------------
+//
+// Get the attributed for the TObject obj. Use dftl for default attributes
+// if given.
+//
+// There is support for:
+//    TPave      <see GetAttPave>
+//    TAttLine   <see GetAttLine>
+//    TAttText   <see GetAttText>
+//    TAttFill   <see GetAttFill>
+//    TAttMarker <see GetAttMarker>
+//
 void MEnv::GetAttributes(const char *name, TObject *obj, TObject *dftl)
 {
@@ -263,11 +623,9 @@
     //TAttTextEditor   *line = dynamic_cast<TAttTextEditor*>(obj);
 
-    TPave      *pave = dynamic_cast<TPave*>(/*(TAttLine*)*/obj);
-    TAttLine   *line = dynamic_cast<TAttLine*>(/*(TAttLine*)*/obj);
-    TAttText   *text = dynamic_cast<TAttText*>(/*(TAttText*)*/obj);
-    TAttFill   *fill = dynamic_cast<TAttFill*>(/*(TAttFill*)*/obj);
-    TAttMarker *mark = dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/obj);
-
-    cout << line << " " << text << " " << fill << " " << mark << endl;
+    TPave      *pave = dynamic_cast<TPave*>(obj);
+    TAttLine   *line = dynamic_cast<TAttLine*>(obj);
+    TAttText   *text = dynamic_cast<TAttText*>(obj);
+    TAttFill   *fill = dynamic_cast<TAttFill*>(obj);
+    TAttMarker *mark = dynamic_cast<TAttMarker*>(obj);
 
     if (pave)
@@ -278,13 +636,171 @@
 
     if (line)
-        GetAttLine(name, *line, dynamic_cast<TAttLine*>(/*(TAttLine*)*/dftl));
+        GetAttLine(name, *line, dynamic_cast<TAttLine*>(dftl));
     if (text)
-        GetAttText(name, *text, dynamic_cast<TAttText*>(/*(TAttText*)*/dftl));
+        GetAttText(name, *text, dynamic_cast<TAttText*>(dftl));
     if (fill)
-        GetAttFill(name, *fill, dynamic_cast<TAttFill*>(/*(TAttFill*)*/dftl));
+        GetAttFill(name, *fill, dynamic_cast<TAttFill*>(dftl));
     if (mark)
-        GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(/*(TAttMarker*)*/dftl));
-}
-
+        GetAttMarker(name, *mark, dynamic_cast<TAttMarker*>(dftl));
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the resources from a TAttLine:
+//   name.LineColor  <see also SetColor>
+//   name.LineStyle
+//   name.LineWidth
+//
+void MEnv::SetAttLine(const char *name, const TAttLine &line)
+{
+    const TString color = Compile(name, "LineColor");
+    const TString style = Compile(name, "LineStyle");
+    const TString width = Compile(name, "LineWidth");
+
+    SetColor(color, line.GetLineColor());
+    SetLineStyle(style, line.GetLineStyle());
+    SetValue(width, line.GetLineWidth());
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the resources from a TAttText:
+//   name.TextColor  <see also SetColor>
+//   name.TextAlign  <see also SetAlign>
+//   name.TextAngle
+//   name.TextFont
+//   name.TextSize
+//
+void MEnv::SetAttText(const char *name, const TAttText &text)
+{
+    const TString color = Compile(name, "TextColor");
+    const TString align = Compile(name, "TextAlign");
+    const TString angle = Compile(name, "TextAngle");
+    const TString font  = Compile(name, "TextFont");
+    const TString size  = Compile(name, "TextSize");
+
+    SetColor(color, text.GetTextColor());
+    SetAlign(align, text.GetTextAlign());
+    SetValue(angle, text.GetTextAngle());
+    SetValue(font,  text.GetTextFont());
+    SetValue(size,  text.GetTextSize());
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the resources from a TAttFill:
+//   name.FillColor  <see also SetColor>
+//   name.FillStyle  <see also SetFillStyle>
+//
+void MEnv::SetAttFill(const char *name, const TAttFill &fill)
+{
+    const TString color = Compile(name, "FillColor");
+    const TString style = Compile(name, "FillStyle");
+
+    SetColor(color, fill.GetFillColor());
+    SetFillStyle(style, fill.GetFillStyle());
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the resources from a TAttMarker:
+//   name.MarkerColor  <see also SetColor>
+//   name.MarkerStyle
+//   name.MarkerSize
+//
+void MEnv::SetAttMarker(const char *name, const TAttMarker &marker)
+{
+    const TString color = Compile(name, "MarkerColor");
+    const TString style = Compile(name, "MarkerStyle");
+    const TString size  = Compile(name, "MarkerSize");
+
+    SetColor(color, marker.GetMarkerColor());
+    SetMarkerStyle(style, marker.GetMarkerStyle());
+    SetValue(size,  marker.GetMarkerSize());
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the resources from a TPave:
+//   name.CornerRadius
+//   name.BorderSize
+//   name.Option
+// Also all resources from TAttLine and TAttFill are supported.
+//
+void MEnv::SetAttPave(const char *str, const TPave &pave)
+{
+    const TString name(str);
+
+    SetAttLine(name, pave);
+    SetAttFill(name, pave);
+
+    const TString corner = Compile(name, "CornerRadius");
+    const TString border = Compile(name, "BorderSize");
+    const TString option = Compile(name, "Option");
+
+    SetValue(corner, const_cast<TPave&>(pave).GetCornerRadius());
+    SetValue(border, const_cast<TPave&>(pave).GetBorderSize());
+    SetValue(option, pave.GetOption());
+}
+
+//---------------------------------------------------------------------------
+//
+// Set the attributed for the TObject obj.
+//
+// There is support for:
+//    TPave      <see SetAttPave>
+//    TAttLine   <see SetAttLine>
+//    TAttText   <see SetAttText>
+//    TAttFill   <see SetAttFill>
+//    TAttMarker <see SetAttMarker>
+//
+void MEnv::SetAttributes(const char *name, const TObject *obj)
+{
+    const TPave      *pave = dynamic_cast<const TPave*>(obj);
+    const TAttLine   *line = dynamic_cast<const TAttLine*>(obj);
+    const TAttText   *text = dynamic_cast<const TAttText*>(obj);
+    const TAttFill   *fill = dynamic_cast<const TAttFill*>(obj);
+    const TAttMarker *mark = dynamic_cast<const TAttMarker*>(obj);
+
+    if (pave)
+    {
+        SetAttPave(name, *pave);
+        return;
+    }
+
+    if (line)
+        SetAttLine(name, *line);
+    if (text)
+        SetAttText(name, *text);
+    if (fill)
+        SetAttFill(name, *fill);
+    if (mark)
+        SetAttMarker(name, *mark);
+}
+
+//---------------------------------------------------------------------------
+//
+// Add all values from TEnv env the this MEnv. To not overwrite existing
+// values set overwrite to kFALSE
+//
+void MEnv::AddEnv(const TEnv &env, Bool_t overwrite)
+{
+    if (!GetTable() || !env.GetTable())
+        return;
+
+    TIter Next(env.GetTable());
+
+    TEnvRec *er;
+    while ((er = (TEnvRec*)Next()))
+    {
+        if (overwrite || !Defined(er->GetName()))
+            SetValue(er->GetName(), er->GetValue(), er->GetLevel(), er->GetType());
+    }
+}
+
+//---------------------------------------------------------------------------
+//
+// Print resources which have never been touched (for debugging)
+//
 void MEnv::PrintUntouched() const
 {
Index: trunk/MagicSoft/Mars/mbase/MEnv.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEnv.h	(revision 7449)
+++ trunk/MagicSoft/Mars/mbase/MEnv.h	(revision 7450)
@@ -21,8 +21,12 @@
     TOrdCollection fChecked;
 
+    TString fName; // A workaround!
+
     TString Compile(TString str, const char *post) const;
 
 public:
-    MEnv(const char *name="") : TEnv(name) { fChecked.SetOwner(); }
+    MEnv(const char *name="") : TEnv(name), fName(name) { fChecked.SetOwner(); }
+
+    TObject    *Clone(const char *newname="") const;
 
     Int_t       GetValue(const char *name, Int_t dflt);
@@ -30,6 +34,10 @@
     const char *GetValue(const char *name, const char *dflt);
 
+    const char *GetName() const { return fName; }
+
     Int_t       GetColor(const char *name, Int_t dftl);
+    Int_t       GetAlign(const char *name, Int_t dftl);
     Int_t       GetFillStyle(const char *name, Int_t dftl);
+    Int_t       GetLineStyle(const char *name, Int_t dftl);
 
     void        GetAttributes(const char *name, TObject *obj, TObject *dftl=0);
@@ -40,4 +48,19 @@
     void        GetAttPave(const char *name, TPave &pave, TPave *dftl=0);
 
+    void        SetColor(const char *name, Int_t col);
+    void        SetAlign(const char *name, Int_t align);
+    void        SetFillStyle(const char *name, Int_t style);
+    void        SetLineStyle(const char *name, Int_t style);
+    void        SetMarkerStyle(const char *name, Int_t style);
+
+    void        SetAttributes(const char *name, const TObject *obj);
+    void        SetAttLine(const char *name, const TAttLine &line);
+    void        SetAttText(const char *name, const TAttText &text);
+    void        SetAttFill(const char *name, const TAttFill &fill);
+    void        SetAttMarker(const char *name, const TAttMarker &marker);
+    void        SetAttPave(const char *name, const TPave &pave);
+
+    void        AddEnv(const TEnv &env, Bool_t overwrite=kTRUE);
+
     void PrintUntouched() const;
 
Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 7449)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 7450)
@@ -460,4 +460,84 @@
 
     return fmod(sum, 1)*TMath::TwoPi();//+TMath::TwoPi();
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the day of the year represented by day, month and year.
+// Valid return values range between 1 and 366, where January 1 = 1.
+//
+UInt_t MTime::DayOfYear() const
+{
+    MTime jan1st;
+    jan1st.Set(Year(), 1, 1);
+
+    const Double_t newyear = TMath::Floor(jan1st.GetMjd());
+    const Double_t mjd     = TMath::Floor(GetMjd());
+
+    return TMath::Nint(mjd-newyear)+1;
+}
+
+// --------------------------------------------------------------------------
+//
+// Get the week of the year. Valid week values are between 1 and 53.
+// 54 is returned if the day belongs to Week=1 of the next year,
+// 0 if it belongs to the Week=53 and -1 if it belongs to the Week=52
+// of the last year (In this case there is no week 53!)
+//
+Int_t MTime::Week() const
+{
+    static const Int_t kFrSaSo = BIT(kFriday)  | BIT(kSaturday)  | BIT(kSunday);
+    static const Int_t kTuWeTh = BIT(kTuesday) | BIT(kWednesday) | BIT(kThursday);
+
+    MTime t;
+    t.Set(Year(), 1, 1);
+
+    // The weekday of Jan 1st.
+    const Int_t day1st = 1<<t.WeekDay();
+
+    // The number of weeks since the first Monday in the year
+    Int_t week = (DayOfYear()-1 + (t.WeekDay()+6)%7) / 7 + 1;
+
+    // Correct the week number if the year has started with Fr, Sa or So
+    if (day1st & kFrSaSo)
+        week--;
+
+    // If the week number is 53 it might already belong to the next year
+    if (week == 53)
+    {
+        t.Set(Year()+1, 1, 1);
+
+        const Int_t daynext = 1<<t.WeekDay();
+        return daynext&kTuWeTh ? 54 : 53;
+    }
+
+    // If the week number is 53 it might still belong to the last year
+    if (week == 0)
+    {
+        t.Set(Year()-1, 1, 1);
+
+        const Int_t dayprev = 1<<t.WeekDay();
+        return !(dayprev&kFrSaSo) && (day1st&kFrSaSo) ?  0  :  -1;
+    }
+
+    return week;
+}
+
+// --------------------------------------------------------------------------
+//
+// Is the given year a leap year.
+// The calendar year is 365 days long, unless the year is exactly divisible
+// by 4, in which case an extra day is added to February to make the year
+// 366 days long. If the year is the last year of a century, eg. 1700, 1800,
+// 1900, 2000, then it is only a leap year if it is exactly divisible by
+// 400. Therefore, 1900 wasn't a leap year but 2000 was. The reason for
+// these rules is to bring the average length of the calendar year into
+// line with the length of the Earth's orbit around the Sun, so that the
+// seasons always occur during the same months each year.
+//
+Bool_t MTime::IsLeapYear() const
+{
+    const UInt_t y = Year();
+    return (y%4==0) && !((y%100==0) && (y%400>0));
 }
 
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 7449)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 7450)
@@ -29,4 +29,8 @@
     static const UInt_t kHour; // [ms] one hour
     static const UInt_t kDay;  // [ms] one day
+
+    enum {
+        kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday
+    };
 
 private:
@@ -120,6 +124,9 @@
     UInt_t Min() const     { Byte_t h, m, s; GetTime(h,m,s); return m; }
     UInt_t Sec() const     { Byte_t h, m, s; GetTime(h,m,s); return s; }
+    UInt_t DayOfYear() const;
+    Int_t  Week() const;
 
     Bool_t IsMidnight() const { return (Long_t)fTime==0 && fNanoSec==0; }
+    Bool_t IsLeapYear() const;
 
     // I/O functions
