Index: /trunk/SophyaExt/FitsIOServer/datacirclefits.cc
===================================================================
--- /trunk/SophyaExt/FitsIOServer/datacirclefits.cc	(revision 1770)
+++ /trunk/SophyaExt/FitsIOServer/datacirclefits.cc	(revision 1770)
@@ -0,0 +1,82 @@
+#include <iostream.h>
+#include "datacirclefits.h"
+
+/*
+   Class used to recover the circles and measures involved in a mission. The parameters needful to create a circle and the number of samples on this circle are read from a FITS data array. In addition, a function returns the measurement at a given angular position psi on the circle.
+*/
+
+DataCircleFits::DataCircleFits() : 
+  _fptr(NULL)
+, _NMeasurements(0)
+, _ICircle(0)
+, _mesures(NULL)
+,_stored_data(false)
+{;}
+
+DataCircleFits::DataCircleFits(FitsInFile& is,int hdunum,bool sdata) :
+  _fptr(NULL)
+, _NMeasurements(0)
+, _ICircle(hdunum)
+, _mesures(NULL)
+,_stored_data(sdata)
+{
+
+  // pointer to the FITS file
+  _fptr= &is;
+
+  // move to the HDU containing a circle
+  _fptr->ReadHeader(hdunum);
+
+  // reference on a DVList containing the keywords
+  DVList dvl= _fptr->DVListFromFits();
+
+  // angles of the circle
+  double theta= dvl.GetD("CIRTHETA");
+  double phi  = dvl.GetD("CIRPHI");
+  double aperture= dvl.GetD("CIRAPER");
+
+  UnitVector temp(theta,phi);
+  SetCircle(temp,aperture);
+
+ _NMeasurements= dvl.GetI("NSAMPLES");
+
+ if(_stored_data) {
+   _mesures= new double[_NMeasurements];
+   int i;
+   for(i = 0; i < _NMeasurements; i++) {
+     _fptr->GetBinTabLine(i,&_mesures[i],NULL,NULL,NULL);
+   }
+ }
+}
+
+DataCircleFits::~DataCircleFits() {
+
+  if(_mesures != NULL) delete [] _mesures;
+}
+
+int DataCircleFits::NMeasurements() const {
+
+  return _NMeasurements;
+}
+
+double DataCircleFits::getData(double psi) const {
+
+  double dtab;
+  int ibin= (int)floor(psi*_NMeasurements/2./M_PI);
+
+  if(_stored_data) {
+    dtab= _mesures[ibin];
+  } else {
+    _fptr->ReadHeader(_ICircle);
+    _fptr->GetBinTabLine(ibin,&dtab,NULL,NULL,NULL);
+  }
+  //cout << "DataCircleFits:: bin= " << ibin << ", " << dtab << endl;
+  return dtab;
+}
+
+void DataCircleFits::print(ostream& out) const {
+
+  out << " Circle:: ApertureAngle= " << ApertureAngle() << ", Theta= " 
+      << Theta() << ", Phi= " << Phi() << ", NSamples= " 
+      << NMeasurements() << endl;
+}
Index: /trunk/SophyaExt/FitsIOServer/datacirclefits.h
===================================================================
--- /trunk/SophyaExt/FitsIOServer/datacirclefits.h	(revision 1770)
+++ /trunk/SophyaExt/FitsIOServer/datacirclefits.h	(revision 1770)
@@ -0,0 +1,27 @@
+#ifndef DATACIRCLEFITS_H_SEEN
+#define DATACIRCLEFITS_H_SEEN
+
+#include "datacirclebase.h"
+#include "fitsfile.h"
+
+class DataCircleFits : public DataCircleBase {
+
+ public:
+
+  DataCircleFits();
+  DataCircleFits(FitsInFile&,int,bool);
+  virtual ~DataCircleFits();
+
+  virtual int NMeasurements() const;
+  virtual double getData(double) const;
+  virtual void print(ostream&) const;
+
+ private:
+
+  FitsInFile* _fptr;
+  int _ICircle;
+  int _NMeasurements;
+  bool _stored_data;
+  double* _mesures;
+};
+#endif
Index: /trunk/SophyaLib/Samba/circle.cc
===================================================================
--- /trunk/SophyaLib/Samba/circle.cc	(revision 1769)
+++ /trunk/SophyaLib/Samba/circle.cc	(revision 1770)
@@ -124,61 +124,4 @@
 }
 
