Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 911)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 912)
@@ -1,82 +1,147 @@
                                                                   -*-*- END -*-*-
+
+ 2001/08/17 - Thomas Bretz:
+
+    * Added:
+      - catalog/SlaStars.cc
+      - catalog/SlaStars.h
+      - catalog/SlaPlanets.cc
+      - catalog/SlaPlanets.h
+      - gui/MGAccuracy.cc
+      - gui/MGAccuracy.h
+
+    * MCosy.[h,cc]:
+      - removed dependance from MGSkyPosition
+      - changed Timer function names
+      - moved timer calls into Slalib calls
+      - changed Slalib to SlaStars
+      - added fAccuracy
+      - added accuracy display to MTGui
+    
+    * Makefile:  
+      - changed order of libraries
+    
+    * Starguider.cc:
+      - changed Timer function names
+    
+    * base/timer.[h,cc]
+      - changed GetTime -> Now
+      - changed GetMjd  -> CalcMjd
+    
+    * catalog/Makefile:
+      - added new file SlaStars.cc
+      - added new file SlaPlanets.cc
+    
+    * catalog/Slalib.[h,cc]:
+      - moved star dependent functions to derived class SlaStars
+      - changed name of Set to SetMjd
+      - made SetMjd virtual
+      - derives from Timer now
+      - added conversion function for XYZ->ZdAz
+    
+    * catalog/StarCatalog.cc:
+      - moved timer calls into Slalib calls
+      - changed Slalib to SlaStars
+
+    * devdrv/macs.cc:
+      - changed names of timer function calls
+
+    * devdrv/shaftencoder.cc:
+      - changed names of timer function calls
+      - changed some cout's to lout's
+    
+    * gui/MGCosy.[h,cc]:
+      - added fAccuracy
+      - moved timer calls into Slalib calls
+      - changed Slalib to SlaStars
+    
+    * gui/MGSkyPosition.[h,cc]:
+      - added display of planet positions
+
+    * slalib/Makefile:
+    - added missing files
+    
+
+
+
  2001/08/15 - Thomas Bretz:
 
-   * Added:
-     - Makefile.conf.general
-     - gui/Makefile
-     - base/Makefile
-     - candrv/Makefile
-     - catalog/Makefile
-     - slalib/Makefile
-     - videodev/Makefile
-     - devdrv/Makefile
-     - base/MThread.[h,cc]
-     - base/MTimeout.[h, cc]
-     - mgui/MGSkyPosition.[h, cc]
-     - catalog/Slalib.[h,cc]
+    * Added:
+      - Makefile.conf.general
+      - gui/Makefile
+      - base/Makefile
+      - candrv/Makefile
+      - catalog/Makefile
+      - slalib/Makefile
+      - videodev/Makefile
+      - devdrv/Makefile
+      - base/MThread.[h,cc]
+      - base/MTimeout.[h, cc]
+      - mgui/MGSkyPosition.[h, cc]
+      - catalog/Slalib.[h,cc]
      
-   * .cosyrc:
-     - changed names
-     - added HomeTime
-   
-   * MCosy.[h,cc]:
-     - added home time
-     - added MTGui, MTTalk
-     - added reading environment
-   
-   * Makefile, Makefile.conf.linux-gnu, Makefile.rules
-     - changed to Mars style
-   
-   * Starguider.cc:
-     - changed include timer.g to base/timer.h
-   
-   * Starguider.[h,cc]:
-     - renamed Execute to ProcessFrame
+    * .cosyrc:
+      - changed names
+      - added HomeTime
+   
+    * MCosy.[h,cc]:
+      - added home time
+      - added MTGui, MTTalk
+      - added reading environment
+   
+    * Makefile, Makefile.conf.linux-gnu, Makefile.rules
+      - changed to Mars style
+   
+    * Starguider.cc:
+      - changed include timer.g to base/timer.h
+   
+    * Starguider.[h,cc]:
+      - renamed Execute to ProcessFrame
  
-   * cosy.cc:
-     - removed unnecessary includes
-   
-   * base/MGList.h:
-     - added debug output
-   
-   * base/msgqueue.cc:
-     - added comments
-   
-   * base/msgqueue.h:
-     - made Break const
-   
-   * candrv/canopen.[h,cc]:
-     - made CobId const
-   
-   * candrv/network.[h,cc]:
-     - fixed typo
-     - StopReceiver -> VmodIcan::Stop
-     - made HasError const
-   
-   * candrv/nodedrv.[h,cc]:
-     - added timeout to WaitForSdo
-   
-   * candrv/sdolist.[h,cc]:
-     - made IsPending const
+    * cosy.cc:
+      - removed unnecessary includes
+   
+    * base/MGList.h:
+      - added debug output
+   
+    * base/msgqueue.cc:
+      - added comments
+   
+    * base/msgqueue.h:
+      - made Break const
+   
+    * candrv/canopen.[h,cc]:
+      - made CobId const
+   
+    * candrv/network.[h,cc]:
+      - fixed typo
+      - StopReceiver -> VmodIcan::Stop
+      - made HasError const
+   
+    * candrv/nodedrv.[h,cc]:
+      - added timeout to WaitForSdo
+   
+    * candrv/sdolist.[h,cc]:
+      - made IsPending const
      
-   * candrv/vmodican.[h,cc]:
-     - changed ReceiveThread to new stylish MThread
-   
-   * devdrv/macs.[h,cc]:
-     - changed SetHome to use a maximum positioning time
-     - added comments
-     - replaces SetSyncMode by StartPosSync and StartVelSync
-
-   * devdrv/shaftencoder.[h,cc]:
-     - removed gui thread (the update is done by MTGui now)
-   
-   * gui/MGCosy.[h,cc]:
-     - some small changed
-     - removed fList->Delete()
-     - added MSkyPosition-Object
-     - gSystem->ExitLoop() replaced by gSystem->Terminate(0)
-   
-   * videodev/Camera.[h,cc]:
-     - renamed Execute to ProcessFrame
+    * candrv/vmodican.[h,cc]:
+      - changed ReceiveThread to new stylish MThread
+   
+    * devdrv/macs.[h,cc]:
+      - changed SetHome to use a maximum positioning time
+      - added comments
+      - replaces SetSyncMode by StartPosSync and StartVelSync
+
+    * devdrv/shaftencoder.[h,cc]:
+      - removed gui thread (the update is done by MTGui now)
+   
+    * gui/MGCosy.[h,cc]:
+      - some small changed
+      - removed fList->Delete()
+      - added MSkyPosition-Object
+      - gSystem->ExitLoop() replaced by gSystem->Terminate(0)
+   
+    * videodev/Camera.[h,cc]:
+      - renamed Execute to ProcessFrame
 
 
Index: trunk/MagicSoft/Cosy/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/MCosy.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/MCosy.cc	(revision 912)
@@ -11,11 +11,9 @@
 
 #include "MGCosy.h"
-#include "Slalib.h"
+#include "SlaStars.h"
 
 #include "macs.h"
 #include "base/timer.h"
 #include "shaftencoder.h"
-
-#include "MGSkyPosition.h" // FIXME!!!!!!!!!!!!!!!!!
 
 //#include <sys/resource.h>  // PRIO_PROCESS
