Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7787)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 7788)
@@ -401,4 +401,5 @@
 //
     point.SetPointAccDec(0.2, 0.1);
+
     point.SetPointVelocity(0.1);
 
@@ -634,5 +635,5 @@
                 // open tpoint file
                 //
-                const TString name = GetFileName("tpoint/old-tpoint_%s.txt");
+                const TString name = GetFileName("tpoint", "old-tpoint", "txt");
                 cout << "TPoint-Cosy File ********* " << name << " ********** " << endl;
 
@@ -675,5 +676,5 @@
 
             ZdAz dest = *((ZdAz*)mp) * kDeg2Rad;
-            if (!SetPosition(dest))
+            if (!SetPosition(dest, kTRUE))
                 return (void*)0x1234;
 
@@ -686,5 +687,28 @@
         //cout << "WM_TrackPosition: done. (return 0xabcd)" << endl;
         return (void*)0xabcd;
-
+/*
+    case WM_ARM:
+        //cout << "WM_Position: start." << endl;
+        {
+            if (!CheckNetwork())
+                return (void*)0xebb0;
+
+            const bool arm = *((bool*)mp);
+            if (arm)
+            {
+                fMac1->Arm();
+                fMac2->Arm();
+                cout << "ARMED" << endl;
+            }
+            else
+            {
+                fMac1->Disarm();
+                fMac2->Disarm();
+                cout << "DISARMED" << endl;
+            }
+        }
+        //cout << "WM_Position: done. (return 0x7777)" << endl;
+        return (void*)0x9999;
+  */
     case WM_POSITION:
         //cout << "WM_Position: start." << endl;
@@ -711,4 +735,44 @@
         return (void*)0x7777;
 
+    case WM_PREPS:
+        //cout << "WM_Track: START" << endl;
+        {
+            if (!CheckNetwork())
+                return (void*)0xebb0;
+
+            const char *preps = (const char*)mp;
+            cout << "Preposition command to " << preps << " received." << endl;
+
+            ifstream fin("prepos.txt");
+            if (!fin)
+            {
+                cout << "ERROR: cannot open prepos.txt." << endl;
+                return (void*)0xebb1;
+            }
+
+            while (1)
+            {
+                Double_t zd, az;
+                fin >> zd >> az;
+
+                TString str;
+                str.ReadLine(fin);
+                if (!fin)
+                    break;
+
+                str.ToLower();
+
+                if (str.Strip(TString::kBoth)==preps)
+                {
+                    ZdAz dest(zd, az);
+                    SetPosition(dest*kDeg2Rad);
+                    return (void*)0x7979;
+                }
+                cout << "ERROR - Requested preposition not found in file..." << endl;
+            }
+        }
+        //cout << "WM_Track: done. (return 0x8888)" << endl;
+        return (void*)0x7878;
+
     case WM_TESTSE:
         //cout << "WM_TestSe: start." << endl;
@@ -730,5 +794,6 @@
 
     case WM_TRACK:
-        //cout << "WM_Track: START" << endl;
+    case WM_GRB:
+        //cout << "WM_Track/GRB: START" << endl;
         {
             RaDec dest = ((RaDec*)mp)[0];
@@ -737,20 +802,11 @@
             if (!CheckNetwork())
                 return (void*)0xebb0;
-            TrackPosition(dest*kDeg2Rad);
+
+            if (msg==WM_TRACK)
+                TrackPosition(dest*kDeg2Rad);
+            else
+                TrackPositionGRB(dest*kDeg2Rad);
         }
-        //cout << "WM_Track: done. (return 0x8888)" << endl;
-        return (void*)0x8888;
-
-    case WM_GRB:
-        //cout << "WM_Track: START" << endl;
-        {
-            RaDec dest = ((RaDec*)mp)[0];
-            if (fStarguider)
-                fStarguider->SetPointingPosition(((RaDec*)mp)[1]);
-            if (!CheckNetwork())
-                return (void*)0xebb0;
-            TrackPositionGRB(dest*kDeg2Rad);
-        }
-        //cout << "WM_Track: done. (return 0x8888)" << endl;
+        //cout << "WM_Track/GRB: done. (return 0x8888)" << endl;
         return (void*)0x8888;
 
@@ -1178,4 +1234,5 @@
     avail |= (fZd2  && !fZd2->IsZombieNode())  ? 0x10 : 0;
     avail |= (fAz   && !fAz->IsZombieNode())   ? 0x20 : 0;
+//    avail |= (!(fStatus&MDriveCom::kError) && 1 ? 0x40 : 0;
 
     if (HasError())
@@ -1471,14 +1528,31 @@
 */
 
