Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7792)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7794)
@@ -130,5 +130,6 @@
 
     fGStarg->Update(fPos, fD);   
-    fGNumStars->Update(fNumStarsDetected, fNumStarsCorrelated);
+    if (fDisplay->IsEntryChecked(IDM_kStarguider))
+        fGNumStars->Update(fNumStarsDetected, fNumStarsCorrelated);
  
     return kTRUE;
@@ -445,5 +446,5 @@
 
     // Set input box for rotation angle
-    const Double_t angle = -0.4;
+    const Double_t angle = -0.2;
     fSao->SetRotationAngle(angle);
     
@@ -458,8 +459,7 @@
 
     // Set input box for pixel size
-    const Double_t pixsize = 48.8; // used to be 23.4
+    const Double_t pixsize = 48.9; // used to be 23.4
 
     fSao->SetPixSize(pixsize);
-    fSao->SetRotationAngle(0);
 
     txt = "";
@@ -519,4 +519,5 @@
     fCRaDec->UnmapWindow();
     fCZdAz->UnmapWindow();
+    fCZdAzText->UnmapWindow();
     fPZdAz->UnmapWindow();
     fPZdAzText->UnmapWindow();
@@ -723,5 +724,4 @@
         fDisplay->CheckEntry(IDM_kCatalog);
         fCRaDec->MapWindow();
-        fCRaDecText-MapWindow();
         fCZdAz->MapWindow();
         fCZdAzText->MapWindow();
@@ -771,5 +771,4 @@
         //catalog
         fCRaDec->UnmapWindow();
-        fCRaDecText-UnmapWindow();
         fCZdAz->UnmapWindow();
         fCZdAzText->UnmapWindow();
@@ -1408,4 +1407,5 @@
 {
     num = leds.GetEntries();
+    //cout << "Num: " << num << endl;
     if (num < 3) //was 1
     {
@@ -1416,4 +1416,5 @@
     }
 
+    //cout << "Cat: " << stars.GetRealEntries() << endl;
     if (stars.GetRealEntries() < 3)
     {
@@ -1437,8 +1438,9 @@
 
     // FIXME: Is predefined value 3 a good idea?
+    Int_t cnt=0;
 
     MStar *star;
     MStarListIter NextStar(&stars);
-    while ((star=NextStar()))
+    while ((star=NextStar()) && cnt<num+5)
     {
         TIter NextSp(&leds);
@@ -1457,5 +1459,6 @@
             x.AddAt(dpos.X(), idx);
             y.AddAt(dpos.Y(), idx);
-            mag.AddAt(spot->GetMag()/star->GetMag(), idx);
+            mag.AddAt(log(spot->GetMag())/star->GetMag(), idx);
+
 #ifdef EXPERT
             if (fout)
@@ -1463,5 +1466,5 @@
                 fout << spot->GetX() << " "
                     << spot->GetY()  << " "
-                    << spot->GetMag()  << " "
+                    << -2.5*log(spot->GetMag())  << " "
                     << star->GetX() << " "
                     << star->GetY()  << " "
@@ -1471,4 +1474,5 @@
 #endif
         }
+        cnt++;
     }
 
@@ -1477,4 +1481,6 @@
     if (numcor<1)
         return 0;
+
+    //cout << "Cor: " << numcor << endl;
 
     fDZdAz->SetCoordinates(d);
@@ -1829,5 +1835,5 @@
         if (fCosy)
             pos = fCosy->GetPointingPos();
-        center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0);
+        center = fCaos->Run(img, printl, printr, pos, t, 19, 3.0);
 	cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl;
 
@@ -1835,5 +1841,6 @@
 
     // Find Star at Center---for Tpoint Procedure
-    if (fDisplay->IsEntryChecked(IDM_kFindStar))
+    if (fDisplay->IsEntryChecked(IDM_kFindStar) &&
+        center.GetX()>0 && center.GetY()>0)
     {
         // SCALE FACTOR ASSUMED TO BE 70
@@ -1888,5 +1895,6 @@
 	     << sgcenter.GetY()-293.6<< "pix" << endl; 	
 #endif
-        if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
+        if (fDisplay->IsEntryChecked(IDM_kStargFindStar) &&
+            sgcenter.GetX()>0 && sgcenter.GetY()>0)
         {
             star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
@@ -1972,11 +1980,11 @@
         MTime time(*tm);
 
-	XY xy = fCRaDec->GetCoordinates();
-	fRaDec->Set(xy.X()*360/24, xy.Y());
+	XY xy = fCRaDec->GetCoordinates();  //[h,  deg]
+	fRaDec->Set(xy.X()*360/24, xy.Y()); //[deg,deg]
 
 	UpdatePosZoom();
 
 	// Always call SetMjd first!
-  	fSao->SetPointing(time.GetMjd(), *fRaDec);
+        fSao->SetPointing(time.GetMjd(), *fRaDec);
   	fCZdAz->SetCoordinates(fSao->GetZdAz());
 
@@ -2048,5 +2056,5 @@
             const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars);
 
-            const Bool_t monitoring = brightnessisvalid && centerisvalid;
+            const Bool_t monitoring = brightnessisvalid && centerisvalid && fNumStarsCorrelated>2;
 
             fStatus = monitoring ? MDriveCom::kMonitoring : MDriveCom::kError;
@@ -2082,11 +2090,4 @@
             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);
-             */
         }
 
@@ -2094,5 +2095,6 @@
 
     // Draw Circles around center of Camera
-    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+    if (fDisplay->IsEntryChecked(IDM_kCaosFilter) &&
+        center.GetX()>0 && center.GetY()>0)
     {
         f2.DrawCircle(center, 0x0a);
@@ -2104,5 +2106,6 @@
     }
 
-    if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
+    if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter) &&
+        sgcenter.GetX()>0 && sgcenter.GetY()>0)
     {
         f2.DrawCircle(sgcenter, 0x0a);
@@ -2110,13 +2113,4 @@
                       fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
     }
-
-//      if (fDisplay->IsEntryChecked(IDM_kCatalog))
-//      {
-//          fSao->PaintImg(cimg, 768, 576);
-//          const float r = 60*60/fSao->GetPixSize();
-//  	f2.DrawCircle(0.5*r, 0x0a);
-//  	f2.DrawCircle(1.0*r, 0x0a);
-//  	f2.DrawCircle(1.5*r, 0x0a);
-//      }
 
     if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
