Index: trunk/SophyaLib/SkyMap/localmap.cc
===================================================================
--- trunk/SophyaLib/SkyMap/localmap.cc	(revision 907)
+++ trunk/SophyaLib/SkyMap/localmap.cc	(revision 908)
@@ -96,7 +96,471 @@
 //--
 {
-  cout<<" LocalMap:: Appel du constructeur de recopie " << endl;
 
   if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
+  recopierVariablesSimples(lm);
+}
+
+//++
+template<class T>
+LocalMap<T>::LocalMap(const LocalMap<T>& lm)
+  : pixels_(lm.pixels_)
+
+//
+//    copy constructor
+//--
+{
+
+  if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
+  recopierVariablesSimples(lm);
+}
+
+//++
+// Titre	Destructor
+//--
+//++
+template<class T>
+LocalMap<T>::~LocalMap()
+//
+//--
+{
+  InitNul();
+}
+
+
+
+//++
+// Titre	Public Methods
+//--
+
+//++
+template<class T>
+void LocalMap<T>::ReSize(int_4 nx, int_4 ny) 
+//
+//    Resize storage area for pixels 
+//--
+{
+  InitNul();
+  nSzX_ = nx;
+  nSzY_ = ny;
+  nPix_= nx*ny;
+  pixels_.ReSize(nPix_);
+  pixels_.Reset();
+}
+
+template<class T>
+LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a)
+   {
+  if (this != &a) 
+    { 
+      recopierVariablesSimples(a);     
+      pixels_.CloneOrShare(a.pixels_);
+      if (mInfo_) delete mInfo_;
+      mInfo_ = NULL;
+      if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
+    }
+  return(*this);
+   }
+
+
+//++
+template<class T>
+int_4 LocalMap<T>::NbPixels() const
+//
+//    Return number of pixels
+//--
+{
+  return(nPix_);
+}
+
+//++
+template<class T>
+T& LocalMap<T>::PixVal(int_4 k)
+//
+//    Return value of pixel with index k
+//--
+{
+  if((k < 0) || (k >= nPix_)) 
+    {
+      cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
+      //  THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
+      THROW(rangeCheckErr);
+      //throw "LocalMap::PIxVal Pixel index out of range";
+    }
+  return(pixels_(k));
+}
+
+//++
+
+template<class T>
+T const& LocalMap<T>::PixVal(int_4 k) const
+//
+//   const version of previous method
+//--
+{
+  if((k < 0) || (k >= nPix_)) 
+    {
+      cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
+      //    THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
+      
+      throw "LocalMap::PIxVal Pixel index out of range"; 
+    } 
+  return *(pixels_.Data()+k);
+}
+
+template<class T>
+bool LocalMap<T>::ContainsSph(double theta, double phi) const
+{
+// $CHECK$  Reza 11/11/99 - A modifier
+return(true);
+}
+
+//++
+template<class T>
+int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
+//
+//    Return index of the pixel with spherical coordinates (theta,phi)
+//--
+{
+  int_4 i,j;
+  if(!(originFlag_) || !(extensFlag_)) 
+    {
+      cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
+      exit(0);
+    }
+
+  // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference)
+  double theta_aux= theta;
+  double phi_aux  = phi;
+  UserToReference(theta_aux, phi_aux);
+
+  // coordonnees dans le plan local en unites de pixels
+  double x,y;
+  AngleProjToPix(theta_aux,phi_aux, x, y);
+
+  double xmin= -x0_-0.5;
+  double xmax= xmin+nSzX_;
+  if((x > xmax) || (x < xmin)) return(-1);
+  double xcurrent= xmin;
+  for(i = 0; i < nSzX_; i++ ) 
+    {
+      xcurrent += 1.;
+      if( x < xcurrent ) break;
+    }
+  double ymin= -y0_-0.5;
+  double ymax= ymin+nSzY_;
+  if((y >  ymax) || (y < ymin)) return(-1);
+  double ycurrent= ymin;
+  for(j = 0; j < nSzY_; j++ ) 
+    {
+      ycurrent += 1.;
+      if( y < ycurrent ) break;
+    }
+  return (j*nSzX_+i);
+}
+
+//++
+template<class T>
+void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
+//
+//    Return (theta, phi) coordinates of pixel with index k
+//--
+{
+  if(!(originFlag_) || !(extensFlag_)) 
+    {
+      cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
+      exit(0);
+    }
+
+  int_4 i,j;
+  Getij(k,i,j);
+
+  double X= double(i-x0_);
+  double Y= double(j-y0_);
+  // situation de ce pixel dans le plan de reference
+  double x= X*cos_angle_-Y*sin_angle_;
+  double y= X*sin_angle_+Y* cos_angle_;
+  // projection sur la sphere
+  PixProjToAngle(x, y, theta, phi);
+  // retour au plan utilisateur
+  ReferenceToUser(theta, phi);
+}
+
+template <class T>
+T LocalMap<T>::SetPixels(T v)
+{
+pixels_.Reset(v);
+return(v);
+}
+ 
+//++
+template<class T>
+double LocalMap<T>::PixSolAngle(int_4 k) const
+//
+//    Pixel Solid angle  (steradians)
+//    All the pixels have not necessarly the same size in (theta, phi)
+//    because of the projection scheme which is not yet fixed.   
+//--
+{
+  int_4 i,j;
+  Getij(k,i,j);
+  double X= double(i-x0_);
+  double Y= double(j-y0_);
+  double XR= X+double(i)*0.5;
+  double XL= X-double(i)*0.5;
+  double YU= Y+double(j)*0.5;
+  double YL= Y-double(j)*0.5;
+
+  // situation  dans le plan de reference
+  double x0= XL*cos_angle_-YL*sin_angle_;
+  double y0= XL*sin_angle_+YL*cos_angle_;
+  double xa= XR*cos_angle_-YL*sin_angle_;
+  double ya= XR*sin_angle_+YL*cos_angle_;
+  double xb= XL*cos_angle_-YU*sin_angle_;
+  double yb= XL*sin_angle_+YU*cos_angle_;
+
+  // projection sur la sphere
+  double thet0,phi0,theta,phia,thetb,phib;
+  PixProjToAngle(x0, y0, thet0, phi0);
+  PixProjToAngle(xa, ya, theta, phia);
+  PixProjToAngle(xb, yb, thetb, phib);
+
+  // angle solide
+  double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0));
+  return sol;
+}
+
+//++
+template<class T>
+void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
+//
+//    set the referential of the map (angles in degrees)
+//    (default x0=siz_x/2,  y0=siz_y/2) 
+//--
+{
+  theta0_= theta0;
+  phi0_  = phi0;
+  angle_ = angle;
+  x0_= nSzX_/2;
+  y0_= nSzY_/2;
+  cos_angle_= cos(angle*Pi/180.);
+  sin_angle_= sin(angle*Pi/180.);
+  originFlag_= true; 
+  cout << " LocalMap:: set origin 1 done" << endl;
+}
+ 
+//++
+template<class T>
+void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
+//
+//    set the referential of the map (angles in degrees)
+//--
+{
+  theta0_= theta0;
+  phi0_  = phi0;
+  angle_ = angle;
+  x0_= x0;
+  y0_= y0;
+  cos_angle_= cos(angle*Pi/180.);
+  sin_angle_= sin(angle*Pi/180.);
+  originFlag_= true;
+  cout << " LocalMap:: set origin 2 done" << endl;
+} 
+
+//++
+template<class T>
+void LocalMap<T>::SetSize(double angleX,double angleY)
+//
+//    angle range of tthe map (angles in degrees)
+//--
+{
+  angleX_= angleX;
+  angleY_= angleY;
+
+  // tangente de la moitie de l'ouverture angulaire totale
+  tgAngleX_= tan(0.5*angleX_*Pi/180.);
+  tgAngleY_= tan(0.5*angleY_*Pi/180.);
+
+  extensFlag_= true;
+  cout << " LocalMap:: set extension done" << endl;
+}
+
+//++
+template<class T>
+void LocalMap<T>::Project(SphericalMap<T>& sphere) const
+//
+//    Projection to a spherical map   
+//--
+{
+  for(int m = 0; m < nPix_; m++) 
+    {
+      double theta,phi;
+      PixThetaPhi(m,theta,phi);
+      sphere(theta,phi)= pixels_(m);
+      // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl;
+    }
+}
+// Titre	Private Methods
+//++
+template<class T>
+void LocalMap<T>::InitNul()
+//
+//    set some attributes to zero
+//--
+{ 
+  originFlag_= false;
+  extensFlag_= false;
+  cos_angle_= 1.0;
+  sin_angle_= 0.0;
+//  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
+}
+
+//++
+template<class T>
+void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
+//
+//    Return 2 indices corresponding to the pixel number k
+//--
+{
+  i= (k+1)%nSzX_-1;
+  if(i == -1) i= nSzX_-1;
+  j= (k-i+2)/nSzX_;
+}
+
+//++
+template<class T>
+void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const
+//
+//    Transform a pair of coordinates (theta, phi) given in 
+//    reference coordinates into map coordinates
+//--     
+{
+  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
+    {
+      throw "LocalMap::ReferenceToUser (theta,phi) out of range"; 
+    } 
+
+  theta= theta0_*Pi/180.+theta-Pi*0.5;
+  if(theta < 0.) 
+    {
+      theta= -theta;
+      phi += Pi;
+    } 
+  else 
+    {
+      if(theta > Pi) 
+	{
+	  theta= 2.*Pi-theta;
+	  phi += Pi;
+	} 
+    }
+
+  phi= phi0_*Pi/180.+phi;
+  while(phi >= 2.*Pi) phi-= 2.*Pi;
+
+  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
+    {
+      cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl;
+      cout << " theta= " << theta << " phi= " << phi << endl;
+      exit(0);
+    }
+}
+
+//++
+template<class T>
+void  LocalMap<T>::UserToReference(double& theta,double& phi) const
+//
+//    Transform a pair of coordinates (theta, phi) given in 
+//    map coordinates into reference coordinates
+//--     
+{
+  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
+    {
+      cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl;
+      // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
+      throw "LocalMap::UserToReference (theta,phi) out of range"; 
+    }
+
+  double phi1= phi-phi0_*Pi/180.;
+  if(phi1 < 0.) phi1+= 2.*Pi;
+
+  double theta1= theta-theta0_*Pi/180.+Pi*0.5;
+  if(theta1 < 0.) 
+    {
+      theta= -theta1;
+      phi1+= Pi;
+    } 
+  else
+    { 
+      if(theta1 > Pi) 
+	{
+	  theta= 2.*Pi-theta1;
+	  phi1+= Pi;
+	}
+    }
+
+  while(phi1 >= 2.*Pi) phi1-= 2.*Pi;
+  phi= phi1;
+  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
+    {
+      cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl;
+      cout << " theta= " << theta << " phi= " << phi << endl;
+      exit(0);
+    }
+}
+
+//++
+template<class T>
+void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const
+//
+//  
+//    Given coordinates in pixel units in the REFERENCE PLANE, return
+//    (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.   
+//--
+{
+  theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_);
+  phi= atan2(2.*x*tgAngleX_,(double)nSzX_);
+  if(phi < 0.) phi += DeuxPi;
+}
+
+//++
+template<class T>
+void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const
+//
+//    Given coordinates  (theta, phi) in "absolute" referential 
+//    theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE.
+//--
+{
+  if(phi >= Pi) phi-= DeuxPi;
+  //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$
+  y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ?  
+  x= 0.5*nSzX_*tan(phi)/tgAngleX_;
+}
+
+template<class T>
+void LocalMap<T>::print(ostream& os) const
+{
+  os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
+  if(LocalMap_isDone())
+    {
+      os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl;
+      os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
+      os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl;
+      os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl;
+      os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl;
+    }
+
+  os << " contenu de pixels : ";
+  for(int i=0; i < nPix_; i++)
+    {
+      if(i%5 == 0) os << endl;
+      os <<  pixels_(i) <<", ";
+    }
+  os << endl;
+}
+
+
+template<class T>
+void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
+{
   nSzX_= lm.nSzX_;
   nSzY_= lm.nSzY_;
@@ -117,432 +581,5 @@
 }
 
