Index: trunk/ArchTOIPipe/Kernel/flagtoidef.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/flagtoidef.h	(revision 1514)
+++ trunk/ArchTOIPipe/Kernel/flagtoidef.h	(revision 1516)
@@ -1,18 +1,22 @@
+#ifndef FLAGTOIDEF_H
+#define FLAGTOIDEF_H
 
 enum FlagToiDef {
-// Out of Range Valuet of Range Value
+// Out of Range Value of Range Value
   FlgToiOut     =  (unsigned long long)1 << 0,
 // Spike-like sample (ex: glitch)
-  FlgToiSpike   =  (unsigned long long)1 << 2,
+  FlgToiSpike   =  (unsigned long long)1 << 1,
 // Discontinuity-like sample (ex: step)
-  FlgToiDisc    =  (unsigned long long)1 << 3,
+  FlgToiDisc    =  (unsigned long long)1 << 2,
 // Large-Sigma-like sample
-  FlgToiSigma   =  (unsigned long long)1 << 4,
+  FlgToiSigma   =  (unsigned long long)1 << 3,
 // Cleaned sample (ex: clean after spike,step...)
-  FlgToiClean   =  (unsigned long long)1 << 5,
+  FlgToiClean   =  (unsigned long long)1 << 4,
 // Sample Value has been interpolated/Replaced ...
-  FlgToiInterp  =  (unsigned long long)1 << 6,
+  FlgToiInterp  =  (unsigned long long)1 << 5,
+};
+
 // et on peut continuer ainsi jusqu'a 1<<63 cad le bit 64 ieme
 // Pour imprimer la valeur: cout<<(unsigned long long)FlgToi...<<endl;
-}
 
+#endif
Index: trunk/ArchTOIPipe/ProcWSophya/toi2map.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1514)
+++ trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1516)
@@ -4,10 +4,13 @@
 #include "ctimer.h"
 #include "toi2map.h"
-#include "xastropack.h"
 
 ////////////////////////////////////////////////////////////////////////
 TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
-  : mSph(sph), mWSph(wsph), mWSphInternal(false), mTypCoor(false), fTypCoor(false), mActualYear(2001.)
+  : mSph(sph), mWSph(wsph), mWSphInternal(false)
 {
+ SetEquinox();
+ SetCoorIn();
+ SetCoorOut();
+
  if(mSph->NbPixels()<1) {
   cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
@@ -44,5 +47,5 @@
   declareInput("Coord1In");     // input index 0
   declareInput("Coord2In");     // input index 1
-  declareInput("BoloIn");      // input index 2
+  declareInput("BoloIn");       // input index 2
 }
 
@@ -61,4 +64,12 @@
   throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
 }
+if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
+  cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
+  throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
+}
+if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
+  cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
+  throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
+}
 
 //---------------------------------------------------------
@@ -69,48 +80,41 @@
 uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
 for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
+double mjd = MJDfrYear(mActualYear);
 
 // Remplissage des spheres
 for(int s=snb;s<=sne;s++) {
-  int_8 fgbolo = 0; 
+  int_8 fgbolo = 0;
   double bolo;
+  //              Equatoriales   /   Galactiques
+  // coord1,2 =   alpha,delta    /   gLon,gLat
+  double coord1 = getData(0,s);
+  double coord2 = getData(1,s);
 
-  double coord1 = getData(0,s); // gLat ou delta entre [-90,90] en degres
-  double coord2 = getData(1,s); // gLon entre [0,360[ en degres ou alpha entre [0,24[ en heures
   getData(2,s,bolo,fgbolo);
+  if(bolo<-32767.) continue; // Bidouille (A CORRIGER QUAND FGBOLO DISPO)
 
-  if(coord2<-90. || coord2>90.) fgbolo=1; 
-  if((coord1<0.) || (!mTypCoor && coord1>=24.) || (mTypCoor && coord1>=360.) ) {fgbolo=1; 
-  cout << "!!!!!!!!" <<coord1 << endl;
+  // sphere phi   entre [0,2*Pi] en radians
+  // sphere theta entre [0,Pi]   en radians
+  double phi,theta;
+  CoordConvertToStd(mTypCoorIn,coord1,coord2);
+  if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
+    EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
+    phi   = coord1 * M_PI/180.;
+  } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&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.;
   }
