Index: trunk/ArchTOIPipe/ProcWSophya/toi2map.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1807)
+++ trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1809)
@@ -3,5 +3,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: toi2map.cc,v 1.23 2001-12-01 13:35:15 aubourg Exp $
+// $Id: toi2map.cc,v 1.24 2001-12-03 20:38:02 cmv Exp $
 
 #include "machdefs.h"
@@ -10,17 +10,17 @@
 #include "ctimer.h"
 #include "toi2map.h"
+// La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta
+#include "smathconst.h"
 
 ////////////////////////////////////////////////////////////////////////
 TOI2Map::TOI2Map(PixelMap<r_8>* map,PixelMap<r_8>* wmap)
-  : mMap(map), mWMap(map), mWMapInternal(false)
+  : mMap(map), mWMap(wmap), mWMapInternal(false)
 {
  SetEquinox();
  SetCoorIn();
- SetCoorOut();
+ SetCoorMap();
  SetTestFlag();
  SetTestMin();
  SetTestMax();
-
- mIsColat = false;
 
  if(mMap->NbPixels()<1) {
@@ -31,8 +31,8 @@
  mMap->SetPixels(0.);
  int nlat = mMap->SizeIndex();
+ string typmap = mMap->TypeOfMap();
 
  if(mWMap==NULL) {
    // We would need a cloning function in maps. $$TBD$$ $CHECK$
-   string typmap = mMap->TypeOfMap();
    if (typmap == "LOCAL") {
      mWMap = new LocalMap<r_8>(*(LocalMap<r_8>*)mMap);
@@ -47,7 +47,15 @@
    mWMapInternal = false;
    if(nlat != mWMap->SizeIndex()) {
-     cout << "TOI2Map::TOI2Map() Bad size for sphere mWMap, does not "
-	  << "correspond to mMap : " << mMap->SizeIndex() << ", " << mWMap->SizeIndex() << endl;
-     throw ParmError("TOI2Map::TOI2Map() - Different sizes for map and wmap");
+     cout<<"TOI2Map::TOI2Map() Bad size for sphere mWMap, does not "
+	 <<"correspond to mMap : "<<mMap->SizeIndex()<<", "<<mWMap->SizeIndex()<<endl;
+     if (typmap == "LOCAL") {
+       throw ParmError("TOI2Map::TOI2Map() - Different sizes for map and wmap");
+     } else if(typmap == "RING") {
+       ((SphereHEALPix<r_8> *)mWMap)->Resize(nlat);
+       cout<<"Resize have been done..."<<endl;
+     } else {
+       cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl;
+       throw ParmError("TOI2Map::TOI2Map() - bad type of map");
+     }
    }
  }
@@ -68,23 +76,11 @@
 void TOI2Map::Print(::ostream & os)
 {
-  os<<"TOI2Map::Print -- Map type " << mMap->TypeOfMap() << " SizeIndex = "<<mMap->SizeIndex()<<endl
-
-    <<"   - Equinoxe="<<mActualYear<<endl
-
-    <<"   - TypCoorIn: Gal("<<((mTypCoorIn&TypCoordGal)?1:0)
-    <<") Eq("<<((mTypCoorIn&TypCoordEq)?1:0)
-    <<") Deg("<<((mTypCoorIn&TypCoordDD)?1:0)
-    <<") Hour("<<((mTypCoorIn&TypCoordHD)?1:0)
-    <<") Rad("<<((mTypCoorIn&TypCoordRR)?1:0)<<")"<<endl
-
-    <<"   - TypCoorOut: Gal("<<((mTypCoorOut&TypCoordGal)?1:0)
-    <<") Eq("<<((mTypCoorOut&TypCoordEq)?1:0)
-    <<") Deg("<<((mTypCoorOut&TypCoordDD)?1:0)
-    <<") Hour("<<((mTypCoorOut&TypCoordHD)?1:0)
-    <<") Rad("<<((mTypCoorOut&TypCoordRR)?1:0)<<")"<<endl
-
-    <<"   - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
-    <<" / Value Min("<<mTMin<<")="<<mValMin
-    <<" , Max("<<mTMax<<")="<<mValMax<<endl;
+ os<<"TOI2Map::Print -- Map type " << mMap->TypeOfMap() << " SizeIndex = "<<mMap->SizeIndex()<<endl
+   <<"   - Equinoxe="<<mActualYear<<endl
+   <<"   - TypCoorIn:  "<<mTypCoorIn<<" = "<<DecodeTypAstro(mTypCoorIn)<<endl
+   <<"   - TypCoorMap: "<<mTypCoorMap<<" = "<<DecodeTypAstro(mTypCoorMap)<<endl
+   <<"  - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
+   <<" / Value Min("<<mTMin<<")="<<mValMin
+   <<" , Max("<<mTMax<<")="<<mValMax<<endl;
 }
 
@@ -116,5 +112,5 @@
   throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
 }
-if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
+if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) {
   cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
   throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
@@ -126,5 +122,5 @@
 
 int ii;
-uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
+uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0;
 for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
 double mjd = MJDfrYear(mActualYear);
@@ -175,29 +171,23 @@
   // sphere phi   entre [0,2*Pi] en radians
   // sphere theta entre [0,Pi]   en radians
-  double phi=-1.,theta;
-  CoordConvertToStd(mTypCoorIn,coord1,coord2);
-
-  if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
+  double phi=-1.;
+  CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
+
+  if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
     EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
-    phi   = coord1 * M_PI/180.;
-  } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
+    phi   = coord1 * Pi/180.;
+  } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
     GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
-    phi   = coord1 * M_PI/12.;
-  } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
-    phi   = coord1 * M_PI/180.;
-  } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
-    phi   = coord1 * M_PI/12.;
+    phi   = coord1 * Pi/12.;
+  } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal
+    phi   = coord1 * Pi/180.;
+  } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq
+    phi   = coord1 * Pi/12.;
   }
-
-  if (phi<0) phi += 2*M_PI;
-  if (phi>=2*M_PI) phi -= 2*M_PI;
-  if (mIsColat) {
-    theta = coord2 * M_PI/180;
-  } else {
-    theta = (90.-coord2) * M_PI/180.;     
-  }
-
-  if(phi<0.   || phi>=2*M_PI) continue;
-  if(theta<0. || theta>=M_PI) continue;
+  ToCoLat(&coord2,TypUniteD);
+  double theta = coord2 * Pi/180.;
+
+  if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
+                     {BadCoorRange++; continue;}
 
   int_4 ipix = mMap->PixIndexSph(theta,phi);
@@ -212,8 +202,5 @@
  for(int_4 i=0;i<mMap->NbPixels();i++) {
    r_8 wf = (*mWMap)(i);
-   if( wf > 0. ) {
-     mNpixFill++;
-     (*mMap)(i) /= wf;
-   }
+   if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
    int_4 nf = int_4(wf);
    if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
@@ -227,4 +214,5 @@
  for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
  cout<<endl;
+ cout<<"  BadCoorRange="<<BadCoorRange<<endl;
 
 #ifndef SANS_BUFFER
