Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 6930)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7230)
@@ -397,9 +397,25 @@
 //    point.SetVelocity(0.2); // fast: 0.6, slow: 0.2
 //#else
+
+// original settings
+//
     point.SetPointAccDec(0.2, 0.1);
     point.SetPointVelocity(0.1);
+
+
 //#endif
 
+//    point.SetPointAccDec(0.4, 0.4);
+//    point.SetPointVelocity(0.4);
+
+
+// original
     return point.SetPosition(dst, track);
+
+// test
+//    return point.SetPosition(dst, kTRUE);
+
+
+
 }
 
@@ -422,6 +438,15 @@
 //    track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
 //#else
+
+
+
     track.SetPointAccDec(0.2, 0.1);
     track.SetPointVelocity(0.1);
+
+    //    track.SetPointAccDec(0.4, 0.4);
+    // track.SetPointVelocity(0.4);
+
+
+
 //#endif
     track.SetTrackAccDec(0.1, 0.1);
@@ -438,6 +463,6 @@
 //    track.SetPointVelocity(0.2); // fast: 0.6, slow: 0.2
 //#else
-    track.SetPointAccDec(0.2, 0.1);
-    track.SetPointVelocity(0.1);
+    track.SetPointAccDec(0.4, 0.4);
+    track.SetPointVelocity(0.3);
 //#endif
     track.SetTrackAccDec(0.1, 0.1);
Index: trunk/MagicSoft/Cosy/main/MPointing.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MPointing.cc	(revision 6930)
+++ trunk/MagicSoft/Cosy/main/MPointing.cc	(revision 7230)
@@ -202,12 +202,26 @@
         else
         {
-            const Double_t y = 15*fCosy->kGearTot.Y()*fCosy->kResSE.Y();
-            if (rd.Az()>-y && rd.Az()<y)
-            {
-                //lout << "--- LO-SPEED Mac1 ---" << endl;
-                SetAccDec(fCosy->fMac1, 0.05, 0.05);
-            }
-            else
-                SetAccDec(fCosy->fMac1, fAcc, fDec);
+            const Double_t y = 15*fCosy->kGearTot.Y()/fCosy->kResSE.Y();
+
+//	    lout << "MPointing::SetPosition y: " << y << " rd.Az(): " << rd.Az() << endl;
+//	    lout << "MPointing::SetPosition fCosy->kGearTot.Y(): " << fCosy->kGearTot.Y() << " fCosy->kResSE.Y(): " << fCosy->kResSE.Y() << endl;
+
+	    if (rd.Az()>-y && rd.Az()<y)
+	      {
+		//lout << "--- LO-SPEED Mac1 ---" << endl;
+		SetAccDec(fCosy->fMac1, 0.05, 0.05);
+	      }
+	    else
+	      {
+
+ 		//lout << "MPointing::SetPosition SetAccDec Mac1: " << fAcc << fDec << endl;
+		
+ 		SetAccDec(fCosy->fMac1, fAcc, fDec);
+		
+	      }
+
+
+	    // new 16.05.05  F.G.
+	    // SetAccDec(fCosy->fMac1, fAcc, fDec);
 
             SetAccDec(fCosy->fMac2, fAcc, fDec);
Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 6930)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7230)
@@ -70,4 +70,5 @@
     IDM_kChannel1,
     IDM_kChannel2,
+    IDM_kChannel3,
     IDM_kContinous,
     IDM_kRate25ps,
@@ -107,5 +108,7 @@
     IDM_kStargCaosFilter,
     IDM_kStargLEDFilter,
-    IDM_kStargFindStar
+    IDM_kStargFindStar,
+    IDM_kTPointAna,
+    IDM_kRoqueLampAna
 
 };
@@ -143,5 +146,10 @@
     fChannel->AddEntry("Starfield Camera", IDM_kChannel1);
     fChannel->AddEntry("TPoint Camera", IDM_kChannel2);
-    fChannel->CheckEntry(channel==0?IDM_kChannel1: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);
+    }
     fChannel->Associate(this);
     fList->Add(fChannel);
@@ -170,4 +178,12 @@
     fList->Add(fDisplay);
 
