Index: trunk/MagicSoft/Cosy/gui/MGCoordinate.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 8813)
+++ trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 8814)
@@ -33,4 +33,5 @@
 {
     fList = new MGList;
+    fList->SetOwner();
 
     const Int_t offset = TString(txt).IsNull() ? 23 : 0;
@@ -91,5 +92,5 @@
     }
 
-    TGLabel *label;
+    TGLabel *label=0;
 
     const char *sdeg = type==kETypeDeg ? "\xb0" : "h";
Index: trunk/MagicSoft/Cosy/gui/MGPngReader.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGPngReader.cc	(revision 8813)
+++ trunk/MagicSoft/Cosy/gui/MGPngReader.cc	(revision 8814)
@@ -193,4 +193,5 @@
 {
     fList = new MGList;
+    fList->SetOwner();
 
     const TGWindow *p=gClient->GetRoot();
Index: trunk/MagicSoft/Cosy/main/MPointing.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MPointing.cc	(revision 8813)
+++ trunk/MagicSoft/Cosy/main/MPointing.cc	(revision 8814)
@@ -1,3 +1,3 @@
-#include "MPointing.h"
+#include "MSlewing.h"
 
 #include "MCosy.h"
@@ -5,5 +5,7 @@
 #include "MDriveCom.h"
 
-ClassImp(MPointing);
+#include "MPointing.h"
+
+ClassImp(MSlewing);
 
 using namespace std;
@@ -22,5 +24,5 @@
 //  target position at the same time.
 //
-void MPointing::SetPosVelocity(const Float_t ratio, Float_t vel)
+void MSlewing::SetPosVelocity(const Float_t ratio, Float_t vel)
 {
     //
@@ -51,5 +53,5 @@
 // if Axis 2==kTRUE. The function waits for the movement to be finished.
 //
-void MPointing::DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2)
+void MSlewing::DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2)
 {
     if (fCosy->HasZombie())
@@ -72,5 +74,5 @@
 }
 
-bool MPointing::SetAccDec(Macs *mac, Float_t acc, Float_t dec)
+bool MSlewing::SetAccDec(Macs *mac, Float_t acc, Float_t dec)
 {
     const int vr = mac->GetVelRes();
@@ -80,5 +82,5 @@
 }
 