-//++
-bool Circle::Intersection(const Circle& c, double* psi) const 
-//
-//    psi contains  4 values of the intersection  angles. 
-//    -1 if  circles do not intersect
-//    psi[0]=psi(i,j,0)
-//    psi[1]=psi(i,j,1)
-//    psi[2]=psi(j,i,0)
-//    psi[3]=psi(j,i,1)
-//--
-{
-  double alphak=_angouv;
-  double alphal=c._angouv;
-  Vector3d ok=_spinaxis;
-  Vector3d ol=c._spinaxis;
-  double gamma=ok.SepAngle(ol);
-
-  if( fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c ) 
-    { 
-      // then the 2 circles intersect
-      double sg=sin(gamma),cg=cos(gamma);
-      double sak=sin(alphak),cak=cos(alphak);
-      double sal=sin(alphal),cal=cos(alphal);
-      double st=sin(_theta),ct=cos(_theta);
-      double stc=sin(c._theta),ctc=cos(c._theta);
-      double dphi=_phi-c._phi;
-      double sdphi=sin(dphi),cdphi=cos(dphi);
-      double sinusk=stc*sdphi/sg,cosinusk=(ctc*st-stc*ct*cdphi)/sg;
-      double sinusl=-st*sdphi/sg,cosinusl=(ct*stc-st*ctc*cdphi)/sg;
-      double gammaik=scangle(sinusk,cosinusk);
-      double gammail=scangle(sinusl,cosinusl);
-      double omegak=acos((cal-cak*cg)/sg/sak);
-      double omegal=acos((cak-cal*cg)/sg/sal);
-      psi[0]=fmod(gammaik-omegak+pi2,pi2);
-      psi[1]=fmod(gammaik+omegak+pi2,pi2);
-      psi[2]=fmod(gammail-omegal+pi2,pi2);
-      psi[3]=fmod(gammail+omegal+pi2,pi2);
-      if( psi[0] > psi[1] ) 
-	{
-	  // psi[0]=psi(i,j,0)
-	  // psi[1]=psi(i,j,1)
-	  // psi[2]=psi(j,i,0)
-	  // psi[3]=psi(j,i,1)
-	  swap(psi[0],psi[1]); 
-	  swap(psi[2],psi[3]); 
-	}                      
-      return true;
-    }
-  else 
-    {
-      psi[0] = -1.;
-      psi[1] = -1.;
-      psi[2] = -1.;
-      psi[3] = -1.;
-      return false;
-    }
-}
 //++
 UnitVector Circle::ConvToSphere(double psi) const 
@@ -305,13 +248,13 @@
 }
 //
