Index: /trunk/MagicSoft/Cosy/.cosyrc
===================================================================
--- /trunk/MagicSoft/Cosy/.cosyrc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/.cosyrc	(revision 1757)
@@ -19,4 +19,10 @@
 Zd_ResRE[re/U_mot]: 500
 
+#Az_Min: -90
+#Az_Max: 318
+
+#Zd_Min: -90
+#Zd_Max: 100
+
 Az_Id-MAC1: 1
 Az_Id-MAC2: 3
Index: /trunk/MagicSoft/Cosy/Changelog
===================================================================
--- /trunk/MagicSoft/Cosy/Changelog	(revision 1756)
+++ /trunk/MagicSoft/Cosy/Changelog	(revision 1757)
@@ -1,25 +1,59 @@
                                                                   -*-*- END -*-*-
 
+ 2003/02/14 - Thomas Bretz (La Palma):
+ 
+   * .cosyrc:
+     - added prototypes for the telescope allowed range
+   
+   * Makefile:
+     - changed test to testse
+   
+   * candrv/vmodican.cc:
+     - added the possibility to start cosy without the CANbus card
+       installed
+   
+   * catalog/SlaPlanets.cc:
+     - fixed the ephemeris configuration
+   
+   * catalog/SlaStars.cc:
+     - added some more comments
+   
+   * catalog/Slalib.[h,cc]:
+     - changed Wuerzburg location to LaPalma location
+     - added Height to the data members
+   
+   * main/MCosy.[h,cc]:
+     - added range checks in positioning and tracking
+   
+   * slalib/Makefile:
+     - added rdplan
+     - added pvobs
+     - added dtt
+     - added dat
+     - added rcc
+
+
+     
  2003/01/23 - Thomas Bretz:
  
-  * .cosyrc:
-    - changed maximum time to reach home from 100 to 150
-  
-  * Makefile:
-    - added devdrv
-  
-  * Makefile.rules, candrv/Makefile, devdrv/Makefile:
-    - changed some ordering
-  
-  * devdrv/shaftencoder.cc:
-    - changed Guarding from 2x125 to 2x175
-  
-  * main/MCosy.cc:
-    - fixed StopWaitingForSDO bug (if this was raised once the
-      'shutdown' never waited correctly for an SDo anymore)
-    - fixed the usage of the bending correction in some places
-
-  * testse.cc:
-    - added
+   * .cosyrc:
+     - changed maximum time to reach home from 100 to 150
+  
+   * Makefile:
+     - added devdrv
+  
+   * Makefile.rules, candrv/Makefile, devdrv/Makefile:
+     - changed some ordering
+  
+   * devdrv/shaftencoder.cc:
+     - changed Guarding from 2x125 to 2x175
+  
+   * main/MCosy.cc:
+     - fixed StopWaitingForSDO bug (if this was raised once the
+       'shutdown' never waited correctly for an SDo anymore)
+     - fixed the usage of the bending correction in some places
+
+   * testse.cc:
+     - added
 
 
Index: /trunk/MagicSoft/Cosy/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/Makefile	(revision 1756)
+++ /trunk/MagicSoft/Cosy/Makefile	(revision 1757)
@@ -20,5 +20,5 @@
 #
 
-PROGRAMS = test cosy starg
+PROGRAMS = testse cosy starg
 SOLIB    = 
 CINT     = M
Index: /trunk/MagicSoft/Cosy/candrv/vmodican.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/candrv/vmodican.cc	(revision 1757)
@@ -64,5 +64,5 @@
 int VmodIcan::Ioctl(int msg, void *arg)
 {
-    return ioctl(fd, msg, (int)arg) >= 0;
+    return fd<0 ? 1 : ioctl(fd, msg, (int)arg) >= 0;
 }
 
@@ -104,4 +104,7 @@
 void *VmodIcan::Thread()
 {
+    if (fd<0)
+        return NULL;
+
     lout << "- Starting Receiver Loop." << endl;
 
@@ -946,5 +949,5 @@
         cout << "Cannot open device '" << dev << "'... exit." << endl;
         cout << strerror(errno) << endl;
-        exit(1);                       // open module
+//        exit(1);                       // open module
     }
 
Index: /trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc
===================================================================
--- /trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 1757)
@@ -29,6 +29,9 @@
 }
 
+#include "SlaStars.h"
+
 void SlaPlanets::UpdatePlanetPos(ePlanets_t planet)
 {
+    /*
     double cp[6] = { 0, 0, 0, 0, 0, 0 };
 
@@ -52,24 +55,75 @@
     case kENeptune:
     case kEPluto:
+    case kESun:
         {
-            //
-            // coordinates of planet: heliocentric, equatoril, J2000
-            //
+        */
+    //
+    // coordinates of planet: heliocentric, equatoril, J2000
+    //
+    double ra,dec,diam;
+    // TDB, planet, elong, phi, *ra, *dec, *diam
 
-            int rc;
-            slaPlanet(GetMjd(), planet, cp, &rc);
+    // One can use TT instead of TDB for all plenets
+    // (except the moon)
 
-            if (rc)
-                return;
-        }
-        // !! Fall through!
+    const double tt = GetMjd() + slaDtt(GetMjd())/60./60./24.;
 
