Index: /trunk/MagicSoft/Cosy/Changelog
===================================================================
--- /trunk/MagicSoft/Cosy/Changelog	(revision 7789)
+++ /trunk/MagicSoft/Cosy/Changelog	(revision 7790)
@@ -1,3 +1,62 @@
                                                                   -*-*- END -*-*-
+ 2006/07/14 Thomas Bretz (La Palma)
+
+   * stargleds.txt:
+     - changed positions slightly
+
+   * gui/GuiLinkDef.h, gui/Makefile:
+     - added MGNumStars
+
+   * gui/MGStars.[h,cc]:
+     - addde
+
+   * gui/MGAccuracy.[h,cc], gui/MGStarg.[h,cc]:
+     - unified
+     - slight changes to layout
+
+   * gui/MGCoordinate.[h,cc], MGCoordinated.[h,cc]:
+     - added a new mode which allows to suppress the title
+
+   * gui/MGCosy.[h,cc]:
+     - added new status box (armed) currently switched on by default
+     - adapted to changes in MGAccuracy
+     - disallow changing the size of the window
+
+   * main/MCaos.cc:
+     - removed an obsolete Print()
+
+   * main/MCosy.cc:
+     - fixed the name of the log-files (2006 instead of 06)
+
+   * main/MStarguider.[h,cc]:
+     - implemented new socket to send triggers to Amc (port 7307)
+     - changed standard limiting magnitude from 7.0 to 9.0
+     - changed layout of display to implement new canvas
+       displaying the number of detected and correlated stars
+     - adapted to changes in MGStarg
+     - added box to change cleaning level of starguider window
+     - set default rotation angle to -0.4deg
+     - disallow changing of window size
+     - CalcTrackingError: check first the number of detected spots 
+       and afterwards the number of found catalog stars
+     - CalcTrackingError: just try to correlate all spots with all stars
+     - decreased box size of LED box in starguider mode
+     - replaced circles around starguider pointing position by
+       camara size hexagons
+     - do not show the starguider pointing position if less than three
+       stars could be correlated
+
+   * tcpip/MTcpIpIO.cc:
+     - fixed a comparison between "signed and unsigned"
+
+   * videodev/FilterLed.[h,cc]:
+     - implemented DrawHexagon based on MGMap::DrawHexagon
+     - renamed *Circle to *Box
+     - replaced old algorithm to find stars in starguider mode (and
+       LEDs) by a new ClusterFinder class
+     - needs more maintanance!
+
+
+
  2006/07/11 Thomas Bretz (La Palma)
 
Index: /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/GuiLinkDef.h	(revision 7790)
@@ -15,4 +15,5 @@
 #pragma link C++ class MGSkyPosition+;
 #pragma link C++ class MGStarg+;
+#pragma link C++ class MGNumStars+;
 
 #pragma link C++ class MGCosy+;
Index: /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 7790)
@@ -1,8 +1,2 @@
-//
-// This File contains the definition of the MGCoordinates-class
-//
-//   Author: Thomas Bretz
-//   Version: V1.0 (1-8-2000)
-
 #include "MGAccuracy.h"
 
@@ -13,5 +7,4 @@
 #include <TText.h>
 #include <TWbox.h>
-#include <TList.h>
 #include <TGaxis.h>
 #include <TGraph.h>
@@ -24,13 +17,30 @@
 ClassImp(MGAccuracy);
 