-//++
-// Titre	Destructor
-//--
-//++
-template<class T>
-LocalMap<T>::~LocalMap()
-//
-//--
-{
-  InitNul();
-}
-
-
-
-//++
-// Titre	Public Methods
-//--
-
-//++
-template<class T>
-void LocalMap<T>::ReSize(int_4 nx, int_4 ny) 
-//
-//    Resize storage area for pixels 
-//--
-{
-  InitNul();
-  nSzX_ = nx;
-  nSzY_ = ny;
-  nPix_= nx*ny;
-  pixels_.ReSize(nPix_);
-  pixels_.Reset();
-}
-
-//++
-template<class T>
-int_4 LocalMap<T>::NbPixels() const
-//
-//    Return number of pixels
-//--
-{
-  return(nPix_);
-}
-
-//++
-template<class T>
-T& LocalMap<T>::PixVal(int_4 k)
-//
-//    Return value of pixel with index k
-//--
-{
-  if((k < 0) || (k >= nPix_)) 
-    {
-      cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
-      //  THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
-      THROW(rangeCheckErr);
-      //throw "LocalMap::PIxVal Pixel index out of range";
-    }
-  return(pixels_(k));
-}
-
-//++
-
-template<class T>
-T const& LocalMap<T>::PixVal(int_4 k) const
-//
-//   const version of previous method
-//--
-{
-  if((k < 0) || (k >= nPix_)) 
-    {
-      cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
-      //    THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
-      
-      throw "LocalMap::PIxVal Pixel index out of range"; 
-    } 
-  return *(pixels_.Data()+k);
-}
-
-template<class T>
-bool LocalMap<T>::ContainsSph(double theta, double phi) const
-{
-// $CHECK$  Reza 11/11/99 - A modifier
-return(true);
-}
-
-//++
-template<class T>
-int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
-//
-//    Return index of the pixel with spherical coordinates (theta,phi)
-//--
-{
-  int_4 i,j;
-  if(!(originFlag_) || !(extensFlag_)) 
-    {
-      cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
-      exit(0);
-    }
-
-  // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference)
-  double theta_aux= theta;
-  double phi_aux  = phi;
-  UserToReference(theta_aux, phi_aux);
-
-  // coordonnees dans le plan local en unites de pixels
-  double x,y;
-  AngleProjToPix(theta_aux,phi_aux, x, y);
-
-  double xmin= -x0_-0.5;
-  double xmax= xmin+nSzX_;
-  if((x > xmax) || (x < xmin)) return(-1);
-  double xcurrent= xmin;
-  for(i = 0; i < nSzX_; i++ ) 
-    {
-      xcurrent += 1.;
-      if( x < xcurrent ) break;
-    }
-  double ymin= -y0_-0.5;
-  double ymax= ymin+nSzY_;
-  if((y >  ymax) || (y < ymin)) return(-1);
-  double ycurrent= ymin;
-  for(j = 0; j < nSzY_; j++ ) 
-    {
-      ycurrent += 1.;
-      if( y < ycurrent ) break;
-    }
-  return (j*nSzX_+i);
-}
-
-//++
-template<class T>
-void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
-//
-//    Return (theta, phi) coordinates of pixel with index k
-//--
-{
-  if(!(originFlag_) || !(extensFlag_)) 
-    {
-      cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
-      exit(0);
-    }
-
-  int_4 i,j;
-  Getij(k,i,j);
-
-  double X= double(i-x0_);
-  double Y= double(j-y0_);
-  // situation de ce pixel dans le plan de reference
-  double x= X*cos_angle_-Y*sin_angle_;
-  double y= X*sin_angle_+Y* cos_angle_;
-  // projection sur la sphere
-  PixProjToAngle(x, y, theta, phi);
-  // retour au plan utilisateur
-  ReferenceToUser(theta, phi);
-}
-
-template <class T>
-T LocalMap<T>::SetPixels(T v)
-{
-pixels_.Reset(v);
-return(v);
-}
- 
-//++
-template<class T>
-double LocalMap<T>::PixSolAngle(int_4 k) const
-//
-//    Pixel Solid angle  (steradians)
-//    All the pixels have not necessarly the same size in (theta, phi)
-//    because of the projection scheme which is not yet fixed.   
-//--
-{
-  int_4 i,j;
-  Getij(k,i,j);
-  double X= double(i-x0_);
-  double Y= double(j-y0_);
-  double XR= X+double(i)*0.5;
-  double XL= X-double(i)*0.5;
-  double YU= Y+double(j)*0.5;
-  double YL= Y-double(j)*0.5;
-
-  // situation  dans le plan de reference
-  double x0= XL*cos_angle_-YL*sin_angle_;
-  double y0= XL*sin_angle_+YL*cos_angle_;
-  double xa= XR*cos_angle_-YL*sin_angle_;
-  double ya= XR*sin_angle_+YL*cos_angle_;
-  double xb= XL*cos_angle_-YU*sin_angle_;
-  double yb= XL*sin_angle_+YU*cos_angle_;
-
-  // projection sur la sphere
-  double thet0,phi0,theta,phia,thetb,phib;
-  PixProjToAngle(x0, y0, thet0, phi0);
-  PixProjToAngle(xa, ya, theta, phia);
-  PixProjToAngle(xb, yb, thetb, phib);
-
-  // angle solide
-  double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0));
-  return sol;
-}
-
-//++
-template<class T>
-void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
-//
-//    set the referential of the map (angles in degrees)
-//    (default x0=siz_x/2,  y0=siz_y/2) 
-//--
-{
-  theta0_= theta0;
-  phi0_  = phi0;
-  angle_ = angle;
-  x0_= nSzX_/2;
-  y0_= nSzY_/2;
-  cos_angle_= cos(angle*Pi/180.);
-  sin_angle_= sin(angle*Pi/180.);
-  originFlag_= true; 
-  cout << " LocalMap:: set origin 1 done" << endl;
-}
- 
-//++
-template<class T>
-void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
-//
-//    set the referential of the map (angles in degrees)
-//--
-{
-  theta0_= theta0;
-  phi0_  = phi0;
-  angle_ = angle;
-  x0_= x0;
-  y0_= y0;
-  cos_angle_= cos(angle*Pi/180.);
-  sin_angle_= sin(angle*Pi/180.);
-  originFlag_= true;
-  cout << " LocalMap:: set origin 2 done" << endl;
-} 
-
-//++
-template<class T>
-void LocalMap<T>::SetSize(double angleX,double angleY)
-//
-//    angle range of tthe map (angles in degrees)
-//--
-{
-  angleX_= angleX;
-  angleY_= angleY;
-
-  // tangente de la moitie de l'ouverture angulaire totale
-  tgAngleX_= tan(0.5*angleX_*Pi/180.);
-  tgAngleY_= tan(0.5*angleY_*Pi/180.);
-
-  extensFlag_= true;
-  cout << " LocalMap:: set extension done" << endl;
-}
-
-//++
-template<class T>
-void LocalMap<T>::Project(SphericalMap<T>& sphere) const
-//
-//    Projection to a spherical map   
-//--
-{
-  for(int m = 0; m < nPix_; m++) 
-    {
-      double theta,phi;
-      PixThetaPhi(m,theta,phi);
-      sphere(theta,phi)= pixels_(m);
-      // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl;
-    }
-}
-// Titre	Private Methods
-//++
-template<class T>
-void LocalMap<T>::InitNul()
-//
-//    set some attributes to zero
-//--
-{ 
-  originFlag_= false;
-  extensFlag_= false;
-  cos_angle_= 1.0;
-  sin_angle_= 0.0;
-//  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
-}
-
-//++
-template<class T>
-void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
-//
-//    Return 2 indices corresponding to the pixel number k
-//--
-{
-  i= (k+1)%nSzX_-1;
-  if(i == -1) i= nSzX_-1;
-  j= (k-i+2)/nSzX_;
-}
-
-//++
-template<class T>
-void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const
-//
-//    Transform a pair of coordinates (theta, phi) given in 
-//    reference coordinates into map coordinates
-//--     
-{
-  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
-    {
-      throw "LocalMap::ReferenceToUser (theta,phi) out of range"; 
-    } 
-
-  theta= theta0_*Pi/180.+theta-Pi*0.5;
-  if(theta < 0.) 
-    {
-      theta= -theta;
-      phi += Pi;
-    } 
-  else 
-    {
-      if(theta > Pi) 
-	{
-	  theta= 2.*Pi-theta;
-	  phi += Pi;
-	} 
-    }
-
-  phi= phi0_*Pi/180.+phi;
-  while(phi >= 2.*Pi) phi-= 2.*Pi;
-
-  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
-    {
-      cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl;
-      cout << " theta= " << theta << " phi= " << phi << endl;
-      exit(0);
-    }
-}
-
-//++
-template<class T>
-void  LocalMap<T>::UserToReference(double& theta,double& phi) const
-//
-//    Transform a pair of coordinates (theta, phi) given in 
-//    map coordinates into reference coordinates
-//--     
-{
-  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
-    {
-      cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl;
-      // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
-      throw "LocalMap::UserToReference (theta,phi) out of range"; 
-    }
-
-  double phi1= phi-phi0_*Pi/180.;
-  if(phi1 < 0.) phi1+= 2.*Pi;
-
-  double theta1= theta-theta0_*Pi/180.+Pi*0.5;
-  if(theta1 < 0.) 
-    {
-      theta= -theta1;
-      phi1+= Pi;
-    } 
-  else
-    { 
-      if(theta1 > Pi) 
-	{
-	  theta= 2.*Pi-theta1;
-	  phi1+= Pi;
-	}
-    }
-
-  while(phi1 >= 2.*Pi) phi1-= 2.*Pi;
-  phi= phi1;
-  if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
-    {
-      cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl;
-      cout << " theta= " << theta << " phi= " << phi << endl;
-      exit(0);
-    }
-}
-
-//++
-template<class T>
-void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const
-//
-//  
-//    Given coordinates in pixel units in the REFERENCE PLANE, return
-//    (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.   
-//--
-{
-  theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_);
-  phi= atan2(2.*x*tgAngleX_,(double)nSzX_);
-  if(phi < 0.) phi += DeuxPi;
-}
-
-//++
-template<class T>
-void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const
-//
-//    Given coordinates  (theta, phi) in "absolute" referential 
-//    theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE.
-//--
-{
-  if(phi >= Pi) phi-= DeuxPi;
-  //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$
-  y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ?  
-  x= 0.5*nSzX_*tan(phi)/tgAngleX_;
-}
-
-template<class T>
-void LocalMap<T>::print(ostream& os) const
-{
-  os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
-  if(LocalMap_isDone())
-    {
-      os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl;
-      os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
-      os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl;
-      os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl;
-      os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl;
-    }
-
-  os << " contenu de pixels : ";
-  for(int i=0; i < nPix_; i++)
-    {
-      if(i%5 == 0) os << endl;
-      os <<  pixels_(i) <<", ";
-    }
-  os << endl;
-}
+
 //++
 // Titre	class FIO_LocalMap