-bool MPointing::Break()
+bool MSlewing::Break()
 {
     return fCosy->Break() || fCosy->HasError() || fCosy->HasZombie();
@@ -96,10 +98,10 @@
 // As a reference the shaftencoder values are used.
 //
-int MPointing::SetPosition(const ZdAz &dst, Bool_t track) // [rad]
+int MSlewing::SetPosition(const ZdAz &dst, Bool_t track) // [rad]
 {
     const ZdAz d = dst*kRad2Deg;
 
     MTime t(-1);
-    lout << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
+    gLog << t << " - Target Position: " << d.Zd() << "deg, " << d.Az() << "deg (Zd/Az)" << endl;
 
     //
@@ -148,5 +150,5 @@
     {
 
-        lout << "- Step #" << i << endl;
+        gLog << "- Step #" << i << endl;
 
         // Get Shaft Encoder Positions
@@ -171,5 +173,5 @@
         {
             t.Now();
-            lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
+            gLog << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
             fCosy->SetStatus(MDriveCom::kStopped);
             fCosy->fCom->SendStatus("Target position reached.");
@@ -206,6 +208,6 @@
             const Double_t y = 15*fCosy->kGearTot.Y()/fCosy->kResSE.Y();
 
-//	    lout << "MPointing::SetPosition y: " << y << " rd.Az(): " << rd.Az() << endl;
-//	    lout << "MPointing::SetPosition fCosy->kGearTot.Y(): " << fCosy->kGearTot.Y() << " fCosy->kResSE.Y(): " << fCosy->kResSE.Y() << endl;
+//	    lout << "MSlewing::SetPosition y: " << y << " rd.Az(): " << rd.Az() << endl;
+//	    lout << "MSlewing::SetPosition fCosy->kGearTot.Y(): " << fCosy->kGearTot.Y() << " fCosy->kResSE.Y(): " << fCosy->kResSE.Y() << endl;
 
 	    if (rd.Az()>-y && rd.Az()<y)
@@ -217,5 +219,5 @@
 	      {
 
- 		//lout << "MPointing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl;
+ 		//lout << "MSlewing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl;
 		
  		SetAccDec(fCosy->fMac1, fAcc, fDec);
@@ -243,12 +245,12 @@
 
         // repositioning (relative)
-        lout << "- Do Relative Positioning..." << endl;
+        gLog << "- Do Relative Positioning..." << endl;
         DoRelPos(rd, cdzd, cdaz);
-        lout << "- Relative Positioning Done" << endl;
+        gLog << "- Relative Positioning Done" << endl;
     }
     if (i==1 && track && !Break()/*(fCosy->Break() || fCosy->HasError() || fCosy->HasZombie())*/)
     {
         t.Now();
-        lout << t << " - Positioning done." << endl;
+        gLog << t << " - Positioning done." << endl;
         fCosy->SetStatus(MDriveCom::kStopped);
         fCosy->fCom->SendStatus("Tracking preposition reached.");
@@ -262,5 +264,5 @@
 
     t.Now();
-    lout << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;
+    gLog << t << " - Warning: Requested position not reached (i=" << dec << i << ")" << endl;
 
     fCosy->fCom->SendStatus("Target position missed!");
Index: trunk/MagicSoft/Cosy/main/MPointing.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MPointing.h	(revision 8813)
+++ trunk/MagicSoft/Cosy/main/MPointing.h	(revision 8814)
@@ -1,16 +1,14 @@
-#ifndef COSY_MPointing
-#define COSY_MPointing
+#ifndef COSY_MSlewing
+#define COSY_MSlewing
 
-#include "coord.h"
-#include "log.h"
-
-#ifndef ROOT_TObject
-#include <TObject.h>
+#ifndef MARS_MLog
+#include "MLog.h"
 #endif
 
 class Macs;
 class MCosy;
+class ZdAz;
 
-class MPointing : public Log, public TObject
+class MSlewing : public MLog
 {
 protected:
@@ -29,11 +27,11 @@
 
 public:
-    MPointing(MCosy *cosy, const Log &log) : Log(log), fCosy(cosy), fVel(0.1), fAcc(0.2), fDec(0.1) { }
+    MSlewing(MCosy *cosy) : fCosy(cosy), fVel(0.1), fAcc(0.2), fDec(0.1) { }
 
     void SetPointAccDec(Float_t acc, Float_t dec) { fAcc = acc; fDec = dec; }
     void SetPointVelocity(Float_t vel) { fVel = vel; }
     int  SetPosition(const ZdAz &dst, Bool_t track=kFALSE);
-  
-    ClassDef(MPointing, 0)
+
+    ClassDef(MSlewing, 0)
 };
 
Index: trunk/MagicSoft/Cosy/main/MTracking.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 8813)
+++ trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 8814)
@@ -52,5 +52,5 @@
     //
     if (fCosy->HasError())
-        lout << "Error while requesting re pos from Macs (SDO #6004)" << endl;
+        gLog << "Error while requesting re pos from Macs (SDO #6004)" << endl;
 
     return false;
@@ -93,5 +93,5 @@
     //
     if (fCosy->HasError())
-        lout << "Error while setting tracking velocity (SDO #3006)" << endl;
+        gLog << "Error while setting tracking velocity (SDO #3006)" << endl;
 
     return kFALSE;
@@ -223,6 +223,6 @@
     {
         vt->Az(maxtrack*vraz*4*sgn(vcalc.Az()));
-        lout << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Az()) << " > " << maxtrack*vraz << ")... limited." << endl;
-        lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl;
+        gLog << "Warning: Azimuth speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Az()) << " > " << maxtrack*vraz << ")... limited." << endl;
+        gLog << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl;
         rc=kTRUE;
     }
@@ -230,6 +230,6 @@
     {
         vt->Zd(maxtrack*vrzd*4*sgn(vcalc.Zd()));
-        lout << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Zd()) <<" > " << maxtrack*vrzd << ")... limited." << endl;
-        lout << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl;
+        gLog << "Warning: Altitude speed limit (" << maxtrack*100 << "%) exceeded (" << fabs(vt->Zd()) <<" > " << maxtrack*vrzd << ")... limited." << endl;
+        gLog << "Vcalc: " << vcalc.Zd() << " " << vcalc.Az() << "re/min" <<endl;
         rc=kTRUE;
     }