-void MGAccuracy::DrawCoordinateSystem()
-{
-    TWbox box;
-    box.DrawWbox(-145*2, 145*2, -15*2, 120*2,  18,  2, 1);
+void MGAccuracy::DrawText(const char *c1, const char *c2, const char *c3, const char*txt)
+{
+    fCanvas->SetEditable(kTRUE);
+    fCanvas->cd();
 
     TText text;
     text.SetTextAlign(22);  // centered, centered (s.TAttText)
-    text.DrawText(-80*2, 132.5*2, "Ctrl Deviation [min]");
-
+    text.DrawText(-150, 265, txt);
+
+    text.SetTextAlign(11);  // left, bottom (s.TAttText)
+    text.SetTextColor(3);
+    text.DrawText(220, -220, c1);
+
+    text.SetTextColor(5);
+    text.DrawText(220, -250, c2);
+
+    text.SetTextColor(2);
+    text.DrawText(220, -280, c3);
+
+    fCanvas->SetEditable(kFALSE);
+}
+
+void MGAccuracy::DrawCircles(Double_t rad)
+{
+    fCanvas->SetEditable(kTRUE);
+    fCanvas->cd();
 
     TArc arc;
@@ -39,27 +49,23 @@
     arc.SetLineColor(3);     // green
     arc.SetLineStyle(2);     // dashed  (s. TAttLine)
-    arc.DrawArc(0, 0, 79.1/2.);        // 0.5se
+    arc.DrawArc(0, 0, rad/2.);         // 0.5se
 
     arc.SetLineColor(5);     // yellow
-    arc.DrawArc(0, 0, 79.1);            // 1.0se
+    arc.DrawArc(0, 0, rad);            // 1.0se
 
     arc.SetLineColor(2);     // red
-    arc.DrawArc(0, 0, 79.1*2.);         // 2.0se
-
-
-    text.SetTextAlign(11);  // left, bottom (s.TAttText)
-    text.SetTextColor(3);
-    text.DrawText(220, -220, "0.5se");
-
-    text.SetTextColor(5);
-    text.DrawText(220, -250, "1.0se");
-
-    text.SetTextColor(2);
-    text.DrawText(220, -280, "2.0se");
-
-
-    TLine line;
-    line.DrawLine(-65*4,     0, 65*4,    0);
-    line.DrawLine(    0, -65*4,    0, 65*4);
+    arc.DrawArc(0, 0, rad*2.);         // 2.0se
+
+    fCanvas->SetEditable(kFALSE);
+}
+
+void MGAccuracy::DrawCoordinateSystem()
+{
+    TWbox box;
+    box.DrawWbox(-290, 290, -10, 240,  18,  2, 1);
+
+//    TLine line;
+//    line.DrawLine(-65*4,     0, 65*4,    0);
+//    line.DrawLine(    0, -65*4,    0, 65*4);
 
     //
@@ -122,5 +128,5 @@
 
 MGAccuracy::MGAccuracy(const TGWindow* p, const UInt_t w)
-: MGEmbeddedCanvas("Accuracy", p, w, 300)
+: MGEmbeddedCanvas("Accuracy", p, w, 300), fColorScale(360*60/16384)
 {
     // FIXME: Overload MapWindow in newer Root versions to remove
@@ -133,7 +139,4 @@
     fGraph->Draw("LP");
     fList->Add(fGraph);
-    //fGraph->SetNameTitle("AccVsT", "Accuracy vs Min of Time");
-    //fGraph->Draw("APL");
-    //fGraph->SetMarkerSize(2);
 
     DrawCoordinateSystem();
@@ -153,5 +156,4 @@
 MGAccuracy::~MGAccuracy()
 {
-    //    cout << "MGAccuracy destroyed." << endl;
 }
 
@@ -172,8 +174,8 @@
 
     fBar->SetY2(dist*60); // [sec]
-    if (dist*16384<1*360*60)
+    if (dist<fColorScale) //1*360*60/16384
         fBar->SetLineColor(kGreen);
     else
-        if (dist*16384<2*360*60)
+        if (dist<2*fColorScale) //2*360*60/16384
             fBar->SetLineColor(kYellow);
         else
@@ -227,12 +229,4 @@
 
     SetModified();
-
-    //cout << "N1 == " << fGraph->GetN() << endl;
-
-    //fGraph->GetHistogram()->SetXTitle("Time");
-    //fGraph->GetHistogram()->SetYTitle("\\Delta [arcmin]");
-    //fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%M %F1995-01-01 00:00:00");
-    //fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
-    //fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
 }
 
@@ -248,7 +242,4 @@
 {
     //
-    // calculate actual time for planet positions
-    // acc [deg]
-    //
     // x["], y["]
     //
Index: /trunk/MagicSoft/Cosy/gui/MGAccuracy.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 7790)
@@ -1,4 +1,4 @@
-#ifndef MGACCURACY_H
-#define MGACCURACY_H
+#ifndef COSY_MGAccuracy
+#define COSY_MGAccuracy
 
 //
@@ -20,4 +20,5 @@
 class MGAccuracy : public MGEmbeddedCanvas
 {
+protected:
     TLine  *fLin1;
     TLine  *fLin2;
@@ -30,4 +31,5 @@
 
     Double_t fTime;
+    Double_t fColorScale;
 
     void DrawCoordinateSystem();
@@ -46,4 +48,9 @@
     ~MGAccuracy();
 
+    void DrawText(const char *c1, const char *c2, const char *c3, const char *txt);
+    void DrawCircles(Double_t rad=79.1);
+
+    void SetColorScale(Double_t scale=1) { fColorScale=scale; }
+
     void Update(ZdAz &pos, ZdAz &acc);
 
@@ -51,3 +58,3 @@
 };
 
-#endif // MGSKYPOSITION_H
+#endif // COSY_MGAccuracy
Index: /trunk/MagicSoft/Cosy/gui/MGCoordinate.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 7790)
@@ -26,12 +26,14 @@
 
 MGCoordinate::MGCoordinate(const TGWindow* p, const Int_t type=kETypeDeg,
-                           const Bool_t flag, const char *txt,
+                           const Int_t flag, const char *txt,
                            const Int_t deg, const UInt_t min, const UInt_t sec)
-: TGFrame(p, 119, flag?76:46, kSunkenFrame|kFixedSize), fSign('+'), fDeg(deg), fMin(min), fSec(sec)
+: TGFrame(p, 119, flag==1?76:46-(TString(txt).IsNull()?23:0), kSunkenFrame|kFixedSize), fSign('+'), fDeg(deg), fMin(min), fSec(sec), fLabel(0)
 {
     fList = new MGList;
 
+    const Int_t offset = TString(txt).IsNull() ? 23 : 0;
+
     // p = pointer to MainFrame (not owner)
-    if (flag)
+    if (flag==1)
     {
         fTextEntryDeg = new TGTextEntry(this, "****", IDM_kDeg);
@@ -41,7 +43,7 @@
         // fTextEntryMin->SetAlignment(kTextCenterX);
         // fTextEntrySec->SetAlignment(kTextCenterX);
-        fTextEntryDeg->Move( 7, 26);
-        fTextEntryMin->Move(47, 26);
-        fTextEntrySec->Move(81, 26);
+        fTextEntryDeg->Move( 7, 26-offset);
+        fTextEntryMin->Move(47, 26-offset);
+        fTextEntrySec->Move(81, 26-offset);
         fTextEntryDeg->MapWindow();
         fTextEntryMin->MapWindow();
@@ -56,5 +58,5 @@
     }
 
-    const int ypos = flag?56:26;
+    const int ypos = (flag==1?56:26)-offset;
 
     fLabelDeg = new TGLabel(this, "****");
@@ -78,9 +80,12 @@
     Set(fLabelSec, fSec);
 
-    fLabel = new TGLabel(this, txt);
-    fLabel->SetTextJustify(kTextLeft);
-    fLabel->Move(4, 4);
-    fLabel->MapWindow();
-    fList->Add(fLabel);
+    if (!TString(txt).IsNull())
+    {
+        fLabel = new TGLabel(this, txt);
+        fLabel->SetTextJustify(kTextLeft);
+        fLabel->Move(4, 4);
+        fLabel->MapWindow();
+        fList->Add(fLabel);
+    }
 
     TGLabel *label;
@@ -90,9 +95,9 @@
     const char *sec = type==kETypeDeg ? "\""   : "s";
 
-    if (flag)
+    if (flag==1)
     {
         label = new TGLabel(this, deg);
         label->SetTextJustify(kTextLeft);
-        label->Move(37, 29);
+        label->Move(37, 29-offset);
         label->MapWindow();
         fList->Add(label);
@@ -100,5 +105,5 @@
         label = new TGLabel(this, min);
         label->SetTextJustify(kTextLeft);
-        label->Move(71, 29);
+        label->Move(71, 29-offset);
         label->MapWindow();
         fList->Add(label);
@@ -106,5 +111,5 @@
         label = new TGLabel(this, sec);
         label->SetTextJustify(kTextLeft);
-        label->Move(107, 29);
+        label->Move(107, 29-offset);
         label->MapWindow();
         fList->Add(label);
@@ -146,5 +151,7 @@
 void MGCoordinate::Print()
 {
-    cout << fLabel->GetText()->GetString() << " " << fSign << fDeg << "\xb0 " << fMin << "' " << fSec << "\"" << endl;
+    if (fLabel)
+        cout << fLabel->GetText()->GetString() << " ";
+    cout << fSign << fDeg << "\xb0 " << fMin << "' " << fSec << "\"" << endl;
 }
 
Index: /trunk/MagicSoft/Cosy/gui/MGCoordinate.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCoordinate.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCoordinate.h	(revision 7790)
@@ -1,4 +1,4 @@
-#ifndef MGCOORDINATE_H
-#define MGCOORDINATE_H
+#ifndef COSY_MGCoordinate
+#define COSY_MGCoordinate
 
 //
@@ -49,5 +49,5 @@
 public:
     MGCoordinate(const TGWindow* p, const Int_t type=kETypeDeg,
-                 const Bool_t flag=kTRUE, const char *txt="Coordinates:",
+                 const Int_t flag=1, const char *txt="Coordinates:",
                  const Int_t deg=0, const UInt_t min=0, const UInt_t sec=0);
     ~MGCoordinate();
@@ -63,3 +63,3 @@
 };
 
-#endif // MGIMAGE_H
+#endif // COSY_MGCoordinates
Index: /trunk/MagicSoft/Cosy/gui/MGCoordinates.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCoordinates.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCoordinates.cc	(revision 7790)
@@ -16,5 +16,5 @@
 MGCoordinates::MGCoordinates(const TGWindow* p,
                              const Int_t type,
-                             const Bool_t flag,
+                             const Int_t flag,
                              const Int_t deg1, const UInt_t min1, const UInt_t sec1,
                              const Int_t deg2, const UInt_t min2, const UInt_t sec2)
@@ -23,11 +23,11 @@
     const Int_t t    = type==kETypeZdAz ? kETypeDeg : kETypeH;
     const char *txt1 = type==kETypeZdAz ? "Zenith Dist [\xb0]:" : "Right Ascension [h]:";
-    const char *txt2 = type==kETypeZdAz ? "Azimuth [\xb0]:" : "Declination [\xb0]:";
+    const char *txt2 = type==kETypeZdAz ? "Azimuth [\xb0]:"     : "Declination [\xb0]:";
 
     // p = pointer to MainFrame (not owner)
-    fX = new MGCoordinate(this, t, flag, txt1, deg1, min1, sec1);
+    fX = new MGCoordinate(this, t, flag, flag>1?"":txt1, deg1, min1, sec1);
     fX->Move(0, 0);
 
-    fY = new MGCoordinate(this, kETypeDeg, flag, txt2, deg2, min2, sec2);
+    fY = new MGCoordinate(this, kETypeDeg, flag, flag>1?"":txt2, deg2, min2, sec2);
     fY->Move(125, 0);
 
Index: /trunk/MagicSoft/Cosy/gui/MGCoordinates.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCoordinates.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCoordinates.h	(revision 7790)
@@ -1,4 +1,4 @@
-#ifndef MGCOORDINATES_H
-#define MGCOORDINATES_H
+#ifndef COSY_MGCoordinates
+#define COSY_MGCoordinates
 
 //
@@ -15,6 +15,7 @@
 
 enum {
-    kETypeZdAz,
-    kETypeRaDec
+    kETypeZdAz = BIT(0),
+    kETypeRaDec= BIT(1),
+    kETypeNone = BIT(3)
 };
 
@@ -28,5 +29,5 @@
 public:
     MGCoordinates(const TGWindow* p, const Int_t type=kETypeZdAz,
-                  const Bool_t flag=kTRUE,
+                  const Int_t flag=1,
                   const Int_t deg1=0, const UInt_t min1=0, const UInt_t sec1=0,
                   const Int_t deg2=0, const UInt_t min2=0, const UInt_t sec2=0);
@@ -41,3 +42,3 @@
 };
 
-#endif // MGIMAGE_H
+#endif // COSY_MGCoordinates
Index: /trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 7790)
@@ -247,4 +247,5 @@
     fList->Add(fAzSoll);
 
+    fArmed     = new TGLabel(f, "Armed");
     fError     = new TGLabel(f, "Error");
     fMoving    = new TGLabel(f, "Moving");
@@ -261,4 +262,6 @@
     ULong_t color;
 
+    gClient->GetColorByName("Magenta", color);
+    fArmed->SetBackgroundColor(color);
     gClient->GetColorByName("Red", color);
     fError->SetBackgroundColor(color);
@@ -278,16 +281,18 @@
     fStopped->SetBackgroundColor(color);
 