-    case kESun:
-        coord[0] = cp[0] - fEarth[0];
-        coord[1] = cp[1] - fEarth[1];
-        coord[2] = cp[2] - fEarth[2];
-        break;
-    }
+    // FIXME: Shell be UT1
+    const double ut1 = fmod(GetMjd(), 1);
 
-    fZdAz[planet] = XYZ2ZdAz(coord);
+    // tt should be tdb, but tt can be used
+    const double tdb = tt + slaRcc(tt, ut1, GetElong(), 8300*cos(GetPhi()), 8300*sin(GetPhi() ))/60./60./24.;
+    /*
+     cout << "Dt: " << slaDtt(GetMjd()) << endl;
+     cout << "Rc: " << slaRcc(tt, ut1, GetElong(), 8300*cos(GetPhi()), 8300*sin(GetPhi() )) << endl;
+     */
+    slaRdplan(tt, planet, GetElong(), GetPhi(),
+              &ra, &dec, &diam);
+    /*
+     switch (planet)
+     {
+     case kEMoon: cout << "Moon: "; break;
+     case kEMercury: cout << "Merkur: "; break;
+     case kEVenus: cout << "Venus: "; break;
+     case kEMars: cout << "Mars: "; break;
+     case kEJupiter: cout << "Jupiter: "; break;
+     case kESaturn: cout << "Saturn: "; break;
+     case kEUranus: cout << "Uranus: "; break;
+     case kENeptune: cout << "Neptun: "; break;
+     case kEPluto: cout << "Pluto: "; break;
+     case kESun: cout << "Sonne: "; break;
+     }
+
+     cout << (int)(ra*12/TMath::Pi()) << "h"<< (int)(ra*12/TMath::Pi()*60)%60 <<"min ";
+     cout << (int)(dec*kRad2Deg) << "deg" << (int)(dec*kRad2Deg*60)%60 << "min" << endl;
+     */
+    /*
+     SlaStars sla;
+     sla.SetMjd(GetMjd());
+     ZdAz za = sla.CalcZdAz(RaDec(ra,dec));
+     cout << za.Zd()*kRad2Deg << " " << fmod(za.Az()*kRad2Deg+720,360.) << endl;
+     fZdAz[planet] = za;
+     */
+
+    double az, el;
+    slaDe2h(GetAlpha()-ra, dec, GetPhi(), &az, &el);
+
+    cout << 90-el*kRad2Deg << " " << fmod(az*kRad2Deg+720,360.) << endl;
+    fZdAz[planet].Set(TMath::Pi()/2-el, az);
+    /*
+     }
+     // !! Fall through!
+     break;
+     case kESun:
+     coord[0] = cp[0] - fEarth[0];
+     coord[1] = cp[1] - fEarth[1];
+     coord[2] = cp[2] - fEarth[2];
+     break;
+     }
+     fZdAz[planet] = XYZ2ZdAz(coord);
+
+     if (planet==kESun)
+     {
+     cout << fZdAz[kESun].Zd()*kRad2Deg << " " <<  fZdAz[kESun].Az()*kRad2Deg << endl;
+     }*/
 }
Index: /trunk/MagicSoft/Cosy/catalog/SlaStars.cc
===================================================================
--- /trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 1757)
@@ -38,13 +38,17 @@
     // ----- calculate star independent parameters ----------
     //
-    slaMappa(2000.0, mjd, fAmprms);
-    slaAoppa(mjd, 0,                    // mjd, UT1-UTC
+
+    // prepare calculation: Mean Place to geocentric apperent
+    slaMappa(2000.0, mjd, fAmprms);        // Epoche, TDB
+
+    // prepare: Apperent to observed place
+    slaAoppa(mjd, 0,                       // mjd, Delta UT=UT1-UTC
              // GetElong(), GetPhi(), 148, // göttingen long, lat, height
-             GetElong(), GetPhi(), 300, // göttingen long, lat, height
-             0, 0,                      // polar motion x, y-coordinate (radians)
+             GetElong(), GetPhi(), GetHeight(), // göttingen long, lat, height
+             0, 0,                         // polar motion x, y-coordinate (radians)
              // 273.155, 1013.25, 0.5,     // temp, pressure, humidity
              273.155+20, 1013.25, 0.5,     // temp, pressure, humidity
              // 0.2, 0.0065,               // wavelength, tropo lapse rate
-             0.55, 0.0065,               // wavelength, tropo lapse rate
+             0.55, 0.0065,                 // wavelength, tropo lapse rate
              fAoprms);
 }