-  
-  
-  
-  if(bolo<-32767.) fgbolo=1;   // Bidouille Archeops
-  
-  if(!fgbolo) {
-    // sphere phi entre [0,2*Pi] en radians
-    // sphere phi entre [0,2*Pi] en radians
-    // sphere theta entre [0,Pi] en radians
-    double phi,theta;
-    if(fTypCoor && !mTypCoor) { //on a alpha,delta et on veut l,b
-      double mjd = MJDfrYear(mActualYear);
-      EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
-    } 
+  theta = (90.-coord2) * M_PI/180.;
+  if(phi<0.   || phi>=2*M_PI) continue;
+  if(theta<0. || theta>=M_PI) continue;
 
-    if(!fTypCoor && mTypCoor) { //on a l,b et on veut alpha,delta
-      double mjd = MJDfrYear(mActualYear);
-      GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
-    }
-    
-    if(fTypCoor) phi = coord1 * M_PI/180.;
-    else  phi = coord1 * M_PI/12.;
-
-    theta = (90.-coord2)*M_PI/180.;
-
-    int_4 ipix = mSph->PixIndexSph(theta,phi);
-    (*mSph)(ipix) += bolo;    
-    ((*mWSph)(ipix))++;
-    mNSnFill++;
-  }
+  int_4 ipix = mSph->PixIndexSph(theta,phi);
+  (*mSph)(ipix) += bolo;    
+  ((*mWSph)(ipix))++;
+  mNSnFill++;
 }
 
@@ -129,7 +133,7 @@
      <<"  mNpixFill="<<mNpixFill
      <<"  mNSnFill="<<mNSnFill<<endl
-     <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"<<endl
-     <<"NFill["<<NFILL<<"] = "<<endl;
- for(ii=0;ii<NFILL;ii++) cout<<NFill[ii]<<" ";
+     <<"  --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
+     <<"  NFill["<<NFILL<<"] ="<<endl;
+ for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
  cout<<endl;
 
Index: trunk/ArchTOIPipe/ProcWSophya/toi2map.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1514)
+++ trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1516)
@@ -5,18 +5,23 @@
 #include "toiprocessor.h"
 #include "spherehealpix.h"
+#include "flagtoidef.h"
+#include "xastropack.h"
 
 //-- Un projecteur de TOI sur une sphere Healpix
-// Lecture de 3 TOI alpha,delta,boloMuV
-// Sortie rien
+// Lecture de 3 TOI coord1,coord2,boloMuV
+// Sortie pas de TOI, une (2) sphere(s) Healpix
 //
 // Structure generale :
-// (les alpha[0,360[,delta[-90,90] sont en degres decimaux)
-//                         |---->Sphere
-//                         |
-//                    -----------
+//                          |---->Sphere
+//                          |
+//                     -----------
 //   toi Coord1In ---> |         |
 //   toi Coord2In ---> | TOI2Map |
-//   toi BoloIn  ---> |         |
-//                    -----------
+//   toi BoloIn   ---> |         |
+//                     -----------
+// Gestion du type de coordonnees :
+// Coord1In,Coord2In : soit Equatoriales (Alpha,Delta)
+//                     soit Galactiques  (GLong,GLat)
+// Sortie sur une sphere en coordonnees Equatoriales ou Galactiques
 
 class TOI2Map : public TOIProcessor {
@@ -25,15 +30,20 @@
   virtual	~TOI2Map();
 
-  virtual void	init(void);  
+  virtual void	init(void);
   virtual void	run(void);
-  inline  void  SetCoorGal(bool mfg=false,bool ffg=false,double actualyear=2000.)
-                          {mTypCoor = mfg; fTypCoor = ffg; mActualYear = actualyear;}
-  
+
+  // Coordonnees donnees en entree et en sortie
+  inline void SetEquinox(double actualyear=2000.)
+              {mActualYear = actualyear;}
+  inline void SetCoorIn(TypAstroCoord mfg=TypCoordGalStd)
+              {mTypCoorIn = mfg;}
+  inline void SetCoorOut(TypAstroCoord mfg=TypCoordGalStd)
+              {mTypCoorOut = mfg;}
+
 protected:
   SphereHEALPix<r_8>* mSph;
   SphereHEALPix<r_8>* mWSph;
   bool mWSphInternal;
-  bool mTypCoor;
-  bool fTypCoor;
+  TypAstroCoord mTypCoorIn, mTypCoorOut;
   double mActualYear;
 };