-    fError   ->MoveResize(10, 25, 60, 20);
-    fMoving  ->MoveResize(10, 25+20, 60, 20);
-    fTracking->MoveResize(10, 25+40, 60, 20);
-    fStopping->MoveResize(10, 25+60, 60, 20);
-    fStopped ->MoveResize(10, 25+80, 60, 20);
-    fAvailMac1->MoveResize(10, 25+120, 60, 20);
-    fAvailMac2->MoveResize(10, 25+140, 60, 20);
+    fArmed   ->MoveResize(10,  25,        60, 20);
+    fError   ->MoveResize(10,  25+25,     60, 20);
+    fMoving  ->MoveResize(10,  25+25+20,  60, 20);
+    fTracking->MoveResize(10,  25+25+40,  60, 20);
+    fStopping->MoveResize(10,  25+25+60,  60, 20);
+    fStopped ->MoveResize(10,  25+25+80,  60, 20);
+    fAvailMac1->MoveResize(10, 25+25+120, 60, 20);
+    fAvailMac2->MoveResize(10, 25+25+140, 60, 20);
     //fAvailMac3->Move(10, 25+160);
-    fAvailSe1->MoveResize(10, 25+200, 60, 20);
-    fAvailSe2->MoveResize(10, 25+220, 60, 20);
-    fAvailSe3->MoveResize(10, 25+180, 60, 20);
-
+    fAvailSe1->MoveResize(10,  25+25+200, 60, 20);
+    fAvailSe2->MoveResize(10,  25+25+220, 60, 20);
+    fAvailSe3->MoveResize(10,  25+25+180, 60, 20);
+
+    fList->Add(fArmed);
     fList->Add(fError);
     fList->Add(fMoving);
@@ -737,4 +742,6 @@
 #endif
     fAccuracy = new MGAccuracy(f1, 300);
+    fAccuracy->DrawText("0.5se", "1.0se", "2.0se", "Ctrl Deviation [min]");
+    fAccuracy->DrawCircles();
 #ifdef DEBUG
     cout << "MGCosy: Creating MGVelocity" << endl;
@@ -822,5 +829,5 @@
     const Int_t w = 1010;
     const Int_t h =  700;
-    SetWMSizeHints(w, h, 1280, 900, 10, 10);  // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(w, h, w, h, 1, 1);  // set the smallest and biggest size of the Main frame
 
     SetWindowName("Cosy Main Window");
@@ -1068,4 +1075,6 @@
     SetLabelColor(fAvailSe2,  stat2&0x10);
     SetLabelColor(fAvailSe3,  stat2&0x20);
+
+    EnableLabel(fArmed, 1);//stat2&0x40);
 
     if (stat&MDriveCom::kTracking)
Index: /trunk/MagicSoft/Cosy/gui/MGCosy.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 7790)
@@ -88,4 +88,5 @@
     TGTab         *fTab;
 
+    TGLabel *fArmed;
     TGLabel *fError;
     TGLabel *fMoving;
Index: /trunk/MagicSoft/Cosy/gui/MGNumStars.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGNumStars.cc	(revision 7790)
+++ /trunk/MagicSoft/Cosy/gui/MGNumStars.cc	(revision 7790)
@@ -0,0 +1,176 @@
+#include "MGNumStars.h"
+
+#include <iostream.h>  // cout
+
+#include <TLine.h>
+#include <TText.h>
+#include <TWbox.h>
+#include <TGaxis.h>
+#include <TGraph.h>
+#include <TCanvas.h>
+
+#include "MTime.h"
+
+ClassImp(MGNumStars);
+
+void MGNumStars::DrawText(const char*txt)
+{
+    fCanvas->SetEditable(kTRUE);
+    fCanvas->cd();
+
+    TText text;
+    text.SetTextAlign(22);  // centered, centered (s.TAttText)
+    text.SetTextSize(0.12);
+    text.DrawText(275, 44, txt);
+
+    fCanvas->SetEditable(kFALSE);
+}
+
+void MGNumStars::DrawCoordinateSystem()
+{
+    fCanvas->Range(-50, -4, 600, 50);
+
+    TWbox box;
+    box.DrawWbox(325-150-50, 38, 325+150-50, 48,  18,  2, 1);
+
+    TLine line;
+    line.DrawLine(0, 0, 600-25, 0);
+    line.SetLineStyle(kDashed);
+    line.SetLineColor(kRed);
+    line.DrawLine(0,  6.5, 600-25, 6.5);
+    line.SetLineColor(kYellow);
+    line.DrawLine(0, 10.5, 600-25, 10.5);
+
+    TGaxis *axe;
+    axe = new TGaxis(0, 0, 0, 47.5, 0, 47.5, 304, "-");
+    axe->SetLabelSize(0.1);
+    axe->SetLabelOffset(0.02);
+    axe->SetBit(kCanDelete);
+    axe->Draw();
+}
+
+void MGNumStars::InitText()
+{
+    fTxt = new TText(600*0.97, 50*0.92, "0/0");
+    fTxt->SetTextAlign(33); // right, top
+    fTxt->SetTextColor(10);
+    fTxt->SetTextSize(0.12);
+    fTxt->Draw();
+
+    fList->Add(fTxt);
+}
+
+void MGNumStars::InitBar(TLine* &bar)
+{
+    bar = new TLine(0, 0, 0, 0);
+    bar->SetLineColor(kBlack);
+    bar->SetLineStyle(1);
+    bar->SetLineWidth(5);
+    bar->Draw();
+
+    fList->Add(bar);
+}
+
+void MGNumStars::InitGraph(TGraph* &graph, Int_t col)
+{
+    graph = new TGraph;
+    graph->SetPoint(0, 0, 0);
+    graph->SetLineColor(col);
+    graph->SetMarkerColor(col);
+    graph->SetMarkerStyle(kFullDotMedium);
+    graph->Draw("LP");
+    fList->Add(graph);
+}
+
+MGNumStars::MGNumStars(const TGWindow* p, const UInt_t w)
+: MGEmbeddedCanvas("NumStars", p, w, 300)
+{
+    DrawCoordinateSystem();
+
+    InitGraph(fGraph1, kBlue);
+    InitGraph(fGraph2, kMagenta);
+
+    InitText();
+    InitBar(fBar1);
+    InitBar(fBar2);
+
+    InitCanvas();
+
+    Resize(245, 100);
+
+    SetNoContextMenu();
+
+    MTime t(-1);
+    fTime = t.GetAxisTime();
+}
+
+MGNumStars::~MGNumStars()
+{
+}
+
+// dist [deg]
+void MGNumStars::UpdateBar(TLine &bar, UInt_t num)
+{
+    bar.SetY2(num);
+    if (num<11)
+        bar.SetLineColor(kYellow);
+    else
+        if (num<7)
+            bar.SetLineColor(kRed);
+        else
+            bar.SetLineColor(kGreen);
+
+    SetModified();
+}
+
+// dist [deg]
+void MGNumStars::UpdateGraph(TGraph &graph, Double_t dtime, UInt_t num)
+{
+    graph.SetPoint(graph.GetN(), dtime, num);
+
+    const Double_t ntime = dtime;
+    for (int i=0; i<graph.GetN(); i++)
+    {
+        Double_t x, y;
+        graph.GetPoint(i, x,       y);
+        graph.SetPoint(i, x+ntime, y);
+    }
+    while (graph.GetN()>0)
+    {
+        Double_t x, y;
+        graph.GetPoint(0, x, y);
+
+        if (x==+ntime && y==0)
+        {
+            graph.RemovePoint(0);
+            continue;
+        }
+
+        if (x<2*4.75*60)
+            break;
+
+        graph.RemovePoint(0);
+    }
+
+    SetModified();
+}
+
+void MGNumStars::Update(UInt_t det, UInt_t cor)
+{
+    char txt[100];
+    sprintf(txt, "%d/%d", cor, det);
+    fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
+
+    UpdateBar(*fBar1, det);
+    UpdateBar(*fBar2, cor);
+
+    MTime t(-1);
+    const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
+
+    UpdateGraph(*fGraph1, dtime, det);
+    UpdateGraph(*fGraph2, dtime, cor);
+
+    fTime = t.GetAxisTime();
+
+    UpdateCanvas();
+}
Index: /trunk/MagicSoft/Cosy/gui/MGNumStars.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGNumStars.h	(revision 7790)
+++ /trunk/MagicSoft/Cosy/gui/MGNumStars.h	(revision 7790)
@@ -0,0 +1,57 @@
+#ifndef COSY_MGNumStars
+#define COSY_MGNumStars
+
+//
+// This File contains the declaration of the MGCoordinates-class
+//
+//   Author: Thomas Bretz
+//   Version: V1.0 (1-8-2000)
+
+#ifndef COSY_MGEmbeddedCanvas
+#include "MGEmbeddedCanvas.h"
+#endif
+
+class TGraph;
+class TLine;
+class TText;
+
+class ZdAz;
+
+class MGNumStars : public MGEmbeddedCanvas
+{
+protected:
+    TLine  *fLin1;
+    TLine  *fLin2;
+
+    TText  *fTxt;
+
+    TLine  *fBar1;
+    TLine  *fBar2;
+
+    TGraph *fGraph1;
+    TGraph *fGraph2;
+
+    Double_t fTime;
+
+    void DrawCoordinateSystem();
+
+    void InitText();
+    void InitCross();
+    void InitBar(TLine* &bar);
+    void InitGraph(TGraph* &graph, Int_t col);
+
+    void UpdateBar(TLine &bar, UInt_t num);
+    void UpdateGraph(TGraph &graph, Double_t dtime, UInt_t num);
+
+public:
+    MGNumStars(const TGWindow* p, const UInt_t w);
+    ~MGNumStars();
+
+    void DrawText(const char *txt);
+
+    void Update(UInt_t det, UInt_t cor);
+
+    ClassDef(MGNumStars, 0)
+};
+
+#endif // COSY_MGNumStars
Index: /trunk/MagicSoft/Cosy/gui/MGStarg.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGStarg.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGStarg.cc	(revision 7790)
@@ -1,270 +1,26 @@
 #include "MGStarg.h"
 