@@ -265,13 +263,10 @@
 void MCosy::TrackPosition(const RaDec &dst) // ra, dec [rad]
 {
-    Slalib sla;
+    SlaStars sla;
 
     //
     // Position to actual position
     //
-    Timer t;
-    t.GetTime();
-
-    sla.Set(t.GetMjd());
+    sla.SetMjd2Now();
     ZdAz dest = sla.CalcZdAz(dst);
 
@@ -311,5 +306,5 @@
     fMac1->SetRpmMode(TRUE);
 
-    /*-*/ int s = t.GetSecs();
+    /*-*/ int s = sla.GetSecs();
     cout << "Start tracking: Ra: " << Rad2Deg(dst.Ra()) << kDEG << "  Dec: ";
     cout << Rad2Deg(dst.Dec()) << kDEG << endl;
@@ -333,11 +328,10 @@
         // Request Real Position from Drive
         //
-        Timer t;
-        t.GetTime();
+        sla.Now();
 
         //
         // Request theoretical Position for a time in the future (To+dt) from CPU
         //
-        sla.Set(t.GetMjd()+dt/(60*60*24));
+        sla.SetMjd(sla.CalcMjd()+dt/(60*60*24));
         dest = CorrectTarget(GetSePos(), sla.CalcZdAz(dst));
 
@@ -367,5 +361,5 @@
         // correct for the duration of RaDec2AltAz
         //
-        const ZdAz v = dest*60.0/(dt-(fMac2->GetTime()-t));
+        const ZdAz v = dest*60.0/(dt-(fMac2->GetTime()-sla));
 
         //
@@ -404,14 +398,16 @@
         {
             const double mjd = fMac2->GetMjd();
-            sla.Set(mjd);
+            sla.SetMjd(mjd);
             ZdAz dest0=CorrectTarget(GetSePos(), sla.CalcZdAz(dst));
             dest0 *= kGearRatio;
             dest0 -= GetRePos()+offset;
             dest0.Round();
+
+            fAccuracy = dest0/kGearRatio2; // [deg]
+
             //cout << "Control deviation: ";
             fout << setprecision(15) << setw(15) << mjd*60.*60.*24. << " ";
             fout << setw(4) << (int)fOffset.Zd() << " ";
             fout << setw(4) << (int)fOffset.Az() << " ";
-
             fout << setw(4) << dest0.Zd() << " ";
             fout << setw(4) << dest0.Az() << " ";
@@ -478,10 +474,6 @@
         {
             cout << "WM_POLARIS: START" << endl;
-            Slalib sla;
-
-            Timer t;
-            t.GetTime();
-
-            sla.Set(t.GetMjd());
+            SlaStars sla;
+            sla.SetMjd2Now();
 
             RaDec rd(37.94, 89.2644);
@@ -608,5 +600,5 @@
     // SetPosition(dest);
 
-    Slalib sla;
+    SlaStars sla;
     while (1)
     {
@@ -665,5 +657,5 @@
                 // calculate were we should be
                 //
-                sla.Set(t);
+                sla.SetMjd(t);
                 sollalt = CorrectTarget(ist, sla.CalcZdAz(fRaDec));
 
@@ -684,5 +676,5 @@
                 // calculate were we should be
                 //
-                sla.Set(t);
+                sla.SetMjd(t);
                 sollaz = CorrectTarget(ist, sla.CalcZdAz(fRaDec));
 
@@ -695,5 +687,4 @@
 void MCosy::GuiThread(MTGui *t)
 {
-    MGSkyPosition *disp = fWin->GetSkyDisplay();
     while (!t->HasStopFlag())
     {
@@ -707,5 +698,6 @@
 
         ZdAz ist = GetSePos()*(360.0/16384.0); // [se]
-        disp->DrawPosition(ist);
+        fWin->Update(ist, fAccuracy);
+
     }
     cout << "Not running anymore." << endl;
@@ -714,5 +706,5 @@
 int MCosy::StopWaitingForSDO() const
 {
-    return Break() || HasError(); //fMac1->HasError() || fMac2->HasError();
+    return Break() || HasError();
 }
 
@@ -773,4 +765,14 @@
 {
     cout << "MCosy::TerminateApp()" << endl;
+/*
+    Int_t rc;
+    TGMessageBox msg(this, gClient->GetRoot(),
+                     "Information",
+                     "Cosy is shutting down the system - this may take wa while!",
+                     kMBIconExclamation,
+                     kMBOK, //kMBClose
+                     &rc, 0);
+*/
+
     gApplication->Terminate(0);
 }
Index: trunk/MagicSoft/Cosy/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/MCosy.h	(revision 911)
+++ trunk/MagicSoft/Cosy/MCosy.h	(revision 912)
@@ -74,4 +74,5 @@
     RaDec fRaDec;     // Position to track
     int   fTracking;  // Flag for present tracking action
+    ZdAz  fAccuracy;  // Actual accuracy of Tracking
 
     ZdAz GetRePos();
Index: trunk/MagicSoft/Cosy/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/Makefile	(revision 911)
+++ trunk/MagicSoft/Cosy/Makefile	(revision 912)
@@ -38,8 +38,8 @@
 #
 SUBDIRS = \
+        gui         \
         candrv      \
+	devdrv      \
         catalog     \
-	devdrv      \
-        gui         \
         videodev    \
 	base        \
Index: trunk/MagicSoft/Cosy/Starguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/Starguider.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/Starguider.cc	(revision 912)
@@ -336,5 +336,5 @@
 
             Timer time(tm);
-            fSao.GetImg(img, cimg, time.GetMjd(), fRaDec);
+            fSao.GetImg(img, cimg, time.CalcMjd(), fRaDec);
             fImage->DrawColImg(img, cimg);
 
Index: trunk/MagicSoft/Cosy/base/timer.cc
===================================================================
--- trunk/MagicSoft/Cosy/base/timer.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/base/timer.cc	(revision 912)
@@ -45,5 +45,5 @@
 }
 
-void Timer::SetTimer(struct timeval *tv)
+void Timer::SetTimer(const struct timeval *tv)
 {
     SetTimer(tv->tv_sec, (double)tv->tv_usec/1000000.0);
@@ -75,15 +75,15 @@
 }
 
-double Timer::GetTime()
+double Timer::Now()
 {
     struct timeval tv;
     gettimeofday(&tv, NULL);
 
-    SetTimer(tv.tv_sec, (double)tv.tv_usec/1000000.0);
+    SetTimer(&tv);
 
     return fMs+fSecs;
 }
 
-double Timer::GetMjd()
+double Timer::CalcMjd()
 {
     int status;
Index: trunk/MagicSoft/Cosy/base/timer.h
===================================================================
--- trunk/MagicSoft/Cosy/base/timer.h	(revision 911)
+++ trunk/MagicSoft/Cosy/base/timer.h	(revision 912)
@@ -27,10 +27,10 @@
 
     void SetTimer(int tv_sec, double tv_usec);
-    void SetTimer(struct timeval *tv);
+    void SetTimer(const struct timeval *tv);
 
 
     int GetSecs() { return fSecs; }
-    double GetTime();
-    double GetMjd();
+    double Now();
+    double CalcMjd();
 
     int H() const { return fHor; }
Index: trunk/MagicSoft/Cosy/catalog/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Makefile	(revision 911)
+++ trunk/MagicSoft/Cosy/catalog/Makefile	(revision 912)
@@ -33,4 +33,6 @@
 SRCFILES = SaoFile.cc \
 	   Slalib.cc \
+	   SlaStars.cc \
+	   SlaPlanets.cc \
 	   StarCatalog.cc
 
Index: trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 912)
@@ -0,0 +1,73 @@
+#include "SlaPlanets.h"
+
+#include <iostream.h>
+
+#include "slalib.h"
+
+SlaPlanets::SlaPlanets() : Slalib(), fDt(slaDt(2000.0)/60./60./24.)
+{
+}
+
+SlaPlanets::~SlaPlanets()
+{
+}
+
+void SlaPlanets::SetMjd(const double mjd)
+{
+    Slalib::SetMjd(mjd);
+
+    //
+    // coordinates of earth: heliocentric, equatoril, J2000
+    //
+    double veb[3]; // barycentric velocity
+    double ceb[3]; // barycentric coordinates
+    double veh[3]; // heliocentric velocity
+
+    slaEvp(mjd + fDt, 2000.0, veb, ceb, veh, fEarth);
+}
+
+void SlaPlanets::UpdatePlanetPos(ePlanets_t planet)
+{
+    double cp[6] = { 0, 0, 0, 0, 0, 0 };
+
+    double coord[6];
+
+    switch (planet)
+    {
+    case kEMoon:
+        //
+        // -- approximate geocentric pos and vel --
+        //
+        slaDmoon(GetMjd() + fDt, coord);
+        break;
+
+    case kEMercury:
+    case kEVenus:
+    case kEMars:
+    case kEJupiter:
+    case kESaturn:
+    case kEUranus:
+    case kENeptune:
+    case kEPluto:
+        {
+            //
+            // coordinates of planet: heliocentric, equatoril, J2000
+            //
+
+            int rc;
+            slaPlanet(GetMjd(), planet, cp, &rc);
+
+            if (rc)
+                return;
+        }
+        // !! Fall through!
+
+    case kESun:
+        coord[0] = cp[0] - fEarth[0];
+        coord[1] = cp[1] - fEarth[1];
+        coord[2] = cp[2] - fEarth[2];
+        break;
+    }
+
+    fZdAz[planet] = XYZ2ZdAz(coord);
+}
Index: trunk/MagicSoft/Cosy/catalog/SlaPlanets.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaPlanets.h	(revision 912)
+++ trunk/MagicSoft/Cosy/catalog/SlaPlanets.h	(revision 912)
@@ -0,0 +1,48 @@
+#ifndef SLAPLANETS_H
+#define SLAPLANETS_H
+
+#ifndef SLALIB_H
+#include "Slalib.h"
+#endif
+
+typedef enum
+{
+    kESun      = 0,
+    kEMercury  = 1,
+    kEVenus    = 2,
+    kEMoon     = 3, // earth moon barycentre
+    kEMars     = 4,
+    kEJupiter  = 5,
+    kESaturn   = 6,
+    kEUranus   = 7,
+    kENeptune  = 8,
+    kEPluto    = 9
+} ePlanets_t;
+
+class SlaPlanets : public Slalib
+{
+private:
+    const double fDt;
+
+    ZdAz fZdAz[10];    // [rad]
+
+    double fEarth[3];  // heliocentric coordinates
+
+    ZdAz   GetMoonPos() const;
+
+public:
+    SlaPlanets();
+    virtual ~SlaPlanets();
+
+    //    const AltAz GetAltAz() const { return fAltAz*360/D2PI; }
+    //    const ZdAz  GetZdAz()  const { return ZdAz(DPI/2-fAltAz.Alt(), fAltAz.Az())*360/D2PI; }
+    //    const RaDec GetRaDec() const { return fRaDec*360/D2PI; }
+
+    void SetMjd(const double mjd);
+
+    void UpdatePlanetPos(ePlanets_t planet);
+    ZdAz GetPlanetPos(ePlanets_t planet) const { return fZdAz[planet]; }
+
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/catalog/SlaStars.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 912)
@@ -0,0 +1,108 @@
+#include "SlaStars.h"
+
+#include "slalib.h"
+
+SlaStars::SlaStars() : Slalib()
+{
+}
+
+SlaStars::~SlaStars()
+{
+}
+
+void SlaStars::Set(const AltAz &altaz)
+{
+    fAltAz = altaz * D2PI/360.0;
+    fRaDec = CalcRaDec(fAltAz);
+}
+
+void SlaStars::Set(const ZdAz &zdaz)
+{
+    fAltAz = AltAz(DPI/2-zdaz.Zd(), zdaz.Az()) * D2PI/360.0;
+    fRaDec = CalcRaDec(fAltAz);
+}
+
+void SlaStars::Set(const RaDec &radec)
+{
+    fRaDec = radec * D2PI/360.0;
+    fAltAz = CalcAltAz(fRaDec);
+}
+
+void SlaStars::SetMjd(const double mjd)
+{
+    Slalib::SetMjd(mjd);
+
+    //
+    // ----- calculate star independent parameters ----------
+    //
+    slaMappa(2000.0, mjd, fAmprms);
+    slaAoppa(mjd, 0,                    // mjd, UT1-UTC
+             GetElong(), GetPhi(), 148, // gttingen long, lat, height
+             0, 0,                      // polar motion x, y-coordinate (radians)
+             273.155, 1013.25, 0.5,     // temp, pressure, humidity
+             0.2, 0.0065,               // wavelength, tropo lapse rate
+             fAoprms);
+}
+
+RaDec SlaStars::CalcRaDec(const AltAz &altaz) const
+{
+    return CalcRaDec(ZdAz(DPI/2-altaz.Alt(), altaz.Az()));
+}
+
+RaDec SlaStars::CalcRaDec(const ZdAz &zdaz) const
+{
+    //
+    // -- observed to apparent --
+    //  Workaraound for slalib: discard const
+    //
+    double r=0, d=0;
+    slaOapqk((char*)"A", zdaz.Az(), zdaz.Zd(), (double*)fAoprms, &r, &d);
+
+    //
+    // -- apparent to mean --
+    //  Workaraound for slalib: discard const
+    //
+    double ra, dec;
+    slaAmpqk(r, d, (double*)fAmprms, &ra, &dec);
+
+    return RaDec(ra, dec);
+}
+
+ZdAz SlaStars::CalcZdAz(const RaDec &radec) const
+{
+    //
+    // ---- Mean to apparent ----
+    //
+
+    double r=0, d=0;
+    slaMapqkz(radec.Ra(), radec.Dec(), (double*)fAmprms, &r, &d);
+    //
+    // Doesn't work - don't know why
+    //
+    //    slaMapqk (radec.Ra(), radec.Dec(), rdpm.Ra(), rdpm.Dec(),
+    //              0, 0, (double*)fAmprms, &r, &d);
+    //
+
+    //
+    // -- apparent to observed --
+    //
+    double r1=0;  // ra
+    double d1=0;  // dec
+    double h0=0;  // ha
+
+    double zd;
+    double az;
+    slaAopqk (r, d, (double*)fAoprms,
+              &az,    // observed azimuth (radians: N=0,E=90)
+              &zd,    // observed zenith distance (radians) [-pi/2, pi/2]
+              &h0,    // observed hour angle (radians)
+              &d1,    // observed declination (radians)
+              &r1);   // observed right ascension (radians)
+
+    return ZdAz(zd, az);
+}
+AltAz SlaStars::CalcAltAz(const RaDec &radec) const
+{
+    ZdAz zdaz = CalcZdAz(radec);
+    return AltAz(DPI/2-zdaz.Zd(), zdaz.Az());
+}
Index: trunk/MagicSoft/Cosy/catalog/SlaStars.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaStars.h	(revision 912)
+++ trunk/MagicSoft/Cosy/catalog/SlaStars.h	(revision 912)
@@ -0,0 +1,36 @@
+#ifndef SLASTARS_H
+#define SLASTARS_H
+
+#include "Slalib.h"
+
+class SlaStars : public Slalib
+{
+private:
+    AltAz    fAltAz;    // [rad]
+    RaDec    fRaDec;    // [rad]
+
+    double   fAmprms[21];
+    double   fAoprms[14];
+
+public:
+    SlaStars();
+    virtual ~SlaStars();
+
+    //    const AltAz GetAltAz() const { return fAltAz*360/D2PI; }
+    //    const ZdAz  GetZdAz()  const { return ZdAz(DPI/2-fAltAz.Alt(), fAltAz.Az())*360/D2PI; }
+    //    const RaDec GetRaDec() const { return fRaDec*360/D2PI; }
+
+    virtual void SetMjd(const double mjd);
+
+    void   Set(const AltAz &altaz);
+    void   Set(const ZdAz  &zdaz);
+    void   Set(const RaDec &radec);
+
+    RaDec  CalcRaDec(const AltAz &altaz) const;
+    RaDec  CalcRaDec(const ZdAz  &altaz) const;
+
+    AltAz  CalcAltAz(const RaDec &radec) const;
+    ZdAz   CalcZdAz (const RaDec &radec) const;
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/catalog/Slalib.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 912)
@@ -6,5 +6,5 @@
 #include "slalib.h"
 
-Slalib::Slalib()
+Slalib::Slalib() : Timer()
 {
     // p = pointer to MainFrame (not owner)
@@ -25,100 +25,43 @@
 }
 
-void Slalib::Set(const AltAz &altaz)
-{
-    fAltAz = altaz * D2PI/360.0;
-    fRaDec = CalcRaDec(fAltAz);
-}
-
-void Slalib::Set(const ZdAz &zdaz)
-{
-    fAltAz = AltAz(DPI/2-zdaz.Zd(), zdaz.Az()) * D2PI/360.0;
-    fRaDec = CalcRaDec(fAltAz);
-}
-
-void Slalib::Set(const RaDec &radec)
-{
-    fRaDec = radec * D2PI/360.0;
-    fAltAz = CalcAltAz(fRaDec);
-}
-
-void Slalib::Set(const double mjd)
+void Slalib::SetMjd(const double mjd)
 {
     fMjd   = mjd;
     fAlpha = slaGmst(fMjd) + fElong;
+}
+
+void Slalib::SetMjd2Now()
+{
+    Now();
+    SetMjd(CalcMjd());
+//    cout << "GetMjd: "<< (*this)() << " " << GetMjd() << endl;
+}
+
+void Slalib::SetMjd(const struct timeval *tm)
+{
+    SetTimer(tm);
+    SetMjd(CalcMjd());
+}
+
+
+ZdAz Slalib::XYZ2ZdAz(double coord[3]) const
+{
+    //
+    // -- xyz to spherical coordinates --
+    //
+    double ra, dec;
+    slaDcc2s(coord, &ra, &dec);
 
     //
-    // ----- calculate star independent parameters ----------
+    // radec[rad] -> hadec[rad]
     //
-    slaMappa(2000.0, fMjd, fAmprms);
-    slaAoppa(fMjd, 0,                // mjd, UT1-UTC
-             fElong, fPhi, 148,      // gttingen long, lat, height
-             0, 0,                   // polar motion x, y-coordinate (radians)
-             273.155, 1013.25, 0.5,  // temp, pressure, humidity
-             0.2, 0.0065,            // wavelength, tropo lapse rate
-             fAoprms);
-}
-
-RaDec Slalib::CalcRaDec(const AltAz &altaz) const
-{
-    return CalcRaDec(ZdAz(DPI/2-altaz.Alt(), altaz.Az()));
-}
-
-RaDec Slalib::CalcRaDec(const ZdAz &zdaz) const
-{
-    //
-    // -- observed to apparent --
-    //  Workaraound for slalib: discard const
-    //
-    double r=0, d=0;
-    slaOapqk ("A", zdaz.Az(), zdaz.Zd(), (double*)fAoprms, &r, &d);
+    const double ha = fAlpha-ra;
 
     //
-    // -- apparent to mean --
-    //  Workaraound for slalib: discard const
+    // hadec[rad] -> altaz[rad]
     //
-    double ra, dec;
-    slaAmpqk(r, d, (double*)fAmprms, &ra, &dec);
+    double alt, az;
+    slaDe2h(ha, dec, fPhi, &az, &alt);
 
-    return RaDec(ra, dec);
+    return ZdAz(DPI/2-alt, az);
 }
-
-ZdAz Slalib::CalcZdAz(const RaDec &radec) const
-{
-    //
-    // ---- Mean to apparent ----
-    //
-
-    double r=0, d=0;
-    slaMapqkz(radec.Ra(), radec.Dec(), (double*)fAmprms, &r, &d);
-    //
-    // Doesn't work - don't know why
-    //
-    //    slaMapqk (radec.Ra(), radec.Dec(), rdpm.Ra(), rdpm.Dec(),
-    //              0, 0, (double*)fAmprms, &r, &d);
-    //
-
-    //
-    // -- apparent to observed --
-    //
-    double r1=0;  // ra
-    double d1=0;  // dec
-    double h0=0;  // ha
-
-    double zd;
-    double az;
-    slaAopqk (r, d, (double*)fAoprms,
-              &az,    // observed azimuth (radians: N=0,E=90)
-              &zd,    // observed zenith distance (radians) [-pi/2, pi/2]
-              &h0,    // observed hour angle (radians)
-              &d1,    // observed declination (radians)
-              &r1);   // observed right ascension (radians)
-
-    return ZdAz(zd, az);
-}
-AltAz Slalib::CalcAltAz(const RaDec &radec) const
-{
-    ZdAz zdaz = CalcZdAz(radec);
-    return AltAz(DPI/2-zdaz.Zd(), zdaz.Az());
-}
-
Index: trunk/MagicSoft/Cosy/catalog/Slalib.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 911)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 912)
@@ -3,19 +3,14 @@
 
 #include "coord.h"
+#include "base/timer.h"
 
-class Slalib
+class Slalib : public Timer
 {
 private:
-    double   fPhi;      // location of observatory
-    double   fElong;
-
-    AltAz    fAltAz;    // [rad]
-    RaDec    fRaDec;    // [rad]
-
     double   fAlpha;
     double   fMjd;
 
-    double   fAmprms[21];
-    double   fAoprms[14];
+    double   fPhi;      // location of observatory
+    double   fElong;
 
 public:
@@ -27,21 +22,16 @@
     //    const RaDec GetRaDec() const { return fRaDec*360/D2PI; }
 
-    void   Set(const double mjd);
+    void SetMjd2Now();
+    void SetMjd(const struct timeval *tm);
 
-    void   Set(const AltAz &altaz);
-    void   Set(const ZdAz  &zdaz);
-    void   Set(const RaDec &radec);
+    virtual void SetMjd(const double mjd);
 
     double GetAlpha() const { return fAlpha; }
+    double GetMjd() const   { return fMjd; }
 
     double GetPhi() const   { return fPhi; }
     double GetElong() const { return fElong; }
 
-    RaDec  CalcRaDec(const AltAz &altaz) const;
-    RaDec  CalcRaDec(const ZdAz  &altaz) const;
-
-    AltAz  CalcAltAz(const RaDec &radec) const;
-    ZdAz   CalcZdAz (const RaDec &radec) const;
-
+    ZdAz   XYZ2ZdAz(double coord[3]) const;
 };
 
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 912)
@@ -9,7 +9,6 @@
 #include "slamac.h"
 #include "File.h"
-#include "timer.h"
-
-StarCatalog::StarCatalog() : fEntries(0)
+
+StarCatalog::StarCatalog() : SlaStars(), fEntries(0)
 {
     // p = pointer to MainFrame (not owner)
@@ -68,5 +67,5 @@
     cout << "  Az: " << fAltAz.Az() << endl;
 
-    fRaDec = sla.CalcRaDec(fAltAz);
+    fRaDec = CalcRaDec(fAltAz);
 
     cout << "Ra: " << 360.0/D2PI*fRaDec.Ra();
@@ -82,5 +81,5 @@
     fRaDec *= D2PI/360.0;
 
-    fAltAz = sla.CalcAltAz(fRaDec);
+    fAltAz = CalcAltAz(fRaDec);
 
     cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << "  ";
@@ -215,6 +214,6 @@
     double de0, de1;
 
-    const double phi   = sla.GetPhi();
-    const double alpha = sla.GetAlpha();
+    const double phi   = GetPhi();
+    const double alpha = GetAlpha();
     //
     // scan horizontal border
@@ -401,5 +400,5 @@
     memset(cimg, 0, 768*576);
 
-    sla.Set(utc);
+    SetMjd(utc);
     //fAlpha = sla.GetAlpha();
     SetRaDec(radec);
@@ -419,5 +418,5 @@
     memset(cimg, 0, 768*576);
 
-    sla.Set(utc);
+    SetMjd(utc);
     //fAlpha = sla.GetAlpha();
     SetAltAz(altaz);
@@ -496,5 +495,5 @@
     // ---- mean to observed ---
     //
-    AltAz altaz=sla.CalcAltAz(sao->GetRaDec()) * 360.0/D2PI;
+    AltAz altaz=CalcAltAz(sao->GetRaDec()) * 360.0/D2PI;
 
     if (sao->MagV() > fLimitMag)
@@ -520,5 +519,5 @@
     // radec[rad] -> hadec[rad]
     //
-    const double ha = sla.GetAlpha()-ra;
+    const double ha = GetAlpha()-ra;
 
     //
@@ -526,5 +525,5 @@
     //
     double alt, az;
-    slaDe2h(ha, dec, sla.GetPhi(), &az, &alt);
+    slaDe2h(ha, dec, GetPhi(), &az, &alt);
 
     //
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 911)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 912)
@@ -8,6 +8,6 @@
 #include "SaoFile.h"
 #endif
