Index: trunk/MagicSoft/Cosy/main/MBending.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MBending.cc	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MBending.cc	(revision 2615)
@@ -65,5 +65,5 @@
 #include <TMinuit.h>
 
-#include "timer.h"
+#include "MTime.h"
 
 ClassImp(MBending);
@@ -262,8 +262,8 @@
     }
 
-    Timer t;
+    MTime t;
     t.Now();
 
-    fout << "MAGIC1 " << t.GetTimeStr() << endl;
+    fout << "MAGIC1 " << t << endl;
     fout << "S   00   000000   000000  0000000" << endl;
     fout << setprecision(8);
@@ -285,4 +285,65 @@
 }
 
+AltAz MBending::AddOffsets(const AltAz &aa) const
+{
+    // Correct [rad]
+    // zdaz    [rad]
+    AltAz p = aa;
+
+    const AltAz I(fIe, fIa);
+    p += I;
+
+    return p;
+}
+
+AltAz MBending::SubtractOffsets(const AltAz &aa) const
+{
+    // Correct [rad]
+    // zdaz    [rad]
+    AltAz p = aa;
+
+    const AltAz I(fIe, fIa);
+    p -= I;
+
+    return p;
+}
+
+AltAz MBending::CalcAnAw(const AltAz &p, Int_t sign) const
+{
+    // Corrections for AN and AW without approximations
+    // as done by Patrick Wallace. The approximation cannot
+    // be used for MAGIC because the correctioon angle
+    // AW (~1.5deg) is not small enough.
+
+    // Vector in cartesian coordinates
+    TVector3 v(1., 1., 1.); 
+
+    // Set Azimuth and Elevation
+    v.SetPhi(p.Az());
+    v.SetTheta(TMath::Pi()/2-p.Alt());
+
+    // Rotate around the x- and y-axis
+    v.RotateY(sign*fAn);
+    v.RotateX(sign*fAw);
+
+    // Calculate Delta Azimuth and Delta Elevation
+    AltAz d(TMath::Pi()/2-v.Theta(), v.Phi());
+    d -= p;
+    d *= sign;
+
+    // Fix 'direction' of output depending on input vector
+    if (sign*p.Alt()>TMath::Pi()/2)
+        d.Alt(d.Alt()-TMath::Pi());
+
+    // Align correction into [-180,180]
+    while (d.Az()>TMath::Pi())
+        d.Az(d.Az()-TMath::Pi()*2);
+    while (d.Az()<-TMath::Pi())
+        d.Az(d.Az()+TMath::Pi()*2);
+
+    return d;
+}
+
+
 AltAz MBending::Correct(const AltAz &aa) const
 {
@@ -350,29 +411,13 @@
     DEBUG(cout << "Bend2: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
 
-    // New Corrections for AW and AN:
-    TVector3 v2(1.,1.,1.); // Vector in cartesian coordinates
-    // Set Azimuth and Elevation
-    v2.SetPhi(p.Az());
-    v2.SetTheta(TMath::Pi()/2-p.Alt());
-    // Rotate around the x- and y-axis
-    v2.RotateX(fAw);
-    v2.RotateY(fAn);
-    // Get Azimuth and Elevation
-    p.Az(v2.Phi());
-    p.Alt(TMath::Pi()/2-v2.Theta());
-
-    /*
-    // Old correction terms for An and Aw:
-    cout << fAw << " " << cos(p.Az()) << " " << tan(p.Alt()) << endl;
-    cout << fAw* cos(p.Az())*tan(p.Alt())*180/3.1415 << endl;
-
-    const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt()));
-    const AltAz AN(-fAn*cos(p.Az()), -fAn*sin(p.Az())*tan(p.Alt()));
-    p += AW;
-    p += AN;
+    const AltAz ANAW(CalcAnAw(p, -1));
+    p += ANAW;
+
+    /* Old correction terms for An and Aw:
+     const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt()));
+     const AltAz AN(-fAn*cos(p.Az()), -fAn*sin(p.Az())*tan(p.Alt()));
+     p += AW;
+     p += AN;
     */
-
-
-
 
     DEBUG(cout << "Bend1: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
@@ -389,5 +434,5 @@
 }
 
-AltAz MBending::AddOffsets(const AltAz &aa) const
+AltAz MBending::CorrectBack(const AltAz &aa) const
 {
     // Correct [rad]
@@ -395,16 +440,4 @@
     AltAz p = aa;
 
-    const AltAz I(fIe, fIa);
-    p += I;
-
-    return p;
-}
-
-AltAz MBending::CorrectBack(const AltAz &aa) const
-{
-    // Correct [rad]
-    // zdaz    [rad]
-    AltAz p = aa;
-
     DEBUG(cout << setprecision(16));
     DEBUG(cout << "Back0: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
@@ -418,6 +451,5 @@
     DEBUG(cout << "Back1: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
 
-    /*
-     //Old correction terms for An and Aw:
+    /* Old correction terms for An and Aw:
      const AltAz AN(-fAn*cos(p.Az()), -fAn*sin(p.Az())*tan(p.Alt()));
      const AltAz AW( fAw*sin(p.Az()), -fAw*cos(p.Az())*tan(p.Alt()));
@@ -426,16 +458,6 @@
      */
 
-    // New Corrections for AN and AW:
-    TVector3 v(1.,1.,1.); // Vector in cartesian coordinates
-    // Set Azimuth and Elevation
-    v.SetPhi(p.Az());
-    v.SetTheta(TMath::Pi()/2-p.Alt());
-    // Rotate around the x- and y-axis
-    v.RotateY(-fAn);
-    v.RotateX(-fAw);
-    // Get Azimuth and Elevation
-    p.Az(v.Phi());
-    p.Alt(TMath::Pi()/2-v.Theta());
-
+    const AltAz ANAW(CalcAnAw(p, -1));
+    p -= ANAW;
 
     DEBUG(cout << "Back2: " << 90-p.Alt()*180/TMath::Pi() << " " << p.Az()*180/TMath::Pi() << endl);
@@ -498,17 +520,4 @@
 }
 
-AltAz MBending::SubtractOffsets(const AltAz &aa) const
-{
-    // Correct [rad]
-    // zdaz    [rad]
-    AltAz p = aa;
-
-    const AltAz I(fIe, fIa);
-    p -= I;
-
-    return p;
-}
-
-
 ZdAz MBending::Correct(const ZdAz &zdaz) const
 {
Index: trunk/MagicSoft/Cosy/main/MBending.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MBending.h	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MBending.h	(revision 2615)
@@ -53,4 +53,5 @@
 
     static Double_t Sign(Double_t val, Double_t alt);
+    AltAz CalcAnAw(const AltAz &p, Int_t sign) const;
 
 public:
Index: trunk/MagicSoft/Cosy/main/MCaos.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 2615)
@@ -12,4 +12,6 @@
 #include <TCanvas.h>
 
+#include "MTime.h"
+
 #include "Led.h"
 #include "Ring.h"
@@ -18,5 +20,4 @@
 
 #include "coord.h"
-#include "base/timer.h"
 
 void MCaos::ReadResources(const char *name="leds.txt")
@@ -306,5 +307,5 @@
 }
 
-void MCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const Timer &t)
+void MCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t)
 {
     Leds &leds = *fLeds;
@@ -354,6 +355,6 @@
 
     // FIXME!
-    static const Timer t0(t);
-    fEvtTime = (double)t-(double)t0;
+    static const MTime t0(t);
+    fEvtTime = t-t0;
 
     if (fHistpr)
Index: trunk/MagicSoft/Cosy/main/MCaos.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCaos.h	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MCaos.h	(revision 2615)
@@ -15,5 +15,5 @@
 class TGraph;
 
-class Timer;
+class MTime;
 class ZdAz;
 
@@ -68,5 +68,5 @@
     void ResetHistograms();
 
-    void Run(byte *img, bool printl, bool printr, const ZdAz &pos, const Timer &t);
+    void Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t);
 };
 
Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 2615)
@@ -18,4 +18,5 @@
 
 #include "MGCosy.h"