-#include <iostream.h>  // cout
-
-#include <TArc.h>
-#include <TLine.h>
-#include <TText.h>
-#include <TWbox.h>
-#include <TList.h>
-#include <TGaxis.h>
-#include <TGraph.h>
 #include <TCanvas.h>
 
 #include <MHexagon.h>
 
-#include "coord.h"
-#include "MTime.h"
-#include "MAstro.h"
-
 ClassImp(MGStarg);
 
-void MGStarg::DrawCoordinateSystem()
+void MGStarg::DrawHexagon()
 {
-    TWbox box;
-    box.DrawWbox(-145*2, 145*2, -15*2, 120*2,  18,  2, 1);
-
-    TText text;
-    text.SetTextAlign(22);  // centered, centered (s.TAttText)
-    text.DrawText(-80*2, 132.5*2, "Misspointing [min]");
+    fCanvas->SetEditable(kTRUE);
+    fCanvas->cd();
 
     MHexagon hex;
-    hex.SetFillColor(39);
     hex.SetFillStyle(4000);
     hex.SetLineColor(17);
-    hex.DrawHexagon(0,0,177.5*2);
+    hex.DrawHexagon(0, 0, 177.5*2);
 
-    text.SetTextAlign(11);  // left, bottom (s.TAttText)
-    text.SetTextColor(3);
-    text.DrawText(220, -220, "0.75'");
-
-    text.SetTextColor(5);
-    text.DrawText(220, -250, "1.50'");
-
-    text.SetTextColor(2);
-    text.DrawText(220, -280, "3.00'");
-
-
-    TLine line;
-    line.DrawLine(-65*4,     0, 65*4,    0);
-    line.DrawLine(    0, -65*4,    0, 65*4);
-
-    //
-    // Can be replaced by TGaxis axe; in a later root version
-    // than 3.01/06. I talked to Rene
-    //
-    TGaxis *axe;
-    axe = new TGaxis(-60*4,   0, 60*4,  0,  -4, 4, 30204, "+-N");
-    axe->SetTitle("Az"); // \xb0
-    axe->SetBit(kCanDelete);
-    axe->Draw();
-
-    axe = new TGaxis(  0, -60*4,  0, 60*4,  -4, 4,   304, "+-N");
-    axe->SetTitle("Zd"); // \xb0
-    axe->SetLabelOffset(-0.02);
-    axe->SetBit(kCanDelete);
-    axe->Draw();
-}
-
-void MGStarg::InitText()
-{
-    fTxt = new TText(280, 280, "0' / 0'");
-    fTxt->SetTextAlign(33); // right, top
-    fTxt->SetTextColor(10);
-    fTxt->Draw();
-
-    fList->Add(fTxt);
-}
-
-void MGStarg::InitBar()
-{
-    fBar = new TLine(0, 0, 0, 0);
-    fBar->SetLineColor(kBlack);
-    fBar->SetLineStyle(1);
-    fBar->SetLineWidth(5);
-    fBar->Draw();
-
-    fList->Add(fBar);
-}
-
-void MGStarg::InitCross()
-{
-    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->SetLineWidth(2);
-    fLin2->SetLineWidth(2);
-
-    fLin1->Draw();
-    fLin2->Draw();
-
-    fList->Add(fLin1);
-    fList->Add(fLin2);
+    fCanvas->SetEditable(kFALSE);
 }
 
 MGStarg::MGStarg(const TGWindow* p, const UInt_t w)
-: MGEmbeddedCanvas("Starg", p, w, 300)
+: MGAccuracy(p, w)
 {
-    // FIXME: Overload MapWindow in newer Root versions to remove
-    //        the contents of the graph!
-    fGraph = new TGraph;
-    fGraph->SetPoint(0, 0, 0);
-    fGraph->SetLineColor(kBlue);
-    fGraph->SetMarkerColor(kBlue);
-    fGraph->SetMarkerStyle(kFullDotMedium);
-    fGraph->Draw("LP");
-    fList->Add(fGraph);
-    //fGraph->SetNameTitle("AccVsT", "Accuracy vs Min of Time");
-    //fGraph->Draw("APL");
-    //fGraph->SetMarkerSize(2);
-
-    DrawCoordinateSystem();
-
-    InitText();
-    InitCross();
-    InitBar();
-
-    InitCanvas();
-
-    SetNoContextMenu();
-
-    MTime t(-1);
-    fTime = t.GetAxisTime();
+    SetColorScale(1.5);
 }
-
-MGStarg::~MGStarg()
-{
-    //    cout << "MGStarg destroyed." << endl;
-}
-
-// dist [deg]
-void MGStarg::UpdateText(Float_t dist)
-{
-    dist *= 3600.; // [sec]
-
-    int rs = (int)floor(fmod(dist, 60.));
-
-    dist /= 60.;   // [min]
-    int rm = (int)dist;
-
-    char txt[100];
-    rm ? sprintf(txt, "%d'%02d\"", rm, rs) : sprintf(txt, "%d\"", rs);
-
-    fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
-
-    fBar->SetY2(dist*60); // [sec]
-    if (dist<1.5)
-        fBar->SetLineColor(kGreen);
-    else
-        if (dist<3)
-            fBar->SetLineColor(kYellow);
-        else
-            fBar->SetLineColor(kRed);
-
-    SetModified();
-}
-
-// dist [deg]
-void MGStarg::UpdateGraph(Float_t dist)
-{
-    MTime t(-1);
-    const Double_t dtime = t.GetAxisTime()-fTime; // range [-0.5h, 0h]
-
-    dist *= 60; // min
-
-    static int odist = -1;
-    if (odist==(int)(dist*10*60) && dtime<10)
-        return;
-
-    odist = (int)(dist*10*60);
-
-    fGraph->SetPoint(fGraph->GetN(), dtime, dist*60);
-
-    const Double_t ntime = dtime;
-    for (int i=0; i<fGraph->GetN(); i++)
-    {
-        Double_t x, y;
-        fGraph->GetPoint(i, x,       y);
-        fGraph->SetPoint(i, x-ntime, y);
-        //cout << i << ":  " << x-ntime << " / " << y << endl;
-    }
-    while (fGraph->GetN()>0)
-    {
-        Double_t x, y;
-        fGraph->GetPoint(0, x, y);
-
-        if (x==-ntime && y==0)
-        {
-            fGraph->RemovePoint(0);
-            continue;
-        }
-
-        if (x>-4.75*60)
-            break;
-
-        fGraph->RemovePoint(0);
-    }
-
-    fTime = t.GetAxisTime();
-
-    SetModified();
-
-}
-
-void MGStarg::Update(Float_t pzd, Float_t azd, Float_t aaz)
-{
-    const double dist = MAstro::GetDevAbs(pzd, azd, aaz);
-
-    UpdateText(dist);
-    UpdateGraph(dist);
-}
-
-void MGStarg::UpdateCross(Float_t x, Float_t y)
-{
-    //
-    // x["], y["]
-    //
-    static int X = ~0;
-    static int Y = ~0;
-
-    int pixx = (int)(x/fPix);  // [pix]
-    int pixy = (int)(y/fPix);  // [pix]
-
-    if (X==pixx && Y==pixy)
-        return;
-
-    X = pixx;
-    Y = pixy;
-
-    fLin1->SetX1(x-5.);
-    fLin1->SetX2(x+5.);
-
-    fLin2->SetX1(x-5.);
-    fLin2->SetX2(x+5.);
-
-    fLin1->SetY1(y-5.);
-    fLin1->SetY2(y+5.);
-
-    fLin2->SetY1(y+5.);
-    fLin2->SetY2(y-5.);
-
-    SetModified();
-}
-
-void MGStarg::Update(ZdAz &pos, ZdAz &dev)
-{
-    // Estimate the distance in az direction on the camera plane
-    const double daz = MAstro::GetDevAbs(pos.Zd(), 0, dev.Az())*3600.;
-
-    //cout << "--> S: " << dev.Az()*60 << " " << dev.Zd()*60. << endl;
-
-    UpdateCross(TMath::Sign(daz, dev.Az()), dev.Zd()*3600.);
-    Update(pos.Zd(), dev.Zd(), dev.Az());
-
-    UpdateCanvas();
-}
Index: /trunk/MagicSoft/Cosy/gui/MGStarg.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGStarg.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/MGStarg.h	(revision 7790)
@@ -1,7 +1,7 @@
-#ifndef MGSTARG_H
-#define MGSTARG_H
+#ifndef COSY_MGStarg
+#define COSY_MGStarg
 