-#ifndef SLALIB_H
-#include "Slalib.h"
+#ifndef SLASTARS_H
+#include "SlaStars.h"
 #endif
 
@@ -16,5 +16,5 @@
 typedef unsigned char byte;
 
-class StarCatalog
+class StarCatalog : public SlaStars
 {
 private:
@@ -22,9 +22,4 @@
     sort_t  *fSrt;
     int      fEntries;
-
-    Slalib   sla;
-
-//    double   fPhi;      // location of observatory
-//    double   fElong;
 
     double   fPixSize;  // [rad/pix] size of one pixel
@@ -46,9 +41,4 @@
     int      fDecMax;
 
-//    double   fAlpha;
-//    double   fMjd;
-//    double   fAmprms[21];
-//    double   fAoprms[14];
-
     void DrawCross(byte *img, const int x, const int y);
     void DrawCircle(int color, byte *img, int xx, int yy, int size);
@@ -65,5 +55,4 @@
     void   SetRaDec(const RaDec &radec);
     void   SetAltAz(const AltAz &altaz);
-//    void   SetMjd(const double mjd);
     void   DrawSCAltAz(byte *img, const int color);
     void   DrawSCRaDec(byte *img, const int color);
Index: trunk/MagicSoft/Cosy/cosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/cosy.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/cosy.cc	(revision 912)
@@ -11,4 +11,8 @@
 int main(int argc, char **argv)
 {
+    cout << endl;
+    cout << "Starting..." << endl;
+    cout << endl;
+
     //
     // this must move to MGCosy !!!! (or MApplication)
Index: trunk/MagicSoft/Cosy/devdrv/macs.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/devdrv/macs.cc	(revision 912)
@@ -419,20 +419,20 @@
 double Macs::GetTime()
 {
-    return fPosTime.GetTime();
+    return fPosTime.Now();
 }
 
 double Macs::GetMjd()
 {
-    return fPosTime.GetMjd();
+    return fPosTime.CalcMjd();
 }
 
 double Macs::GetPdoTime()
 {
-    return fPdoTime.GetTime();
+    return fPdoTime.Now();
 }
 
 double Macs::GetPdoMjd()
 {
-    return fPdoTime.GetMjd();
+    return fPdoTime.CalcMjd();
 }
 
Index: trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/devdrv/shaftencoder.cc	(revision 912)
@@ -32,42 +32,42 @@
     {
     case 0x1000:
-        cout << "Model: ";
+        lout << "- Model: ";
         switch (val&0xffff)
         {
         case 0x0196:
-            cout << "Shaft Encoder  Type: ";
+            lout << "Shaft Encoder  Type: ";
             switch ((val>>16)&0xff)
             {
             case 0x01:
-                cout << "Singleturn" << endl;
+                lout << "Singleturn" << endl;
                 return;
             case 0x02:
-                cout << "Multiturn" << endl;
+                lout << "Multiturn" << endl;
                 return;
             default:
-                cout << "?" << endl;
+                lout << "?" << endl;
                 return;
             }
         default:
-            cout << "???" << endl;
+            lout << "???" << endl;
             return;
         }
     case 0x100b:
-        cout << "Node ID: " << dec << val << endl;
+        lout << "Node ID: " << dec << val << endl;
         return;
 
     case 0x6000:
     case 0x6500:
-        cout << "Counting: " << (val&1   ?"anti-clockwise":"clockwise") << "  ";
-        cout << "HwTest: " <<   (val&2   ?"on":"off") << "  ";
-        cout << "Scaling: " <<  (val&4   ?"on":"off") << "  ";
-        cout << "Modulo: " <<   (val&4096?"on":"off") << endl;
+        lout << "- Counting: " << (val&1   ?"anti-clockwise":"clockwise") << "  ";
+        lout << "HwTest: " <<   (val&2   ?"on":"off") << "  ";
+        lout << "Scaling: " <<  (val&4   ?"on":"off") << "  ";
+        lout << "Modulo: " <<   (val&4096?"on":"off") << endl;
 
     case 0x6001:
-        cout << "Logical Ticks/Turn: " << dec << val << endl;
+        lout << "- Logical Ticks/Revolution: " << dec << val << endl;
         return;
 
     case 0x6004:
-        cout << "Position: " << dec << val << endl;
+        lout << "- Position: " << dec << val << endl;
         fPos  = val;
         fTurn = 0;
@@ -76,10 +76,10 @@
 
     case 0x6501:
-        cout << "Phys. Ticks/Turn: " << dec << val << endl;
+        lout << "- Phys. Ticks/Revolution: " << dec << val << endl;
         fTicks = val;
         return;
 
     case 0x6502:
-        cout << "Possible Turns: " << dec << val << endl;
+        lout << "- Possible Turns: " << dec << val << endl;
         fTurns = val ? val : 1; // Single Turn = Multiturn with one turn
         return;
@@ -209,10 +209,10 @@
 double ShaftEncoder::GetTime()
 {
-    return fTime.GetTime();
+    return fTime.Now();
 }
 
 double ShaftEncoder::GetMjd()
 {
-    return fTime.GetMjd();
+    return fTime.CalcMjd();
 }
 
@@ -228,24 +228,24 @@
     // Requesting and checking (FIXME) type of encoder
     //
-    lout << "- Requesting SDO 0x1000 of " << (int)GetId() << endl;
+    lout << "- Requesting Hardware Type (SDO 0x1000) of " << (int)GetId() << endl;
     RequestSDO(0x1000);
     WaitForSdo(0x1000);
 
     //
-    // Read physical ticks per turn
-    //
-    lout << "- Requesting SDO 0x6501 of " << (int)GetId() << endl;
+    // Read physical ticks per revolution
+    //
+    lout << "- Requesting physical ticks/revolution (SDO 0x6501) of " << (int)GetId() << endl;
     RequestSDO(0x6501);
     WaitForSdo(0x6501);
 
     //
-    // Read number of possible ticks per turn
-    //
-    lout << "- Requesting SDO 0x6502 of " << (int)GetId() << endl;
+    // Read number of possible ticks per revolution
+    //
+    lout << "- Requesting possible ticks/revolution (SDO 0x6502) of " << (int)GetId() << endl;
     RequestSDO(0x6502);
     WaitForSdo(0x6502);
 
     //
-    // Set logic ticks per turn = physical ticks per turn => scale factor = 1
+    // Set logic ticks/revolution = physical ticks/revolution => scale factor = 1
     //
     lout << "- Configuring SDO 0x6001 of " << (int)GetId() << endl;
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 912)
@@ -0,0 +1,141 @@
+//
+// This File contains the definition of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+#include "MGAccuracy.h"
+
+#include <iostream.h>  // cout
+
+#include <TArc.h>
+#include <TLine.h>
+#include <TList.h>
+#include <TCanvas.h>
+
+#include "coord.h"
+
+void MGAccuracy::DrawCoordinateSystem()
+{
+    TLine line;
+
+    line.SetLineColor(13);
+    line.SetLineStyle(3);  // dotted  (s. TAttLine)
+    line.DrawLine(-.5,  -1.05, -.5,   1.05);
+    line.DrawLine( -1.05, -.5,   1.05, -.5);
+    line.DrawLine( .5,  -1.05,  .5,   1.05);
+    line.DrawLine( -1.05,  .5,   1.05,  .5);
+
+    line.DrawLine(-.25,  -1.05, -.25,   1.05);
+    line.DrawLine( -1.05, -.25,   1.05, -.25);
+    line.DrawLine( .25,  -1.05,  .25,   1.05);
+    line.DrawLine( -1.05,  .25,   1.05,  .25);
+
+    line.DrawLine(-.75,  -1.05, -.75,   1.05);
+    line.DrawLine( -1.05, -.75,   1.05, -.75);
+    line.DrawLine( .75,  -1.05,  .75,   1.05);
+    line.DrawLine( -1.05,  .75,   1.05,  .75);
+
+    line.SetLineColor(12);
+    line.SetLineStyle(2);  // dashed  (s. TAttLine)
+    line.DrawLine(-1, -1.05, -1,  1.05);
+    line.DrawLine(-1.05, -1,  1.05, -1);
+    line.DrawLine( 1, -1.05,  1,  1.05);
+    line.DrawLine(-1.05,  1,  1.05,  1);
+
+    line.SetLineColor(1);  // black
+    line.SetLineStyle(1);  // solid  (s. TAttLine)
+    line.DrawLine(-1.05,     0, 1.05,    0);
+    line.DrawLine(    0, -1.05,    0, 1.05);
+
+    TArc arc;
+    arc.SetFillStyle(4000);  // transparent
+    arc.SetFillColor(39);
+    arc.SetLineColor(3);     // green
+    arc.SetLineStyle(2);     // dashed  (s. TAttLine)
+    arc.DrawArc(0, 0, 20./60);
+
+    arc.SetLineColor(5);     // yellow
+    arc.DrawArc(0, 0, 40./60);
+
+    arc.SetLineColor(2);     // red
+    arc.DrawArc(0, 0, 1);
+}
+
+void MGAccuracy::InitPosition()
+{
+    fLin1 = new TLine(0, 0, 0, 0);
+    fLin2 = new TLine(0, 0, 0, 0);
+
+    fLin1->SetLineColor(10); // white (s. TAttFill)
+    fLin2->SetLineColor(10); // white
+    fLin1->SetLineStyle(1);  // solid (s. TAttLine)
+    fLin2->SetLineStyle(1); 
+
+    fLin1->Draw();
+    fLin2->Draw();
+
+    fList->Add(fLin1);
+    fList->Add(fLin2);
+}
+
+MGAccuracy::MGAccuracy(const TGWindow* p, const Int_t w, const Int_t h)
+    : TRootEmbeddedCanvas("Accuracy", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
+    fModified(kFALSE)
+{
+    fCanvas = GetCanvas();
+
+    fCanvas->SetFillColor(39); // s. TAttFill
+    fCanvas->Range(-1.1, -1.1, 1.1, 1.1);
+
+    fList = new TList;
+    fList->SetOwner();
+
+    DrawCoordinateSystem();
+    InitPosition();
+
+    Resize(w, h); //GetDefaultSize()); // ???
+
+    MapSubwindows();
+}
+
+MGAccuracy::~MGAccuracy()
+{
+    delete fList;
+
+    cout << "MGAccuracy destroyed." << endl;
+}
+
+void MGAccuracy::Update(ZdAz &zdaz)
+{
+    //
+    // calculate actual time for planet positions
+    //
+
+    fLin1->SetX1(zdaz.Zd()*60.-0.02);
+    fLin1->SetX2(zdaz.Zd()*60.+0.02);
+
+    fLin2->SetX1(zdaz.Zd()*60.-0.02);
+    fLin2->SetX2(zdaz.Zd()*60.+0.02);
+
+    fLin1->SetY1(zdaz.Az()*60.-0.02);
+    fLin1->SetY2(zdaz.Az()*60.+0.02);
+
+    fLin2->SetY1(zdaz.Az()*60.+0.02);
+    fLin2->SetY2(zdaz.Az()*60.-0.02);
+
+    fCanvas->Modified();
+    fCanvas->Update();
+
+    /*
+    DrawPosition(pos.Zd(), pos.Az());
+
+    if (!fModified)
+        return;
+
+    // FIXME: Sometimes (if the canvas couldn't be created correctly:
+    // X11 Pixmap error) Update hangs the Gui system.
+
+    fModified = kFALSE;
+    */
+}
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 912)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 912)
@@ -0,0 +1,49 @@
+#ifndef MGACCURACY_H
+#define MGACCURACY_H
+
+//
+// This File contains the declaration of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+
+#ifndef ROOT_TRootEmbeddedCanvas
+#include <TRootEmbeddedCanvas.h>
+#endif
+
+class TList;
+class TLine;
+class TCanvas;
+
+class ZdAz;
+class SlaPlanets;
+
+class MGAccuracy : public TRootEmbeddedCanvas
+{
+    TCanvas    *fCanvas;
+
+    TLine      *fLin1;
+    TLine      *fLin2;
+/*
+    TLine      *fLin2;
+*/
+    TList      *fList;
+
+    Bool_t fModified;
+
+    void InitPosition();
+
+    //    void SetLin1(int x, int y);
+    //    void SetLin2(int x1, int y1, int x2, int y2);
+
+    void DrawCoordinateSystem();
+
+public:
+    MGAccuracy(const TGWindow* p, const Int_t w, const Int_t h);
+    ~MGAccuracy();
+
+    void Update(ZdAz &pos);
+};
+
+#endif // MGSKYPOSITION_H
Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 912)
@@ -12,12 +12,13 @@
 #include <TApplication.h>  // gApplication
 
