Index: trunk/SophyaLib/SkyMap/fiospherehealpix.cc
===================================================================
--- trunk/SophyaLib/SkyMap/fiospherehealpix.cc	(revision 2973)
+++ trunk/SophyaLib/SkyMap/fiospherehealpix.cc	(revision 2978)
@@ -81,4 +81,10 @@
 uint_8 itab[3];
 is.Get(itab, 3);
+ 
+//  Juin 2006 : NumVer 1->2 avec mise en place de HEALPix NESTED
+//  Si itab[2]==1 --> NESTED 
+bool fgring = true;
+if (itab[2] == 1) fgring = false;
+
 // Let's Read the SphereCoordSys object  -- ATTENTIOn - $CHECK$
   FIO_SphereCoordSys fio_scs( dobj_->GetCoordSys());
@@ -100,5 +106,5 @@
   double Omega;
   is.GetR8(Omega);
-  dobj_->setParameters(nSide,nPix, Omega);
+  dobj_->setParameters(nSide,nPix, Omega, fgring);
 
 // On lit les DataBlocks;
@@ -124,8 +130,11 @@
 //  On ecrit 3 uint_8 
 //  0 : Numero de version,  1 : Size index,  2  reserve a l
+//  Juin 2006 : NumVer 1->2 avec mise en place de HEALPix NESTED
+//  totalement back-compatible , on utilise itab[2] qu'on met a 1
+//  pour NESTED
 uint_8 itab[3];
-itab[0] = 1;
+itab[0] = 2;
 itab[1] = dobj_->SizeIndex();
-itab[2] = 0;
+itab[2] = (dobj_->IfRING()) ? 0 : 1;
 os.Put(itab, 3);
 // Let's write the SphereCoordSys object
@@ -164,4 +173,5 @@
 
 #ifdef __CXX_PRAGMA_TEMPLATES__
+#pragma define_template FIO_SphereHEALPix<uint_2>
 #pragma define_template FIO_SphereHEALPix<int_4>
 #pragma define_template FIO_SphereHEALPix<r_8>