Index: trunk/ArchTOIPipe/SMakefile
===================================================================
--- trunk/ArchTOIPipe/SMakefile	(revision 1514)
+++ trunk/ArchTOIPipe/SMakefile	(revision 1516)
@@ -15,5 +15,5 @@
             $(AOBJ)simtoipr.o $(AOBJ)map2toi.o $(AOBJ)toi2map.o $(AOBJ)nooppr.o
 EXEOLIST := $(AOBJ)fits2asc.o $(AOBJ)tsttoi.o $(AOBJ)tsttoi2.o $(AOBJ)simtst.o \
-            $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o \
+            $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(AOBJ)sfftc.o $(AOBJ)mesovh.o \
             $(AOBJ)fits2ascii.o $(AOBJ)tgenw.o $(AOBJ)tstmap2toi.o $(AOBJ)tsttoi2map.o 
 EXELIST := $(AOBJ)sfftc $(AOBJ)simtst $(AOBJ)mesovh $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi \
Index: trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1514)
+++ trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1516)
@@ -19,9 +19,35 @@
  cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
      <<"           [-a label_coord1] [-d label_coord2] [-b label_bolomuv]"<<endl
-     <<"           [-n nlat] coord_ini coord_fin fitsin_bolo fitsin_point fitsphout fitsphwout"<<endl
-     <<" coord_ini[_fin] = G for Galactic coordinates"<<endl
-     <<"                 = Q for equatorial coordinates"<<endl
-     <<" coord1 = alpha or longitude ; coord2 = delta or latitude"<<endl;
- return;
+     <<"           [-n nlat] [-i c,h] [-o c,h]"<<endl
+     <<"           fitsin_point fitsin_bolo fitsphout [fitsphwout]"<<endl
+     <<" -p lp : print level (def=0)"<<endl
+     <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
+     <<" -w data_window_size : window size for pipe (def=8192)"<<endl
+     <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
+     <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
+     <<"          coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
+     <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
+     <<" -n nlat : nlat for Healpix sphere (def=128)"<<endl
+     <<" -i c,h : coord1 caracteristics (c=G/E h=H/D) (def=G,D)"<<endl
+     <<" -o c,h : idem -i for coord2"<<endl
+     <<" fitsin_point : fits file for pointing"<<endl
+     <<" fitsin_bolo : fits file for bolo values"<<endl
+     <<" fitsphout : fits file for output Healpix sphere"<<endl
+     <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
+}
+
+unsigned long typecoord(char typc=' ',char hd=' ');
+unsigned long typecoord(char typc,char hd)
+// typc : G=galactiques, E=equatoriales, autres=galactiques
+// hd : H=heure, D=degre, autres=(heure si typc==E, degre si typc==G)
+{
+  if(typc!='G' && typc!='E') typc='G';
+  if(hd!='H' && hd!='D') {if(typc=='E') hd='H'; else hd='D';}
+ unsigned long rc=TypCoordUndef;
+  if(typc=='G') rc |= TypCoordGal;
+    else        rc |= TypCoordEq;
+  if(hd=='D')   rc |= TypCoordDD;
+    else        rc |= TypCoordHD;
+  return rc;
 }
 
@@ -36,6 +62,8 @@
 char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
 long sdeb,sfin;