Index: trunk/SophyaLib/SkyMap/localmap.h
===================================================================
--- trunk/SophyaLib/SkyMap/localmap.h	(revision 907)
+++ trunk/SophyaLib/SkyMap/localmap.h	(revision 908)
@@ -72,6 +72,8 @@
 LocalMap(int_4 nx, int_4 ny);
 LocalMap(const LocalMap<T>& lm, bool share=false);
+LocalMap(const LocalMap<T>& lm);
 virtual ~LocalMap();
 
+inline virtual bool IsTemp(void) const { return pixels_.IsTemp();}
 /*! Setting blockdata to temporary (see ndatablock documentation) */
 inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
@@ -166,4 +168,8 @@
 void print(ostream& os) const;
 
+inline  LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);}
+
+
+
 // ---------- Méthodes internes -----------------------------
           
@@ -189,4 +195,8 @@
 */
 void AngleProjToPix(double theta,double phi,double& x,double& y) const; 
+
+void recopierVariablesSimples(const LocalMap<T>& lm);
+LocalMap<T>& Set(const LocalMap<T>& a);
+
 
 // ---------- Variables internes ----------------------------
Index: trunk/SophyaLib/SkyMap/pixelmap.h
===================================================================
--- trunk/SophyaLib/SkyMap/pixelmap.h	(revision 907)
+++ trunk/SophyaLib/SkyMap/pixelmap.h	(revision 908)
@@ -19,4 +19,11 @@
 \endverbatim
 */
