Index: trunk/MagicSoft/Cosy/catalog/SlaStars.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 3897)
+++ trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 4076)
@@ -159,6 +159,6 @@
     double az;
     slaAopqk (r, d, (double*)fAoprms,
-              &az,    // observed azimuth (radians: N=0,E=90)
-              &zd,    // observed zenith distance (radians) [-pi/2, pi/2]
+              &az,    // observed azimuth (radians: N=0,E=90) [-pi, pi]
+              &zd,    // observed zenith distance (radians)   [-pi/2, pi/2]
               &h0,    // observed hour angle (radians)
               &d1,    // observed declination (radians)
@@ -175,4 +175,6 @@
 ZdAz SlaStars::GetApproxVel(const RaDec &radec) const // [rad/rad]
 {
+    // radec        [rad]
+    // GetApproxVel [rad/rad]
     double az, vaz, aaz;
     double el, vel, ael;
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 3897)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 4076)
@@ -5,4 +5,5 @@
 
 #include <TSystem.h>
+#include <TRotation.h>
 
 #include "slalib.h"
@@ -11,56 +12,25 @@
 
 #include "MStarList.h"
+#include "MAstroCatalog.h"
 
 ClassImp(StarCatalog);
 
-StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fSao(NULL), fSrt(NULL), fEntries(0), fSinAngle(0), fCosAngle(1)
-{
-    // p = pointer to MainFrame (not owner)
-
-    //
-    // read index file
-    //
-    File idx("sao/sao-sort.idx", "r");
-    if (!idx)
-        return;
-
-    while (!idx.Eof())
-    {
-        idx.Newline();
-        fEntries++;
-    }
-
-    idx.Reset();
-
-    fSrt = new sort_t[fEntries];
-
-    for (int i=0; i<fEntries; i++)
-    {
-        fSrt[i].ra  = idx.Geti(4);
-        fSrt[i].dec = idx.Geti(4);
-        fSrt[i].nr  = idx.Geti(10);
-        idx.Newline();
-    }
-
-    //
-    // open catalog
-    //
-    fSao = new SaoFile("sao/sao-sort.cmp");
+StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1)
+{
+    fAstro = new MAstroCatalog;
+    fAstro->SetObservatory(*this);
+    fAstro->SetPlainScreen();
 }
 
 StarCatalog::~StarCatalog()
 {
-    if (fSrt)
-        delete fSrt;
-    if (fSao)
-        delete fSao;
+    delete fAstro;
 }
 
 void StarCatalog::SetPixSize(const double pixsize)
 {
-    fPixSize = D2PI/360.0 * pixsize;
-
-    fWidth  = fPixSize * 768/2;
-    fHeight = fPixSize * 576/2;
+    // pixsize [arcsec/pixel]
+    fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)]
+    fAstro->SetRadiusFOV(pixsize, 768, 576);
 }
 
@@ -70,328 +40,47 @@
 }
 