-#include "timer.h"         // Timer
+//#include "timer.h"         // Timer
 
 #include "MCosy.h"
 #include "MGList.h"
+#include "MGAccuracy.h"
 #include "MGCoordinates.h"
 #include "MGSkyPosition.h"
 
-#include "Slalib.h"
+#include "SlaStars.h"
 
 #define IDM_EXIT 1
@@ -155,7 +156,10 @@
     fList->Add(fCoord);
 
-    fSkyPosition = new MGSkyPosition(this);
+    fAccuracy = new MGAccuracy(this, 200, 200);
+    fAccuracy->Move(320, 260);
+    fList->Add(fAccuracy);
+
+    fSkyPosition = new MGSkyPosition(this, 200, 200);
     fSkyPosition->Move(320, 40);
-    fSkyPosition->Resize(200, 200);
     fList->Add(fSkyPosition);
 
@@ -163,5 +167,5 @@
     //   Map the window, set up the layout, etc.
     //
-    SetWMSizeHints(550, 250, 550, 250, 10, 10);  // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(550, 500, 550, 500, 10, 10);  // set the smallest and biggest size of the Main frame
 
     MapSubwindows();
@@ -190,4 +194,10 @@
 
     cout << "MGCosy deleted." << endl;
+}
+// ======================================================================
+void MGCosy::Update(ZdAz pos, ZdAz acc)
+{
+    fSkyPosition->Update(pos);
+    fAccuracy->Update(acc);
 }
 // ======================================================================