-TString MCosy::GetFileName(const char *fmt)
+TString MCosy::GetFileName(const char *path, const char *name, const char *ext)
 {
     // FIXME: Timeout missing
+
     while (1)
     {
         MTime time(-1);
-        const TString name = Form(fmt, (const char*)time.GetFileName());
-        if (gSystem->AccessPathName(name, kFileExists))
-            return name;
-            break;
+
+        // This is the full qualified date which is part of the name
+        const TString clock = time.GetStringFmt("%y%m%d_%H%M%S");
+
+        // This gives the night in which the date belongs to
+        time.SetMjd(TMath::Nint(time.GetMjd()));
+
+        const TString night = time.GetStringFmt("%Y_%m_%d");
+
+        const TString dir   = Form("%s/%s", path, night.Data());
+        const TString fname = Form("%s_%s.%s", name, clock.Data(), ext);
+
+        const TString full  = Form("%s/%s", dir.Data(), fname.Data());
+
+        gSystem->mkdir(dir, kTRUE);
+
+        if (gSystem->AccessPathName(full, kFileExists))
+            return full;
+
+        break;// !!!!!!!!!!!!!!!!!!!!!!!
 
         usleep(1000);
@@ -1498,5 +1572,5 @@
     const Int_t id6 = env.GetValue("Az_Id-SE",   6); //6
 
-    TString name = GetFileName("rep/cosy_%s.rep");
+    TString name = GetFileName("rep", "cosy", "rep");
     cout << "Open Repfile: " << name << endl;
     fOutRep = new MLog(name, kTRUE);
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 7787)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 7788)
@@ -38,4 +38,6 @@
 #define WM_ENDSWITCH    0x1010
 #define WM_GRB          0x1011
+#define WM_PREPS        0x1012
+#define WM_ARM          0x1013
 
 class ShaftEncoder;
@@ -187,5 +189,5 @@
     void SetStarguider(MStarguider *s) { fStarguider = s; }
 
-    static TString GetFileName(const char *name);
+    static TString GetFileName(const char *path, const char *name, const char *ext);
 
     MGCosy *GetWin() { return fWin; }
Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7787)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 7788)
@@ -1,2 +1,3 @@
+#undef EXPERT
 #undef EXPERT
 
@@ -335,25 +336,25 @@
 
     fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+12);
+    fCZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+581+20-4);
     AddFrame(fCZdAz);
     fList->Add(fCZdAz);
 
     fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*12);
+    fPZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+627+2*20-4);
     AddFrame(fPZdAz);
     fList->Add(fPZdAz);
 
     fDZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*12);
+    fDZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+673+3*20-4);
     AddFrame(fDZdAz);
     fList->Add(fDZdAz);
 
     fSZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
-    fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*12);
+    fSZdAz->Move(240+12+28, fMenu->GetDefaultHeight()+719+4*20-4);
     AddFrame(fSZdAz);
     fList->Add(fSZdAz);
 
     fTPoint = new TGTextButton(this, "TPoint");
-    fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*12+25);
+    fTPoint->Move(4, fMenu->GetDefaultHeight()+722+3*15+15);
     fTPoint->AllowStayDown(kTRUE);
     AddFrame(fTPoint);
@@ -361,5 +362,5 @@
 
     fStargTPoint = new TGTextButton(this, "StargTPoint");
-    fStargTPoint->Move(240+12+20, fMenu->GetDefaultHeight()+785);
+    fStargTPoint->Move(240+12+28, fMenu->GetDefaultHeight()+785);
     fStargTPoint->AllowStayDown(kTRUE);
     AddFrame(fStargTPoint);
@@ -368,10 +369,10 @@
     fFps = new TGLabel(this, "---fps");
     fFps->SetTextJustify(kTextRight);
-    fFps->Move(650-440, fMenu->GetDefaultHeight()+619+13+60+20);
+    fFps->Move(650-495, fMenu->GetDefaultHeight()+619+13+60+20+2);
     AddFrame(fFps);
     fList->Add(fFps);
 
-    fPosZoom = new TGLabel(this, "----.--d/----.--d (----, ----)");
-    fPosZoom->SetTextJustify(kTextRight);
+    fPosZoom = new TGLabel(this, "(----, ----) ----.--d/----.--d");
+    fPosZoom->SetTextJustify(kTextLeft);
     fPosZoom->Move(4, fMenu->GetDefaultHeight()+765);
     AddFrame(fPosZoom);
@@ -386,5 +387,5 @@
     TGLabel *l = new TGLabel(this, "arcsec/pix");
     l->SetTextJustify(kTextLeft);
-    l->Move(605-400, fMenu->GetDefaultHeight()+619+13+60);
+    l->Move(606-412, fMenu->GetDefaultHeight()+619+13+60);
     AddFrame(l);
     fList->Add(l);
@@ -392,5 +393,5 @@
     l = new TGLabel(this, "deg");
     l->SetTextJustify(kTextLeft);
-    l->Move(605-410, fMenu->GetDefaultHeight()+619-10+60);
+    l->Move(606-412, fMenu->GetDefaultHeight()+619-10+60);
     AddFrame(l);
     fList->Add(l);
@@ -398,5 +399,5 @@
     l = new TGLabel(this, "Telescope pointing at");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20, fMenu->GetDefaultHeight()+584-5);
+    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+584-5);
     AddFrame(l);
     fList->Add(l);