+void StarCatalog::SetLimitMag(const float mag)
+{
+    fLimitMag = mag;
+    fAstro->SetLimMag(mag);
+}
+
+void StarCatalog::SetMjd(double mjd)
+{
+    SlaStars::SetMjd(mjd);
+    fAstro->SetTime(MTime(mjd));
+}
 
 void StarCatalog::SetAltAz(const AltAz &altaz)
 {
     fAltAz = altaz * D2PI/360.0;
-
-    cout << "Set --> Alt: " << 360.0/D2PI*fAltAz.Alt();
-    cout << "  Az: " << fAltAz.Az() << endl;
-
     fRaDec = CalcRaDec(fAltAz);
 
-    cout << "Ra: " << 360.0/D2PI*fRaDec.Ra();
-    cout << "  Dec: " << 360.0/D2PI*fRaDec.Dec() << endl;
-
-    CalcAltAzRange();
-    CalcRaDecRange();
+    fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec());
+}
+
+void StarCatalog::Reload()
+{
+    fAstro->SetLimMag(99);
+    //fAstro->ReadBSC("bsc5.dat");
+    //fAstro->ReadHeasarcPPM("heasarc_ppm.tdat");
+    fAstro->ReadCompressed("ppm9.bin");
+    fAstro->SetLimMag(fLimitMag);
 }
 
 void StarCatalog::SetRaDec(const RaDec &radec)
 {
-    fRaDec = radec;
-    fRaDec *= D2PI/360.0;
-
+    const RaDec rd = fRaDec*360.0/D2PI;;
+
+    const Bool_t same =
+        rd.Ra() >radec.Ra() -1e-5 && rd.Ra() <radec.Ra() +1e-5 &&
+        rd.Dec()>radec.Dec()-1e-5 && rd.Dec()<radec.Dec()+1e-5;
+
+    fRaDec = radec * D2PI/360.0;
     fAltAz = CalcAltAz(fRaDec);
 
-    //cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << "  ";
-    //cout << "Az: "  << 360.0/D2PI*fAltAz.Az()  << endl;
-
-    CalcRaDecRange();
-    CalcAltAzRange();
-}
-
-void StarCatalog::CalcAltAzRange()
-{
-    byte fAlt0[180];
-
-    for (int h=0; h<180; h++)
-        fAlt0[h] = kFALSE;
-
-    for (int h=0; h<360; h++)
-        fAz0[h] = kFALSE;
-
-    double az0, alt0;
-    double az1, alt1;
-    //
-    // scan horizontal border
-    //
-    for (int x=-768/2; x<768/2+1; x++)
-    {
-        slaDh2e(DPI+x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &az0, &alt0);
-        slaDh2e(DPI+x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &az1, &alt1);
-
-        const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360;
-        const int t0 = (int)(360.0/D2PI*alt0);
-
-        fAz0[z0] = kTRUE;
-
-        if (-89<=t0 && t0<=90)
-            fAlt0[90-t0] = kTRUE;
-
-        const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360;
-        const int t1 = (int)(360.0/D2PI*alt1);
-
-        fAz0[z1] = kTRUE;
-
-        if (-89<=t1 && t1<=90)
-            fAlt0[90-t1] = kTRUE;
-    }
-
-    //
-    // scan vertical border
-    //
-    for (int y=-576/2; y<576/2+1; y++)
-    {
-        slaDh2e(DPI-fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az0, &alt0);
-        slaDh2e(DPI+fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az1, &alt1);
-
-        const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360;
-        const int t0 = (int)(360.0/D2PI*alt0);
-
-        fAz0[z0] = kTRUE;
-
-        if (-89<=t0 && t0<=90)
-            fAlt0[90-t0] = kTRUE;
-
-        const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360;
-        const int t1 = (int)(360.0/D2PI*alt1);
-
-        fAz0[z1] = kTRUE;
-
-        if (-89<=t1 && t1<=90)
-            fAlt0[90-t1] = kTRUE;
-    }
-
-    //
-    // count degrees of azimut
-    //
-    fAzCnt=0;
-    for (int x=0; x<360; x++)
-        if (fAz0[x])
-            fAzCnt++;
-
-    //cout << "fAzCnt: " << setw(3) << fAzCnt << "  " << flush;
-
-    //
-    // calculate min and max of altitude
-    //
-    fAltMin=0;
-    fAltMax=0;
-    for (int y=0; y<180; y++)
-    {
-        if (fAlt0[y])
-            fAltMax = y;
-
-        if (fAlt0[179-y])
-            fAltMin = 179-y;
-    }
-
-    fAltMin -= 90;
-    fAltMax -= 90;
-
-    //
-    // check whether altaz north- or south-pole is in the visible region
-    //
-    byte img[768*576];
-    if (DrawAltAz(0, img, 90, 0))
-    {
-        fAltMax=89;
-        cout << "Alt Az Pole1 Inside!" << endl;
-    }
-    if (DrawAltAz(0, img, -90, 0))
-    {
-        fAltMin=-90;
-        cout << "Alt Az Pole2 Inside!" << endl;
-    }
-
-    //cout << "fAltMin: " << setw(3) << fAltMin << "  ";
-    //cout << "fAltMax: " << setw(3) << fAltMax << endl;
-}
-
-void StarCatalog::CalcRaDecRange()
-{
-    //
-    // calculate range to search in
-    //
-    byte fDec[180];
-
-    for (int h=0; h<180; h++)
-        fDec[h] = kFALSE;
-
-    for (int h=0; h<360; h++)
-        fRa0[h] = kFALSE;
-
-    double ha0, ha1;
-    double de0, de1;
-
-    const double phi   = GetPhi();
-    const double alpha = GetAlpha();
-    //
-    // scan horizontal border
-    //
-    for (int x=-768/2; x<768/2+1; x++)
-    {
-        double dx, dy;
-        slaDh2e(DPI-x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &dx, &dy);
-        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0);
-
-        slaDh2e(DPI-x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &dx, &dy);
-        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1);
-
-        const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360;
-        const int d0 = (int)(360.0/D2PI*de0);
-
-        fRa0[h0] = kTRUE;
-
-        if (-90<=d0 && d0<=89)
-            fDec[d0+90] = kTRUE;
-
-        const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360;
-        const int d1 = (int)(360.0/D2PI*de1);
-
-        fRa0[h1] = kTRUE;
-
-        if (-90<=d1 && d1<=89)
-            fDec[d1+90] = kTRUE;
-    }
-
-    //
-    // scan vertical border
-    //
-    for (int y=-576/2; y<576/2+1; y++)
-    {
-        double dx, dy;
-        slaDh2e(DPI-fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy);
-        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0);
-
-        slaDh2e(DPI+fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy);
-        slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1);
-
-        const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360;
-        const int d0 = (int)(360.0/D2PI*de0);
-
-        fRa0[h0] = kTRUE;
-
-        if (-90<=d0 && d0<=89)
-            fDec[d0+90] = kTRUE;
-
-        const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360;
-        const int d1 = (int)(360.0/D2PI*de1);
-
-        fRa0[h1] = kTRUE;
-
-        if (-90<=d1 && d1<=89)
-            fDec[d1+90] = kTRUE;
-    }
-
-    //
-    // count degrees of right ascension
-    //
-    fRaCnt=0;
-    for (int x=0; x<360; x++)
-        if (fRa0[x])
-            fRaCnt++;
-    //cout << "fRaCnt: " << setw(3) << fRaCnt << "  " << flush;
-
-    //
-    // calculate min and max of declination
-    //
-    for (int y=0; y<180; y++)
-    {
-        if (fDec[y])
-            fDecMax = y;
-
-        if (fDec[179-y])
-            fDecMin = 179-y;
-    }
-
-    fDecMin -= 90;
-    fDecMax -= 90;
-
-    //
-    // check whether radec north- or south-pole is in the visible region
-    //
-    byte img[768*576];
-    if (DrawRaDec(0, img, 0, 90))
-    {
-        fDecMax=89;
-        cout << "Ra Dec Pole1 Inside!" << endl;
-    }
-    if (DrawRaDec(0, img, 0, -90))
-    {
-        fDecMin=-90;
-        cout << "Ra Dec Pole1 Inside!" << endl;
-    }
-
-    //cout << "fDecMin: " << setw(3) << fDecMin << "  ";
-    //cout << "fDecMax: " << setw(3) << fDecMax << endl;
-}
-
-void StarCatalog::DrawSCAltAz(byte *img, const int color) const
-{
-    //
-    // ------------ draw az lines ---------------
-    //
-    for (int az=0; az<360; az++)
-    {
-        if (!fAz0[az])
-            continue;
-
-        for (double alt=fAltMin-1; alt<fAltMax+1; alt+=0.006*(fAltMax-fAltMin))
-        {
-            if ((alt>88 && az%5) || alt>89.5)
-                continue;
-
-            DrawAltAz(color, img, alt, az);
-        }
-    }
-
-    //
-    // ------------ draw alt lines ---------------
-    //
-    for (int alt=fAltMin; alt<fAltMax+1; alt++)
-    {
-        for (double az=0; az<360; az+=0.004*fAzCnt)
-        {
-            if (!fAz0[(int)az] && !fAz0[(int)(az+359)%360] && !fAz0[(int)(az+1)%360])
-                continue;
-
-            DrawAltAz(color, img, alt, az);
-        }
-    }
-}
-
-void StarCatalog::DrawSCRaDec(byte *img, const int color) const
-{
-    //
-    // ------------ draw ra lines ---------------
-    //
-    for (int ra=0; ra<360; ra++)
-    {
-        if (!fRa0[ra])
-            continue;
-
-        for (double dec=fDecMin-1; dec<fDecMax+1; dec+=0.005*(fDecMax-fDecMin))
-        {
-            if ((dec>88 && ra%5) || dec>89.5)
-                continue;
-
-            DrawRaDec(color, img, ra, dec, ra==0||ra==90);
-        }
-    }
-
-    //
-    // ------------ draw dec lines ---------------
-    //
-    for (int dec=fDecMin; dec<fDecMax+1; dec++)
-    {
-        for (double ra=0; ra<360; ra+=0.003*fRaCnt)
-        {
-            if (!fRa0[(int)ra])
-                continue;
-
-            DrawRaDec(color, img, ra, dec, dec==89);
-        }
-    }
+    fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec());
+    if (!same)
+        Reload();
 }
 