+#include "MTime.h"
 #include "MDriveCom.h"
 #include "MStarguider.h"
@@ -25,5 +26,4 @@
 
 #include "macs.h"
-#include "base/timer.h"
 #include "shaftencoder.h"
 
@@ -341,5 +341,5 @@
         return;
 
-    Timer t;
+    MTime t;
     t.Now();
     lout << t << " - MCosy::WaitForEndMovement aborted...";
@@ -449,5 +449,5 @@
     const ZdAz d = dst*kRad2Deg;
 
-    Timer t;
+    MTime t;
     t.Now();
     lout << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
@@ -958,5 +958,5 @@
 
     sla.Now();
-    lout << sla << " - Start tracking:";
+    lout << sla.GetTime() << " - Start tracking:";
     lout << " Ra: " << xy.X() << "h  " << "Dec: " << xy.Y() << "\xb0" << endl;
 /*#ifdef EXPERT
@@ -1105,5 +1105,5 @@
     StopMovement();
 
-    lout << sla << " - Tracking stopped." << endl;
+    lout << sla.GetTime() << " - Tracking stopped." << endl;
 }
 
@@ -2184,5 +2184,5 @@
     fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
 }
-
+/*
 void MCosy::ConstructorSE(Int_t id4, Int_t id5, Int_t id6)
 {
@@ -2231,6 +2231,6 @@
     fWin=new MGCosy(fObservatory, this, gClient->GetRoot(), 1, 1);
 }
-
-MCosy::MCosy(int mode, const char *dev, const int baud, MLog &out)
+*/
+MCosy::MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out)
 : Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(MDriveCom::kStopped)
 {
@@ -2242,12 +2242,12 @@
     const Int_t id5 = env.GetValue("Zd_Id-SE2",  5); //5
     const Int_t id6 = env.GetValue("Az_Id-SE",   6); //6
-
+/*
     lout << "- Program in ";
     switch (mode)
     {
     case 0:
-        lout << "<<Standard mode>>" << endl;
+        lout << "<<Standard mode>>" << endl;*/
         fBending.Load("bending.txt");
-        Constructor(id1, id2, id3, id4, id5, id6);
+        Constructor(id1, id2, id3, id4, id5, id6);/*
         break;
     case 1:
@@ -2260,5 +2260,5 @@
         ConstructorDemo();
     }
-
+*/
     lout.SetOutputGui(fWin->GetLog(), kTRUE);
 
@@ -2267,15 +2267,16 @@
     fAz->SetDisplay(fWin->GetLabel1());
 
-    int i=0;
-    char name[100];
+    //
+    // open tpoint file
+    //
+    MTime time;
+    TString name;
     while (1)
     {
-        sprintf(name, "tpoint/tpoint%03d.txt", i++);
+        time.Now();
+        name = Form("tpoint/tpoint_%s.txt", (const char*)time.GetFileName());
         if (gSystem->AccessPathName(name, kFileExists))
             break;
     }
-
-    Timer time;
-    time.Now();
 
     cout << "TPoint File ********* " << name << " ********** " << endl;
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 2615)
@@ -168,6 +168,6 @@
 
     void Constructor(Int_t id1, Int_t id2, Int_t id3, Int_t id4, Int_t id5, Int_t id6);