+
+    fOperations = new MGPopupMenu(p);
+    fOperations->AddEntry("TPoint Analysis",     IDM_kTPointAna);
+    fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
+    fOperations->Associate(this);
+    fList->Add(fOperations);
+
+
     fFileType = new MGPopupMenu(p);
     fFileType->AddEntry("PP&M", IDM_kPPM);
@@ -281,7 +297,10 @@
 
     fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
-    fMenu->AddPopup("&Display",   fDisplay,         NULL);
-    fMenu->AddPopup("&WritePics", fWritePictures,   NULL);
-    fMenu->AddPopup("&Setup",     fSetup,           NULL);
+    fMenu->AddPopup("&Display",    fDisplay,         NULL);
+    fMenu->AddPopup("&WritePics",  fWritePictures,   NULL);
+    fMenu->AddPopup("&Setup",      fSetup,           NULL);
+
+    fMenu->AddPopup("&Operations", fOperations,      NULL);
+
     fMenu->Resize(fMenu->GetDefaultSize());
     fMenu->BindKeys(this);
@@ -457,5 +476,11 @@
 
 MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
-    : TGMainFrame(gClient->GetRoot(), 768, 840), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2), fStatus(MDriveCom::kStandby)
+    : TGMainFrame(gClient->GetRoot(), 768, 840), 
+      fCosy(NULL), 
+      fOutTp(0), 
+      fOutRq(0),
+      fDx((768-kZOOM)/2), 
+      fDy((512-kZOOM)/2), 
+      fStatus(MDriveCom::kStandby)
 {
     
@@ -517,4 +542,7 @@
     if (fOutTp)
         delete fOutTp;
+
+    if (fOutRq)
+        delete fOutRq;
 
     cout << "Camera Display destroyed." << endl;
@@ -585,7 +613,20 @@
                 return kTRUE;
 
+	   case IDM_kRoqueLampAna:
+  	        Toggle(fOperations, IDM_kRoqueLampAna);
+		//		if (!fDisplay->IsEntryChecked(IDM_kCatalog))
+		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)) {
+	        Toggle(fDisplay, IDM_kStargFindStar);         
+	        if (fDisplay->IsEntryChecked(IDM_kStargFindStar)) {
 		    fSZdAz->MapWindow();
 		} else {
@@ -615,15 +656,18 @@
 
 		    const Int_t ch0 = 
-			fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
-                    const Int_t ch1 = 0;
-
-                    if (ch0!=ch1)
-		    {
-
+		      fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
+		    const Int_t ch1 = 0;
+		    
+		    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_kChannel3)) {
+			  fGetter=new PngReader(*this);
+			} else {		      
+			  fGetter = new Camera(*this, ch1);
+			  ((Camera*)fGetter)->Loop(0);
+			}
+		      }
 
 		    fChannel->CheckEntry(IDM_kChannel1);
@@ -854,6 +898,11 @@
                     delete fGetter;
                     usleep(150000); // FIX: Device or resource busy.
-                    fGetter = new Camera(*this, ch1);
-                    ((Camera*)fGetter)->Loop(0);
+		    if (fChannel->IsEntryChecked(IDM_kChannel3))
+		      fGetter=new PngReader(*this);
+		    else
+		      {
+			fGetter = new Camera(*this, ch1);
+			((Camera*)fGetter)->Loop(0);
+		      }
                 }
                 return kTRUE;
@@ -1109,5 +1158,5 @@
 }
 
-ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
+XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Double_t box, XY SearchCenter)
 {
     // Set search Paremeters (FIXME: Get them from user input!)
@@ -1117,5 +1166,43 @@
     // Try to find Led in this area
     Leds leds;
-    f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
+    f.FindStarCircle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y());
+
+    // Check whether star found
+    Led *star = (Led*)leds.At(0);
+    if (!star || leds.GetEntries()<1)
+        return XY(.0,.0);
+
+//    cout << "Found Roque Lamp @ " << flush;
+    star->Print();
+    f.MarkPoint(star->GetX(), star->GetY(), 500);
+
+//    cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl;
+
+    XY roquepos(star->GetX(), star->GetY());
+    XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY());
+
+    // If no file open: open new Roque Lamp file
+    if (!fOutRq)
+    {
+        const TString name = MCosy::GetFileName("tpoint/starg_roquelamp_%s.txt");
+        cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
+        fOutRq = new ofstream(name);
+        *fOutRq << "# Magic Roque Lamp file  " << t << endl;
+    }
+
+
+    return relroquepos;
+}
+  
+
+ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
+{
+    // Set search Paremeters (FIXME: Get them from user input!)
+    f.SetCut(cut);  // 3.5
+    f.SetBox(box);  // 70
+
+    // Try to find Led in this area
+    Leds leds;
+    f.FindStarCircle(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
 
     // Check whether star found
@@ -1329,4 +1416,7 @@
             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;
+
     }
 
@@ -1390,4 +1480,63 @@
     }
 
+// Find Roque Lamp
+
+    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);
+
+	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;
+	cout << ">=>=>=> Roque Lamp found at:         >=>=>=> (" << roquelamp.X() << "," 
+	     << roquelamp.Y() << ") <=<=<=<" << endl;
+
+    }
+
+// Find Spot on Camera Center in Starguider camera
+
+    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna)) {
+
+	XY cameraspot(0,0);
+
+	Double_t imageclean = 5;
+	Double_t boxradius = 60;
+	Double_t scalefactor = 1;
+	//	XY searchcenter(sgcenter.GetX(),sgcenter.GetY());
+	XY searchcenter(60.,290.);
+
+	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() << "," 
+	     << cameraspot.Y() << ") <<<<<" << endl;
+
+        f2.DrawCircle(sgcenter, 5.0, 0x0fa);
+        f2.DrawCircle(sgcenter, 115.0, 0x0fa);
+
+    }
+
+
+
     // we calculate the offset given by the three ETH Leds visible to
     // the guide camera
@@ -1451,4 +1600,5 @@
   	    Leds spots;
   	    f.SetBox(230);
+//	    f.SetCut(1.5);
 	    double bright;
   	    f.ExecuteAndMark(spots, 530, 292, bright);
@@ -1528,5 +1678,6 @@
     if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
         fDisplay->IsEntryChecked(IDM_kCatalog)    ||
-        fDisplay->IsEntryChecked(IDM_kFindStar))
+        fDisplay->IsEntryChecked(IDM_kFindStar)   ||
+	fOperations->IsEntryChecked(IDM_kRoqueLampAna)) 
         fImage->DrawColImg(img, cimg);
     else
Index: trunk/MagicSoft/Cosy/main/MStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 6930)
+++ trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 7230)
@@ -67,4 +67,6 @@
     MGPopupMenu   *fChannel;
 
+    MGPopupMenu   *fOperations;
+
     MGPopupMenu   *fCaosWrite;
     MGPopupMenu   *fCaosPrint;
@@ -104,4 +106,5 @@
 
     ofstream *fOutTp;
+    ofstream *fOutRq;
 
     Int_t fDx;
@@ -121,4 +124,8 @@
     ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag) const;
     bool Interpolate(const unsigned long n, byte *img) const;
+
+    XY FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, 
+		     Double_t cut, Double_t box, XY SearchCenter);
+
     ZdAz FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, 
 		  Double_t cut, Double_t box, Double_t scalefactor);
