Index: trunk/SophyaLib/SkyMap/sphereecp.cc
===================================================================
--- trunk/SophyaLib/SkyMap/sphereecp.cc	(revision 2620)
+++ trunk/SophyaLib/SkyMap/sphereecp.cc	(revision 2621)
@@ -15,4 +15,6 @@
   _phi2 = 2*M_PI;
   _outofmapidx = -99;
+  _outofmapnphi = 0;
+  _outofmapntet = 0;
   _outofmappix = 0;
   _outofmapval = 0;
@@ -31,4 +33,6 @@
   _phi2 = 2*M_PI;
   _outofmapidx = -99;
+  _outofmapnphi = 0;
+  _outofmapntet = 0;
   _outofmappix = 0;
   _outofmapval = 0;
@@ -46,4 +50,6 @@
   _phi2 = 2*M_PI; 
   _outofmapidx = -99;
+  _outofmapnphi = 0;
+  _outofmapntet = 0;
   _outofmappix = 0;
   _outofmapval = 0;
@@ -67,8 +73,17 @@
   _phi2 = phi2; 
   _outofmapidx = _pixels.Size()+659;
+  // Reza, 23 sep 2004 
+  // pour des cartes partielles, et des pixels sur la sphere, mais 
+  // en dehors de la couverture, on code le numero de tranche en theta, 
+  // compte a partir de theta=0,phi=0 +  _outofmapidx
+  // theta -> idx =  _outofmapidx + theta/_dtheta*_outofmapnphi +  _outofmapntet
+  _outofmapntet = 0;
   _outofmappix = 0;
   _outofmapval = 0;
   _dtheta = (_theta2-_theta1)/ntet;
   _dphi = (_phi2-_phi1)/nphi;
+
+  _outofmapntet = M_PI/_dtheta;
+  _outofmapnphi = 2*M_PI/_dphi;
 }
 
@@ -83,4 +98,6 @@
   _phi2 = a._phi2;   
   _outofmapidx = a._outofmapidx;
+  _outofmapnphi = a._outofmapnphi;
+  _outofmapntet = a._outofmapntet;
   _outofmappix = a._outofmappix;
   _outofmapval = a._outofmapval;
@@ -99,4 +116,6 @@
   _phi2 = a._phi2;   
   _outofmapidx = a._outofmapidx;
+  _outofmapnphi = a._outofmapnphi;
+  _outofmapntet = a._outofmapntet;
   _outofmappix = a._outofmappix;
   _outofmapval = a._outofmapval;