-    void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
-    void ConstructorDemo();
+    //void ConstructorSE(Int_t id1, Int_t id2, Int_t id3);
+    //void ConstructorDemo();
 
     void ReadConfig();
@@ -176,5 +176,5 @@
 
 public:
-    MCosy(int mode, const char *dev, const int baud, MLog &out=gLog);
+    MCosy(/*int mode,*/ const char *dev, const int baud, MLog &out=gLog);
     ~MCosy();
 
Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 2615)
@@ -839,5 +839,5 @@
     static unsigned long n0 = n;
 
-    Timer t(tm);
+    MTime t(*tm);
 
     const Double_t d = t-fTime;
@@ -894,5 +894,5 @@
     if (fDisplay->IsEntryChecked(IDM_kCatalog))
     {
-        Timer time(tm);
+        MTime time(*tm);
 
         XY xy = fCRaDec->GetCoordinates();
@@ -934,4 +934,5 @@
     if (fDisplay->IsEntryChecked(IDM_kCatalog))
     {
+        // FIXME: Necessary?
         fSao->Now();
         AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
Index: trunk/MagicSoft/Cosy/main/MStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 2613)
+++ trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 2615)
@@ -5,7 +5,13 @@
 #include <TGFrame.h>
 #endif
+
 #include "PixClient.h"
+
 #ifndef MARS_MObservatory
 #include "MObservatory.h"
+#endif
+
+#ifndef MARS_MTime
+#include "MTime.h"
 #endif
 
@@ -14,5 +20,4 @@
 
 #include "coord.h"
-#include "timer.h"
 
 class TArrayF;
@@ -76,5 +81,5 @@
 
     TTimer *fTimer;
-    Timer   fTime;
+    MTime   fTime;
 
     Int_t fDx;
