Index: trunk/Cosy/main/MTracking.cc
===================================================================
--- trunk/Cosy/main/MTracking.cc	(revision 10008)
+++ trunk/Cosy/main/MTracking.cc	(revision 10024)
@@ -25,4 +25,10 @@
     fTrackAcc(0, 0), fWobbleOffset(-1), fWobbleAngle(0), fOut(0)
 {
+    fMoon = new MMoonPointing("MoonShadowOffsets.root");
+}
+
+MTracking::~MTracking()
+{
+    delete fMoon;
 }
 
@@ -227,7 +233,5 @@
     if (fTrackType==(kEMoon|0x100))
     {
-        // FIXME: Read file only once!
-        MMoonPointing moon("MoonShadowOffsets.root");
-        if (moon.IsZombie())
+        if (fMoon->IsZombie())
         {
             gLog << err << "ERROR - Could not initialize MMoonPointing." << endl;
@@ -235,17 +239,33 @@
         }
 
-        moon.SetOffsetShadow(TMath::DegToRad()*fWobbleAngle);
-        moon.SetOffsetWobble(TMath::DegToRad()*fWobbleOffset);
+        //moon.SetOffsetShadow(fWobbleAngle);
+        //moon.SetOffsetWobble(fWobbleOffset);
+
+        const ZdAz za = sla.GetZdAzRad();
 
         ZdAz srcpos, pointpos;
-
-        const ZdAz za = sla.GetZdAzRad();
-        if (!moon.CalcPosition(za, srcpos, pointpos))
+        if (!fMoon->CalcPosition(za, srcpos, pointpos))
         {
             gLog << err << "ERROR - Calculation of moon shadow pointing position failed." << endl;
+            gLog << "        WoAngle    =" << fWobbleAngle << endl;
+            gLog << "        WoOffset   =" << fWobbleOffset << endl;
+            gLog << "        TrackType  =" << fTrackType << endl;
+            gLog << "        TT&0xff    =" << (fTrackType&0xff) << endl;
+            gLog << "        mjd        =" << sla.GetMjd() << endl;
+            gLog << "        za.Zd      =" << za.Zd() << endl;
+            gLog << "        za.Az      =" << za.Az() << endl;
+            gLog << "        srcpos.Zd  =" << srcpos.Zd() << endl;
+            gLog << "        srcpos.Az  =" << srcpos.Az() << endl;
+            gLog << "        pointpos.Zd=" << pointpos.Zd() << endl;
+            gLog << "        pointpos.Az=" << pointpos.Az() << endl;
             return kFALSE;
         }
 
-        sla.Set(pointpos);
+        sla.Set(pointpos/TMath::DegToRad());
+
+//        return kTRUE;
+
+        //RaDec rd = sla.GetRaDec();
+        //ZdAz  zd = sla.GetZdAz();
 
         // Ra/Dec, Zd/Az from pointpos
@@ -263,6 +283,5 @@
         }
         */
-    //    if (fCosy->fStarguider)
-    //        fCosy->fStarguider->SetPointingPosition(sla.GetRaDec());
+    return kTRUE;
 }
 
@@ -275,4 +294,6 @@
     fCosy->fRaDec     = fSlalib.GetRaDecRad();
     fCosy->fHourAngle = fSlalib.GetHourAngle();
+
+    return kTRUE;
 }
 
@@ -290,5 +311,5 @@
 
     if (fTrackType>=0)
-       gLog << all << fSlalib.GetTime() << ": Tracking Planet with Id " << fTrackType << endl;
+       gLog << all << fSlalib.GetTime() << ": Tracking Planet with Id " << fTrackType << " (" << fWobbleOffset << ", " << fWobbleAngle << ")" << endl;
     gLog << all << fSlalib.GetTime() << ": Track Position " << dst.Ra()*kRad2Deg/15 << "h, " << dst.Dec()*kRad2Deg <<"deg" << endl;
 
@@ -321,4 +342,8 @@
     fTrackType = -1;
 
+    // Just for convenience
+    fMoon->SetOffsetShadow(0);
+    fMoon->SetOffsetWobble(0);
+
     // Start tracking
     Track();
@@ -330,4 +355,8 @@
     fTrackType = planet;
 
+    // Just for convenience
+    fMoon->SetOffsetShadow(0);
+    fMoon->SetOffsetWobble(0);
+
     // Start tracking
     Track();
@@ -341,4 +370,7 @@
     fWobbleOffset = TMath::DegToRad()*wobble;
     fWobbleAngle  = TMath::DegToRad()*offset;
+
+    fMoon->SetOffsetShadow(fWobbleAngle);
+    fMoon->SetOffsetWobble(fWobbleOffset);
 
     // Start tracking
@@ -473,4 +505,12 @@
             break;
 
+        // Now the tracking procedure is finished and we have some time
+        // left to set the nominal pointing position for the starguider
+        // if available. This should be thread safe. Doing this in
+        // UpdateSlalib would also update it from the Thread
+        // which leads to problems.
+        if (fCosy->fStarguider)
+            fCosy->fStarguider->SetPointingPosition(fSlalib.GetRaDec());
+
         //
         // Update speed as often as possible.
@@ -513,6 +553,8 @@
     //SlaPlanets sla(fSlalib.GetObservatoryKey());
     SlaPlanets sla(MObservatory::kMagic1);
-
-    UpdateSlalib(sla);
+    sla.Now();
+
+    if (!UpdateSlalib(sla))
+        gLog << err << "UpdateSlalib in Thread failed." << endl;
 
     //
Index: trunk/Cosy/main/MTracking.h
===================================================================
--- trunk/Cosy/main/MTracking.h	(revision 10008)
+++ trunk/Cosy/main/MTracking.h	(revision 10024)
@@ -17,4 +17,5 @@
 class RaDec;
 class SlaStars;
+class MMoonPointing;
 
 class MTracking : public MSlewing, public MThread
@@ -32,4 +33,6 @@
 
     MLog   *fOut;
+
+    MMoonPointing *fMoon;
 
     Bool_t UpdateSlalib(SlaPlanets &sla);
@@ -49,4 +52,5 @@
 public:
     MTracking(MCosy *cosy);
+    ~MTracking();
 
     void TrackPosition(const RaDec &dst); // ra, dec [rad]