@@ -131,5 +150,6 @@
 T& SphereECP<T>::PixVal(int_4 k)
 {
-  if ((_partial) && (k==_outofmapidx))   return _outofmappix;
+  // On pourrait etre plus strict en demandant aussi k<_outofmapidx+_outofmapnphi*_outofmapntet (Reza 23/09/04)
+  if ((_partial) && (k>=_outofmapidx))   return _outofmappix;
   if((k < 0) || (k >= _pixels.Size()) )  
      throw RangeCheckError("SphereECP::PIxVal() Pixel index out of range");
@@ -140,5 +160,6 @@
 T const& SphereECP<T>::PixVal(int_4 k)  const
 {
-  if ((_partial) && (k==_outofmapidx))   return _outofmapval;
+  // On pourrait etre plus strict en demandant aussi k<_outofmapidx+_outofmapnphi*_outofmapntet (Reza 23/09/04)
+  if ((_partial) && (k>=_outofmapidx))   return _outofmapval;
   if((k < 0) || (k >= _pixels.Size()) )  
      throw RangeCheckError("SphereECP::PIxVal() Pixel index out of range");
@@ -165,5 +186,5 @@
   if (_partial) {
     if ( (theta < _theta1) || (theta > _theta2) ||
-	 (phi < _phi1) || (phi > _phi2) )  return _outofmapidx;
+	 (phi < _phi1) || (phi > _phi2) )  return _outofmapidx+theta/_dtheta*_outofmapnphi+phi/_dphi;
   }
   int_4 it = (theta-_theta1)/_dtheta;
@@ -175,7 +196,7 @@
 void  SphereECP<T>::PixThetaPhi(int_4 k, double& theta, double& phi) const
 {
-  if ((_partial) && (k==_outofmapidx)) {
-    theta = M_PI;
-    phi = 2*M_PI;
+  if ((_partial) && (k>=_outofmapidx)) {
+    theta = (((k-_outofmapidx) / _outofmapnphi)+0.5)*_dtheta;
+    phi = (((k-_outofmapidx) % _outofmapnphi)+0.5)*_dphi;;
     return;
   }
@@ -185,6 +206,6 @@
   int_4 it = k / _pixels.SizeX();
   int_4 jp = k % _pixels.SizeX();
-  theta = _theta1+it*_dtheta;
-  phi = _phi1*jp*_dphi;
+  theta = _theta1+(it+0.5)*_dtheta;
+  phi = _phi1*(jp+0.5)*_dphi;
   return;
 }
@@ -200,5 +221,11 @@
 double  SphereECP<T>::PixSolAngle(int_4 k) const
 {
-  if ((k < 0) || (k >= _pixels.Size()))  return (_dtheta*_dphi);
+  if ((_partial) && (k>=_outofmapidx)) {
+    double theta = (((k-_outofmapidx) / _outofmapnphi)+0.5)*_dtheta;
+    return (_dtheta*_dphi*sin(theta));
+  }
+  if((k < 0) || (k >= _pixels.Size()) )  
+     throw RangeCheckError("SphereECP::PixSolAngle(int_4 k) Pixel index out of range");
+
   int_4 it = k / _pixels.SizeX();
   double theta = _theta1+it*_dtheta;
@@ -229,4 +256,7 @@
   _dtheta = (_theta2-_theta1)/m;
   _dphi = (_phi2-_phi1)/mphi;
+
+  _outofmapntet = M_PI/_dtheta;
+  _outofmapnphi = 2*M_PI/_dphi;
   return;
 }
@@ -245,5 +275,5 @@
      throw RangeCheckError("SphereECP::GetThetaSlice() theta index out of range");
 
-  theta = _theta1 + index*_dtheta;
+  theta = _theta1 + (index+0.5)*_dtheta;
   int_4 nphit = 2.*M_PI/_dphi;
   phi.ReSize(nphit); 
@@ -252,13 +282,13 @@
   int_4 i;
   for(i=0; i<ioff; i++) {
-    phi(i) = _phi1 + (i-ioff)*_dphi;
+    phi(i) = _phi1 + (i-ioff+0.5)*_dphi;
     value(i) = _outofmapval;
   }
   for(i=ioff; i<ioff+_pixels.SizeX(); i++) {
-    phi(i) = _phi1 + (i-ioff)*_dphi;
+    phi(i) = _phi1 + (i-ioff+0.5)*_dphi;
     value(i) = _pixels(i-ioff,index,0);
   }
   for(i=ioff+_pixels.SizeX(); i<nphit; i++) {
-    phi(i) = _phi1 + (i-ioff)*_dphi;
+    phi(i) = _phi1 + (i-ioff+0.5)*_dphi;
     value(i) = _outofmapval;
   }
@@ -273,7 +303,7 @@
     throw RangeCheckError("SphereECP::GetThetaSlice() theta index out of range");
   
-  theta = _theta1 + index*_dtheta;
+  theta = _theta1 + (index+0.5)*_dtheta;
   int_4 ioff = _phi1/_dphi;
-  phi0 = _phi1 - ioff*_dphi;
+  phi0 = _phi1 - (ioff-0.5)*_dphi;
 
   int_4 nphit = 2.*M_PI/_dphi;
@@ -283,5 +313,5 @@
   int_4 i;
   for(i=0; i<ioff; i++) {
-    pixidx(i) =  _outofmapidx;
+    pixidx(i) = _outofmapidx+theta/_dtheta*_outofmapnphi+phi0/_dphi+i;
     value(i) = _outofmapval;
   }
@@ -291,5 +321,5 @@
   }
   for(i=ioff+_pixels.SizeX(); i<nphit; i++) {
-    pixidx(i) =  _outofmapidx;
+    pixidx(i) = _outofmapidx+theta/_dtheta*_outofmapnphi+phi0/_dphi+i;
     value(i) = _outofmapval;
   }
@@ -322,4 +352,6 @@
   _phi2 = a._phi2;   
   _outofmapidx = a._outofmapidx;
+  _outofmapnphi = a._outofmapnphi;
+  _outofmapntet = a._outofmapntet;
   _outofmappix = a._outofmappix;
   _outofmapval = a._outofmapval;