@@ -329,5 +329,5 @@
     ZdAz dest = sla.CalcZdAz(dst);
 
-    lout << sla.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl;
+    gLog << sla.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl;
 
     // If the star is culminating behind the zenith (South) we want to
@@ -338,5 +338,5 @@
     {
         // align az from -180/180 to 0/360
-        lout << "Star culminating behind zenith: Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl;
+        gLog << "Star culminating behind zenith: Adding 360deg to Azimuth " << dest.Az()*kRad2Deg << endl;
         dest.Az(dest.Az() + TMath::TwoPi());
     }
@@ -347,5 +347,5 @@
     if (!SetPosition(dest, kTRUE))
     {
-        lout << "Error: Cannot start tracking, positioning failed." << endl;
+        gLog << "Error: Cannot start tracking, positioning failed." << endl;
         return;
     }
@@ -369,6 +369,5 @@
     fCosy->fRaDec = dst;
 
-    // StartThread
-    Start();
+    RunThread();
 
     //
@@ -387,6 +386,6 @@
     // Some output
     XY xy(Rad2Deg(dst.Ra())*24/360, Rad2Deg(dst.Dec()));
-    lout << sla.GetTime() << " - Start Tracking: Ra=" << xy.X() << "h Dec=";
-    lout << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl;
+    gLog << sla.GetTime() << " - Start Tracking: Ra=" << xy.X() << "h Dec=";
+    gLog << xy.Y() << "\xb0 @ Zd=" << pos.Zd()*kRad2Deg <<"deg Az=" << pos.Az()*kRad2Deg <<"deg" << endl;
 
     //
@@ -470,7 +469,7 @@
         if (LimitSpeed(&v, sla))
         {
-            lout << "vt: " << v.Zd() << " " << v.Az() << "re/min" << endl;
-            lout << "Dest: " << dest.Zd() << " " << dest.Az() << endl;
-        }              
+            gLog << "vt: " << v.Zd() << " " << v.Az() << "re/min" << endl;
+            gLog << "Dest: " << dest.Zd() << " " << dest.Az() << endl;
+        }
 
         //
@@ -488,5 +487,5 @@
         if (vt.Zd()>.9*fCosy->fMac1->GetVelRes() || vt.Az()>.9*fCosy->fMac2->GetVelRes())
         {
-            lout << "Error: Tracking speed faster than 90% of possible maximum velocity." << endl;
+            gLog << "Error: Tracking speed faster than 90% of possible maximum velocity." << endl;
             break;
         }
@@ -524,31 +523,30 @@
         //
         usleep(1000000); // 1s
-// *****FIXME****        cout << "." << flush;
     }
 
     sla.Now();
 
-    // StopThread
-    Stop();
-
+    CancelThread();
+
+    // If CancelPoints are used we have to make this a Cleanup!
     fCosy->StopMovement();
 
-    lout << sla.GetTime() << " - Tracking stopped @ Zd=";
-    lout << fCosy->fZdAzSoll.Zd()*TMath::RadToDeg() <<"deg Az=";
-    lout << fCosy->fZdAzSoll.Az()*TMath::RadToDeg() <<"deg" << endl;
-}
-
-void *MTracking::Thread()
+    gLog << sla.GetTime() << " - Tracking stopped @ Zd=";
+    gLog << fCosy->fZdAzSoll.Zd()*TMath::RadToDeg() <<"deg Az=";
+    gLog << fCosy->fZdAzSoll.Az()*TMath::RadToDeg() <<"deg" << endl;
+}
+
+Int_t MTracking::Thread()
 {
     if (fCosy->fZd1->IsZombieNode() && fCosy->fZd2->IsZombieNode())
-        return (void*)1;
+        return 1;
 
     if (fCosy->fAz->IsZombieNode())
-        return (void*)2;
+        return 2;
 
     if (!fCosy->fMac1 || !fCosy->fMac2)
-        return (void*)3;
-
-    lout << "- Tracking Thread started (" << MTime(-1) << ")" << endl;
+        return 3;
+
+    gLog << "- Tracking Thread started (" << MTime(-1) << ")" << endl;
 
     //const XY re2se = fCosy->kGearTot/fCosy->kResSE; //[re/se]
@@ -571,5 +569,5 @@
     //ZdAz oldse = fCosy->GetSePos();
 
-    while (!HasStopFlag())
+    while (1)
     {
         // Make changes (eg wind) smoother - attenuation of control function
@@ -589,6 +587,9 @@
             phca2 = fCosy->fZd2->PosHasChanged();
             phcaz = fCosy->fAz->PosHasChanged();
+
             usleep(1);
-        } while (!phca1 && !phca2 && !phcaz && !HasStopFlag());
+            TThread::CancelPoint();
+
+        } while (!phca1 && !phca2 && !phcaz);
 
         // Get time from last shaftencoder position change (position: ist)