Index: /trunk/MagicSoft/Cosy/catalog/Slalib.cc
===================================================================
--- /trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 1757)
@@ -18,6 +18,13 @@
     //
     int status;
-    slaDaf2r(51, 38, 48.0, &fPhi,   &status);
-    slaDaf2r( 9, 56, 36.0, &fElong, &status);
+    //slaDaf2r(51, 38, 48.0, &fPhi,   &status);
+    //slaDaf2r( 9, 56, 36.0, &fElong, &status);
+    //fHeight = 300;
+
+    slaDaf2r(28, 45, 30.0, &fPhi,   &status);
+    slaDaf2r(17, 52, 48.0, &fElong, &status);
+
+    fElong *= -1;
+    fHeight = 2326;
 
     cout << "Latitude: 51\x9c 38'48.0\" = " <<  kRad2Deg*fPhi << "   ";
Index: /trunk/MagicSoft/Cosy/catalog/Slalib.h
===================================================================
--- /trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 1756)
+++ /trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 1757)
@@ -16,4 +16,6 @@
     double   fElong;
 
+    double   fHeight;
+
 public:
     Slalib();
@@ -29,9 +31,11 @@
     virtual void SetMjd(const double mjd);
 
-    double GetAlpha() const { return fAlpha; }
-    double GetMjd() const   { return fMjd; }
+    double GetAlpha() const  { return fAlpha; }
+    double GetMjd() const    { return fMjd; }
 
-    double GetPhi() const   { return fPhi; }
-    double GetElong() const { return fElong; }
+    double GetPhi() const    { return fPhi; }
+    double GetElong() const  { return fElong; }
+
+    double GetHeight() const { return fHeight; }
 
     ZdAz   XYZ2ZdAz(double coord[3]) const;
Index: /trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1756)
+++ /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 1757)
@@ -391,4 +391,12 @@
 {
     // FIXME: Correct by fOffset ?
+
+    const ZdAz d = dst*kRad2Deg;
+    if (d.Zd()<fMin.Zd() || d.Zd()>fMax.Zd() || d.Az()<fMin.Az() || d.Az()>fMax.Az())
+    {
+        lout << "ERROR: Requested Position not inside allowed range." << endl;
+        return kFALSE;
+    }
+
 
     /*
@@ -724,5 +732,13 @@
         ZdAz dummy = fBending(sla.CalcZdAz(fRaDec));
         dest = CorrectTarget(GetSePos(), dummy); // [se]
+
+        const ZdAz d = dest*360./16384; // [deg]
         dest *= kGearRatio;  // [re]
+
+        if (d.Zd()<fMin.Zd() || d.Zd()>fMax.Zd() || d.Az()<fMin.Az() || d.Az()>fMax.Az())
+        {
+            lout << "ERROR: Calculated position for T+dt not inside allowed range." << endl;
+            break;
+        }
 
         ZdAz vcalc = sla.GetApproxVel(fRaDec) * kGearRatio2*4./60.;  // [re/min]
@@ -1070,4 +1086,17 @@
     TEnv env(".cosyrc");
     cout << "done." << endl;
+
+    cout << "Reading telescope range..." << flush;
+    const Double_t amin = env.GetValue("Az_Min", -90.0);
+    const Double_t zmin = env.GetValue("Zd_Min", -90.0);
+    fMin.Set(zmin, amin);
+
+    cout << " Min: " << zmin << "deg  " << amin << "deg" << endl;
+
+    const Double_t amax = env.GetValue("Az_Max", 318.0);
+    const Double_t zmax = env.GetValue("Zd_Max", 100.0);
+    fMax.Set(zmax, amax);
+
+    cout << " Max: " << zmax << "deg  " << amax << "deg" << endl;
 
     cout << "Reading gear ratios..." << flush;
Index: /trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1756)
+++ /trunk/MagicSoft/Cosy/main/MCosy.h	(revision 1757)
@@ -83,4 +83,6 @@
     ZdAz  fAccuracy;      // Actual accuracy of Tracking
     ZdAz  fVelocity;      // Actual velocity of Tracking
+    ZdAz  fMin;
+    ZdAz  fMax;
 
     XY kGearRatio;        // describing the gear of the system [re/se]
Index: /trunk/MagicSoft/slalib/Makefile
===================================================================
--- /trunk/MagicSoft/slalib/Makefile	(revision 1756)
+++ /trunk/MagicSoft/slalib/Makefile	(revision 1757)
@@ -38,5 +38,5 @@
         drange.c deuler.c cldj.c   aopqk.c  refz.c  dh2e.c  de2h.c   \
         dt.c     dmoon.c  planet.c planel.c el2ue.c ue2pv.c pv2ue.c  \
-        altaz.c
+        altaz.c  rdplan.c pvobs.c  dtt.c    dat.c   rcc.c
 #	addet.c
 #        afin.c airmas.c altaz.c amp.c \