-#ifndef COSY_MGEmbeddedCanvas
-#include "MGEmbeddedCanvas.h"
+#ifndef COSY_MGAccuracy
+#include "MGAccuracy.h"
 #endif
 
@@ -12,36 +12,38 @@
 class ZdAz;
 
-class MGStarg : public MGEmbeddedCanvas
+class MGStarg : public MGAccuracy
 {
-    TLine  *fLin1;
-    TLine  *fLin2;
+//    TLine  *fLin1;
+//    TLine  *fLin2;
 
-    TText  *fTxt;
+//    TText  *fTxt;
 
-    TLine  *fBar;
+//    TLine  *fBar;
 
-    TGraph *fGraph;
+//    TGraph *fGraph;
 
-    Double_t fTime;
+//    Double_t fTime;
 
-    void DrawCoordinateSystem();
+//    void InitText();
+//    void InitCross();
+//    void InitBar();
 
-    void InitText();
-    void InitCross();
-    void InitBar();
+//    void UpdateCross(Float_t x, Float_t y);
+//    void UpdateText(Float_t dist);
+//    void UpdateGraph(Float_t acc);
+//    void Update(Float_t zd, Float_t x, Float_t y);
 
-    void UpdateCross(Float_t x, Float_t y);
-    void UpdateText(Float_t acc);
-    void UpdateGraph(Float_t acc);
-    void Update(Float_t zd, Float_t x, Float_t y);
 
 public:
     MGStarg(const TGWindow* p, const UInt_t w);
-    ~MGStarg();
+//    ~MGStarg();
 
-    void Update(ZdAz &pos, ZdAz &acc);
+//    virtual void DrawText();
+    void DrawHexagon();
+
+//    void Update(ZdAz &pos, ZdAz &acc);
 
     ClassDef(MGStarg, 0)
 };
 
-#endif // MGSTARG_H
+#endif // COSY_MGStarg
Index: /trunk/MagicSoft/Cosy/gui/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/gui/Makefile	(revision 7789)
+++ /trunk/MagicSoft/Cosy/gui/Makefile	(revision 7790)
@@ -40,4 +40,5 @@
 	   MGAccuracy.cc \
 	   MGStarg.cc \
+	   MGNumStars.cc \
 	   MGSkyPosition.cc
   
Index: /trunk/MagicSoft/Cosy/main/MCaos.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 7790)
@@ -34,5 +34,4 @@
     cout << " Reading " << name << ":" << endl;
     cout << "------------------------------" << endl;
-
     while (1)
     {
@@ -336,4 +335,16 @@
     leds.Clear();
 
+    /*
+    //the following lines are just to test the new setup
+    static int i=0;
+    i++;
+    i%=2;
+    if (i==0)
+        ReadResources("leds0.txt");
+    else
+        ReadResources("leds1.txt");
+    cout << "LEDs " << i << " " << flush;
+     */
+
     //          img  width height radius sigma
     FilterLed f(img, 768, 576, box, cut);
@@ -378,6 +389,7 @@
 
     const Ring &center = rings.GetCenter();
-    
-    center.Print();
+
+//uncommented for testing
+//    center.Print();
 
     // FIXME!
@@ -423,4 +435,9 @@
     }
 
+    /*
+    //test - give number of rings
+    cout << rings.GetEntries() << " " << flush;
+    */
+
     if (printl)
         leds.Print();
Index: /trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7790)
@@ -1537,5 +1537,5 @@
 
         // This is the full qualified date which is part of the name
-        const TString clock = time.GetStringFmt("%y%m%d_%H%M%S");
+        const TString clock = time.GetStringFmt("%Y%m%d_%H%M%S");
 
         // This gives the night in which the date belongs to
Index: /trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7790)
@@ -13,4 +13,6 @@
 #include <TSystem.h>
 #include <TFile.h> // temp writeout of histos
+#include <TSocket.h>
+
 #include "MAstro.h"
 #include "MString.h"
@@ -31,4 +33,5 @@
 
 #include "MGStarg.h" 
+#include "MGNumStars.h"
 #include "TGFrame.h"
 
@@ -90,4 +93,5 @@
     IDM_kPixSize,
     IDM_kAngle,
+    IDM_kCut,
     IDM_kInterpol250,
     IDM_kInterpol125,
@@ -126,4 +130,5 @@
 
     fGStarg->Update(fPos, fD);   
+    fGNumStars->Update(fNumStarsDetected, fNumStarsCorrelated);
  
     return kTRUE;
@@ -237,9 +242,9 @@
     fLimMag->AddEntry("8", IDM_kLimMag8);
     fLimMag->AddEntry("9", IDM_kLimMag9);
-    fLimMag->CheckEntry(IDM_kLimMag8);
+    fLimMag->CheckEntry(IDM_kLimMag9);
     fLimMag->Associate(this);
     fList->Add(fLimMag);
 
-    fSao->SetLimitMag(7.0);
+    fSao->SetLimitMag(9.0);
 
     fInterpol = new MGPopupMenu(p);
@@ -305,5 +310,4 @@
     fMenu->AddPopup("&WritePics",  fWritePictures,   NULL);
     fMenu->AddPopup("&Setup",      fSetup,           NULL);
-
     fMenu->AddPopup("&Operations", fOperations,      NULL);
 
@@ -327,4 +331,6 @@
 
     fGStarg = new MGStarg(this, 235);
+    fGStarg->DrawText("0.75'", "1.50'", "3.00'", "Misspointing [min]");
+    fGStarg->DrawHexagon();
     fGStarg->Move(530,596+5);
     fList->Add(fGStarg);
@@ -335,26 +341,31 @@
     fList->Add(fCRaDec);
 
-    fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+20-4);
+    fCZdAz = new MGCoordinates(this, kETypeZdAz, 2);
+    fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+597);
     AddFrame(fCZdAz);
     fList->Add(fCZdAz);
 
-    fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*20-4);
+    fPZdAz = new MGCoordinates(this, kETypeZdAz, 2);
+    fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+640);
     AddFrame(fPZdAz);
     fList->Add(fPZdAz);
 
-    fDZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*20-4);
+    fDZdAz = new MGCoordinates(this, kETypeZdAz, 2);
+    fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+683);
     AddFrame(fDZdAz);
     fList->Add(fDZdAz);
 
-    fSZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*20-4);
+    fSZdAz = new MGCoordinates(this, kETypeZdAz, 2);
+    fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+795);
     AddFrame(fSZdAz);
     fList->Add(fSZdAz);
 
+    fGNumStars = new MGNumStars(this, 235);
+    fGNumStars->DrawText("Number of stars");
+    fGNumStars->Move(278, fMenu->GetDefaultHeight()+713);
+    fList->Add(fGNumStars);
+
     fTPoint = new TGTextButton(this, "TPoint");
-    fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*15+15);
+    fTPoint->Move(4, fMenu->GetDefaultHeight()+785);
     fTPoint->AllowStayDown(kTRUE);
     AddFrame(fTPoint);
@@ -362,5 +373,5 @@
 
     fStargTPoint = new TGTextButton(this, "StargTPoint");