@@ -409,61 +98,6 @@
     memset(cimg, 0, 768*576);
 
-    DrawSCAltAz(cimg, 2<<4);
-    DrawSCRaDec(cimg, 2);
-
     DrawStars(list, cimg);
     DrawCross(img, 768/2, 576/2);
-}
-
-void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,
-                         const RaDec &radec)
-{
-    MStarList list;
-    GetStars(list, utc, radec);
-    GetImg(img, cimg, list);
-    /*
-     // memset(img,  0, 768*576);
-     SetMjd(utc);
-     //fAlpha = sla.GetAlpha();
-     SetRaDec(radec);
-     //CalcImg(cimg);
-     */
-}
-
-void StarCatalog::GetImg(byte *img, byte *cimg, const double utc,
-                         const AltAz &altaz)
-{
-    MStarList list;
-    GetStars(list, utc, altaz);
-    GetImg(img, cimg, list);
-    /*
-     // memset(img,  0, 768*576);
-
-     SetMjd(utc);
-     //fAlpha = sla.GetAlpha();
-     SetAltAz(altaz);
-
-     CalcRaDecRange();
-
-     //CalcImg(img);
-     */
-
-}
-
-void StarCatalog::GetStars(MStarList &list, const double utc, const RaDec &radec)
-{
-    SetMjd(utc);
-    SetRaDec(radec);
-
-    CalcStars(list);
-}
-
-void StarCatalog::GetStars(MStarList &list, const double utc, const AltAz &altaz)
-{
-    SetMjd(utc);
-    SetAltAz(altaz);
-
-    CalcRaDecRange();
-    CalcStars(list);
 }
 