@@ -253,9 +263,6 @@
             case kPB_CALCALTAZ:
                 {
-                    Timer t;
-                    t.GetTime();
-
-                    Slalib sla;
-                    sla.Set(t.GetMjd());
+                    SlaStars sla;
+                    sla.SetMjd2Now();
 
                     XY xy = fCoord->GetCoordinates();
Index: trunk/MagicSoft/Cosy/gui/MGCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 911)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 912)
@@ -16,4 +16,6 @@
 #include <iostream.h>
 
+#include "coord.h"
+
 class TGLabel;
 class TGPopupMenu;
@@ -27,4 +29,5 @@
 class MGCoordinates;
 class MGSkyPosition;
+class MGAccuracy;
 
 class MGCosy : public TGMainFrame
@@ -46,4 +49,5 @@
     MGCoordinates *fCoord;
     MGSkyPosition *fSkyPosition;
+    MGAccuracy    *fAccuracy;
 
     MsgQueue      *fQueue;
@@ -63,5 +67,5 @@
     TGLabel **GetLabel3() { return fLabel3; }
 
-    MGSkyPosition *GetSkyDisplay() { return fSkyPosition; }
+    void Update(ZdAz pos, ZdAz acc);
 
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 911)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 912)
@@ -8,49 +8,171 @@
 
 #include <iostream.h>  // cout
