Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7338)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7614)
@@ -634,5 +634,5 @@
                 // open tpoint file
                 //
-                const TString name = GetFileName("tpoint/tpoint_%s.txt");
+                const TString name = GetFileName("tpoint/old-tpoint_%s.txt");
                 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl;
 
Index: trunk/MagicSoft/Cosy/main/MStargHistograms.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStargHistograms.cc	(revision 7338)
+++ trunk/MagicSoft/Cosy/main/MStargHistograms.cc	(revision 7614)
@@ -47,5 +47,5 @@
         }
 
-        TTree *tree = new TTree("Data", "Real CaOs Data");
+        TTree *tree = new TTree("Data", "Real Starg Data");
 
 
Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7338)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7614)
@@ -1,3 +1,3 @@
-#define EXPERT
+#undef EXPERT
 
 #include "MStarguider.h"
@@ -104,11 +104,10 @@
     IDM_kCaosWriteStop,
     IDM_kResetHistograms,
-    IDM_kStargHistograms,
     IDM_kStargAnalysis,
     IDM_kStargCaosFilter,
-    IDM_kStargLEDFilter,
     IDM_kStargFindStar,
-    IDM_kTPointAna,
-    IDM_kRoqueLampAna
+    IDM_kRoqueLampAna,
+    IDM_kStarguiderMode,
+    IDM_kTpointMode
 
 };
@@ -147,9 +146,8 @@
     fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
     fChannel->AddEntry("Read from File", IDM_kChannel3);
-    if (channel<0) {
-      fChannel->CheckEntry(IDM_kChannel3);
-    } else {
-      fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
-    }
+    if (channel<0)
+        fChannel->CheckEntry(IDM_kChannel3);
+    else
+        fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
     fChannel->Associate(this);
     fList->Add(fChannel);
@@ -161,16 +159,14 @@
     fDisplay->AddEntry("&Filter",      IDM_kFilter);
     fDisplay->AddEntry("Find &Star",   IDM_kFindStar);
-    fDisplay->AddEntry("C&aos Filter",  IDM_kCaosFilter);
+    fDisplay->AddEntry("C&aos Filter", IDM_kCaosFilter);
     fDisplay->AddEntry("SAO &Catalog", IDM_kCatalog);
     fDisplay->AddEntry("Stretch",      IDM_kStretch);
     fDisplay->AddSeparator();
-    fDisplay->AddEntry("Starguider",   IDM_kStarguider);
-    fDisplay->AddEntry("Starguider LED Filter",  IDM_kStargCaosFilter);
-    fDisplay->AddEntry("Starguider Find Star",   IDM_kStargFindStar);
-    fDisplay->AddEntry("Starguider Analysis",   IDM_kStargAnalysis);
+    fDisplay->AddEntry("Starguider",            IDM_kStarguider);
+    fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
+    fDisplay->AddEntry("Starguider Find Star",  IDM_kStargFindStar);
     fDisplay->AddSeparator();    
     if (channel>=0)
         fDisplay->AddPopup("&Input",   fChannel);
-    fDisplay->DisableEntry(IDM_kStargAnalysis);
     fDisplay->DisableEntry(IDM_kStargFindStar);
     fDisplay->CheckEntry(IDM_kStretch);
@@ -178,8 +174,14 @@
     fList->Add(fDisplay);
 
+    fMode = new MGPopupMenu(p);
+    fMode->AddEntry("Starguider",    IDM_kStarguiderMode);
+    fMode->AddEntry("Tpoint",        IDM_kTpointMode);
+    fMode->Associate(this);
+    fList->Add(fMode);
 
     fOperations = new MGPopupMenu(p);
-    fOperations->AddEntry("TPoint Analysis",     IDM_kTPointAna);
     fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
+    fOperations->AddEntry("Starguider Analysis",   IDM_kStargAnalysis);
+    fOperations->DisableEntry(IDM_kStargAnalysis);
     fOperations->Associate(this);
     fList->Add(fOperations);
@@ -298,4 +300,5 @@
     fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
     fMenu->AddPopup("&Display",    fDisplay,         NULL);
+    fMenu->AddPopup("&Mode",       fMode,            NULL);
     fMenu->AddPopup("&WritePics",  fWritePictures,   NULL);
     fMenu->AddPopup("&Setup",      fSetup,           NULL);
@@ -355,4 +358,10 @@
     AddFrame(fTPoint);
     fList->Add(fTPoint);
+
+    fStargTPoint = new TGTextButton(this, "StargTPoint");
+    fStargTPoint->Move(240+12+20, fMenu->GetDefaultHeight()+785);
+    fStargTPoint->AllowStayDown(kTRUE);
+    AddFrame(fStargTPoint);
+    fList->Add(fStargTPoint);
 
     fFps = new TGLabel(this, "---fps");
@@ -458,4 +467,5 @@
     MapSubwindows();
     fTPoint->UnmapWindow();
+    fStargTPoint->UnmapWindow();
     fGStarg->UnmapWindow();
     fPZdAz->UnmapWindow();
@@ -479,4 +489,5 @@
       fCosy(NULL), 
       fOutTp(0), 
+      fOutStargTp(0),
       fOutRq(0),
       fDx((768-kZOOM)/2), 
@@ -509,4 +520,7 @@
 
     fTime.Now();
+
+    fTimeFromTp.Set(1970,1,1);
+    fAltAzOffsetFromTp = AltAz(-1000,-1000);
                                              
     gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
@@ -538,8 +552,13 @@
     delete fStargHistograms;
     delete fSao;