-    fStargTPoint->Move(240+12+28, fMenu->GetDefaultHeight()+785);
+    fStargTPoint->Move(170, fMenu->GetDefaultHeight()+785);
     fStargTPoint->AllowStayDown(kTRUE);
     AddFrame(fStargTPoint);
@@ -369,5 +380,5 @@
     fFps = new TGLabel(this, "---fps");
     fFps->SetTextJustify(kTextRight);
-    fFps->Move(650-495, fMenu->GetDefaultHeight()+619+13+60+20+2);
+    fFps->Move(650-495, fMenu->GetDefaultHeight()+714+23);
     AddFrame(fFps);
     fList->Add(fFps);
@@ -385,17 +396,23 @@
     fList->Add(fSkyBright);
 
-    TGLabel *l = new TGLabel(this, "arcsec/pix");
+    TGLabel *l = new TGLabel(this, "deg");
     l->SetTextJustify(kTextLeft);
-    l->Move(606-412, fMenu->GetDefaultHeight()+619+13+60);
+    l->Move(606-412, fMenu->GetDefaultHeight()+669);
     AddFrame(l);
     fList->Add(l);
 
-    l = new TGLabel(this, "deg");
+    l = new TGLabel(this, "arcsec/pix");
     l->SetTextJustify(kTextLeft);
-    l->Move(606-412, fMenu->GetDefaultHeight()+619-10+60);
+    l->Move(606-412, fMenu->GetDefaultHeight()+692);
     AddFrame(l);
     fList->Add(l);
 
-    l = new TGLabel(this, "Telescope pointing at");
+    l = new TGLabel(this, "sigma");
+    l->SetTextJustify(kTextLeft);
+    l->Move(606-412, fMenu->GetDefaultHeight()+715);
+    AddFrame(l);
+    fList->Add(l);
+
+    l = new TGLabel(this, "Zd/Az telescope pointing at");
     l->SetTextJustify(kTextLeft);
     l->Move(240+12+20+7, fMenu->GetDefaultHeight()+584-5);
@@ -403,13 +420,13 @@
     fList->Add(l);
 
-    l = new TGLabel(this, "Starguider position");
+    l = new TGLabel(this, "Zd/Az starguider pointing at");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5);
+    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5-23);
     AddFrame(l);
     fList->Add(l);
 
-    l = new TGLabel(this, "Misspointing");
+    l = new TGLabel(this, "Zd/Az misspointing");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5);
+    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5-46);
     AddFrame(l);
     fList->Add(l);
@@ -422,5 +439,19 @@
     fList->Add(l);
 #endif
+
+    // Set input box for rotation angle
+    const Double_t angle = -0.4;
+    fSao->SetRotationAngle(angle);
     
+    TString txt;
+    txt += angle;
+
+    fAngle = new TGTextEntry(this, txt, IDM_kAngle);
+    fAngle->SetAlignment(kTextCenterX);
+    fAngle->Move(547-410, fMenu->GetDefaultHeight()+667);
+    AddFrame(fAngle);
+    fList->Add(fAngle);
+
+    // Set input box for pixel size
     const Double_t pixsize = 48.8; // used to be 23.4
 
@@ -428,24 +459,24 @@
     fSao->SetRotationAngle(0);
 
-    TString txt;
+    txt = "";
     txt += pixsize;
 
     fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
     fPixSize->SetAlignment(kTextCenterX);
-    fPixSize->Move(547-410, fMenu->GetDefaultHeight()+617+13+60);
+    fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690);
     AddFrame(fPixSize);
     fList->Add(fPixSize);
 
-    const Double_t angle = -0.4;
-    fSao->SetRotationAngle(angle);
+    // Set input box for cleaning cut
+    const Double_t cut = 3.0;
 
     txt = "";
-    txt += angle;
-
-    fAngle = new TGTextEntry(this, txt, IDM_kAngle);
-    fAngle->SetAlignment(kTextCenterX);
-    fAngle->Move(547-410, fMenu->GetDefaultHeight()+617-10+60);
-    AddFrame(fAngle);
-    fList->Add(fAngle);
+    txt += cut;
+
+    fCut = new TGTextEntry(this, txt, IDM_kCut);
+    fCut->SetAlignment(kTextCenterX);
+    fCut->Move(547-410, fMenu->GetDefaultHeight()+713);
+    AddFrame(fCut);
+    fList->Add(fCut);
 
     // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
@@ -467,4 +498,8 @@
     fList->Add(fImage);
 
+    const Int_t w = 768;
+    const Int_t h = 840;
+    SetWMSizeHints(w, h, w, h, 1, 1);  // set the smallest and biggest size of the Main frame
+
     //
     // Make everything visible
@@ -477,4 +512,5 @@
     fStargTPoint->UnmapWindow();
     fGStarg->UnmapWindow();
+    fGNumStars->UnmapWindow();
     fPZdAz->UnmapWindow();
     fDZdAz->UnmapWindow();
@@ -503,6 +539,7 @@
       fStatus(MDriveCom::kStandby)
 {
-    
     cout << " #### FIXME: Make MCaos Thread safe!" << endl;
+
+    fAmcSocket = new TSocket("amc", 7307);
 
     fSao = new StarCatalog(obs);
@@ -573,5 +610,30 @@
         delete fOutRq;
 
+    delete fAmcSocket;
+
     cout << "Camera Display destroyed." << endl;
+}
+
+bool MStarguider::SendAmcTrigger(const char *msg)
+{
+    if (!fAmcSocket->IsValid())
+        return false;
+
+    TString txt("TRIGGER ");
+    txt += msg;
+
+    const Int_t len = fAmcSocket->SendRaw(txt.Data(), txt.Length());
+    if (len<0)
+    {
+        cout << "ERROR - Sending Trigger to Amc" << endl;
+        return false;
+    }
+    if (len!=txt.Length())
+    {
+        cout << "Send wrong number (" << len << ") of Bytes to Amc." << endl;
+        return false;
+    }
+
+    return true;
 }
 
@@ -648,4 +710,5 @@
         fDisplay->CheckEntry(IDM_kCatalog);
         fGStarg->MapWindow();
+        fGNumStars->MapWindow();
 
         const Int_t ch0 =
@@ -682,4 +745,5 @@
         fSkyBright->UnmapWindow();
         fGStarg->UnmapWindow();
+        fGNumStars->UnmapWindow();
 
         fChannel->EnableEntry(IDM_kChannel2);
@@ -730,4 +794,5 @@
     fStargTPoint->UnmapWindow();
     fGStarg->UnmapWindow();
+    fGNumStars->UnmapWindow();
     fPZdAz->UnmapWindow();
     fDZdAz->UnmapWindow();
@@ -757,4 +822,10 @@
                     cout << "Rotation Angle changed to " << angle << "deg" << endl;
                     fSao->SetRotationAngle(angle);
+                    return kTRUE;
+                }
+            case IDM_kCut:
+                {
+                    const Float_t cut = atof(fCut->GetText());
+                    cout << "Starguider cleaning level changed to " << cut << " sigma." << endl;
                     return kTRUE;
                 }
@@ -1292,5 +1363,13 @@
                                      ZdAz &d, MTime &t, double &bright, Int_t &num)
 {
-    const Int_t max = leds.GetEntries();
+    num = leds.GetEntries();
+    if (num < 3) //was 1
+    {
+        cout << "Sorry, less than 3 detected spot in FOV!" << endl;
+        if (fStargTPoint->IsDown())
+            fStargTPoint->SetDown(kFALSE);
+        return 0;
+    }
+
     if (stars.GetRealEntries() < 3)
     {
@@ -1300,11 +1379,4 @@
         return 0;
     }
-    if (max < 3) //was 1
-    {
-        cout << "Sorry, less than 3 detected spot in FOV!" << endl;
-        if (fStargTPoint->IsDown())
-            fStargTPoint->SetDown(kFALSE);
-        return 0;
-    }
 
     stars.Sort(); // Sort by magnitude
@@ -1320,11 +1392,9 @@
     TArrayF x, y, mag;
 
-    num = 0;
-
     // FIXME: Is predefined value 3 a good idea?
 
     MStar *star;
     MStarListIter NextStar(&stars);
-    while ((star=NextStar()) && num++<max+3) 
+    while ((star=NextStar()))
     {
         TIter NextSp(&leds);
@@ -1441,5 +1511,5 @@
     *fOutStargTp << " " << d.Zd() << " " << d.Az();
     *fOutStargTp << " " << setprecision(11) << t.GetMjd();
-    *fOutStargTp << " " << max;
+    *fOutStargTp << " " << num;
     *fOutStargTp << " " << bright;
     *fOutStargTp << endl;
@@ -1536,5 +1606,8 @@
 #endif
 
-    // Convert from Pixel to millimeter (1pix=2.9mm)
+    // MAKE SURE THAT THIS VALUE CAN BE SETUP
+    // (Scalefactor describes the difference between the tpoint (=1)
+    //  and the starguider (!=1) camera
+    // Convert from Pixel to millimeter (1pix=2.6mm)
     x *= (2.58427 * scalefactor);
     y *= (2.58427 * scalefactor);
@@ -1544,5 +1617,5 @@
     y /= 1.0713;
 
-    // Calculate Offset
+    // Convert offset from camera plane into local ccordinates
     Double_t dzd, daz;
     ac.GetDiffZdAz(x, y, dzd, daz);
@@ -1719,5 +1792,9 @@
     // Find Star at Center---for Tpoint Procedure
     if (fDisplay->IsEntryChecked(IDM_kFindStar))
+    {
+        // SCALE FACTOR ASSUMED TO BE 70
         FindStar(f, f2, center, t, 3.5, 70);
+        SendAmcTrigger("TPoint");
+    }
 
     byte zimg[kZOOM*kZOOM];
@@ -1751,5 +1828,5 @@
             pos = fCosy->GetPointingPos();
 
-        sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 30, 3.0); // [px]
+        sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 19, 3.0); // [px]
 
         //const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