+
+
+namespace SOPHYA {
+
+
+
+
 template<class T>
 class PixelMap  : public AnyDataObj 
@@ -136,3 +143,6 @@
 }
 
+
+} // Fin du namespace
+
 #endif
Index: trunk/SophyaLib/SkyMap/spherehealpix.cc
===================================================================
--- trunk/SophyaLib/SkyMap/spherehealpix.cc	(revision 907)
+++ trunk/SophyaLib/SkyMap/spherehealpix.cc	(revision 908)
@@ -246,11 +246,4 @@
 void SphereHEALPix<T>::CloneOrShare(const SphereHEALPix<T>& a)
 {
-  string exmsg = "SphereHEALPix<T>::CloneOrShare()";
-  if (nSide_ != a.nSide_ ) 
-    {
-      cout << " spheres of different sizes " << endl;
-      string exmsg = "SphereHEALPix<T>::CloneOrShare()";
-      throw( ParmError(exmsg) );
-    }
   pixels_.CloneOrShare(a.pixels_);
   sliceBeginIndex_.CloneOrShare(a.sliceBeginIndex_);
@@ -263,9 +256,10 @@
   if (this != &a) 
     { 
-      CloneOrShare(a);
       nSide_= a.nSide_;
      nPix_ = a.nPix_;
      omeg_ = a.omeg_;
+     CloneOrShare(a);
      if (mInfo_) delete mInfo_;
+     mInfo_ = NULL;
      if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
     }
Index: trunk/SophyaLib/SkyMap/spherehealpix.h
===================================================================
--- trunk/SophyaLib/SkyMap/spherehealpix.h	(revision 907)
+++ trunk/SophyaLib/SkyMap/spherehealpix.h	(revision 908)
@@ -84,4 +84,11 @@
 virtual ~SphereHEALPix();
 
+  // Temporaire?
+inline virtual bool   IsTemp(void) const {
+
+    if (sliceBeginIndex_.IsTemp() != pixels_.IsTemp() || sliceLenght_.IsTemp() != pixels_.IsTemp() )
+      throw PException(" l'etat 'temporaire' de la spherehealpix est incoherent"); 
+    return pixels_.IsTemp();
+}
 /*! Setting blockdata to temporary (see ndatablock documentation) */
 inline virtual void SetTemp(bool temp=false) const 
@@ -206,7 +213,4 @@
 
 
- void CloneOrShare(const SphereHEALPix<T>& a);
-
- SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
 
 inline  SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a) 