@@ -489,143 +123,9 @@
 }
 
-Bool_t StarCatalog::DrawAltAz(const int color, byte *img, double alt, double az, int size) const
-{
-    //
-    // alt/az[deg] -> alt/az[rad]
-    //
-    alt *= D2PI/360.0;
-    az  *= D2PI/360.0;
-
-    //
-    // alt/az[rad] -> alt/az[pix]
-    //
-    double dx, dy;
-    slaDe2h(az-fAltAz.Az(), -alt, DPI/2-fAltAz.Alt(), &dx, &dy);
-
-    //
-    // Align alt/az[pix]
-    //
-    const int xx = (int)(((dx-DPI)*fCosAngle - dy*fSinAngle + fWidth)/fPixSize);
-    const int yy = (int)(((dx-DPI)*fSinAngle + dy*fCosAngle + fHeight)/fPixSize);
-    //const int xx = 767-(int)((fWidth-dx+DPI)/fPixSize);
-    //const int yy =     (int)((fHeight+dy)/fPixSize);
-
-    //
-    // Range Check
-    //
-    if (!(0<=xx && xx<768 && 0<=yy && yy<576))
-        return kFALSE;
-
-    //
-    // Draw
-    //
-    DrawCircle(color, img, xx, yy, size);
-
-    return kTRUE;
-}
-
-Bool_t StarCatalog::Draw(const int color, byte *img, const AltAz &altaz)
-{
-    return DrawAltAz(color, img, altaz.Alt(), altaz.Az());
-}
-
-/*
-Bool_t StarCatalog::Draw(const int color, byte *img, const SaoFile *sao)
-{
-    if (sao->MagV() > fLimitMag)
-        return kFALSE;
-
-    //
-    // ---- mean to observed ---
-    //
-    AltAz altaz=CalcAltAz(sao->GetRaDec()) * 360.0/D2PI;
-
-    const int mag = (10 - (sao->MagV()>1 ? (int)sao->MagV() : 1))/2;
-
-    //
-    // ---- imaging -----
-    //
-    return DrawAltAz(color, img, altaz.Alt(), altaz.Az(), mag);
-}
-*/
-
-Bool_t StarCatalog::DrawRaDec(const int color, byte *img, double ra, double dec, int size) const
-{
-    //
-    // radec[deg] -> radec[rad]
-    //
-    ra  *= D2PI/360.0;
-    dec *= D2PI/360.0;
-
-    //
-    // radec[rad] -> hadec[rad]
-    //
-    const double ha = GetAlpha()-ra;
-
-    //
-    // hadec[rad] -> altaz[rad]
-    //
-    double alt, az;
-    slaDe2h(ha, dec, GetPhi(), &az, &alt);
-
-    //
-    // altaz[rad] -> altaz[deg]
-    //
-    alt *= 360.0/D2PI;
-    az  *= 360.0/D2PI;
-
-    return DrawAltAz(color, img, alt, az, size);
-}
-
-Bool_t StarCatalog::Draw(const int color, byte *img, const RaDec &radec)
-{
-    return DrawRaDec(color, img, radec.Ra(), radec.Dec());
-}
-/*
-void StarCatalog::CalcImg(byte *img)
-{
-
-    //
-    // --------- search for stars in catalog ----------
-    //
-    int count   = 0;
-    int deleted = 0;
-
-    int idx     = 0;
-
-    while (fSrt[idx].dec<fDecMin)
-        idx++;
-
-    idx--;
-    while (++idx<fEntries && fSrt[idx].dec<fDecMax+1)
-    {
-        const int ra = fSrt[idx].ra;
-
-        if (!fRa0[ra])
-            continue;
-
-        int nr = fSrt[idx].nr;
-        do
-        {
-            //
-            // Get entry from catalog
-            //
-            fSao->GetEntry(nr++);
-
-            //
-            // Try to draw star into the image
-            //  white = 0xff
-            //
-            if (!Draw(0x0f, img, fSao))
-                deleted++;
-
-            count++;
-        }
-        while ((int)(360.0/D2PI*fSao->Ra())==ra);
-    }
-
-    cout << " " << count << "-" << deleted << "=" << count-deleted << " " << flush;
-}
-*/
+void StarCatalog::PaintImg(unsigned char *buf, int w, int h)
+{
+    fAstro->PaintImg(buf, w, h);
+}
+
 void StarCatalog::DrawStars(MStarList &list, byte *img)
 {
@@ -637,6 +137,5 @@
         const int mag = (10 - (star->GetMag()>1 ? (int)star->GetMag() : 1))/2;
 
-        Double_t color = 0x0f;
-
+        Double_t color = 0xf0; //0x0f;
         DrawCircle(color, img, (int)star->GetX(), (int)star->GetY(), mag);
     }