@@ -1775,4 +1852,6 @@
 #endif
             fSZdAz->SetCoordinates(star); // Misspointing found from Camera
+
+            SendAmcTrigger("Starguider");
         }
     }
@@ -1891,25 +1970,18 @@
 
 	// Next we evaluate the offset given by the LEDs. This we obtain
-	// in Zd/Az and add it to the tracking error.
+        // in Zd/Az and add it to the tracking error.
 	if (fDisplay->IsEntryChecked(IDM_kStarguider))
         {
+            const Float_t cut = atof(fCut->GetText());
+
   	    Leds spots;
   	    f.SetBox(230);
-	    f.SetCut(2.5);
+	    f.SetCut(cut);
 
             double bright;
   	    f.ExecuteAndMark(spots, 530, 292, bright);
 
-            MString txt;
- 	    txt.Print("Sky Brightness: %.1f", bright);
- 	    fSkyBright->SetText(txt);
-
-            const Bool_t brightnessisvalid = bright<1.75*fLastBright &&
-                bright>30 && bright<110;
-
-            fLastBright = bright;
-
             ULong_t color;
-	    gClient->GetColorByName("Green", color);    
+	    gClient->GetColorByName("Green", color);
             if (bright> 60)
                 gClient->GetColorByName("Yellow", color);
@@ -1920,4 +1992,13 @@
             fSkyBright->SetBackgroundColor(color);
 
+            MString txt;
+ 	    txt.Print("Sky Brightness: %.1f", bright);
+ 	    fSkyBright->SetText(txt);
+
+            const Bool_t brightnessisvalid = bright<1.75*fLastBright &&
+                bright>30 && bright<110;
+
+            fLastBright = bright;
+
             Int_t numstars = 0;
             const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars);
@@ -1934,4 +2015,7 @@
                                        fSao->GetZdAz(), sgcenter, /*sgcenterzdaz,*/
                                        star, bright, fPos, t);
+
+            fNumStarsDetected   = numstars;
+            fNumStarsCorrelated = rc;
 
             if (fCosy)
@@ -1945,14 +2029,20 @@
         } //kStarguider
 
-        if (centerisvalid)
+        if (centerisvalid && fNumStarsCorrelated>2)
         {
-            f2.DrawCircle(skycenter, 2.0, 0x0a);
-
-            f2.DrawCircle(skycenter, 7.4, 0x0a); //0.1deg
-
-            f2.DrawCircle(skycenter, 2.06*.5*74.0, 0x0a);
-            f2.DrawCircle(skycenter, 2.32*.5*74.0, 0x0a);
-            f2.DrawCircle(skycenter, 3.50*.5*74.0, 0x0a);
-            f2.DrawCircle(skycenter, 3.84*.5*74.0, 0x0a);
+            f2.DrawCircle(skycenter,   2.0,     0x0a);
+
+            const Double_t ap = fSao->GetPixSize()/3600; //[deg/pix]
+
+            f2.DrawCircle(skycenter,  0.10/ap, 0x0a); //0.1deg
+            f2.DrawHexagon(skycenter, 2.06/ap, 0x0a);
+            f2.DrawHexagon(skycenter, 3.50/ap, 0x0a);
+
+            /*
+             f2.DrawCircle(skycenter, 2.06*.5*74.0, 0x0a);
+             f2.DrawCircle(skycenter, 2.32*.5*74.0, 0x0a);
+             f2.DrawCircle(skycenter, 3.50*.5*74.0, 0x0a);
+             f2.DrawCircle(skycenter, 3.84*.5*74.0, 0x0a);
+             */
         }
 
Index: /trunk/MagicSoft/Cosy/main/MStarguider.h
===================================================================
--- /trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 7790)
@@ -20,4 +20,5 @@
 class TGButton;
 class TString;
+class TSocket;
 
 class TTimer;
@@ -38,4 +39,5 @@
 // class MStargLeds;
 class MStargHistograms;
+class MGNumStars;
 class MGStarg;
 class FilterLed;
@@ -56,4 +58,5 @@
 
     MGStarg       *fGStarg;
+    MGNumStars    *fGNumStars;
 
     MGPopupMenu   *fDisplay;
@@ -84,4 +87,5 @@
     TGTextEntry   *fPixSize;
     TGTextEntry   *fAngle;
+    TGTextEntry   *fCut;
 
     TGLabel       *fFps;
@@ -95,10 +99,13 @@
     ZdAz          fD;
     AltAz         fAltAzOffsetFromTp;
-    
+
+    Double_t fNumStarsDetected;
+    Double_t fNumStarsCorrelated;
+
     StarCatalog   *fSao;
     MCosy         *fCosy;
     MCaos         *fCaos;
     MCaos         *fStargCaos;
-    //    MStargLeds    *fStargLeds;
+    TSocket       *fAmcSocket;
     MStargHistograms *fStargHistograms;
     
@@ -145,4 +152,6 @@
     void InitGui(Int_t channel);
 
+    bool SendAmcTrigger(const char *msg);
+
     //void OpenFile();
 
Index: /trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
===================================================================
--- /trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 7790)
@@ -91,5 +91,5 @@
         return false;
 
-    const UInt_t len = fTxSocket->SendRaw(msg, strlen(msg));
+    const Int_t len = fTxSocket->SendRaw(msg, strlen(msg));
     if (len<0)
     {
@@ -97,5 +97,5 @@
         return false;
     }
-    if (len!=strlen(msg))
+    if (len!=(Int_t)strlen(msg))
     {
         cout << "Send wrong number (" << len << ") of Bytes." << endl;
Index: /trunk/MagicSoft/Cosy/videodev/FilterLed.cc
===================================================================
--- /trunk/MagicSoft/Cosy/videodev/FilterLed.cc	(revision 7789)
+++ /trunk/MagicSoft/Cosy/videodev/FilterLed.cc	(revision 7790)
@@ -45,4 +45,9 @@
 }
 
+void FilterLed::DrawHexagon(float cx, float cy, float r, byte col) const
+{
+    MGMap::DrawHexagon(fImg, 768, 576, cx, cy, r, col);
+}
+
 void FilterLed::DrawCircle(const Ring &l, byte col) const
 {
@@ -53,4 +58,9 @@
 {
     DrawCircle(l.GetX(), l.GetY(), r, col);
+}
+
+void FilterLed::DrawHexagon(const Ring &l, double r, byte col) const
+{
+    DrawHexagon(l.GetX(), l.GetY(), r, col);
 }
 
@@ -121,7 +131,7 @@
 }
 
-int FilterLed::GetMeanPositionCircle(const int x, const int y,
-				     const int box, float &mx, 
-				     float &my, unsigned int &sum) const
+int FilterLed::GetMeanPositionBox(const int x, const int y,
+                                  const int box, float &mx,
+                                  float &my, unsigned int &sum) const
 {
     //-------------------------------
@@ -188,10 +198,10 @@
 }
 
-int FilterLed::GetMeanPositionCircle(const int x, const int y, 
-				     const int box) const
+int FilterLed::GetMeanPositionBox(const int x, const int y,
+                                  const int box) const
 {
     float mx, my;
     unsigned int sum;
-    return GetMeanPositionCircle(x, y, box, mx, my, sum);
+    return GetMeanPositionBox(x, y, box, mx, my, sum);
 }
 
