Index: /trunk/ArchTOIPipe/ProcWSophya/map2toi.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/map2toi.cc	(revision 1463)
+++ /trunk/ArchTOIPipe/ProcWSophya/map2toi.cc	(revision 1463)
@@ -0,0 +1,78 @@
+#include "toimanager.h"
+#include "pexceptions.h"
+#include "ctimer.h"
+#include "map2toi.h"
+
+////////////////////////////////////////////////////////////////////////
+Map2TOI::Map2TOI(SphereHEALPix<r_8>& sph)
+: mSph(sph)
+{
+}
+
+Map2TOI::~Map2TOI()
+{
+}
+
+////////////////////////////////////////////////////////////////////////
+void Map2TOI::init() {
+  cout << "Map2TOI::init" << endl;
+  declareInput("AlphaIn");     // input  index 0
+  declareInput("DeltaIn");     // input  index 1
+  declareOutput("AlphaOut");   // output index 0
+  declareOutput("DeltaOut");   // output index 1
+  declareOutput("BoloOut");    // output index 2
+}
+
+////////////////////////////////////////////////////////////////////////
+void Map2TOI::run() {
+
+if(mSph.NbPixels()<1) {
+  cout<<"Map2TOI::Map2TOI() Bad number of pixels in sphere "<<mSph.NbPixels()<<endl;
+  throw ParmError("Map2TOI::Map2TOI() - Bad number of pixels in sphere");
+}
+
+long snb = getMinIn();
+long sne = getMaxIn();
+if(snb>sne) {
+  cout<<"Map2TOI::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
+  throw ParmError("Map2TOI::run() - Bad sample interval");
+}
+if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1)) {
+  cout<<"Map2TOI::run() - Input TOI (AlphaIn or DeltaIn) not connected! "<<endl;
+  throw ParmError("Map2TOI::run() Output TOI (AlphaIn or DeltaIn) not connected!");
+}
+bool connected_AlphaOut = checkOutputTOIIndex(0);
+bool connected_DeltaOut = checkOutputTOIIndex(1);
+if(!checkOutputTOIIndex(2)) {
+  cout<<"Map2TOI::run() - Output TOI (BoloOut) not connected! "<<endl;
+  throw ParmError("Map2TOI::run() Output TOI (BoloOut) not connected!");
+}
+
+//---------------------------------------------------------
+try {
+
+for(int k=snb;k<=sne;k++) {
+
+  double alpha = getData(0,k); // alpha entre [0,24[ en heures
+  if(alpha<0. || alpha>=24.) continue;
+  double delta = getData(1,k); // delta entre [-90,90] en degres
+  if(delta<-90. || delta>90.) continue;
+
+  double phi   = alpha *M_PI/12.; // sphere phi entre [0,2*Pi] en radian
+  double teta  = (90.-delta) *M_PI/180.; // sphere teta entre [0,Pi] en radian
+
+  double bolo  = mSph(teta,phi);
+
+  if(connected_AlphaOut) putData(0,k,alpha,0);
+  if(connected_DeltaOut) putData(1,k,delta,0);
+  putData(2,k,bolo,0);
+}
+
+//---------------------------------------------------------
+} catch (PException & exc) {
+  cout<<"Map2TOI: Catched Exception "<<(string)typeid(exc).name()
+      <<"\n .... Msg= "<<exc.Msg()<<endl;
+}
+
+return;                                                                            
+}
Index: /trunk/ArchTOIPipe/ProcWSophya/map2toi.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/map2toi.h	(revision 1463)
+++ /trunk/ArchTOIPipe/ProcWSophya/map2toi.h	(revision 1463)
@@ -0,0 +1,34 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef MAP2TOI_H
+#define MAP2TOI_H
+
+#include "toiprocessor.h"
+#include "spherehealpix.h"
+
+//-- Un generateur de TOI a partir d'une sphere et de 2 TOIs alpha,delta
+// Lecture de 2 TOI alpha,delta et d'une Sphere Healpix
+// Sortie de 3 TOI alpha,delta,boloMuV
+//
+// Structure generale :
+// (les alpha[0,360[,delta[-90,90] sont en degres decimaux)
+//             Sphere ---- |
+//                         |
+//                    -----------
+//   toi AlphaIn ---> |         | ---> toi AlphaOut
+//                    | Map2TOI | ---> toi DeltaOut
+//   toi DeltaIn ---> |         | ---> toi BoloOut
+//                    -----------
+
+class Map2TOI : public TOIProcessor {
+public:
+                 Map2TOI(SphereHEALPix<r_8>& sph);
+  virtual	~Map2TOI();
+
+  virtual void	init(void);  
+  virtual void	run(void);
+  
+protected:
+  SphereHEALPix<r_8>& mSph;
+};
+
+#endif
Index: /trunk/ArchTOIPipe/ProcWSophya/toi2map.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1463)
+++ /trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 1463)
@@ -0,0 +1,129 @@
+#include "machdefs.h"
+#include "toimanager.h"
+#include "pexceptions.h"
+#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), mActualYear(2001.)
+{
+ if(mSph->NbPixels()<1) {
+  cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
+      <<mSph->NbPixels()<<endl;
+  throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
+ }
+ mSph->SetPixels(0.);
+ int nlat = mSph->SizeIndex();
+
+ if(mWSph==NULL) {
+   mWSph = new SphereHEALPix<r_8>(nlat);
+   mWSphInternal = true;
+ } else {
+   mWSphInternal = false;
+   if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
+ }
+ if(mWSph->NbPixels()<1) {
+   cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
+       <<mWSph->NbPixels()<<endl;
+   throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
+ }
+ mWSph->SetPixels(0);
+
+}
+
+TOI2Map::~TOI2Map()
+{
+ if(mWSph && !mWSphInternal) delete mWSph;
+}
+
+////////////////////////////////////////////////////////////////////////
+void TOI2Map::init() {
+  cout << "TOI2Map::init" << endl;
+  declareInput("AlphaIn");     // input index 0
+  declareInput("DeltaIn");     // input index 1
+  declareInput("BoloIn");      // input index 2
+}
+
+////////////////////////////////////////////////////////////////////////
+void TOI2Map::run()
+{
+long snb = getMinIn();
+long sne = getMaxIn();
+
+if(snb>sne) {
+  cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
+  throw ParmError("TOI2Map::run() - Bad sample interval");
+}
+if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
+  cout<<"TOI2Map::run() - Input TOI (AlphaIn or DeltaIn or BoloIn) not connected! "<<endl;
+  throw ParmError("TOI2Map::run() Output TOI (AlphaIn or DeltaIn or BoloIn) not connected!");
+}
+
+//---------------------------------------------------------
+#define NFILL 25
+try {
+
+int ii;
+uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
+for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
+
+// Remplissage des spheres
+for(int s=snb;s<=sne;s++) {
+  int_4 fgbolo = 0; 
+
+  double alpha = getData(0,s); // alpha entre [0,24[ en heures
+  double delta = getData(1,s); // delta entre [-90,90] en degres
+  double bolo  = getData(2,s);
+  //fgbolo = getFlag(2,s);
+
+  if(delta<-90. || delta>90.)  fgbolo=1;
+  if(alpha<0.   || alpha>=24.) fgbolo=1;
+  if(bolo<-32767.) fgbolo=1;   // Bidouille Archeops
+
+  if(!fgbolo) {
+    // sphere phi entre [0,2*Pi] en radians
+    // sphere theta entre [0,Pi] en radians
+    double phi,theta;
+    if(mTypCoor) {
+      double mjd = MJDfrYear(mActualYear);
+      EqtoGal(mjd,alpha,delta,&alpha,&delta);
+      phi   = alpha * M_PI/180.;
+    } else phi   = alpha * M_PI/12.;
+    theta = (90.-delta)*M_PI/180.;
+    int_4 ipix = mSph->PixIndexSph(theta,phi);
+    (*mSph)(ipix) += bolo;
+    ((*mWSph)(ipix))++;
+    mNSnFill++;
+  }
+
+}
+
+// Remplissage des spheres
+ for(int_4 i=0;i<mSph->NbPixels();i++) {
+   r_8 wf = (*mWSph)(i);
+   if( wf > 0. ) {
+     mNpixFill++;
+     (*mSph)(i) /= wf;
+   }
+   int_4 nf = int_4(wf);
+   if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
+ }
+
+ cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
+     <<"  mNpixFill="<<mNpixFill
+     <<"  mNSnFill="<<mNSnFill<<endl
+     <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"<<endl
+     <<"NFill["<<NFILL<<"] = "<<endl;
+ for(ii=0;ii<NFILL;ii++) cout<<NFill[ii]<<" ";
+ cout<<endl;
+
+//---------------------------------------------------------
+} catch (PException & exc) {
+  cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
+      <<"\n .... Msg= "<<exc.Msg()<<endl;
+}
+
+return;                                                                            
+}
Index: /trunk/ArchTOIPipe/ProcWSophya/toi2map.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1463)
+++ /trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1463)
@@ -0,0 +1,40 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef TOI2MAP_H
+#define TOI2MAP_H
+
+#include "toiprocessor.h"
+#include "spherehealpix.h"
+
+//-- Un projecteur de TOI sur une sphere Healpix
+// Lecture de 3 TOI alpha,delta,boloMuV
+// Sortie rien
+//
+// Structure generale :
+// (les alpha[0,360[,delta[-90,90] sont en degres decimaux)
+//                         |---->Sphere
+//                         |
+//                    -----------
+//   toi AlphaIn ---> |         |
+//   toi DeltaIn ---> | TOI2Map |
+//   toi BoloIn  ---> |         |
+//                    -----------
+
+class TOI2Map : public TOIProcessor {
+public:
+                 TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph=NULL);
+  virtual	~TOI2Map();
+
+  virtual void	init(void);  
+  virtual void	run(void);
+  inline  void  SetCoorGal(bool fg=false,double actualyear=2000.)
+                          {mTypCoor = fg; mActualYear = actualyear;}
+  
+protected:
+  SphereHEALPix<r_8>* mSph;
+  SphereHEALPix<r_8>* mWSph;
+  bool mWSphInternal;
+  bool mTypCoor;
+  double mActualYear;
+};
+
+#endif
Index: /trunk/ArchTOIPipe/TestPipes/fits2ascii.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/fits2ascii.cc	(revision 1463)
+++ /trunk/ArchTOIPipe/TestPipes/fits2ascii.cc	(revision 1463)
@@ -0,0 +1,87 @@
+#include <unistd.h>
+#include <stdexcept>
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toimanager.h"
+#include "toiseqbuff.h"
+#include "asciitoiwtr.h"
+
+void usage(void);
+void usage(void) {
+ cout<<"fits2ascii [-h] [-s samplemin,samplemax] [-w data_window_size]"
+     <<" fitsin asciiout"<<endl;
+ return;
+}
+
+////////////////////////////////////////////////////////////////
+int main(int narg, char** arg) {
+
+TOIManager* mgr = TOIManager::getManager();
+
+//-- Decodage arguments
+long sdeb,sfin;
+int width = 8192;
+char c;
+while((c = getopt(narg,arg,"hs:w:")) != -1) {
+  switch (c) {
+  case 's' :
+    sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
+    cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
+    if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
+    else {cout<<"Bad sample interval "<<endl; exit(-2);}
+    break;
+  case 'w' :
+    sscanf(optarg,"%d",&width);
+    if(width<=0) width=8192;
+    cout<<"Data window size "<<width<<endl;
+    break;
+  case 'h' :
+    usage(); exit(-1);
+  }
+}
+if(optind+1>=narg) {usage(); exit(-2);}
+
+/////////////////////////////////////
+try {
+  FITSTOIReader r(arg[optind]);
+  ASCIITOIWriter w(arg[optind+1]);
+
+  int ncol = r.getNOut();
+  cout<<"Number of columns in fits file : "<<ncol<<endl;
+  if(ncol<=0) exit(-3);
+
+  TOISeqBuffered **toi = new TOISeqBuffered *[ncol];
+
+  for(int i=0;i<ncol;i++) {
+    string col = r.getOutName(i);
+    toi[i] = new TOISeqBuffered(col,width);
+    cout<<"...got TOI "<<col<<endl;
+    r.addOutput(col,toi[i]);
+    w.addInput(col,toi[i]);
+  }
+
+  r.start();
+  w.start();
+
+  mgr->joinAll();
+
+  r.PrintStatus(cout);
+  w.PrintStatus(cout);
+
+  for(int i=0;i<ncol;i++) if(toi[i]) delete toi[i];
+  delete toi;
+
+} catch (PThrowable & exc) {
+  cout << "\nfits2ascii: Catched Exception \n" << (string)typeid(exc).name() 
+       << " - Msg= " << exc.Msg() << endl;
+} catch (const std::exception & sex) {
+  cout << "\nfits2ascii: Catched std::exception \n" 
+       << (string)typeid(sex).name() << endl; 
+} catch (...) {
+  cout << "\nfits2ascii: some other exception was caught ! " << endl;
+}
+
+return(0);
+}
Index: /trunk/ArchTOIPipe/TestPipes/tstmap2toi.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tstmap2toi.cc	(revision 1463)
+++ /trunk/ArchTOIPipe/TestPipes/tstmap2toi.cc	(revision 1463)
@@ -0,0 +1,165 @@
+#include <unistd.h>
+#include <stdexcept>
+
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toimanager.h"
+#include "toiseqbuff.h"
+
+#include "sambainit.h"
+#include "map2toi.h"
+#include "fitsspherehealpix.h" 
+#include "timing.h"
+
+void usage(void);
+void usage(void) {
+ cout<<"tstmap2toi [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
+     <<"           [-a label_alpha] [-d label_delta] [-b label_bolomuv]"<<endl
+     <<"           fitsin fitsphere fitsout"<<endl;
+ return;
+}
+
+////////////////////////////////////////////////////////////////
+int main(int narg, char** arg) {
+
+TOIManager* mgr = TOIManager::getManager();
+
+//-- Decodage arguments
+int lp = 0, width = 8192;
+char *label_alpha = "alpha", *label_delta = "delta", *label_bolomuv = "boloMuV";
+long sdeb,sfin;
+char c;
+while((c = getopt(narg,arg,"hp:s:w:a:d:b:")) != -1) {
+  switch (c) {
+  case 's' :
+    sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
+    cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
+    if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
+    else {cout<<"Bad sample interval "<<endl; exit(-2);}
+    break;
+  case 'w' :
+    sscanf(optarg,"%d",&width);
+    if(width<=0) width=8192;
+    cout<<"Data window size "<<width<<endl;
+    break;
+  case 'p' :
+    sscanf(optarg,"%d",&lp);
+    if(lp<0) lp=0;
+    break;
+  case 'a' :
+    label_alpha = optarg;
+    break;
+  case 'd' :
+    label_delta = optarg;
+    break;
+  case 'b' :
+    label_bolomuv = optarg;
+    break;
+  case 'h' :
+    usage(); exit(-1);
+    break;
+  default:
+    usage(); exit(-1);
+  }
+}
+if(optind+2>=narg) {usage(); exit(-2);}
+char * fitsin          = arg[optind];
+string const fitsphere = arg[optind+1];
+char * fitsout         = arg[optind+2];
+
+cout<<">>>> tstmap2toi:"<<endl
+    <<"Fits Infile(snum,alpha,delta)= "<<fitsin<<endl
+    <<"  ...label_alpha "<<label_alpha<<"  ,  label_delta "<<label_delta<<endl
+    <<"Fits Sphere Healpix"<<fitsphere<<endl
+    <<"Fits Outfile(snum,[alpha,delta],boloMuV)"<<fitsout<<endl
+    <<"  ...label_bolomuv "<<label_bolomuv<<endl;
+
+SophyaInit();
+InitTim();
+
+//--------------------------------------------------------------------
+try {
+//--------------------------------------------------------------------
+
+ // FITS reader et writer
+ FITSTOIReader rfits(fitsin);
+ int ncol = rfits.getNOut();
+ cout<<"Number of columns in fits Infile : "<<ncol<<endl;
+ if(ncol<2) exit(-3);
+
+ FITSTOIWriter wfits(fitsout);
+ wfits.setOutFlags(true);
+ cout << "fits reader and writer created"<<endl;
+
+ // Lecture de la sphere Healpix
+ SphereHEALPix<r_8> sph;        
+ FitsInFile sfits(fitsphere);
+ sfits >> sph;
+ cout<<"SphereHEALPix: Type de map : "<<sph.TypeOfMap()<<endl
+     <<"               Nombre de pixels : "<<sph.NbPixels()<<endl;
+
+ // TOI Processor
+ Map2TOI m2toi(sph);
+ cout<<"Map2TOI created"<<endl;
+
+ // Definition des tuyaux
+ TOISeqBuffered * toialphain = new TOISeqBuffered("toi_alpha_in",width);
+ if(lp) toialphain->setDebugLevel(1);
+ rfits.addOutput(label_alpha,toialphain);
+ m2toi.addInput("AlphaIn",toialphain);
+
+ TOISeqBuffered * toialphaout = new TOISeqBuffered("toi_alpha_out",width);
+ m2toi.addOutput("AlphaOut",toialphaout);
+ wfits.addInput(label_alpha,toialphaout);
+
+ TOISeqBuffered * toideltain = new TOISeqBuffered("toi_delta_in",width);
+ if(lp) toideltain->setDebugLevel(1);
+ rfits.addOutput(label_delta,toideltain);
+ m2toi.addInput("DeltaIn",toideltain);
+
+ TOISeqBuffered * toideltaout = new TOISeqBuffered("toi_delta_out",width);
+ m2toi.addOutput("DeltaOut",toideltaout);
+ wfits.addInput(label_delta,toideltaout);
+
+ TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width);
+ if(lp) toibolout->setDebugLevel(1);
+ m2toi.addOutput("BoloOut",toibolout);
+ wfits.addInput(label_bolomuv,toibolout);
+
+ // Run
+ cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
+ rfits.PrintStatus(cout);
+ cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
+ wfits.PrintStatus(cout);  
+
+ PrtTim("starting threads");
+ rfits.start();
+ m2toi.start();
+ wfits.start();
+
+ if(lp>1)
+   for(int jjjj=0;jjjj<5;jjjj++) {
+     cout<<*toialphain; 
+     cout<<*toibolout; 
+     sleep(2);
+   }
+
+ mgr->joinAll();
+ PrtTim("End threads");
+
+//--------------------------------------------------------------------
+} catch (PThrowable & exc) {
+ cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name() 
+     <<" - Msg= "<<exc.Msg()<<endl;
+} catch (const std::exception & sex) {
+ cout<<"\ntstmap2toi: Catched std::exception \n" 
+     <<(string)typeid(sex).name()<<endl; 
+} catch (...) {
+ cout<<"\ntstmap2toi: some other exception was caught ! "<<endl;
+}
+//--------------------------------------------------------------------
+
+exit(0);
+}
Index: /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1463)
+++ /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1463)
@@ -0,0 +1,186 @@
+#include <unistd.h>
+#include <stdexcept>
+
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toimanager.h"
+#include "toiseqbuff.h"
+
+#include "sambainit.h"
+#include "toi2map.h"
+#include "fitsspherehealpix.h" 
+#include "timing.h"
+
+void usage(void);
+void usage(void) {
+ cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
+     <<"           [-a label_alpha] [-d label_delta] [-b label_bolomuv]"<<endl
+     <<"           [-n nlat] [-G] fitsin fitsphout fitsphwout"<<endl;
+ return;
+}
+
+////////////////////////////////////////////////////////////////
+int main(int narg, char** arg) {
+
+TOIManager* mgr = TOIManager::getManager();
+
+//-- Decodage arguments
+int lp = 0, width = 8192;
+int nlat = 128;   // npixel = 12 * nlat^2
+char *label_alpha = "alpha", *label_delta = "delta", *label_bolomuv = "boloMuV";
+bool coorgal=false;
+long sdeb,sfin;
+char c;
+while((c = getopt(narg,arg,"hGp:s:w:a:d:b:n:")) != -1) {
+  switch (c) {
+  case 's' :
+    sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
+    cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
+    if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
+    else {cout<<"Bad sample interval "<<endl; exit(-2);}
+    break;
+  case 'w' :
+    sscanf(optarg,"%d",&width);
+    if(width<=0) width=8192;
+    cout<<"Data window size "<<width<<endl;
+    break;
+  case 'p' :
+    sscanf(optarg,"%d",&lp);
+    if(lp<0) lp=0;
+    break;
+  case 'a' :
+    label_alpha = optarg;
+    break;
+  case 'd' :
+    label_delta = optarg;
+    break;
+  case 'b' :
+    label_bolomuv = optarg;
+    break;
+  case 'n' :
+    sscanf(optarg,"%d",&nlat);
+    if(nlat<0) nlat=128;
+    break;
+  case 'G' :
+    coorgal = true;
+    break;
+  case 'h' :
+    usage(); exit(-1);
+    break;
+  default:
+    usage(); exit(-1);
+  }
+}
+if(optind+1>=narg) {usage(); exit(-2);}
+char * fitsin          = arg[optind];
+string const fitsphout = arg[optind+1];
+string fitsphwout = "";
+if(optind+2<narg) fitsphwout = arg[optind+2];
+
+cout<<">>>> tsttoi2map:"<<endl
+    <<"Fits Infile(snum,alpha,delta,bolomuv)= "<<fitsin<<endl
+    <<"  ...label_alpha "<<label_alpha<<"  ,  label_delta "<<label_delta<<endl
+    <<"  ...label_bolomuv "<<label_bolomuv<<endl
+    <<"Fits Sphere Healpix"<<fitsphout<<endl
+    <<"  ...nlat "<<nlat<<endl
+    <<"Fits Sphere Healpix Error "<<fitsphwout<<endl;
+
+SophyaInit();
+InitTim();
+
+//--------------------------------------------------------------------
+try {
+//--------------------------------------------------------------------
+
+ // FITS reader
+ FITSTOIReader rfits(fitsin);
+ int ncol = rfits.getNOut();
+ cout<<"Number of columns in fits Infile : "<<ncol<<endl;
+ if(ncol<3) exit(-3);
+
+ // Creation de la sphere Healpix
+ SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
+ cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
+     <<"               Nombre de pixels : "<<sph->NbPixels()<<endl;
+
+ // Creation de la sphere de poids Healpix
+ SphereHEALPix<r_8>* wsph = NULL;
+ if(fitsphwout.size()>0) {
+   wsph = new SphereHEALPix<r_8>;
+   cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
+       <<"               Nombre de pixels : "<<wsph->NbPixels()<<endl;
+ }
+
+ // TOI Processor
+ TOI2Map toi2m(sph,wsph);
+ cout<<"TOI2Map created"<<endl;
+ toi2m.SetCoorGal(coorgal,2000.);  // equinoxe de ref. 2000. (pour archtoi)
+
+ // Definition des tuyaux
+ TOISeqBuffered * toialphain = new TOISeqBuffered("toi_alpha_in",width);
+ if(lp) toialphain->setDebugLevel(1);
+ rfits.addOutput(label_alpha,toialphain);
+ toi2m.addInput("AlphaIn",toialphain);
+
+ TOISeqBuffered * toideltain = new TOISeqBuffered("toi_delta_in",width);
+ if(lp) toideltain->setDebugLevel(1);
+ rfits.addOutput(label_delta,toideltain);
+ toi2m.addInput("DeltaIn",toideltain);
+
+ TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
+ if(lp) toibolin->setDebugLevel(1);
+ rfits.addOutput(label_bolomuv,toibolin);
+ toi2m.addInput("BoloIn",toibolin);
+
+ // Run
+ cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
+ rfits.PrintStatus(cout);
+
+ PrtTim("starting threads");
+ rfits.start();
+ toi2m.start();
+
+ if(lp>1)
+   for(int jjjj=0;jjjj<5;jjjj++) {
+     cout<<*toialphain; 
+     cout<<*toibolin; 
+     sleep(2);
+   }
+
+ mgr->joinAll();
+ PrtTim("End threads");
+
+ // Ecriture de la sphere Healpix sur fits
+ {
+ FitsOutFile sfits(fitsphout);
+ cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
+ sfits << *sph;
+ }
+
+ // Ecriture de la sphere Healpix sur fits
+ if(wsph) {
+   FitsOutFile swfits(fitsphwout);
+   cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
+   swfits << *wsph;
+ }
+
+ // Nettoyage
+ delete sph;
+ if(wsph) delete wsph;
+
+//--------------------------------------------------------------------
+} catch (PThrowable & exc) {
+ cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name() 
+     <<" - Msg= "<<exc.Msg()<<endl;
+} catch (const std::exception & sex) {
+ cout<<"\ntsttoi2map: Catched std::exception \n" 
+     <<(string)typeid(sex).name()<<endl; 
+} catch (...) {
+ cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
+}
+//--------------------------------------------------------------------
+
+exit(0);
+}