@@ -645,80 +144,68 @@
 void StarCatalog::CalcStars(MStarList &list) const
 {
-    //
-    // --------- search for stars in catalog ----------
-    //
-    if (fEntries==0)
-        return;
-
-    int count   = 0;
-    int deleted = 0;
-
-    int idx     = 0;
-
-    while (fSrt[idx].dec<fDecMin)
-        idx++;
-
-    idx--;
-    while (++idx<fEntries && fSrt[idx].dec<fDecMax+1)
+    // Align stars into telescope system
+    // (Move the telescope to pointing position)
+    TRotation align;
+    align.RotateZ(-fAltAz.Az());
+    align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
+    align.RotateZ(TMath::Pi()/2);
+
+    // For an apropriate unit conversion to pixels
+    const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
+
+    // Get List of stars from catalog
+    TIter Next(fAstro->GetList());
+    TVector3 *star=0;
+
+    const Double_t limmag = pow(10, -fLimitMag/2.5);
+
+    while ((star=(TVector3*)Next()))
     {
-        const int ra = fSrt[idx].ra;
-
-        if (!fRa0[ra])
+        // Check for limiting magnitude
+        const Double_t mag = star->Mag();
+        if (mag < limmag)
             continue;
 
-        int nr = fSrt[idx].nr;
-        do
-        {
-            //
-            // Get entry from catalog
-            //
-            fSao->GetEntry(nr++);
-
-            if (fSao->MagV() > fLimitMag)
-                continue;
-
-            //
-            // ---- mean to observed ---
-            //
-            AltAz altaz=CalcAltAz(fSao->GetRaDec());
-
-            //
-            // alt/az[rad] -> alt/az[pix]
-            //
-            double dx, dy;
-            slaDe2h(altaz.Az()-fAltAz.Az(), -altaz.Alt(),
-                    DPI/2-fAltAz.Alt(), &dx, &dy);
-
-            //
-            // Align and rotate alt/az[pix]
-            //
-            float xx = ((dx-DPI)*fCosAngle - dy*fSinAngle + fWidth)/fPixSize;
-            float yy = ((dx-DPI)*fSinAngle + dy*fCosAngle + fHeight)/fPixSize;
-
-            //
-            // Range Check, add stars to the list
-            //
-            if (!(0<=xx && xx<768 && 0<=yy && yy<576))
-            {
-                deleted++;
-                continue;
-            }
-
-            list.Add(xx, yy, fSao->MagV());
-            count++;
-        }
-        while ((int)(360.0/D2PI*fSao->Ra())==ra);
+        // Get star position and do an apropiate
+        // conversion to local coordinates
+        const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
+        const ZdAz  za(CalcZdAz(rd));
+
+        // Virtually move telescope to pointing position
+        TVector3 loc;
+        loc.SetMagThetaPhi(1, za.Zd(), za.Az());
+        loc *= align;
+
+        // Sanity check
+        if (loc(2)<0)
+            continue;
+
+        // Stretch such, that the Z-component is alwas the same. Now
+        // X and Y contains the intersection point between the star-light
+        // and the plain of a virtual plain screen (ccd...)
+        loc *= 1./loc(2);
+
+        // Do an apropriate unit conversion to pixels
+        loc *= scale;
+
+        // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
+        //     continue;
+
+        // Rotate by the rotation angle of the video camera
+        Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle;
+        Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle;
+
+        // Store pixel coordinates of star in list
+        list.Add(xx+768/2, yy+576/2, -2.5*log10(mag));
     }
-
-    cout << "Showing " << count+deleted << "-" << deleted << "=" << count << " stars." << endl;
 }
 
 AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
 {
-    pixx *= fPixSize;
-    pixy *= fPixSize;
-
-    const double dx =  (pixx-fWidth)*fCosAngle + (pixy-fHeight)*fSinAngle;
-    const double dy = -(pixx-fWidth)*fSinAngle + (pixy-fHeight)*fCosAngle;
+    double dx =  (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
+    double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
+
+    dx *= fPixSize;
+    dy *= fPixSize;
 
     //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 3897)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 4076)
@@ -4,4 +4,7 @@
 #ifndef ROOT_TROOT
 #include <TROOT.h>
+#endif
+#ifndef ROOT_GuiTypes
+#include <GuiTypes.h>
 #endif
 #ifndef SAOFILE_H
@@ -17,15 +20,12 @@
 
 class MStarList;
+class MAstroCatalog;
 
 class StarCatalog : public SlaStars
 {
 private:
-    SaoFile *fSao;
-    sort_t  *fSrt;
-    int      fEntries;
+    MAstroCatalog *fAstro;
 
     double   fPixSize;  // [rad/pix] size of one pixel
-    double   fWidth;    // size of display
-    double   fHeight;   //
     double   fSinAngle;
     double   fCosAngle;
@@ -34,41 +34,11 @@
 
     AltAz    fAltAz;    // [rad]
-    byte     fAz0[360];
-    int      fAltMin;
-    int      fAltMax;
-    int      fAzCnt;
-
     RaDec    fRaDec;    // [rad]
-    byte     fRa0[360];
-    int      fRaCnt;
-    int      fDecMin;
-    int      fDecMax;
 
     static void DrawCross(byte *img, const int x, const int y);
     static void DrawCircle(int color, byte *img, int xx, int yy, int size);
 
-    Bool_t DrawAltAz(const int color, byte *img, double alt, double az,  int size=0) const;
-    Bool_t DrawRaDec(const int color, byte *img, double ra,  double dec, int size=0) const;
-
-    Bool_t Draw(const int color, byte *img, const AltAz &altaz);
-    Bool_t Draw(const int color, byte *img, const RaDec &radec);
-
-    //Bool_t Draw(const int color, byte *img, const SaoFile *sao);
-    //void   CalcImg(byte *);
-
-    void   CalcStars(MStarList &list) const;
-
-    static void DrawStars(MStarList &list, byte *img);
-
     void   SetRaDec(const RaDec &radec);
     void   SetAltAz(const AltAz &altaz);
-    void   DrawSCAltAz(byte *img, const int color) const;
-    void   DrawSCRaDec(byte *img, const int color) const;
-  
-    void   CalcRaDecRange();
-    void   CalcAltAzRange();
-
-//    RaDec  AltAz2RaDec(const AltAz &altaz) const;
-//    AltAz  RaDec2AltAz(const RaDec &radec, const RaDec &rdpm) const;
 
 public:
@@ -77,9 +47,5 @@
 
     void GetImg(byte *img, byte *cimg, MStarList &list) const;
-    void GetImg(byte *img, byte *cimg, const double utc, const RaDec &radec);
-    void GetImg(byte *img, byte *cimg, const double utc, const AltAz &altaz);
-
-    void GetStars(MStarList &list, const double utc, const RaDec &radec);
-    void GetStars(MStarList &list, const double utc, const AltAz &altaz);
+    void PaintImg(unsigned char *buf, int w, int h);
 
     const AltAz GetAltAz() const { return fAltAz*kRad2Deg; }
@@ -88,6 +54,7 @@
 
     void  SetPixSize(const double pixsize);
-    void  SetLimitMag(const float mag) { fLimitMag = mag; }
+    void  SetLimitMag(const float mag);
     void  SetRotationAngle(const float angle) { fSinAngle = sin(angle/kRad2Deg); fCosAngle = cos(angle/kRad2Deg); }
+    void  Reload();
 
     double GetPixSize() const;
@@ -95,4 +62,14 @@
     AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const;
 
+    virtual void SetMjd(double mjd);
+
+    void SetPointing(double mjd, const RaDec &radec)
+    {
+        SetMjd(mjd); SetRaDec(radec);
+    }
+
+    void   CalcStars(MStarList &list) const;
+    static void DrawStars(MStarList &list, byte *img);
+
     ClassDef(StarCatalog, 0)
 };