Index: trunk/MagicSoft/Cosy/main/MTracking.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 6930)
+++ trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 7230)
@@ -244,10 +244,58 @@
 ZdAz MTracking::GetPointingPosRE(Bool_t pdo) const
 {
-    // Conversion factor from se to re
-    const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se]
-
-    Int_t pzd1 = fCosy->fZd1->GetPos();
-    Int_t pzd2 = fCosy->fZd2->GetPos();
-    Int_t paz  = fCosy->fAz->GetPos();
+     // Conversion factor from se to re
+     const XY re = fCosy->kGearTot/fCosy->kResSE; //[re/se]
+
+     const bool bool1 = fCosy->fZd1->DirHasChanged();
+     const bool bool2 = fCosy->fZd2->DirHasChanged();
+
+     if (bool1 && bool2) {
+       fCosy->fZd1->ResetDirHasChanged();
+       fCosy->fZd2->ResetDirHasChanged();
+     }
+ 
+     Int_t pzd1 = !bool1 ? fCosy->fZd1->GetPos() : fCosy->fZd1->GetDirChangedPos();
+     Int_t pzd2 = !bool2 ? fCosy->fZd2->GetPos() : fCosy->fZd2->GetDirChangedPos();
+     Int_t paz  =          fCosy->fAz->GetPos();
+ 
+     // Get current shaftencoder position of the telescope
+     Double_t seposzd1 = ((pzd1+8192)%16384)*re.X();
+     Double_t seposzd2 = ((pzd2+8192)%16384)*re.X();
+     Double_t seposaz  =   paz              *re.Y();
+ 
+     // distance between (To+dt) and To [re]
+     // position time difference < 5usec
+     // fRePos does the synchronization between the
+     // Shaft- and the rotary encoders
+     const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();
+ 
+     const Int_t offset1 = !bool1 ? fCosy->fZd1->GetOffset() : fCosy->fZd1->GetDirChangedOffset();
+     const Int_t offset2 = !bool2 ? fCosy->fZd2->GetOffset() : fCosy->fZd2->GetDirChangedOffset();
+ 
+     // Calculate the part of one SE which the motors moved
+     // since the last SE has changed its value
+     const Double_t offzd1 = repos.Zd() - offset1;
+     const Double_t offzd2 = repos.Zd() - offset2;
+     const Double_t offaz  = repos.Az() - fCosy->fAz->GetOffset();
+ 
+     // Correct for the direction in which the motor is moving
+     // (in which the shaftencoders should change its values)
+     if (offaz<0)
+         seposaz += re.Y();
+     if (offzd1<0)
+         seposzd1 += re.X();
+     if (offzd2<0)
+         seposzd2 += re.X();
+ 
+     // and interpolate the shaftencoder steps using the motor
+     // encoder positon (Be carefull the minus-sign is important)
+     seposzd1 += offzd1;
+     seposzd2 -= offzd2;
+     seposaz  += offaz;
+ 
+
+
+     return ZdAz((seposzd1-seposzd2)/2, seposaz);
+}
 /*
     if (fCosy->fZd1->DirHasChanged() != fCosy->fZd2->DirHasChanged())
@@ -262,38 +310,4 @@
     }
   */
-    // Get current shaftencoder position of the telescope
-    Double_t seposzd1 = ((pzd1+8192)%16384)*re.X();
-    Double_t seposzd2 = ((pzd2+8192)%16384)*re.X();
-    Double_t seposaz  =   paz              *re.Y();
-
-    // distance between (To+dt) and To [re]
-    // position time difference < 5usec
-    // fRePos does the synchronization between the
-    // Shaft- and the rotary encoders
-    const ZdAz repos = pdo ? fCosy->GetRePosPdo() : fCosy->GetRePos();
-
-    // Calculate the part of one SE which the motors moved
-    // since the last SE has changed its value
-    const Double_t offzd1 = repos.Zd() - fCosy->fZd1->GetOffset();
-    const Double_t offzd2 = repos.Zd() - fCosy->fZd2->GetOffset();
-    const Double_t offaz  = repos.Az() - fCosy->fAz->GetOffset();
-
-    // Correct for the direction in which the motor is moving
-    // (in which the shaftencoders should change its values)
-    if (offaz<0)
-        seposaz += re.Y();
-    if (offzd1<0)
-        seposzd1 += re.X();
-    if (offzd2<0)
-        seposzd2 += re.X();
-
-    // and interpolate the shaftencoder steps using the motor
-    // encoder positon (Be carefull the minus-sign is important)
-    seposzd1 += offzd1;
-    seposzd2 -= offzd2;
-    seposaz  += offaz;
-
-    return ZdAz((seposzd1-seposzd2)/2, seposaz);
-}
 
 void MTracking::TrackPosition(const RaDec &dst) // ra, dec [rad]