@@ -233,4 +237,7 @@
   }
 
+ void CloneOrShare(const SphereHEALPix<T>& a);
+ SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
+
 // ------------- variables internes -----------------------
 
Index: trunk/SophyaLib/SkyMap/spherethetaphi.cc
===================================================================
--- trunk/SophyaLib/SkyMap/spherethetaphi.cc	(revision 907)
+++ trunk/SophyaLib/SkyMap/spherethetaphi.cc	(revision 908)
@@ -64,16 +64,22 @@
 template <class T>
 SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s, bool share)
-  : pixels_(s.pixels_ , share)
+  : NPhi_(s.NPhi_, share), TNphi_(s.TNphi_, share), Theta_(s.Theta_, share),
+    pixels_(s.pixels_ , share) 
 {
   if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
+
   NTheta_= s.NTheta_;
   NPix_  = s.NPix_;
-  NPhi_.ReSize(NTheta_);
-  Theta_.ReSize(NTheta_+1);
-  TNphi_.ReSize(NTheta_+1);
-
-  NPhi_  = s.NPhi_;
-  TNphi_ = s.TNphi_;
-  Theta_ = s.Theta_;
+  Omega_ = s.Omega_;
+}
+
+template <class T>
+SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s)
+  : NPhi_(s.NPhi_), TNphi_(s.TNphi_), Theta_(s.Theta_), pixels_(s.pixels_) 
+{
+  if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
+
+  NTheta_= s.NTheta_;
+  NPix_  = s.NPix_;
   Omega_ = s.Omega_;
 }