@@ -334,4 +344,113 @@
 }
 
+class ClusterFinder
+{
+private:
+    byte *fImg;
+
+    UInt_t fW;
+    UInt_t fH;
+
+    Int_t fX0;
+    Int_t fX1;
+
+    Int_t fY0;
+    Int_t fY1;
+
+    UInt_t fCount;
+    Float_t fSumX;
+    Float_t fSumY;
+
+    Float_t FindCluster(Int_t x, Int_t y)
+    {
+        // if edge is touched stop finding cluster
+        if (x<fX0 || x>=fX1 || y<fY0 || y>=fY1)
+            return -1;
+
+        if (fCount>999)
+            return -1;
+
+        // get the value
+        Float_t val = fImg[y*fW+x];
+
+        // if its empty we have found the border of the cluster
+        if (val==0)
+            return 0;
+
+        // mark the point as processed
+        fImg[y*fW+x] = 0;
+
+        fSumX += x*val; // sumx
+        fSumY += y*val; // sumy
+        fCount++;
+
+        Float_t rc[4];
+        rc[0] = FindCluster(x+1, y  );
+        rc[1] = FindCluster(x,   y+1);
+        rc[2] = FindCluster(x-1, y  );
+        rc[3] = FindCluster(x,   y-1);
+
+        for (int i=0; i<4; i++)
+        {
+            if (rc[i]<0) // check if edge is touched
+                return -1;
+
+            val += rc[i];
+        }
+
+        return val;
+    }
+public:
+    ClusterFinder(byte *img, UInt_t w, UInt_t h)
+    {
+        fW = w;
+        fH = h;
+
+        fImg = new byte[fW*fH];
+
+        memcpy(fImg, img, fW*fH);
+    }
+
+    ~ClusterFinder()
+    {
+        delete fImg;
+    }
+    void FindCluster(Leds &leds, Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0)
+    {
+        fX0 = x0;
+        fY0 = y0;
+        fX1 = x1==0?fW:x1;
+        fY1 = y1==0?fH:y1;
+
+        for (Int_t x=fX0; x<fX1; x++)
+            for (Int_t y=fY0; y<fY1; y++)
+            {
+                const byte &b = fImg[y*fW+x];
+                if (b==0)
+                    continue;
+
+                fCount = 0;
+                fSumX  = 0;
+                fSumY  = 0;
+
+                const Float_t mag = FindCluster(x, y);
+                if (fCount>999)
+                {
+                    cout << "ERROR - Spot with Size>999 detected..." << endl;
+                    return;
+                }
+
+                if (mag>0 && fCount>6)
+                {
+                    Float_t M = mag/0xff;
+                    if (M>0xf0)
+                        M=0xf0;
+
+                    leds.Add(fSumX/mag, fSumY/mag, 0, 0, 0xf0);
+                }
+            }
+        leds.Compress();
+    }
+};
 
 void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const
@@ -353,4 +472,57 @@
             byte &b = fImg[y*fW+x];
 
+            // Skip saturating pixels
+            if (b>0xf0)
+                continue;
+
+            sum += b;
+            sq  += b*b;
+        }
+
+    sum /= wx*hy;
+    sq  /= wx*hy;
+
+    bright=sum;
+
+    
+    // 254 because b<=max and not b<max
+    const double sdev = TMath::Sqrt(sq-sum*sum);
+    const byte   max  = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);
+
+    //
+    // clean image from noise
+    // (FIXME: A lookup table could accelerate things...
+    //
+    for (int x=x0; x<x1; x++)
+        for (int y=y0; y<y1; y++)
+        {
+            byte &b = fImg[y*fW+x];
+            if (b<=max)
+                b = 0;
+        }
+
+    ClusterFinder find(fImg, fW, fH);
+    find.FindCluster(leds, x0, y0, x1, y1);
+}
+
+/*
+void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const
+{
+    const int x0 = TMath::Max(xc-fBox, 0);
+    const int y0 = TMath::Max(yc-fBox, 0);
+    const int x1 = TMath::Min(xc+fBox, fW);
+    const int y1 = TMath::Min(yc+fBox, fH);
+
+    const int wx = x1-x0;
+    const int hy = y1-y0;
+
+    double sum = 0;
+    double sq  = 0;
+
+    for (int x=x0; x<x1; x++)
+        for (int y=y0; y<y1; y++)
+        {
+            byte &b = fImg[y*fW+x];
+
             sum += b;
             sq  += b*b;
@@ -387,7 +559,9 @@
     byte mag[maxpnt]; // (Use 'new' instead for big numbers!)
 
+    const int r = 5;
+
     int cnt = 0;
-    for (int x=x0; x<x1; x++)
-        for (int y=y0; y<y1; y++)
+    for (int x=x0+r; x<x1-r; x++)
+        for (int y=y0+r; y<y1-r; y++)
         {
             byte &b = fImg[y*fW+x];
@@ -395,5 +569,5 @@
                 continue;
 
-            const int ipos = GetMeanPosition(x, y, 5);
+            const int ipos = GetMeanPosition(x, y, r);
 
             int j;
@@ -402,6 +576,6 @@
                 if (pos[j]==ipos)
                 {
-                    if (mag[j] < 0xf0)
-                        mag[j] += 0x10;
+                    if (mag[j]<0xff)
+                        mag[j]++;  // how often found (area)
                     break;
                 }
@@ -411,5 +585,5 @@
 
             pos[cnt] = ipos;
-            mag[cnt] = 0x10;
+            mag[cnt] = 1;
 
             cnt++;
@@ -428,18 +602,18 @@
     for (int i=0; i<cnt; i++)
     {
-        if (mag[i]<=0x80) // 0xa0
+        if (mag[i]<=7)
             continue;
 
         Float_t mx, my;
         unsigned int sum;
-        GetMeanPosition(pos[i]%fW, pos[i]/fW, 5, mx, my, sum);
-
-        leds.Add(mx, my, 0, 0, mag[i]);
-    }
-
-    RemoveTwinsInterpol(leds, first, 5);
-}
-
-void FilterLed::FindStar(Leds &leds, int xc, int yc, bool circle) const
+        GetMeanPosition(pos[i]%fW, pos[i]/fW, r, mx, my, sum);
+
+        leds.Add(mx, my, 0, 0, 0);//mag[i]*10);
+    }
+
+    RemoveTwinsInterpol(leds, first, r);
+}
+*/
+void FilterLed::FindStar(Leds &leds, int xc, int yc, bool box) const
 {
     // fBox: radius of the inner (signal) box
@@ -535,5 +709,5 @@
     float mx, my;
     unsigned int mag;
-    int pos = circle ? GetMeanPositionCircle(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag);
+    int pos = box ? GetMeanPositionBox(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag);
 
     if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev)
Index: /trunk/MagicSoft/Cosy/videodev/FilterLed.h
===================================================================
--- /trunk/MagicSoft/Cosy/videodev/FilterLed.h	(revision 7789)
+++ /trunk/MagicSoft/Cosy/videodev/FilterLed.h	(revision 7790)
@@ -20,4 +20,7 @@
     float fCut;
 
+    Float_t FindCluster(int &cnt, float *sum, UInt_t x, UInt_t y,
+                        UInt_t x0, UInt_t y0, UInt_t x1, UInt_t y1) const;
+
     void GetMinMax(const int offset, byte *min, byte *max) const;
     int  GetMeanPosition(const int x, const int y, const int box) const;
@@ -25,9 +28,9 @@
 			 float &mx, float &my, unsigned int &sum) const;
 
-    int  GetMeanPositionCircle(const int x, const int y, 
-			       const int box) const;
-    int  GetMeanPositionCircle(const int x, const int y, 
-			       const int box, float &mx, float &my, 
-			       unsigned int &sum) const;
+    int  GetMeanPositionBox(const int x, const int y,
+                            const int box) const;
+    int  GetMeanPositionBox(const int x, const int y,
+                            const int box, float &mx, float &my,
+                            unsigned int &sum) const;
 
     void RemoveTwinsInterpol(Leds &leds, Int_t first, Double_t radius) const;
@@ -66,4 +69,6 @@
     void DrawCircle(const Ring &c, byte col=0x40) const;
     void DrawCircle(const Ring &c, double r, byte col) const;
+    void DrawHexagon(float cx, float cy, float r, byte col=0x40) const;
+    void DrawHexagon(const Ring &c, double r, byte col) const;
 
     ClassDef(FilterLed, 0)