-    delete fRaDec;    
+    delete fRaDec;
+    delete fTPoint;//
+    delete fStargTPoint;//
 
     if (fOutTp)
         delete fOutTp;
+
+    if (fOutStargTp)
+        delete fOutStargTp;
 
     if (fOutRq)
@@ -569,4 +588,140 @@
     else
         p->CheckEntry(id);
+}
+
+void MStarguider::ToggleStargAnalysis()
+{
+    if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
+        fStargHistograms->OpenFile();
+    else
+        fStargHistograms->CloseFile();
+}
+
+void MStarguider::ToggleFindStar()
+{
+    if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
+        fTPoint->MapWindow();
+    else
+    {
+        fTPoint->UnmapWindow();
+        fTPoint->SetDown(kFALSE);
+    }
+}
+
+void MStarguider::ToggleStarguider()
+{
+    if (fDisplay->IsEntryChecked(IDM_kStarguider))
+    {
+        fLastBright = 0xff;
+
+        if (!fChannel->IsEntryEnabled(IDM_kChannel1))
+            fChannel->EnableEntry(IDM_kChannel1);
+        if (fDisplay->IsEntryEnabled(IDM_kFindStar))
+            fDisplay->DisableEntry(IDM_kFindStar);
+        if (fDisplay->IsEntryEnabled(IDM_kCaosFilter))
+            fDisplay->DisableEntry(IDM_kCaosFilter);
+        if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+            fOperations->EnableEntry(IDM_kStargAnalysis);
+
+        fStargTPoint->MapWindow();
+
+        fPZdAz->MapWindow();
+        fDZdAz->MapWindow();
+        fSkyBright->MapWindow();
+
+        fSao->SetLimitMag(8.3);
+        fIntRate = 125;
+
+        if (!fDisplay->IsEntryChecked(IDM_kCatalog))
+            fDisplay->CheckEntry(IDM_kCatalog);
+        fGStarg->MapWindow();
+
+        const Int_t ch0 =
+            fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
+        const Int_t ch1 = 0;
+
+        if (ch0!=ch1)
+        {
+            delete fGetter;
+            usleep(150000); // FIX: Device or resource busy.
+            if (fChannel->IsEntryChecked(IDM_kChannel3))
+                fGetter=new PngReader(*this);
+            else
+            {
+                fGetter = new Camera(*this, ch1);
+                ((Camera*)fGetter)->Loop(0);
+            }
+        }
+
+        if (fChannel->IsEntryChecked(IDM_kChannel2))
+            fChannel->UnCheckEntry(IDM_kChannel2);
+        if (fChannel->IsEntryEnabled(IDM_kChannel2))
+            fChannel->DisableEntry(IDM_kChannel2);
+        if (!fChannel->IsEntryChecked(IDM_kChannel1))
+            fChannel->CheckEntry(IDM_kChannel1);
+
+    }
+    else
+    {
+
+        fStatus = MDriveCom::kStandby;
+
+        fStargTPoint->UnmapWindow();
+        fStargTPoint->SetDown(kFALSE);
+
+        fPZdAz->UnmapWindow();
+        fDZdAz->UnmapWindow();
+        fSkyBright->UnmapWindow();
+        fGStarg->UnmapWindow();
+        if (!fChannel->IsEntryEnabled(IDM_kChannel2))
+            fChannel->EnableEntry(IDM_kChannel2);
+        if (!fDisplay->IsEntryEnabled(IDM_kFindStar))
+            fDisplay->EnableEntry(IDM_kFindStar);
+        if (!fDisplay->IsEntryEnabled(IDM_kCaosFilter))
+            fDisplay->EnableEntry(IDM_kCaosFilter);
+        if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+            fOperations->DisableEntry(IDM_kStargAnalysis);
+    }
+    gSystem->Unlink("tracking_error.txt");
+}
+
+void MStarguider::ToggleCaosFilter()
+{
+    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+    {
+        if (!fMode->IsEntryChecked(IDM_kStarguiderMode)
+            && !fMode->IsEntryChecked(IDM_kTpointMode))
+            fMenu->AddPopup("&CaOs", fCaOs, NULL);
+    }
+    else
+    {
+        if (fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
+            fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
+        if (fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
+            fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
+        if (fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
+        {
+            fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
+            fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
+            fCaos->DeleteHistograms();
+        }
+        if (fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
+        {
+            fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
+            fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
+            fCaos->CloseFile();
+        }
+        fMenu->RemovePopup("CaOs");
+    }
+    fMenu->Resize(fMenu->GetDefaultSize());
+    MapSubwindows(); // maps everything, but we don't want that
+    fTPoint->UnmapWindow();
+    fStargTPoint->UnmapWindow();
+    fGStarg->UnmapWindow();
+    fPZdAz->UnmapWindow();
+    fDZdAz->UnmapWindow();
+    fSZdAz->UnmapWindow();
+    fSkyBright->UnmapWindow();
+    MapWindow();
 }
 
@@ -616,96 +771,242 @@
   	        Toggle(fOperations, IDM_kRoqueLampAna);
 		//		if (!fDisplay->IsEntryChecked(IDM_kCatalog))
-		if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
-		  fDisplay->CheckEntry(IDM_kStargCaosFilter);
-		}
-		else {
-		  fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
-		}
+                if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+                    fDisplay->CheckEntry(IDM_kStargCaosFilter);
+                else
+                    fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
 		  
 		return kTRUE;
 
-
            case IDM_kStargFindStar:
 	        Toggle(fDisplay, IDM_kStargFindStar);         
-	        if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
-		    fSZdAz->MapWindow();
-		} else {
-		    fSZdAz->UnmapWindow();
-		}
+                if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
+                    fSZdAz->MapWindow();
+                else
+                    fSZdAz->UnmapWindow();
                 return kTRUE;
 
             case IDM_kStarguider:
                 Toggle(fDisplay, IDM_kStarguider);
-
-		if (fDisplay->IsEntryChecked(IDM_kStarguider)) {	
-
-  		    fLastBright = 0xff;
-
-		    fDisplay->DisableEntry(IDM_kFindStar);
-		    fDisplay->EnableEntry(IDM_kStargAnalysis);		  
-		    
-		    fPZdAz->MapWindow();
-		    fDZdAz->MapWindow();
-		    fSkyBright->MapWindow();
-
-		    fSao->SetLimitMag(8.3);
-		    fIntRate = 125;
-
-		    fDisplay->CheckEntry(IDM_kCatalog);
-		    fGStarg->MapWindow();
-
-		    const Int_t ch0 = 
-		      fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
-		    const Int_t ch1 = 0;
-		    
-		    if (ch0!=ch1)
-		      {
-			delete fGetter;
-			usleep(150000); // FIX: Device or resource busy.
-			if (fChannel->IsEntryChecked(IDM_kChannel3)) {
-			  fGetter=new PngReader(*this);
-			} else {		      
-			  fGetter = new Camera(*this, ch1);
-			  ((Camera*)fGetter)->Loop(0);
-			}
-		      }
-
-		    fChannel->CheckEntry(IDM_kChannel1);
-		    fChannel->UnCheckEntry(IDM_kChannel2);
-		    fChannel->DisableEntry(IDM_kChannel2);
-
-		} else {
-
-		    fStatus = MDriveCom::kStandby;
-		
-		    fPZdAz->UnmapWindow();
-		    fDZdAz->UnmapWindow();
-		    fSkyBright->UnmapWindow();
-		    fGStarg->UnmapWindow();		
-		    fChannel->EnableEntry(IDM_kChannel2);
-		    fDisplay->EnableEntry(IDM_kFindStar);
-		    fDisplay->DisableEntry(IDM_kStargAnalysis);		    
-		}
-
-                gSystem->Unlink("tracking_error.txt");
-
+                ToggleStarguider();
                 return kTRUE;
 
             case IDM_kStargAnalysis:
-                Toggle(fDisplay, IDM_kStargAnalysis);
-		if (fDisplay->IsEntryChecked(IDM_kStargAnalysis)) {
-		    fStargHistograms->OpenFile();
-		} else {
-		    fStargHistograms->CloseFile();
-		}
-
-                return kTRUE;
-
-            case IDM_kStargHistograms:
-                Toggle(fDisplay, IDM_kStargHistograms);
-                return kTRUE;
-
-            case IDM_kStargLEDFilter:
-                Toggle(fDisplay, IDM_kStargLEDFilter);
+                Toggle(fOperations, IDM_kStargAnalysis);
+                ToggleStargAnalysis();
+                return kTRUE;
+
+            case IDM_kStarguiderMode:
+                Toggle(fMode, IDM_kStarguiderMode);
+
+                if (fMode->IsEntryChecked(IDM_kStarguiderMode))
+                {
+
+                    //uncheck not needed items
+                    //general
+                    if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
+                        fDisplay->UnCheckEntry(IDM_kStargFindStar);
+
+                    if (fDisplay->IsEntryChecked(IDM_kFilter))
+                        fDisplay->UnCheckEntry(IDM_kFilter);
+                    if (fDisplay->IsEntryEnabled(IDM_kFilter))
+                        fDisplay->DisableEntry(IDM_kFilter);
+
+                    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+                        fOperations->UnCheckEntry(IDM_kRoqueLampAna);
+                    if (fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
+                        fOperations->DisableEntry(IDM_kRoqueLampAna);
+
+                    if (fChannel->IsEntryChecked(IDM_kChannel3))
+                        fChannel->UnCheckEntry(IDM_kChannel3);
+                    if (fChannel->IsEntryEnabled(IDM_kChannel3))
+                        fChannel->DisableEntry(IDM_kChannel3);
+
+                    //tpoint
+                    if (fDisplay->IsEntryChecked(IDM_kFindStar))
+                        fDisplay->UnCheckEntry(IDM_kFindStar);
+                    ToggleFindStar();
+
+                    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+                        fDisplay->UnCheckEntry(IDM_kCaosFilter);
+                    ToggleCaosFilter();
+
+                    if (fMode->IsEntryChecked(IDM_kTpointMode))
+                        fMode->UnCheckEntry(IDM_kTpointMode);
+
+                    //enable starguider items
+//                    if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+//                        fOperations->EnableEntry(IDM_kStargAnalysis);
+                    if (!fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
+                        fDisplay->EnableEntry(IDM_kStargCaosFilter);
+                    if (!fDisplay->IsEntryEnabled(IDM_kStarguider))
+                        fDisplay->EnableEntry(IDM_kStarguider);
+                    if (!fDisplay->IsEntryEnabled(IDM_kCatalog))
+                        fDisplay->EnableEntry(IDM_kCatalog);
+
+                    //check needed items
+                    if (!fDisplay->IsEntryChecked(IDM_kStretch))
+                        fDisplay->CheckEntry(IDM_kStretch);
+
+                    if (!fDisplay->IsEntryChecked(IDM_kStarguider))
+                        fDisplay->CheckEntry(IDM_kStarguider);
+                    ToggleStarguider();
+
+                    if (!fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
+                        fDisplay->CheckEntry(IDM_kStargCaosFilter);
+
+//                    if (!fOperations->IsEntryChecked(IDM_kStargAnalysis))
+//                        fOperations->CheckEntry(IDM_kStargAnalysis);
+//                    ToggleStargAnalysis();
+                    if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
+                        fOperations->UnCheckEntry(IDM_kStargAnalysis);
+                    if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+                        fOperations->DisableEntry(IDM_kStargAnalysis);
+
+
+                }
+                else
+                {
+                    //uncheck starguider items
+//                    if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
+//                        fOperations->UnCheckEntry(IDM_kStargAnalysis);
+//                    ToggleStargAnalysis();
+
+                    if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
+                        fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
+
+                    if (fDisplay->IsEntryChecked(IDM_kStarguider))
+                        fDisplay->UnCheckEntry(IDM_kStarguider);
+                    ToggleStarguider();
+
+                    if (fDisplay->IsEntryChecked(IDM_kCatalog))
+                        fDisplay->UnCheckEntry(IDM_kCatalog);
+
+                    if (!fChannel->IsEntryEnabled(IDM_kChannel3))
+                        fChannel->EnableEntry(IDM_kChannel3);
+
+                    if (!fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
+                        fOperations->EnableEntry(IDM_kRoqueLampAna);
+
+                    if (!fDisplay->IsEntryEnabled(IDM_kFilter))
+                        fDisplay->EnableEntry(IDM_kFilter);
+
+                }
+                return kTRUE;
+
+            case IDM_kTpointMode:
+                Toggle(fMode, IDM_kTpointMode);
+
+                if (fMode->IsEntryChecked(IDM_kTpointMode))
+                {
+                    //unchecking not needed items
+                    //general
+                    if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
+                        fDisplay->UnCheckEntry(IDM_kStargFindStar);
+
+                    if (fDisplay->IsEntryChecked(IDM_kFilter))
+                        fDisplay->UnCheckEntry(IDM_kFilter);
+                    if (fDisplay->IsEntryEnabled(IDM_kFilter))
+                        fDisplay->DisableEntry(IDM_kFilter);
+
+                    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+                        fOperations->UnCheckEntry(IDM_kRoqueLampAna);
+                    if (fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
+                        fOperations->DisableEntry(IDM_kRoqueLampAna);
+
+                    if (fChannel->IsEntryChecked(IDM_kChannel3))
+                        fChannel->UnCheckEntry(IDM_kChannel3);
+                    if (fChannel->IsEntryEnabled(IDM_kChannel3))
+                        fChannel->DisableEntry(IDM_kChannel3);
+
+                    //from starguider
+                    if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
+                        fOperations->UnCheckEntry(IDM_kStargAnalysis);
+                    ToggleStargAnalysis();
+                    if (fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+                        fOperations->DisableEntry(IDM_kStargAnalysis);
+
+                    if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
+                        fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
+                    if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
+                        fDisplay->DisableEntry(IDM_kStargCaosFilter);
+
+                    if (fDisplay->IsEntryChecked(IDM_kStarguider))
+                        fDisplay->UnCheckEntry(IDM_kStarguider);
+                    ToggleStarguider();
+                    if (fDisplay->IsEntryEnabled(IDM_kStarguider))
+                        fDisplay->DisableEntry(IDM_kStarguider);
+
+                    if (fDisplay->IsEntryChecked(IDM_kCatalog))
+                        fDisplay->UnCheckEntry(IDM_kCatalog);
+                    if (fDisplay->IsEntryEnabled(IDM_kCatalog))
+                        fDisplay->DisableEntry(IDM_kCatalog);
+
+                    if (fMode->IsEntryChecked(IDM_kStarguiderMode))
+                        fMode->UnCheckEntry(IDM_kStarguiderMode);
+
+                    //switch camera
+                    const Int_t ch0 =
+                        fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
+                    const Int_t ch1 = 1;
+
+                    if (ch0!=ch1)
+                    {
+                        delete fGetter;
+                        usleep(150000); // FIX: Device or resource busy.
+                        fGetter = new Camera(*this, ch1);
+                        ((Camera*)fGetter)->Loop(0);
+                    }
+
+                    if (fChannel->IsEntryChecked(IDM_kChannel1))
+                        fChannel->UnCheckEntry(IDM_kChannel1);
+                    if (fChannel->IsEntryEnabled(IDM_kChannel1))
+                        fChannel->DisableEntry(IDM_kChannel1);
+                    if (!fChannel->IsEntryChecked(IDM_kChannel2))
+                        fChannel->CheckEntry(IDM_kChannel2);
+
+                    //checking needed items
+                    if (!fDisplay->IsEntryChecked(IDM_kStretch))
+                        fDisplay->CheckEntry(IDM_kStretch);
+
+                    if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
+                        fDisplay->CheckEntry(IDM_kCaosFilter);
+                    ToggleCaosFilter();
+
+                    if (!fDisplay->IsEntryChecked(IDM_kFindStar))
+                        fDisplay->CheckEntry(IDM_kFindStar);
+                    ToggleFindStar();
+
+                }
+                else
+                {
+                    //enable starguider items
+                    if (!fOperations->IsEntryEnabled(IDM_kStargAnalysis))
+                        fOperations->EnableEntry(IDM_kStargAnalysis);
+                    if (!fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
+                        fDisplay->EnableEntry(IDM_kStargCaosFilter);
+                    if (!fDisplay->IsEntryEnabled(IDM_kStarguider))
+                        fDisplay->EnableEntry(IDM_kStarguider);
+                    if (!fDisplay->IsEntryEnabled(IDM_kCatalog))
+                        fDisplay->EnableEntry(IDM_kCatalog);
+
+                    if (!fDisplay->IsEntryEnabled(IDM_kFilter))
+                        fDisplay->EnableEntry(IDM_kFilter);
+                    if (!fOperations->IsEntryEnabled(IDM_kRoqueLampAna))
+                        fOperations->EnableEntry(IDM_kRoqueLampAna);
+                    if (!fChannel->IsEntryEnabled(IDM_kChannel3))
+                        fChannel->EnableEntry(IDM_kChannel3);
+
+                    if (fDisplay->IsEntryChecked(IDM_kFindStar))
+                        fDisplay->UnCheckEntry(IDM_kFindStar);
+                    ToggleFindStar();
+
+                    if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
+                        fDisplay->UnCheckEntry(IDM_kCaosFilter);
+                    ToggleCaosFilter();
+
+                    if (!fChannel->IsEntryEnabled(IDM_kChannel1))
+                        fChannel->EnableEntry(IDM_kChannel1);
+
+                }
                 return kTRUE;
 
@@ -727,11 +1028,5 @@
             case IDM_kFindStar:
                 Toggle(fDisplay, IDM_kFindStar);
-                if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
-                    fTPoint->MapWindow();
-                else
-                {
-                    fTPoint->UnmapWindow();
-                    fTPoint->SetDown(kFALSE);
-                }
+                ToggleFindStar();
                 return kTRUE;
 
@@ -744,46 +1039,14 @@
                 //    fCaos->OpenFile();
                 Toggle(fDisplay, IDM_kCaosFilter);
-                if (fDisplay->IsEntryChecked(IDM_kCaosFilter)) {
-                    fMenu->AddPopup("&CaOs", fCaOs, NULL);
-		}
-                else
-                {
-                    if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
-                        fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
-                    if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
-                        fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
-                    if(fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
-                    {
-                        fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
-                        fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
-                        fCaos->DeleteHistograms();
-                    }
-                    if(fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
-                    {
-                        fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
-                        fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
-                        fCaos->CloseFile();
-                    }
-                    fMenu->RemovePopup("CaOs");
-                }
-                fMenu->Resize(fMenu->GetDefaultSize());
-                MapSubwindows(); // maps everything, but we don't want that
-		fTPoint->UnmapWindow(); 
-		fGStarg->UnmapWindow();
-		fPZdAz->UnmapWindow();
-		fDZdAz->UnmapWindow();
-		fSZdAz->UnmapWindow();
-		fSkyBright->UnmapWindow();
-                MapWindow();
+                ToggleCaosFilter();
                 return kTRUE;
 
             case IDM_kStargCaosFilter:             
 		Toggle(fDisplay, IDM_kStargCaosFilter);                
-		if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter)) {
-		    fDisplay->EnableEntry(IDM_kStargFindStar);
-		} else {
-		    fDisplay->DisableEntry(IDM_kStargFindStar);
-		}
-		return kTRUE;
+                if (fDisplay->IsEntryEnabled(IDM_kStargCaosFilter))
+                    fDisplay->EnableEntry(IDM_kStargFindStar);
+                else
+                    fDisplay->DisableEntry(IDM_kStargFindStar);
+                return kTRUE;
 
             case IDM_kCaosPrintLeds:
@@ -899,10 +1162,10 @@
                     usleep(150000); // FIX: Device or resource busy.
 		    if (fChannel->IsEntryChecked(IDM_kChannel3))
-		      fGetter=new PngReader(*this);
-		    else
-		      {
-			fGetter = new Camera(*this, ch1);
-			((Camera*)fGetter)->Loop(0);
-		      }
+                        fGetter=new PngReader(*this);
+                    else
+                    {
+                        fGetter = new Camera(*this, ch1);
+                        ((Camera*)fGetter)->Loop(0);
+                    }
                 }
                 return kTRUE;
@@ -988,5 +1251,8 @@
     // chose a bit coarser binning to enhance excess 
     // important: chose binning symmetrical around (0|0)!
-    TH2F h("Hist", "dX/dY", 49, -768/2-8, 768/2+8, 37, -576/2-8, 576/2+8); // 3
+    //    TH2F h("Hist", "dX/dY", 49, -576/2-8, 576/2+8, 37, -576/2-8, 576/2+8); // 3
+    // reduced range in which histogram is filled, made bins a bit smaller
+    // 72pix equivalent to 0.6deg
+    TH2F h("Hist", "dX/dY", 7, -72, 72, 7, -72, 72);
 
 //     TH1F hmag("HistMag", "Mag", 19, 0, 100);
@@ -1010,8 +1276,8 @@
 
     const double xmax = h.GetXaxis()->GetBinCenter(mx);
-    const double dx   = h.GetXaxis()->GetBinWidth(mx);
+    const double dx   = h.GetXaxis()->GetBinWidth(mx)/2;
 
     const double ymax = h.GetYaxis()->GetBinCenter(my);
-    const double dy   = h.GetYaxis()->GetBinWidth(my);
+    const double dy   = h.GetYaxis()->GetBinWidth(my)/2;
 
 #ifdef EXPERT
@@ -1069,20 +1335,27 @@
 //	}
 
+    //deleting histogram and graph
+    h.Delete();
+    g.Delete();
     return ZdAz(-pos1.Alt(), pos1.Az());
 }
 
-bool MStarguider::CalcTrackingError(Leds &leds, MStarList &stars, ZdAz &d, MTime &t)
+bool MStarguider::CalcTrackingError(Leds &leds, MStarList &stars, ZdAz &d, MTime &t, double &bright)
 {
     const Int_t max = leds.GetEntries();
-      if (stars.GetRealEntries() < 3)
-      {
-          cout << "Sorry, less than 3 stars in FOV!" << endl;
-          return kFALSE;
-      }
-      if (max < 3) //was 1
-      {
-          cout << "Sorry, less than 3 detected spot in FOV!" << endl;	 
-          return kFALSE;	 
-      }
+    if (stars.GetRealEntries() < 3)
+    {
+        cout << "Sorry, less than 3 stars in FOV!" << endl;
+        if (fStargTPoint->IsDown())
+            fStargTPoint->SetDown(kFALSE);
+        return kFALSE;
+    }
+    if (max < 3) //was 1
+    {
+        cout << "Sorry, less than 3 detected spot in FOV!" << endl;
+        if (fStargTPoint->IsDown())
+            fStargTPoint->SetDown(kFALSE);
+        return kFALSE;
+    }
 
     stars.Sort(); // Sort by magnitude
@@ -1122,16 +1395,17 @@
             mag.AddAt(spot->GetMag()/star->GetMag(), idx);
 #ifdef EXPERT
-            if (fout) {
-		fout << spot->GetX() << " " 
-		     << spot->GetY()  << " " 
-		     << spot->GetMag()  << " " 
-		     << star->GetX() << " " 
-		     << star->GetY()  << " " 
-		     << star->GetMag()  << " ";
+            if (fout)
+            {
+                fout << spot->GetX() << " "
+                    << spot->GetY()  << " "
+                    << spot->GetMag()  << " "
+                    << star->GetX() << " "
+                    << star->GetY()  << " "
+                    << star->GetMag()  << " ";
                 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
-	    }
+            }
 #endif
         }
-    }  
+    }
 
     d = TrackingError(x, y, mag);
@@ -1154,5 +1428,73 @@
     fPZdAz->SetCoordinates(cpos);
 
-    return kTRUE; 
+
+    // Check StargTPoint data set request
+    if (!fStargTPoint->IsDown())
+        return kTRUE;
+    fStargTPoint->SetDown(kFALSE);
+
+    // If no file open: open new file
+    if (!fOutStargTp)
+    {
+        // open tpoint file
+        const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
+        cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
+
+        fOutStargTp = new ofstream(name);
+        *fOutStargTp << "Magic Model  STARGTPOINT data file" << endl;
+        *fOutStargTp << ": ALTAZ" << endl;
+        *fOutStargTp << "49 48 0 ";
+        *fOutStargTp << t << endl;
+    }
+
+    // Get tracking coordinates
+    const XY    xy = fCRaDec->GetCoordinates();
+    const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
+
+    // From the star position in the camera we calculate the Alt/Az
+    // position we are currently tracking (real pointing position)
+    fSao->SetMjd(t.GetMjd());
+    AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
+
+    //correction with offset from last tpoint measurement
+    za0 -= fAltAzOffsetFromTp;
+    MTime t2 = fTimeFromTp;
+
+    //if the difference between the tpoint and the starguider tpoint
+    //is too big, the starguider tpoint is not stored
+    cout << "     mjd difference: " << t.GetMjd()-t2.GetMjd() << endl;
+//        cout << "t: " << setprecision(11) << t.GetMjd() << endl;
+//        cout << "t2: " << setprecision(11) << t2.GetMjd() << endl;
+    if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec
+    {
+        cout << "time difference between tpoint and starguider-tpoint > " <<
+            t.GetMjd()-t2.GetMjd() << "s => starguider tpoint hasn't been stored. Please repeat whole procedure. " << endl;
+        return kTRUE;
+    }
+
+
+    // Write real pointing position
+    cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
+    *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
+
+    // Write system pointing position
+    cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
+    *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
+
+    *fOutStargTp << " " << xy.X() << " " << xy.Y();
+    *fOutStargTp << " " << d.Zd() << " " << d.Az();
+    *fOutStargTp << " " << setprecision(11) << t.GetMjd();
+    *fOutStargTp << " " << max;
+    *fOutStargTp << " " << bright;
+    *fOutStargTp << endl;
+
+
+
+
+
+
+    fTimeFromTp.Set(1970,1,1);
+
+    return kTRUE;
 
 }
@@ -1212,5 +1554,12 @@
     Led *star = (Led*)leds.At(0);
     if (!star)
+    {
+        if (fTPoint->IsDown())
+        {
+            fTPoint->SetDown(kFALSE);
+            cout << "No star found. Couldn't take a tpoint." << endl;
+        }
         return ZdAz(.0,.0);
+    }
 
     cout << "Found star @ " << flush;
@@ -1236,5 +1585,7 @@
     Double_t y = center.GetY()-star->GetY();
 
+#ifdef EXPERT
     cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix  dy=" << y << "pix" << endl;
+#endif
 
     // Convert from Pixel to millimeter (1pix=2.9mm)
@@ -1250,5 +1601,7 @@
     ac.GetDiffZdAz(x, y, dzd, daz);
 
+#ifdef EXPERT
     cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d  dAz=" << daz << "d" << endl;
+#endif
 
     ZdAz zdaz(dzd,daz);
@@ -1265,5 +1618,5 @@
         // open tpoint file
         //
-        const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
+        const TString name = MCosy::GetFileName("tpoint/tpoint_%s.txt");
         cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
 
@@ -1286,4 +1639,7 @@
     //ZdAz za0 = fSao->GetZdAz();
     za0 -= AltAz(-dzd, daz);
+    fAltAzOffsetFromTp = AltAz(-dzd, daz);
+    fTimeFromTp=t;
+
 
     // From the Shaftencoders we get the current 'pointing' position
@@ -1388,5 +1744,5 @@
         if (fFileType->IsEntryChecked(IDM_kPNG))
             Writer::Png("pix/file", img, tm, fCRaDec->GetCoordinates());
-	
+
         if (fFileType->IsEntryChecked(IDM_kPPM))
             Writer::Ppm("pix/file", img, tm, fCRaDec->GetCoordinates());
@@ -1419,5 +1775,4 @@
             pos = fCosy->GetPointingPos();
         center = fCaos->Run(img, printl, printr, pos, t, 50, 3.0);
-
 	cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << endl;
 
@@ -1453,11 +1808,11 @@
 
     if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
-    {    
+    {
         ZdAz pos;
         if (fCosy)
             pos = fCosy->GetPointingPos();
-        sgcenter = 
-	    fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 30, 3.0); // [px]
-	const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
+        sgcenter =
+            fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 30, 3.0); // [px]
+        const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
 
         // BE CAREFULL: This transformation is WRONG. It is just
@@ -1473,22 +1828,24 @@
 	     << sgcenter.GetY()-293.6<< "pix" << endl; 	
 #endif
-	if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
-	    star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
+        if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
+        {
+            star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
 #ifdef EXPERT
-	    cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az=" 
-		 << star.Az()*60 << "'" << endl;	    
+            cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az="
+                << star.Az()*60 << "'" << endl;
 #endif
-	    fSZdAz->SetCoordinates(star); // Misspointing found from Camera
-	}
+            fSZdAz->SetCoordinates(star); // Misspointing found from Camera
+        }
     }
 
 // Find Roque Lamp
 
-    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
-
-	XY roquelamp(0,0);
-
-	Double_t imageclean = 1.5;
-	Double_t boxradius = 60;
+    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+    {
+
+        XY roquelamp(0,0);
+
+        Double_t imageclean = 1.5;
+        Double_t boxradius = 60;
 	Double_t scalefactor = 1;
 	XY searchcenter(768/2-1,576/2+25);
@@ -1496,13 +1853,14 @@
 	roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
 
-	if (fOutRq) {
-	  ZdAz pos = fCosy->GetPointingPos();
-
-	  *fOutRq << "RoqueLampDirect:    " << MTime(-1) << "  " 
-	          << pos.Zd() << " " << pos.Az() << "   "
-		  << roquelamp.X() << " " << roquelamp.Y() << endl;
-	}
-
-	cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
+        if (fOutRq)
+        {
+            ZdAz pos = fCosy->GetPointingPos();
+
+            *fOutRq << "RoqueLampDirect:    " << MTime(-1) << "  "
+                << pos.Zd() << " " << pos.Az() << "   "
+                << roquelamp.X() << " " << roquelamp.Y() << endl;
+        }
+
+        cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
 	cout << ">=>=>=> Roque Lamp found at:         >=>=>=> (" << roquelamp.X() << "," 
 	     << roquelamp.Y() << ") <=<=<=<" << endl;
@@ -1512,9 +1870,9 @@
 // Find Spot on Camera Center in Starguider camera
 
-    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
-
-	XY cameraspot(0,0);
-
-	Double_t imageclean = 5;
+    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+    {
+        XY cameraspot(0,0);
+
+        Double_t imageclean = 5;
 	Double_t boxradius = 60;
 	Double_t scalefactor = 1;
@@ -1524,18 +1882,18 @@
 	cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
 
-	if (fOutRq) {
-	  ZdAz pos = fCosy->GetPointingPos();
-
-	  *fOutRq << "RoqueLampReflected: "  << MTime(-1) << "  "
-		  << pos.Zd() << " " << pos.Az() << "   "
-		  << cameraspot.X() << " " << cameraspot.Y() << endl;
-	}
-
-	cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << "," 
+        if (fOutRq)
+        {
+            ZdAz pos = fCosy->GetPointingPos();
+
+            *fOutRq << "RoqueLampReflected: "  << MTime(-1) << "  "
+                << pos.Zd() << " " << pos.Az() << "   "
+                << cameraspot.X() << " " << cameraspot.Y() << endl;
+        }
+
+        cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << ","
 	     << cameraspot.Y() << ") <<<<<" << endl;
 
         f2.DrawCircle(sgcenter, 5.0, 0x0fa);
         f2.DrawCircle(sgcenter, 115.0, 0x0fa);
-
     }
 
@@ -1556,6 +1914,6 @@
     if (fDisplay->IsEntryChecked(IDM_kCatalog))
     {
-	MTime time(*tm);
-	  
+        MTime time(*tm);
+
 	XY xy = fCRaDec->GetCoordinates();
 	fRaDec->Set(xy.X()*360/24, xy.Y());
@@ -1570,12 +1928,14 @@
     	fSao->SetBox(230); // Region of interest around center
 
-  	// very careful: If center of camera cannot be determined
+        // very careful: If center of camera cannot be determined
 	// sgcenter jumps to (0,0)  
 	double sgcenteroffsetX = 0.0;
 	double sgcenteroffsetY = 0.0;
-	if ((double)sgcenter.GetX() > 0.0 && (double)sgcenter.GetY() > 0.0) {
-	    sgcenteroffsetX = sgcenter.GetX()-53.2;
-	    sgcenteroffsetY = sgcenter.GetY()-293.6;
-	}
+        if ((double)sgcenter.GetX() > 0.0 && (double)sgcenter.GetY() > 0.0)
+        {
+            //Please never change this offsets!!!
+            sgcenteroffsetX = sgcenter.GetX()-53.2;
+            sgcenteroffsetY = sgcenter.GetY()-293.6;
+        }
 
     	// we obtain stars in the effective star FOV and draw them.
@@ -1600,5 +1960,5 @@
        
 	if (fDisplay->IsEntryChecked(IDM_kStarguider))
-	{
+        {
   	    Leds spots;
   	    f.SetBox(230);
@@ -1612,33 +1972,36 @@
             ULong_t color;
 	    gClient->GetColorByName("Green", color);    
-	    if (bright> 60) gClient->GetColorByName("Yellow", color);    
-	    if (bright> 85) gClient->GetColorByName("Orange", color);    
-	    if (bright> 95) gClient->GetColorByName("Red", color);    
+            if (bright> 60)
+                gClient->GetColorByName("Yellow", color);
+            if (bright> 85)
+                gClient->GetColorByName("Orange", color);
+            if (bright> 95)
+                gClient->GetColorByName("Red", color);
             fSkyBright->SetBackgroundColor(color);
-	   
-  	    bool rc = CalcTrackingError(spots, stars, fD, t);
-
-	    if (rc && (bright <= 1.75* fLastBright) && (bright < 110)) {
-	      fStatus = MDriveCom::kMonitoring;
-	    } else {
-	      fStatus = MDriveCom::kError;
-	    }
-            
+
+  	    bool rc = CalcTrackingError(spots, stars, fD, t, bright);
+
+            if (rc && (bright <= 1.75* fLastBright) && (bright < 110))
+                fStatus = MDriveCom::kMonitoring;
+            else
+                fStatus = MDriveCom::kError;
+
 	    if (fCosy)
 		fPos = fCosy->GetPointingPos();   
 	 
-  	    if (fDisplay->IsEntryChecked(IDM_kStargAnalysis)) 
-    		fStargHistograms->Fill(spots, stars, fD, 
-		   fSao->GetZdAz(), sgcenter, sgcenterzdaz,
-		   star, bright, fPos, t);
+  	    if (fOperations->IsEntryChecked(IDM_kStargAnalysis)) 
+                fStargHistograms->Fill(spots, stars, fD,
+                                       fSao->GetZdAz(), sgcenter, sgcenterzdaz,
+                                       star, bright, fPos, t);
 
 	    fLastBright = bright;
 
-            if (fCosy) {
+            if (fCosy)
+            {
                 MDriveCom &com = *fCosy->GetDriveCom();
                 com.SendStargReport(fStatus, fD, fSao->GetZdAz(), sgcenter, spots.GetEntries(), bright, time.GetMjd(), 0, 0);    // Report
             }
 
-	} //kStarguider
+        } //kStarguider
 
 	f2.DrawCircle(skycenter, 2.0, 0x0a);
@@ -1666,6 +2029,6 @@
     {
         f2.DrawCircle(sgcenter, 0x0a);
-        f2.DrawCircle(sgcenter,   5.0, 
-		      fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
+        f2.DrawCircle(sgcenter,   5.0,
+                      fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
     }
 
@@ -1682,5 +2045,5 @@
         fDisplay->IsEntryChecked(IDM_kCatalog)    ||
         fDisplay->IsEntryChecked(IDM_kFindStar)   ||
-	fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 
+        fOperations->IsEntryChecked(IDM_kRoqueLampAna))
         fImage->DrawColImg(img, cimg);
     else
@@ -1694,5 +2057,5 @@
     {
         // FIXME: Necessary?
-	fSao->Now();
+        fSao->Now();
         AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
         if (aa.Az()<0)
Index: trunk/MagicSoft/Cosy/main/MStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 7338)
+++ trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 7614)
@@ -58,4 +58,5 @@
 
     MGPopupMenu   *fDisplay;
+    MGPopupMenu   *fMode;
     MGPopupMenu   *fWritePictures;
     MGPopupMenu   *fFileType;
@@ -89,7 +90,9 @@
 
     TGButton      *fTPoint;
+    TGButton      *fStargTPoint;
 
     ZdAz          fPos;
     ZdAz          fD;
+    AltAz         fAltAzOffsetFromTp;
     
     StarCatalog   *fSao;
@@ -104,6 +107,8 @@
     TTimer *fTimer;
     MTime   fTime;
+    MTime   fTimeFromTp;
 
     ofstream *fOutTp;
+    ofstream *fOutStargTp;
     ofstream *fOutRq;
 
@@ -119,6 +124,10 @@
     void SetPixSize(const double pixsize);
     void Toggle(MGPopupMenu *p, UInt_t id);
+    void ToggleStargAnalysis();
+    void ToggleFindStar();
+    void ToggleStarguider();
+    void ToggleCaosFilter();
     //void GetCoordinates();
-    bool CalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &);
+    bool CalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &, double &bright);
     //void CalcTrackingError(Leds &, MStarList &);
     ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const;