-#include <TRootEmbeddedCanvas.h>
-#include <TGWindow.h>
+
 #include <TArc.h>
+#include <TLine.h>
+#include <TList.h>
 #include <TCanvas.h>
-#include <TH1.h>
-#include <TLine.h>
 
 #include "coord.h"
-
-MGSkyPosition::MGSkyPosition(const TGWindow* p)
-: TRootEmbeddedCanvas("SkyPosition", p, 50, 50, kSunkenFrame)//, 0) //234, 76, kFixedSize)
+#include "SlaPlanets.h"
+
+void MGSkyPosition::InitPlanets()
+{
+    //
+    // Magnitudes:
+    // -----------
+    //   Moon     -12.8
+    //   Jupiter   -4.6
+    //   Venus     -4.0
+    //   Mars      -2.0
+    //   Merkur     0.0
+    //   Saturn     0.7
+    //   Uranus     5.5
+    //   Neptun     7.8
+    //
+    fSlalib = new SlaPlanets;
+
+    //
+    // Colors: black .. white:
+    //
+    //   1, 12, 13, 14, 15, 16, 17, 18, 19, 10
+    //
+    fMars = new TArc(0, 0, 1);
+    fMars->SetFillStyle(1001);     // solid      (s. TAttFill)
+    fMars->SetFillColor(13);       // light grey (s. TAttFill)
+    fMars->SetLineColor(12);
+    fMars->Draw();
+
+    fVenus = new TArc(0, 0, 2);
+    fVenus->SetFillStyle(1001);    // solid      (s. TAttFill)
+    fVenus->SetFillColor(15);      // light grey (s. TAttFill)
+    fVenus->SetLineColor(14);
+    fVenus->Draw();
+
+    fJupiter = new TArc(0, 0, 2);
+    fJupiter->SetFillStyle(1001);  // solid      (s. TAttFill)
+    fJupiter->SetFillColor(17);    // light grey (s. TAttFill)
+    fJupiter->SetLineColor(16);
+    fJupiter->Draw();
+
+    fMoon = new TArc(0, 0, 3, 290, 70);
+    fMoon->SetFillStyle(1001);     // solid      (s. TAttFill)
+    fMoon->SetFillColor(19);       // light grey (s. TAttFill)
+    fMoon->SetLineColor(15);
+    fMoon->Draw();
+
+    for (int i=0; i<4; i++)
+    {
+        fSunL[i] = new TLine(0,0,0,0);
+        fSunL[i]->SetLineColor(10);    // white gray
+        fSunL[i]->SetLineStyle(1);     // solid  (s. TAttLine)
+        fSunL[i]->Draw();
+
+        fList->Add(fSunL[i]);
+    }
+
+    fSun = new TArc(0, 0, 2);
+    fSun->SetFillStyle(1001);     // solid      (s. TAttFill)
+    fSun->SetFillColor(10);       // white      (s. TAttFill)
+    fSun->SetLineColor(19);
+    fSun->Draw();
+
+    fList->Add(fMars);
+    fList->Add(fVenus);
+    fList->Add(fJupiter);
+    fList->Add(fMoon);
+    fList->Add(fSun);
+
+    //
+    // Reset 'static' positions of planets
+    //
+    for (int i=0; i<9; i++)
+    {
+        fX[i] = ~0;
+        fY[i] = ~0;
+    }
+}
+
+void MGSkyPosition::DrawCoordinateSystem()
+{
+    TArc arc;
+    arc.SetFillStyle(4000);  // transparent
+    arc.SetLineColor(13);    // dark gray
+    arc.SetLineStyle(1);     // solid  (s. TAttLine)
+    arc.DrawArc(0, 0, 90);
+    arc.DrawArc(0, 0, 67.5);
+    arc.DrawArc(0, 0, 45);
+    arc.DrawArc(0, 0, 22.5);
+
+    TLine line;
+    line.SetLineColor(1);  // black
+    line.SetLineStyle(1);  // solid  (s. TAttLine)
+    line.DrawLine(-95,   0, 95,  0);
+    line.DrawLine(  0, -95,  0, 95);
+}
+
+void MGSkyPosition::InitPosition()
+{
+    fLin1a = new TLine(0, 0, 0, 0);
+    fLin1b = new TLine(0, 0, 0, 0);
+    fLin2  = new TLine(0, 0, 0, 0);
+
+    fLin1a->SetLineColor(5);  // yellow (s. TAttFill)
+    fLin1b->SetLineColor(5);  // yellow
+    fLin2 ->SetLineColor(10); // white
+    fLin1a->SetLineStyle(1);  // solid  (s. TAttLine)
+    fLin1b->SetLineStyle(2);  // dashed
+
+    fLin1a->Draw();
+    fLin1b->Draw();
+    fLin2->Draw();
+
+    fList->Add(fLin1a);
+    fList->Add(fLin1b);
+    fList->Add(fLin2);
+}
+
+MGSkyPosition::MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h)
+    : TRootEmbeddedCanvas("SkyPosition", p, w-1, h-1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
+    fModified(kFALSE)
 {
     fCanvas = GetCanvas();
 
+    fCanvas->SetFillColor(39); // s. TAttFill
     fCanvas->Range(-100, -100, 100, 100);
 
-    fArc = new TArc;
-    fArc->SetLineColor(15);
-    fArc->DrawArc(0, 0, 90);
-    fArc->DrawArc(0, 0, 67.5);
-    fArc->DrawArc(0, 0, 45);
-    fArc->DrawArc(0, 0, 22.5);
-
-    fLin1 = new TLine;
-    fLin1->DrawLine(-95,   0, 95,  0);
-    fLin1->DrawLine(  0, -95,  0, 95);
-    fLin2 = new TLine;
-
-    //    fCanvas->Modified();
-    //    fCanvas->Update();
-
+    fList = new TList;
+    fList->SetOwner();
+
+    DrawCoordinateSystem();
+    InitPosition();
+    InitPlanets();
+
+    Resize(w, h); //GetDefaultSize()); // ???
     MapSubwindows();
-    //    MapWindow();
-
-    //    DrawPosition(66, 25);
-    //    DrawPosition(22, 278);
 }
 
 MGSkyPosition::~MGSkyPosition()
 {
-    delete fLin1;
-    delete fLin2;
-    delete fArc;
+    delete fList;
+    delete fSlalib;
 
     cout << "MGSkyPosition destroyed." << endl;
+}
+
+void MGSkyPosition::SetLin1(int x, int y)
+{
+    fLin1a->SetX2(x);
+    fLin1a->SetY2(y);
+    fLin1b->SetX2(-x);
+    fLin1b->SetY2(-y);
+}
+
+void MGSkyPosition::SetLin2(int x1, int y1, int x2, int y2)
+{
+    fLin2->SetX1(x1);
+    fLin2->SetX2(x2);
+    fLin2->SetY1(y1);
+    fLin2->SetY2(y2);
 }
 
@@ -71,26 +193,91 @@
         return;
 
-    const int dx = (int)(s*6);
-    const int dy = (int)(c*6);
-
-    delete fArc;
-    fArc = new TArc(x, y, 2);
-    fArc->SetFillStyle(1001);
-    fArc->SetFillColor(43);
-    fArc->Draw();
-
-    delete fLin1;
-    delete fLin2;
-    //fLin1 = new TLine(x-dx, y-dy, x+dx, y+dy);
-    fLin1 = new TLine(0, 0, s*95, c*95);
-    fLin2 = new TLine(x+dy, y-dx, x-dy, y+dx);
-    fLin1->Draw();
-    fLin2->Draw();
-
+    X = x;
+    Y = y;
+
+    const int dx = (int)(s*4);
+    const int dy = (int)(c*4);
+
+    SetLin1(s*95, c*95);
+    SetLin2(x+dy, y-dx, x-dy, y+dx);
+
+    fModified = kTRUE;
+}
+
+void MGSkyPosition::Update(ZdAz &pos)
+{
+    //
+    // calculate actual time for planet positions
+    //
+    fSlalib->SetMjd2Now();
+
+    DrawPlanet(kESun,     fSun);
+    DrawPlanet(kEMoon,    fMoon);
+    DrawPlanet(kEJupiter, fJupiter);
+    DrawPlanet(kEVenus,   fVenus);
+    DrawPlanet(kEMars,    fMars);
+
+    DrawPosition(pos.Zd(), pos.Az());
+
+    if (!fModified)
+        return;
+
+    // FIXME: Sometimes (if the canvas couldn't be created correctly:
+    // X11 Pixmap error) Update hangs the Gui system.
+
+    fCanvas->Modified();
     fCanvas->Update();
-}
-
-void MGSkyPosition::DrawPosition(ZdAz &pos)
-{
-    DrawPosition(pos.Zd(), pos.Az());
-}
+
+    fModified = kFALSE;
+}
+
+void MGSkyPosition::DrawPlanet(Int_t planet, TArc *arc)
+{
+    //
+    // calculate actual position of planet
+    //
+    fSlalib->UpdatePlanetPos((ePlanets_t)planet);
+
+    ZdAz zdaz = fSlalib->GetPlanetPos((ePlanets_t)planet);
+
+    //
+    // check whether we have to change the position where it is drawn
+    //
+    const float s = sin(zdaz.Az());
+    const float c = cos(zdaz.Az());
+
+    const float deg = 360.0/D2PI*zdaz.Zd();
+
+    const int x = (int)(s*deg);
+    const int y = (int)(c*deg);
+
+    if (fX[planet]==x && fY[planet]==y)
+        return;
+
+    fX[planet] = x;
+    fY[planet] = y;
+
+    //
+    // Set new position
+    //
+    arc->SetX1(x);
+    arc->SetY1(y);
+
+    fModified = kTRUE;
+
+    if (planet!=kESun)
+        return;
+
+    cout << "Sun: x=" << x << " y=" << y;
+    cout << "   Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
+
+    fSunL[0]->SetX1(x-4); fSunL[0]->SetX2(x+4);
+    fSunL[1]->SetX1(x-3); fSunL[1]->SetX2(x+3);
+    fSunL[2]->SetX1(x-3); fSunL[2]->SetX2(x+3);
+    fSunL[3]->SetX1(x  ); fSunL[3]->SetX2(x  );
+
+    fSunL[0]->SetY1(y  ); fSunL[0]->SetY2(y  );
+    fSunL[1]->SetY1(y-3); fSunL[1]->SetY2(y+3);
+    fSunL[2]->SetY1(y+3); fSunL[2]->SetY2(y-3);
+    fSunL[3]->SetY1(y-4); fSunL[3]->SetY2(y+4);
+}
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 911)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.h	(revision 912)
@@ -13,23 +13,57 @@
 #endif
 