@@ -111,4 +117,34 @@
   Pixelize(m);
 }
+
+template<class T>
+void  SphereThetaPhi<T>::CloneOrShare(const  SphereThetaPhi<T>& a)
+{
+
+    NPhi_.CloneOrShare(a.NPhi_);
+    TNphi_.CloneOrShare(a.TNphi_);
+    Theta_.CloneOrShare(a.Theta_);
+    pixels_.CloneOrShare(a.pixels_);
+}
+
+template<class T>
+SphereThetaPhi<T>& SphereThetaPhi<T>::Set(const SphereThetaPhi<T>& a)
+   {
+  if (this != &a) 
+    { 
+
+
+      NTheta_= a.NTheta_;
+      NPix_  = a.NPix_;
+      Omega_ = a.Omega_;
+      CloneOrShare(a);
+      if (mInfo_) delete mInfo_;
+      mInfo_ = NULL;
+      if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
+    }
+  return(*this);
+   }
+
+
 
 /* --Methode-- */
Index: trunk/SophyaLib/SkyMap/spherethetaphi.h
===================================================================
--- trunk/SophyaLib/SkyMap/spherethetaphi.h	(revision 907)
+++ trunk/SophyaLib/SkyMap/spherethetaphi.h	(revision 908)
@@ -42,9 +42,25 @@
 */
 SphereThetaPhi(int_4 m);