-int c;
-while((c = getopt(narg,arg,"hGp:s:w:a:d:b:n:")) != -1) {
+string fitsphwout = "";
+unsigned long tcoorin=typecoord(), tcoorout=typecoord();
+int c; char t=' ',h=' ';
+while((c = getopt(narg,arg,"hp:s:w:a:d:b:n:i:o:")) != -1) {
   switch (c) {
   case 's' :
@@ -43,5 +71,5 @@
     cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
     if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
-    else {cout<<"Bad sample interval "<<endl; exit(-2);}
+    else {cout<<"Bad sample interval "<<endl; exit(2);}
     break;
   case 'w' :
@@ -67,34 +95,43 @@
     if(nlat<0) nlat=128;
     break;
+  case 'i' :
+    sscanf(optarg,"%c,%c",&t,&h);
+    tcoorin=typecoord(t,h);
+    break;
+  case 'o' :
+    sscanf(optarg,"%c,%c",&t,&h);
+    tcoorout=typecoord(t,h);
+    break;
   case 'h' :
-    usage(); exit(-1);
-    break;
   default:
-    usage(); exit(-1);
+    usage(); exit(1);
+    break;
   }
 }
-if(optind+3>=narg) {usage(); exit(-2);}
-bool mcoorgal=true;
-bool fcoorgal=true;
+if(optind+2>=narg) {usage(); exit(3);}
  
-if ( strcmp(arg[optind],"Q") == 0) mcoorgal=false; 
-if ( strcmp(arg[optind+1],"Q") == 0) fcoorgal=false; 
- 
-char * fitsin_bolo = arg[optind+2];
-char * fitsin_point = arg[optind+3];
-string const fitsphout = arg[optind+4];
-string fitsphwout = "";
-if(optind+5<narg) fitsphwout = arg[optind+5];
-
+char * fitsin_point = arg[optind];
+char * fitsin_bolo = arg[optind+1];
+string const fitsphout = arg[optind+2];
+if(optind+3<narg) fitsphwout = arg[optind+3];
+
+{
+unsigned long tg,te,hd,dd;
 cout<<">>>> tsttoi2map:"<<endl
-    <<"Fits Infile(snum,bolomuv)= "<<fitsin_bolo<<endl
-    <<"Fits Infile(snum,coord1,coord2)= "<<fitsin_point<<endl
-    <<"  ...label_coord1 "<<label_coord1<<"  ,  label_coord2 "<<label_coord2<<endl
-    <<"  with coordinates Gal "<<mcoorgal<<endl
-    <<"  ...label_bolomuv "<<label_bolomuv<<endl
-    <<"Fits Sphere Healpix"<<fitsphout<<endl
+    <<"Pipe Window Size "<<width<<endl
+    <<"Fits Infile Bolo "<<fitsin_bolo<<endl
+    <<"  ...label_bolomuv "<<label_bolomuv<<endl;
+tg = tcoorin&TypCoordGal; te = tcoorin&TypCoordEq;
+hd = tcoorin&TypCoordHD;  dd = tcoorin&TypCoordDD;
+cout<<"  ...label_coord1 "<<label_coord1<<endl
+    <<"  ...label_coord2 "<<label_coord2<<endl
+    <<"  ...... Gal="<<tg<<" Eq="<<te<<"   hour="<<hd<<" deg="<<dd<<endl;
+tg = tcoorout&TypCoordGal; te = tcoorout&TypCoordEq;
+hd = tcoorout&TypCoordHD;  dd = tcoorout&TypCoordDD; 
+cout<<"Fits Healpix Sphere "<<fitsphout<<endl
     <<"  ...nlat "<<nlat<<endl
-    <<"  with coordinates Gal "<<fcoorgal<<endl
-    <<"Fits Sphere Healpix Error "<<fitsphwout<<endl;
+    <<"  ...... Gal="<<tg<<" Eq="<<te<<"   hour="<<hd<<" deg="<<dd<<endl;
+cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl;
+}
 
 SophyaInit();
@@ -109,10 +146,10 @@
  int ncolb = rfitsb.getNOut();
  cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
- if(ncolb<1) exit(-3);
+ if(ncolb<1) exit(-4);
 
  FITSTOIReader rfitsp(fitsin_point);
  int ncolp = rfitsp.getNOut();
  cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
- if(ncolp<2) exit(-3);
+ if(ncolp<2) exit(-5);
 
  // Creation de la sphere Healpix
@@ -126,5 +163,5 @@
    wsph = new SphereHEALPix<r_8>;
    cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
-       <<"               Nombre de pixels : "<<wsph->NbPixels()<<endl;
+       <<"              Nombre de pixels : "<<wsph->NbPixels()<<endl;
  }
 
@@ -132,19 +169,21 @@
  TOI2Map toi2m(sph,wsph);
  cout<<"TOI2Map created"<<endl;
- toi2m.SetCoorGal(mcoorgal,fcoorgal,2000.);  // equinoxe de ref. 2000. (pour archtoi)
+ toi2m.SetEquinox(2000.);
+ toi2m.SetCoorIn((TypAstroCoord) tcoorin);
+ toi2m.SetCoorOut((TypAstroCoord) tcoorout);
 
  // Definition des tuyaux
  TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
- if(lp) toicoord1in->setDebugLevel(1);
+ // toicoord1in->setDebugLevel(1);
  rfitsp.addOutput(label_coord1,toicoord1in);
  toi2m.addInput("Coord1In",toicoord1in);
 
  TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
- if(lp) toicoord2in->setDebugLevel(1);
+ // toicoord2in->setDebugLevel(1);
  rfitsp.addOutput(label_coord2,toicoord2in);
  toi2m.addInput("Coord2In",toicoord2in);
  
  TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
- if(lp) toibolin->setDebugLevel(1);
+ // toibolin->setDebugLevel(1);
  rfitsb.addOutput(label_bolomuv,toibolin);
  toi2m.addInput("BoloIn",toibolin);