+class TArc;
+class TList;
+class TLine;
 class TCanvas;
-class TArc;
-class TLine;
+
 class ZdAz;
+class SlaPlanets;
 
 class MGSkyPosition : public TRootEmbeddedCanvas
 {
-    TCanvas *fCanvas;
+    TCanvas    *fCanvas;
 
-    TArc    *fArc;
-    TLine   *fLin1;
-    TLine   *fLin2;
+    TArc       *fMoon;
+    TArc       *fJupiter;
+    TArc       *fVenus;
+    TArc       *fMars;
+    TArc       *fSun;
+
+    TLine      *fLin1a;
+    TLine      *fLin1b;
+    TLine      *fLin2;
+
+    TLine      *fSunL[4];
+
+    SlaPlanets *fSlalib;
+
+    TList      *fList;
+
+    Int_t fX[9];
+    Int_t fY[9];
+
+    Bool_t fModified;
+
+    void InitPlanets();
+    void InitPosition();
+
+    void SetLin1(int x, int y);
+    void SetLin2(int x1, int y1, int x2, int y2);
+
+    void DrawPlanet(Int_t planet, TArc *arc);
+    void DrawPosition(Float_t zd, Float_t az);
+    void DrawCoordinateSystem();
+
+    Bool_t CheckRange(Int_t x, Int_t y) const
+    {
+        return x>-95 && x<95 && y>-95 && y<95;
+    }
 
 public:
-    MGSkyPosition(const TGWindow* p);
+    MGSkyPosition(const TGWindow* p, const Int_t w, const Int_t h);
     ~MGSkyPosition();
 
-    void DrawPosition(Float_t zd, Float_t az);
-    void DrawPosition(ZdAz &pos);
+    void Update(ZdAz &pos);
 };
 