@@ -172,4 +182,5 @@
 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 namespace SOPHYA {
+template class FIO_SphereHEALPix<uint_2>;
 template class FIO_SphereHEALPix<int_4>;
 template class FIO_SphereHEALPix<r_8>;
Index: trunk/SophyaLib/SkyMap/pixelmap.h
===================================================================
--- trunk/SophyaLib/SkyMap/pixelmap.h	(revision 2973)
+++ trunk/SophyaLib/SkyMap/pixelmap.h	(revision 2978)
@@ -161,5 +161,6 @@
 {
 os << "PixelMap<T>::Show() class: " << typeid(*this).name() 
-   << " T= " << DataTypeInfo<T>::getTypeName() << endl;
+   << " T= " << DataTypeInfo<T>::getTypeName() 
+   << " TypeOfMap= " << TypeOfMap() << endl;
 double solang = 0.;
 if (NbPixels() > 0) solang = PixSolAngle(NbPixels()/2);
Index: trunk/SophyaLib/SkyMap/skymapinit.cc
===================================================================
--- trunk/SophyaLib/SkyMap/skymapinit.cc	(revision 2973)
+++ trunk/SophyaLib/SkyMap/skymapinit.cc	(revision 2978)
@@ -54,4 +54,7 @@
 
   // ---------- Les SphereHEALPix ---------
+
+  PPRegister(FIO_SphereHEALPix<uint_2>);  
+  DObjRegister(FIO_SphereHEALPix<uint_2>, SphereHEALPix<uint_2>);
 
   PPRegister(FIO_SphereHEALPix<int_4>);  
Index: trunk/SophyaLib/SkyMap/sphereecp.h
===================================================================
--- trunk/SophyaLib/SkyMap/sphereecp.h	(revision 2973)
+++ trunk/SophyaLib/SkyMap/sphereecp.h	(revision 2978)
@@ -25,5 +25,5 @@
 //! return the size index value corresponding to resolution res (in radian)
 static inline int_4 ResolToSizeIndex(double res)
-  { return (M_PI/res); }
+  { return (int_4)((M_PI/res)+0.5); }
 
   // Constructeur par defaut
Index: trunk/SophyaLib/SkyMap/spherehealpix.cc
===================================================================
--- trunk/SophyaLib/SkyMap/spherehealpix.cc	(revision 2973)
+++ trunk/SophyaLib/SkyMap/spherehealpix.cc	(revision 2978)
@@ -62,8 +62,8 @@
 /* --Methode-- */
 
-template<class T>
-SphereHEALPix<T>::SphereHEALPix() : pixels_(), sliceBeginIndex_(), 
-                                                sliceLenght_()
-
+//! Default constructor - optional pixelisation scheme parameter
+template<class T>
+SphereHEALPix<T>::SphereHEALPix(bool fgring) : fgring_(fgring), pixels_(), 
+				    sliceBeginIndex_(), sliceLenght_()
 
 {
@@ -71,7 +71,8 @@
 }
 
-/*! \fn   SOPHYA::SphereHEALPix::SphereHEALPix(int_4 m)
- 
+/*! \brief Constructor with specification of nside and optional pixelisation scheme
+  
   \param <m> : "nside" of the Healpix algorithm
+  \param <fgring> : if true -> RING pixelisation (default), if not NESTED
 
   The total number of pixels will be Npix =  12*nside**2
@@ -81,7 +82,8 @@
 
 template<class T>
-SphereHEALPix<T>::SphereHEALPix(int_4 m)
-
-{
+SphereHEALPix<T>::SphereHEALPix(int_4 m, bool fgring)
+
+{
+  fgring_ = fgring;
   InitNul();
   Pixelize(m);
@@ -98,4 +100,5 @@
   nPix_ = s.nPix_;
   omeg_ = s.omeg_;
+  fgring_ = s.fgring_;
   if(s.mInfo_) this->mInfo_= new DVList(*s.mInfo_);
 }
@@ -111,4 +114,5 @@
   nPix_ = s.nPix_;
   omeg_ = s.omeg_;
+  fgring_ = s.fgring_;
   if(s.mInfo_) this->mInfo_= new DVList(*s.mInfo_);
   //  CloneOrShare(s);
@@ -123,4 +127,5 @@
   nPix_ = a.nPix_;
   omeg_ = a.omeg_;
+  fgring_ = a.fgring_;
   pixels_.CloneOrShare(a.pixels_);
   sliceBeginIndex_.CloneOrShare(a.sliceBeginIndex_);
@@ -137,4 +142,5 @@
   nPix_ = a.nPix_;
   omeg_ = a.omeg_;
+  fgring_ = a.fgring_;
   pixels_.Share(a.pixels_);
   sliceBeginIndex_.Share(a.sliceBeginIndex_);
@@ -148,7 +154,5 @@
 SphereHEALPix<T>& SphereHEALPix<T>::Set(const SphereHEALPix<T>& a)
 {
-  if (this != &a) 
-    { 
-      
+  if (this != &a)   { 
       if (a.NbPixels() < 1) 
 	throw RangeCheckError("SphereHEALPix<T>::Set(a ) - SphereHEALPix a not allocated ! ");
@@ -156,9 +160,8 @@
       else CopyElt(a);
       
-      
       if (this->mInfo_) delete this->mInfo_;
       this->mInfo_ = NULL;
       if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
-    }
+  }
   return(*this);
 }
@@ -168,12 +171,19 @@
 {
   if (NbPixels() < 1) 
-    throw RangeCheckError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>& )  - Not Allocated SphereHEALPix ! ");
+    throw RangeCheckError("SphereHEALPix<T>::CopyElt(a)  - Not Allocated SphereHEALPix ! ");
   if (NbPixels() != a.NbPixels()) 
-    throw(SzMismatchError("SphereHEALPix<T>::CopyElt(const SphereHEALPix<T>&) SizeMismatch")) ;
+    throw(SzMismatchError("SphereHEALPix<T>::CopyElt(a) SizeMismatch")) ;
   nSide_= a.nSide_;
   nPix_ = a.nPix_;
   omeg_ = a.omeg_;
   int k;
-  for (k=0; k< nPix_; k++) pixels_(k) = a.pixels_(k);
+  if (fgring_ != a.fgring_) 
+    for (k=0; k< nPix_; k++) pixels_(k) = a.pixels_(k);
+  else {
+    if (fgring_)  for (k=0; k< nPix_; k++) 
+      pixels_(k) = a.pixels_(ring2nest(nSide_, k));
+    else  for (k=0; k< nPix_; k++) 
+      pixels_(k) = a.pixels_(nest2ring(nSide_, k));			     
+  }
   for (k=0; k< a.sliceBeginIndex_.Size(); k++) sliceBeginIndex_(k) = a.sliceBeginIndex_(k);
   for (k=0; k< a.sliceLenght_.Size(); k++) sliceLenght_(k) = a.sliceLenght_(k);
@@ -181,20 +191,8 @@
 }
 
-
-
-//++
-// Titre	Destructor
-//--
-//++
 template<class T>
 SphereHEALPix<T>::~SphereHEALPix()
-
-//--
-{
-}
-
-//++
-// Titre	Public Methods
-//--
+{
+}
 
 /*!  \fn   void SOPHYA::SphereHEALPix::Resize(int_4 m)
@@ -207,6 +205,4 @@
 template<class T>
 void SphereHEALPix<T>::Resize(int_4 m)
-
-
 {
   if ((m <= 0 && nSide_ > 0))  {
@@ -219,11 +215,17 @@
 }
 
+
+//! return type of the map pixelisation : RING or NESTED
+template<class T>
+string SphereHEALPix<T>::TypeOfMap() const 
+{
+  if (fgring_)  return string("RING");
+  else return string("NESTED");
+}
+
 template<class T>
 void  SphereHEALPix<T>::Pixelize( int_4 m) 
-
 //    prépare la pixelisation Gorski (m a la même signification 
 //    que pour le constructeur)
-//
-//    
 {
   if (m<=0 || m> 8192) {
@@ -291,9 +293,8 @@
 {
   uint_4 nbslices = uint_4(4*nSide_-1);
-  if (nSide_<=0) 
-    {
-      nbslices = 0;
-      throw PException(" sphere not pixelized, NbSlice=0 ");
-    }
+  if (nSide_<=0)  {
+    nbslices = 0;
+    throw PException(" sphere not pixelized, NbSlice=0 ");
+  }
   return nbslices;
 }
@@ -338,28 +339,33 @@
 template<class T>
 void SphereHEALPix<T>::GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const 
-
-{
-
-  if (index<0 || index >= NbThetaSlices()) 
-    {
+{
+  if (index<0 || index >= NbThetaSlices())  {
       cout << " SphereHEALPix::GetThetaSlice : Pixel index out of range" <<endl;
       throw RangeCheckError(" SphereHEALPix::GetThetaSlice()  index out of range");
-    }
-
+  }
 
   int_4 iring= sliceBeginIndex_(index);
   int_4 lring  =  sliceLenght_(index);
 
-   phi.ReSize(lring);
-   value.ReSize(lring);
+  phi.ReSize(lring);
+  value.ReSize(lring);
 
   double TH= 0.;
   double FI= 0.;
-  for(int_4 kk = 0; kk < lring;kk++) 
-    {
+  if (fgring_) {  // RING pixelisation scheme
+    for(int_4 kk = 0; kk < lring;kk++)  {
       PixThetaPhi(kk+iring,TH,FI);
       phi(kk)= FI;
-      value(kk)= PixVal(kk+iring);
-    }
+      value(kk)= pixels_(kk+iring);
+    }
+  }
+  else {  // NESTED pixelisation scheme
+    for(int_4 kk = 0; kk < lring;kk++)  {
+      int kkn = ring2nest(nSide_, kk+iring);
+      PixThetaPhi(kkn,TH,FI);
+      phi(kk)= FI;
+      value(kk)= pixels_(kkn);
+    }
+  }
   theta= TH;
 }
@@ -394,10 +400,19 @@
   value.ReSize(lring);
 
-  for(int_4 kk = 0; kk < lring;kk++) 
-    {
+  if (fgring_) {  // RING pixelisation scheme
+    for(int_4 kk = 0; kk < lring;kk++)  {
       pixelIndices(kk)= kk+iring;
-      value(kk)= PixVal(kk+iring);
-    }
-  PixThetaPhi(iring, theta, phi0);
+      value(kk)= pixels_(kk+iring);
+    }
+    PixThetaPhi(iring, theta, phi0);
+  }
+  else {  // NESTED pixelisation scheme
+    for(int_4 kk = 0; kk < lring;kk++)  {
+      int_4 kkn = ring2nest(nSide_, kk+iring);
+      pixelIndices(kk)= kkn;
+      value(kk)= pixels_(kkn);
+    }
+    PixThetaPhi(ring2nest(nSide_,iring), theta, phi0);    
+  }
 }
 
@@ -427,8 +442,6 @@
 
 
-/*! \fn T& SOPHYA::SphereHEALPix::PixVal(int_4 k)
-
-   \return value of  pixel with "RING" index k 
-*/
+
+//!   \return value of the \b k th pixel 
 template<class T>
 T& SphereHEALPix<T>::PixVal(int_4 k)
@@ -436,14 +449,9 @@
 {
   if((k < 0) || (k >= nPix_)) 
-    {
-      throw RangeCheckError("SphereHEALPix::PIxVal Pixel index out of range");
-    }
+      throw RangeCheckError("SphereHEALPix::PixVal() Pixel index out of range");
   return pixels_(k);
 }
 
-/*! \fn T const& SOPHYA::SphereHEALPix::PixVal(int_4 k) const
-
-   \return value of  pixel with "RING" index k 
-*/
+//!   \return value of the \b k th pixel 
 template<class T>
 T const& SphereHEALPix<T>::PixVal(int_4 k) const
@@ -451,7 +459,5 @@
 {
   if((k < 0) || (k >= nPix_)) 
-    {
-      throw RangeCheckError("SphereHEALPix::PIxVal Pixel index out of range");
-    }
+    throw RangeCheckError("SphereHEALPix::PIxVal Pixel index out of range");
   return *(pixels_.Data()+k);
 }
@@ -460,5 +466,5 @@
 
    \return value of  pixel with "NESTED" index k 
-*/
+
 template<class T>
 T& SphereHEALPix<T>::PixValNest(int_4 k)
@@ -472,9 +478,8 @@
   return pixels_(nest2ring(nSide_,k));
 }
-
+*/
 /*!  \fn T const& SOPHYA::SphereHEALPix::PixValNest(int_4 k) const
 
   \return value of  pixel with "NESTED" index k 
-*/
 
 template<class T>
@@ -489,4 +494,5 @@
   return *(pixels_.Data()+pix);
 }