-SphereThetaPhi(const SphereThetaPhi<T>& s, bool share=false);
+SphereThetaPhi(const SphereThetaPhi<T>& s, bool share);
+SphereThetaPhi(const SphereThetaPhi<T>& s);
 virtual ~SphereThetaPhi();
 
+  // Temporaire?
+inline virtual bool IsTemp(void) const {
+
+    if (  NPhi_.IsTemp()  != pixels_.IsTemp() || 
+	  TNphi_.IsTemp() != pixels_.IsTemp()|| 
+	  Theta_.IsTemp() != pixels_.IsTemp()    )
+      throw PException(" l'etat 'temporaire' de la spherethetaphi est incoherent"); 
+    return pixels_.IsTemp();
+}
 /*! Setting blockdata to temporary (see ndatablock documentation) */
-inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
+inline virtual void SetTemp(bool temp=false) const 
+  {
+    NPhi_.SetTemp(temp);
+    TNphi_.SetTemp(temp);
+    Theta_.SetTemp(temp);
+    pixels_.SetTemp(temp);
+  };
 
 // ------------ Definition of PixelMap abstract methods -
@@ -164,4 +180,8 @@
 /* impression */ 
 void print(ostream& os) const;
+
+inline  SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a) 
+                                                       {return Set(a);}
+
 
 private :
@@ -175,4 +195,7 @@
     NTheta_= nbThetaIndex;
   }
+void CloneOrShare(const SphereThetaPhi<T>& a);
+
+SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
 
 // ------------- variables internes ---------------------
Index: trunk/SophyaLib/SkyMap/sphericalmap.h
===================================================================
--- trunk/SophyaLib/SkyMap/sphericalmap.h	(revision 907)
+++ trunk/SophyaLib/SkyMap/sphericalmap.h	(revision 908)
@@ -16,4 +16,11 @@
 //         SphereIco
 //      LocalMap
+
+
+
+
+namespace SOPHYA {
+
+
 
 template<class T>
@@ -39,4 +46,11 @@
 virtual void GetThetaSlice(int_4 sliceIndex, r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const=0 ;
 };
+
+
+} // Fin du namespace
+
+
+
+
 #endif
 