Index: trunk/MagicSoft/Cosy/gui/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/gui/Makefile	(revision 911)
+++ trunk/MagicSoft/Cosy/gui/Makefile	(revision 912)
@@ -35,4 +35,5 @@
 	   MGCosy.cc \
 	   MGImage.cc \
+	   MGAccuracy.cc \
 	   MGSkyPosition.cc
 
Index: trunk/MagicSoft/slalib/Makefile
===================================================================
--- trunk/MagicSoft/slalib/Makefile	(revision 911)
+++ trunk/MagicSoft/slalib/Makefile	(revision 912)
@@ -32,9 +32,10 @@
 
 SRCFILES = \
-	daf2r.c  gmst.c   mappa.c aoppa.c  oapqk.c ampqk.c mapqkz.c \
-	dr2af.c  dcs2c.c  dimxv.c dvdv.c   dvn.c   dcc2s.c dranrm.c \
-        geoc.c   refco.c  eqeqx.c aoppat.c dd2tf.c epj.c   prenut.c \
-        nutc.c   dmxv.c   refro.c prec.c   nut.c   dmxm.c  evp.c \
-        drange.c deuler.c cldj.c  aopqk.c  refz.c  dh2e.c  de2h.c
+	daf2r.c  gmst.c   mappa.c  aoppa.c  oapqk.c ampqk.c mapqkz.c \
+	dr2af.c  dcs2c.c  dimxv.c  dvdv.c   dvn.c   dcc2s.c dranrm.c \
+        geoc.c   refco.c  eqeqx.c  aoppat.c dd2tf.c epj.c   prenut.c \
+        nutc.c   dmxv.c   refro.c  prec.c   nut.c   dmxm.c  evp.c    \
+        drange.c deuler.c cldj.c   aopqk.c  refz.c  dh2e.c  de2h.c   \
+        dt.c     dmoon.c  planet.c planel.c el2ue.c ue2pv.c pv2ue.c
 #	addet.c
 #        afin.c airmas.c altaz.c amp.c \