+*/
 
 /*! \fn bool SOPHYA::SphereHEALPix::ContainsSph(double theta, double phi) const
@@ -508,5 +514,6 @@
 
 {
-  return ang2pix_ring(nSide_,theta,phi);
+  if (fgring_) return ang2pix_ring(nSide_,theta,phi);
+  else return ang2pix_nest(nSide_,theta,phi);
 }
 
@@ -514,5 +521,5 @@
 
  \return "NESTED" index of the pixel corresponding to direction (theta, phi).
- */
+
 template<class T>
 int_4 SphereHEALPix<T>::PixIndexSphNest(double theta,double  phi) const
@@ -521,20 +528,15 @@
   return ang2pix_nest(nSide_,theta,phi);
 }
-
-
-/* --Methode-- */
-/*! \fn void SOPHYA::SphereHEALPix::PixThetaPhi(int_4 k,double& theta,double& phi) const
- \return (theta,phi) coordinates of middle of  pixel with "RING" index k
- */
+*/
+
+//!  \return (theta,phi) coordinates of middle of  pixel with "RING" index k
 template<class T>
 void SphereHEALPix<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
 {
-  pix2ang_ring(nSide_,k,theta,phi);
-}
-
-/*! \fn T SOPHYA::SphereHEALPix::SetPixels(T v)
-
-Set all pixels to value v 
-*/
+  if (fgring_) pix2ang_ring(nSide_,k,theta,phi);
+  else pix2ang_nest(nSide_,k,theta,phi);
+}
+
+//! Set all pixels to value v 
 template <class T>
 T SphereHEALPix<T>::SetPixels(T v)