@@ -619,4 +620,8 @@
             fCosy->fZdAzSoll.Zd(dummy.Zd());
             soll.Zd(fCosy->fBending(dummy).Zd()); // [rad]
+
+            fCosy->fTrackingError.Zd(soll.Zd()-istse.Zd());
+
+            TThread::CancelPoint();
         }
         if (phcaz)
@@ -626,16 +631,22 @@
             fCosy->fZdAzSoll.Az(dummy.Az());
             soll.Az(fCosy->fBending(dummy).Az()); // [rad]
+
+            fCosy->fTrackingError.Az(soll.Az()-istse.Az());
+
+            TThread::CancelPoint();
         }
 
+
         //fCosy->fZdAzSoll = soll;
-
-        // Calculate the aligned tracking posotion from 'soll'-position
+/*
+        // Calculate the aligned tracking position from 'soll'-position
         if (phca1 || phca2)
             fCosy->fTrackingError.Zd(soll.Zd()-istse.Zd());
         if (phcaz)
             fCosy->fTrackingError.Az(soll.Az()-istse.Az());
-    }
-
-    lout << "- Tracking Thread done. (" << MTime(-1) << ")" << endl;
+            */
+    }
+
+    gLog << "- Tracking Thread done. (" << MTime(-1) << ")" << endl;
     return 0;
 }
Index: trunk/MagicSoft/Cosy/main/MTracking.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MTracking.h	(revision 8813)
+++ trunk/MagicSoft/Cosy/main/MTracking.h	(revision 8814)
@@ -4,9 +4,9 @@
 #include "coord.h"
 
-#ifndef COSY_MPointing
-#include "MPointing.h"
+#ifndef COSY_MSlewing
+#include "MSlewing.h"
 #endif
 
-#ifndef COSY_MThread
+#ifndef MARS_MThread
 #include "MThread.h"
 #endif
@@ -14,5 +14,5 @@
 class SlaStars;
 
-class MTracking : public MPointing, public MThread
+class MTracking : public MSlewing, public MyThreadX
 {
 private:
@@ -39,8 +39,8 @@
     ZdAz GetPointingPosRE(Bool_t pdo=kFALSE) const;
 
-    void *Thread();
+    Int_t Thread();
 
 public:
-    MTracking(MCosy *cosy, const Log &log) : MPointing(cosy, log), MThread(kFALSE), fTrackAcc(0.1), fTrackDec(0.1), fOut(0) { }
+    MTracking(MCosy *cosy) : MSlewing(cosy), MyThreadX("MTracking"), fTrackAcc(0.1), fTrackDec(0.1), fOut(0) { }
 
     void TrackPosition(const RaDec &dst); // ra, dec [rad]
Index: trunk/MagicSoft/Cosy/main/MainLinkDef.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MainLinkDef.h	(revision 8813)
+++ trunk/MagicSoft/Cosy/main/MainLinkDef.h	(revision 8814)
@@ -5,12 +5,10 @@
 #pragma link off all functions;
 
-#pragma link C++ class MCosy;
+#pragma link C++ class MCosy+;
 #pragma link C++ class MStarguider+;
 #pragma link C++ class MStargHistograms+;
 
-#pragma link C++ class MBending;
-
-#pragma link C++ class MPointing;
-#pragma link C++ class MTracking;
+#pragma link C++ class MSlewing+;
+#pragma link C++ class MTracking+;
 
 #endif