-bool Circle::intersection(const Circle* c) const
+bool Circle::Intersection(const Circle& c) const
 {
   double alphak= _angouv;
-  double alphal= c->_angouv;
+  double alphal= c._angouv;
   Vector3d ok= _spinaxis;
-  Vector3d ol= c->_spinaxis;
+  Vector3d ol= c._spinaxis;
   double gamma= ok.SepAngle(ol);
 
-  if(fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != c) {
+  if(fabs(alphak-alphal) < gamma && gamma <= (alphak+alphal) && this != &c) {
     return true;
   } else {
@@ -320,5 +263,5 @@
 }
 //
-bool Circle::intersection(const Circle& c, double* psi) const
+bool Circle::Intersection(const Circle& c, double* psi) const
 {
   double alphak= _angouv;
Index: /trunk/SophyaLib/Samba/circle.h
===================================================================
--- /trunk/SophyaLib/Samba/circle.h	(revision 1769)
+++ /trunk/SophyaLib/Samba/circle.h	(revision 1770)
@@ -43,7 +43,7 @@
     psi[3]=psi(j,i,1)
   */
-  bool Intersection(const Circle&, double* psi) const;
-  bool intersection(const Circle&, double*) const;
-  bool intersection(const Circle*) const;
+
+  bool Intersection(const Circle&, double*) const;
+  bool Intersection(const Circle&) const;
 
   // donne le UnitVector correspondant a une position donnee sur le cercle
Index: /trunk/SophyaLib/Samba/datacirclebase.h
===================================================================
--- /trunk/SophyaLib/Samba/datacirclebase.h	(revision 1770)
+++ /trunk/SophyaLib/Samba/datacirclebase.h	(revision 1770)
@@ -0,0 +1,19 @@
+#ifndef DATACIRCLEBASE_H_SEEN
+#define DATACIRCLEBASE_H_SEEN
+
+#include "circle.h"
+
+class DataCircleBase : public Circle {
+
+ public:
+
+  DataCircleBase() {;}
+  DataCircleBase(double theta,double phi,double aperture) : Circle(theta,phi,aperture) {;}
+
+  virtual ~DataCircleBase() {;}
+
+  virtual int NMeasurements() const = 0;
+  virtual double getData(double) const = 0;
+  virtual void print(ostream&) const= 0;
+};
+#endif
Index: /trunk/SophyaLib/Samba/datacirclefake.cc
===================================================================
--- /trunk/SophyaLib/Samba/datacirclefake.cc	(revision 1770)
+++ /trunk/SophyaLib/Samba/datacirclefake.cc	(revision 1770)
@@ -0,0 +1,38 @@
+#include <iostream.h>
+#include "datacirclefake.h"
+
+DataCircleFake::DataCircleFake() : _NMeasurements(0), _mesures(NULL) 
+{;}
+
+DataCircleFake::DataCircleFake(double theta,double phi,double aperture,int NEch,double tl) : DataCircleBase(theta,phi,aperture), _NMeasurements(NEch), _mesures(NULL)
+{
+  _mesures= new double[NEch];
+  int i;
+  for(i = 0; i < NEch; i++) {
+    _mesures[i]= tl;
+  }
+}
+
+DataCircleFake::~DataCircleFake()
+{
+  if(_mesures != NULL) delete [] _mesures;
+}
+
+double DataCircleFake::getData(double psi) const {
+
+  int ibin= (int)floor(psi*_NMeasurements/2./M_PI);
+  //cout << "bin= " << ibin << ", " << _mesures[ibin] << endl;
+  return _mesures[ibin];
+}
+
+int DataCircleFake::NMeasurements() const { 
+
+  return _NMeasurements;
+}
+
+void DataCircleFake::print(ostream& out) const {
+
+  out << " Circle:: ApertureAngle= " << ApertureAngle() << ", Theta= " 
+      << Theta() << ", Phi= " << Phi() << ", NSamples= " 
+      << NMeasurements() << endl;
+}
Index: /trunk/SophyaLib/Samba/datacirclefake.h
===================================================================
--- /trunk/SophyaLib/Samba/datacirclefake.h	(revision 1770)
+++ /trunk/SophyaLib/Samba/datacirclefake.h	(revision 1770)
@@ -0,0 +1,23 @@
+#ifndef DATACIRCLEFAKE_H_SEEN
+#define DATACIRCLEFAKE_H_SEEN
+
+#include "datacirclebase.h"
+
+class DataCircleFake : public DataCircleBase {
+
+ public:
+
+  DataCircleFake();
+  DataCircleFake(double,double,double,int,double);
+  virtual ~DataCircleFake();
+
+  virtual int NMeasurements() const;
+  virtual double getData(double) const;
+  virtual void print(ostream&) const;
+
+ private:
+
+  int _NMeasurements;
+  double* _mesures;
+};
+#endif