@@ -549,5 +551,4 @@
 
   \return (theta,phi) coordinates of middle of  pixel with "NESTED" index k
- */
 template<class T>
 void SphereHEALPix<T>::PixThetaPhiNest(int_4 k,double& theta,double& phi) const
@@ -556,22 +557,14 @@
   pix2ang_nest(nSide_,k,theta,phi);
 }
-
-
-/*! \fn int_4 SOPHYA::SphereHEALPix::NestToRing(int_4 k) const
-
-   translation from NESTED index  into RING index 
-*/
+*/
+
+//!  Conversion from NESTED index  into RING index 
 template<class T>
 int_4 SphereHEALPix<T>::NestToRing(int_4 k) const
-
 {
   return  nest2ring(nSide_,k);
 }
 
-
-/*!  \fn  int_4 SOPHYA::SphereHEALPix::RingToNest(int_4 k) const
-
- translation from  RING index  into NESTED index 
-*/
+//!  Conversion from  RING index  into NESTED index 
 template<class T>
 int_4 SphereHEALPix<T>::RingToNest(int_4 k) const
@@ -592,5 +585,5 @@
 }
 
-/*! Add a constant value \b x to a SphereHEALPix */
+//! Add a constant value \b x to a SphereHEALPix 
 template <class T>
 SphereHEALPix<T>& SphereHEALPix<T>::Add(T a)