@@ -404,5 +405,5 @@
     l = new TGLabel(this, "Starguider position");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20, fMenu->GetDefaultHeight()+630+12-5);
+    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+630+20-5);
     AddFrame(l);
     fList->Add(l);
@@ -410,5 +411,5 @@
     l = new TGLabel(this, "Misspointing");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20, fMenu->GetDefaultHeight()+676+2*12-5);
+    l->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5);
     AddFrame(l);
     fList->Add(l);
@@ -417,5 +418,5 @@
     l = new TGLabel(this, "Misspointing/FindStar (Experts Only!)");
     l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*12-5);
+    l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5);
     AddFrame(l);
     fList->Add(l);
@@ -436,5 +437,11 @@
     fList->Add(fPixSize);
 
-    fAngle = new TGTextEntry(this, "         0", IDM_kAngle);
+    const Double_t angle = -0.4;
+    fSao->SetRotationAngle(angle);
+
+    txt = "";
+    txt += angle;
+
+    fAngle = new TGTextEntry(this, txt, IDM_kAngle);
     fAngle->SetAlignment(kTextCenterX);
     fAngle->Move(547-410, fMenu->GetDefaultHeight()+617-10+60);
@@ -1385,5 +1392,5 @@
     {
         // open tpoint file
-        const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
+        const TString name = MCosy::GetFileName("tpoint", "starg", "txt");
         cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
 
@@ -1451,5 +1458,5 @@
     // Try to find Led in this area
     Leds leds;
-    f.FindStarCircle(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y());
+    f.FindStar(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y(), true);
 
     // Check whether star found
@@ -1470,5 +1477,5 @@
     if (!fOutRq)
     {
-        const TString name = MCosy::GetFileName("tpoint/starg_roquelamp_%s.txt");
+        const TString name = MCosy::GetFileName("tpoint", "roquelamp", "txt");
         cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
         fOutRq = new ofstream(name);
@@ -1476,8 +1483,6 @@
     }
 
-
     return relroquepos;
 }
-  
 
 ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Double_t box, Double_t scalefactor = 1.0)
@@ -1489,5 +1494,5 @@
     // Try to find Led in this area
     Leds leds;
-    f.FindStarCircle(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
+    f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true);
 
     if (leds.GetEntries()<0)
@@ -1505,5 +1510,4 @@
         return ZdAz(.0,.0);
     }
-
     cout << "Found star @ " << flush;
     star->Print();
@@ -1561,5 +1565,5 @@
         // open tpoint file
         //
-        const TString name = MCosy::GetFileName("tpoint/tpoint_%s.txt");
+        const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt");
         cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
 
@@ -1715,5 +1719,5 @@
     // Find Star at Center---for Tpoint Procedure
     if (fDisplay->IsEntryChecked(IDM_kFindStar))
-        /*ZdAz zdaz =*/ FindStar(f, f2, center, t, 3.5, 70);
+        FindStar(f, f2, center, t, 3.5, 70);
 
     byte zimg[kZOOM*kZOOM];
@@ -1779,6 +1783,4 @@
     {
 
-        XY roquelamp(0,0);
-
         Double_t imageclean = 1.5;
         Double_t boxradius = 60;
@@ -1786,5 +1788,5 @@
 	XY searchcenter(768/2-1,576/2+25);
 
-	roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
+	XY roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
 
         if (fOutRq)
@@ -1804,5 +1806,4 @@
 
     // Find Spot on Camera Center in Starguider camera
-
     if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
     {
@@ -1832,5 +1833,4 @@
         f2.DrawCircle(sgcenter, 115.0, 0x0fa);
     }
-
     // we calculate the offset given by the three ETH Leds visible to
     // the guide camera
@@ -1884,5 +1884,5 @@
 
         // Position around which the circles are drawn.
-        const Ring skycenter(768/2+off.X(), 576/2+off.Y());
+        const Ring skycenter(768/2-off.X(), 576/2+off.Y());
 
 	// There are two corrections to the misspointing
@@ -1896,8 +1896,10 @@
   	    Leds spots;
   	    f.SetBox(230);
-//	    f.SetCut(1.5);
-	    double bright;
+	    f.SetCut(2.5);
+
+            double bright;
   	    f.ExecuteAndMark(spots, 530, 292, bright);
- 	    MString txt;
+
+            MString txt;
  	    txt.Print("Sky Brightness: %.1f", bright);
  	    fSkyBright->SetText(txt);
@@ -1961,5 +1963,5 @@
     {
         f2.DrawCircle(center, 0x0a);
-        f2.DrawCircle(center,   5.0, 
+        f2.DrawCircle(center,   7.0,
 		      fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
         f2.DrawCircle(center, 115.0, 0x0a);
@@ -2003,5 +2005,5 @@
         if (aa.Az()<0)
             aa.Az(aa.Az()+360);
-        txt.Print("%.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);
+        txt.Print("(%d, %d) %.1fd/%.1fd", fDx, fDy, -aa.Alt(), aa.Az()-180);
     }
     else