@@ -641,7 +634,8 @@
 {
   if (NbPixels() != a.NbPixels() )
-    {
-    throw(SzMismatchError("SphereHEALPix<T>::AddElt(const SphereHEALPix<T>&) SizeMismatch")) ;
-    }
+    throw(SzMismatchError("SphereHEALPix<T>::AddElt(a) SizeMismatch")) ;
+  if (fgring_ != a.fgring_) 
+    throw(ParmError("SphereHEALPix<T>::AddElt(a) different pixelisation RING<>NESTED")) ;
+
   pixels_ += a.pixels_;
   return (*this);
@@ -653,7 +647,8 @@
 {
   if (NbPixels() != a.NbPixels() )
-    {
-    throw(SzMismatchError("SphereHEALPix<T>::SubElt(const SphereHEALPix<T>&) SizeMismatch")) ;
-    }
+    throw(SzMismatchError("SphereHEALPix<T>::SubElt(a) SizeMismatch")) ;
+  if (fgring_ != a.fgring_) 
+    throw(ParmError("SphereHEALPix<T>::SubElt(a) different pixelisation RING<>NESTED")) ;
+
   pixels_ -= a.pixels_;
   return (*this);
@@ -665,7 +660,8 @@
 {
   if (NbPixels() != a.NbPixels() )
-    {
-    throw(SzMismatchError("SphereHEALPix<T>::MulElt(const SphereHEALPix<T>&) SizeMismatch")) ;
-    }
+    throw(SzMismatchError("SphereHEALPix<T>::MulElt(a) SizeMismatch")) ;
+  if (fgring_ != a.fgring_) 
+    throw(ParmError("SphereHEALPix<T>::MulElt(a) different pixelisation RING<>NESTED")) ;
+
   pixels_ *= a.pixels_;
   return (*this);
@@ -677,7 +673,7 @@
 {
   if (NbPixels() != a.NbPixels() )
-    {
-    throw(SzMismatchError("SphereHEALPix<T>::DivElt(const SphereHEALPix<T>&) SizeMismatch")) ;
-    }
+    throw(SzMismatchError("SphereHEALPix<T>::DivElt(a) SizeMismatch")) ;
+  if (fgring_ != a.fgring_) 
+    throw(ParmError("SphereHEALPix<T>::DivElt(a) different pixelisation RING<>NESTED")) ;
   pixels_ /= a.pixels_;
   return (*this);
@@ -691,11 +687,9 @@
 {
   Show(os);
+  os << "SphereHEALPix<T>(" << TypeOfMap() << ") NSide= " 
+     << nSide_ << " nPix_   = " << nPix_  << " omeg_ = " << omeg_   << endl;
+
   if(this->mInfo_) os << "  DVList Info= " << *(this->mInfo_) << endl;
-  //
-  os << " nSide_ = " << nSide_  << endl;
-  os << " nPix_   = " << nPix_   << endl;
-  os << " omeg_ = " << omeg_   << endl;
-
-  os << " content of pixels : ";
+  os << "... Pixel values : ";
   for(int i=0; i < nPix_; i++)
     {
Index: trunk/SophyaLib/SkyMap/spherehealpix.h
===================================================================
--- trunk/SophyaLib/SkyMap/spherehealpix.h	(revision 2973)
+++ trunk/SophyaLib/SkyMap/spherehealpix.h	(revision 2978)
@@ -52,6 +52,6 @@
          { return  HEALPix::ResolToSizeIndex(res); }
 
-SphereHEALPix();
-SphereHEALPix(int_4 m);
+SphereHEALPix(bool fgring=true);
+SphereHEALPix(int_4 m, bool fgring=true);
 SphereHEALPix(const SphereHEALPix<T>& s, bool share);
 SphereHEALPix(const SphereHEALPix<T>& s);
@@ -93,5 +93,5 @@
 virtual T SetPixels(T v);
 
-/*! Pixel Solid angle  (steradians)
+/*! \brief Pixel Solid angle  (steradians)
 
     All the pixels have the same solid angle. The dummy argument is
@@ -108,20 +108,15 @@
 
 virtual void Resize(int_4 m);
-
-/*! 
-
-\return type of storage of the map : RING or NESTED
-
-at the moment, always RING
-*/
-inline virtual string TypeOfMap() const {return string("RING");};
-
-
+virtual string TypeOfMap() const;
+
+inline bool IfRING() const { return fgring_; } 
+inline bool IfNESTED() const { return ( (fgring_) ? false : true ); } 
+
+/*
 virtual T& PixValNest(int_4 k);
 virtual T const& PixValNest(int_4 k) const;
-
 virtual int_4 PixIndexSphNest(double theta,double phi) const;
-
 virtual void PixThetaPhiNest(int_4 k,double& theta,double& phi) const;
+*/
 
 void Pixelize(int_4); 
@@ -138,12 +133,5 @@
 inline void Print(ostream& os) const { print(os); }
 
-
-
- 
-
-
-
-// Operations diverses  = , +=, ...
-
+//--------------------- Operations diverses  = , +=, ...
 
 SphereHEALPix<T>& Set(const SphereHEALPix<T>& a);
@@ -153,5 +141,5 @@
 // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
 
-  //! Fill SphereHEALPix with all elements equal to \b x
+//! Fill SphereHEALPix with all elements equal to \b x
 virtual SphereHEALPix<T>& SetT(T a); 
 inline  SphereHEALPix<T>& operator = (T a) {return SetT(a);}
@@ -202,10 +190,12 @@
 void SetThetaSlices(); 
 
-inline void setParameters(int_4 nside, int_4 nbpixels, double solangle) 
-  {
-    nSide_= nside;
-    nPix_= nbpixels;
-    omeg_= solangle;
-  }
+inline void setParameters(int_4 nside, int_4 nbpixels, double solangle, 
+			  bool fgring) 
+{
+  nSide_= nside;
+  nPix_= nbpixels;
+  omeg_= solangle;
+  fgring_ = fgring;
+}
 
 // ------------- variables internes -----------------------
@@ -214,7 +204,8 @@
 int_4 nPix_;
 double omeg_;
+bool fgring_;  // true -> RING pixelisation , false -> NESTED
 
 NDataBlock<T> pixels_;
-NDataBlock<int_4> sliceBeginIndex_;	    // Rationalisation Mac. D.Y.
+NDataBlock<int_4> sliceBeginIndex_;    // Indices in RING scheme
 NDataBlock<int_4> sliceLenght_;
 
Index: trunk/SophyaLib/SkyMap/spherethetaphi.h
===================================================================
--- trunk/SophyaLib/SkyMap/spherethetaphi.h	(revision 2973)
+++ trunk/SophyaLib/SkyMap/spherethetaphi.h	(revision 2978)
@@ -29,5 +29,5 @@
 //! return the size index value corresponding to resolution res (in radian)
 static inline int_4 ResolToSizeIndex(double res)
-  { return (M_PI/2./res); }
+  { return (int_4)((M_PI/2./res)+0.5); }
 
 SphereThetaPhi();
