Index: trunk/ArchTOIPipe/ProcWSophya/simcleaner.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simcleaner.cc	(revision 2050)
+++ trunk/ArchTOIPipe/ProcWSophya/simcleaner.cc	(revision 2054)
@@ -20,6 +20,8 @@
   SetCleanForMeanThrNSig();
   SetFlaggingThrNSig();
-
+  
   SetRange();
+  SetFlagMask();
+
   FillMeanSigNTuple();
   char* noms[] = {"sn","mean","sigma"};
@@ -29,4 +31,6 @@
   totnbblock = 0;
   ns_outofrange = ns_flag1p = ns_flag2p = ns_flag1m = ns_flag2m = 0;
+  ns_inflagged = 0;
+  ns_cleannsig = 0;
   gl_sum = gl_sum2 = 0.;  ns_glms = 0;
 }
@@ -51,5 +55,7 @@
   TOIProcessor::PrintStatus(os);
   os << " ProcessedSampleCount=" << ProcessedSampleCount() 
+     << " NS_InFlagged= " << ns_inflagged
      << " NS_OutOfRange= " << ns_outofrange 
+     << " NS_CleanNSig= " << ns_cleannsig << endl 
      << " NS_Flag1(+)= " << ns_flag1p << " NS_Flag2(+)= " << ns_flag2p
      << " NS_Flag1(-)= " << ns_flag1m << " NS_Flag2(-)= " << ns_flag2m << endl;
@@ -131,5 +137,5 @@
       double cleanthrmin = range_min;
       double cleanthrmax = range_max;
-      if ((kb > 0) && ( ns_glms > wsize/2) ) {
+      if ((kb > mNbW/2) && ( ns_glms > 3*wsize) ) {
         cleanthrmin = cur_mean-nsigclean*cur_sig;
 	cleanthrmax = cur_mean+nsigclean*cur_sig;
@@ -137,6 +143,10 @@
       for(j=0; j<wsize; j++) {
 	double x = vin(j);
+	if ((vfg(j)&flag_mask)) { ns_inflagged++; continue; }
 	if ((x > range_max) || (x < range_min) ) continue;
-	if ((x > cleanthrmax) || (x < cleanthrmin) )  continue;	  
+	if ((x > cleanthrmax) || (x < cleanthrmin) )  { 
+	  ns_cleannsig++;
+	  continue;	  
+	}   
 	sum += x;  sum2 += x*x;   nok++;
       }
@@ -295,4 +305,5 @@
       if (fgout)  for(j=0; j<wsize; j++) { 
 	double x = vinc(j);
+	if ((vfgc(j)&flag_mask))  ns_inflagged++; 
 	if ((x > range_max) || (x < range_min) ) {
 	  ns_outofrange++; vfgc(j) |= FlgToiOut;
Index: trunk/ArchTOIPipe/ProcWSophya/simcleaner.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simcleaner.h	(revision 2050)
+++ trunk/ArchTOIPipe/ProcWSophya/simcleaner.h	(revision 2054)
@@ -40,5 +40,9 @@
   inline void   GetRange(double& min, double& max) const 
     { min = range_min; max = range_max; }
-  inline void   SetCleanForMeanThrNSig(double ns=3.)
+  inline void   SetFlagMask(uint_8 mask = 0)  // Aucun flag utilise par defaut
+    { flag_mask = mask; }
+  inline uint_8 GetFlagMask() { return flag_mask; }
+
+  inline void   SetCleanForMeanThrNSig(double ns=5.)
     { nsigclean = ns; }
   inline double GetCleanForMeanThrNSig()
@@ -75,5 +79,9 @@
   int min_npt2;       // Min NPoints a += nsig2 
   double range_min, range_max;  // Range acceptable pour in
+  uint_8 flag_mask;     // mask de flag utilise
+  int_4 ns_inflagged;     // Nb d'echantillons flagges
+
   int_4 ns_outofrange;  // Nb de points out of range
+  int_4 ns_cleannsig;   // Nb de points nettoyes a +/- nsigclean 
   int_4 ns_flag1p;       // Nb de points flagges avec nsig1 (> mean) 
   int_4 ns_flag2p;       // Nb de points flagges avec nsig2 (> mean)
Index: trunk/ArchTOIPipe/ProcWSophya/toi2map.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 2050)
+++ trunk/ArchTOIPipe/ProcWSophya/toi2map.cc	(revision 2054)
@@ -3,5 +3,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: toi2map.cc,v 1.25 2002-05-16 20:39:52 ansari Exp $
+// $Id: toi2map.cc,v 1.26 2002-06-11 17:14:25 ansari Exp $
 
 #include "machdefs.h"
@@ -194,4 +194,5 @@
 
   int_4 ipix = mMap->PixIndexSph(theta,phi);
+  if ((ipix < 0) || (ipix >= mMap->NbPixels()) ) continue;
   (*mMap)(ipix) += bolo;    
   ((*mWMap)(ipix)) += 1;
Index: trunk/ArchTOIPipe/TestPipes/aksj02.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/aksj02.cc	(revision 2050)
+++ trunk/ArchTOIPipe/TestPipes/aksj02.cc	(revision 2054)
@@ -40,5 +40,5 @@
   else {
     cout << "\n Usage : aksj02 [-intoi toiname] [-start snb] [-end sne] \n" 
-	 << "         [-dbg] [-wtoi sz] [-wclean wsz,nbw] [-range min,max] \n"
+	 << "         [-dbg] [-wtoi sz] [-wclean wsz,nbw] [-range min,max] [-cleannsig nsig]\n"
 	 << "         [-soff wsz,nptfit,degpol] [-soffnt PPFName] \n"
 	 << "         [-soff2 wsz,nptfit,degpol] [-soff2nt PPFName] \n"
@@ -46,5 +46,5 @@
 	 << "         [-bgalcut bmin,bmax]  [-bgal2cut bmin,bmax] \n"
 	 << "         [-gfilt wsz,sigma] \n" 
-	 << "         [-nooutflg] [-wrtms] [-wrtifo] [-prstat] [-useseqbuff] \n"
+	 << "         [-nooutflg] [-wrtms] [-wrtifo] [-noprstat] [-useseqbuff] \n"
 	 << "         inFitsName outFitsName \n" 
 	 << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
@@ -56,4 +56,5 @@
 	 << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
 	 << "   -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
+         << "   -cleannsig nsig : Sets cleanner ThrNSig (default = 999999.) \n"
 	 << "   -soff wsz,nptfit,degpol : set SimpleOffsetEstimator parameters\n"
 	 << "   -soffnt PPFName : Writes out SimpleOffsetEstimator NTuple \n"
@@ -97,6 +98,4 @@
   int wdegli = 512;
   
-  int wfft = 4096;
-  int keepfft = 0;
   int nmax = 10;
   int istart = 0;
@@ -109,4 +108,5 @@
   int clean_wsz = 256;
   int clean_nbw = 5;
+  double clean_nsig = 999999.;
 
   // SimpleOffsetEstimator parameters
@@ -154,8 +154,4 @@
 
   bool fg_f_filt = false;
-  bool fg_killfreq = false;
-  int bf_killfreq = 1;
-  int nharm_killfreq = 1;
-  double sigf_killfreq = 1.;
 
   if (narg < 4) Usage(true);
@@ -181,4 +177,12 @@
       sscanf(arg[ia+1],"%d,%d",  &clean_wsz, &clean_nbw);
     }    
+    else if (strcmp(arg[ia],"-cleannsig") == 0) {
+      if (ia == narg-1) Usage(true);  
+      clean_nsig = atof(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-cleannsig") == 0) {
+      if (ia == narg-1) Usage(true);  
+      clean_nsig = atof(arg[ia+1]); ia++;
+    }    
     else if (strcmp(arg[ia],"-soff") == 0) {
       if (ia == narg-1) Usage(true);
@@ -291,4 +295,5 @@
 	 << " - " << range_max << endl;
     cleaner.SetRange(range_min, range_max);
+    cleaner.SetCleanForMeanThrNSig(clean_nsig);
 
     cout << "> Creating SimpleOffsetEstimator(" << soff_mwsz << "," << soff_nptfit 
Index: trunk/ArchTOIPipe/TestPipes/toistat.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/toistat.cc	(revision 2050)
+++ trunk/ArchTOIPipe/TestPipes/toistat.cc	(revision 2054)
@@ -44,5 +44,5 @@
     cout << " toistat : produce a stat NTuple (mean,sigma) from a TOI" << endl;
     cout << "\n Usage : toistat [-intoi toiname] [-start snb] [-end sne] \n" 
-	 << "         [-wtoi sz] [-wclean wsz,nbw] [-range min,max] \n"
+	 << "         [-wtoi sz] [-wclean wsz,nbw] [-range min,max] [-cleannsig nsig] \n"
 	 << "         [-outppf] [-noprstat] [-useseqbuff] \n"
 	 << "         inFitsName outFileName \n" 
@@ -54,4 +54,5 @@
 	 << "   -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
 	 << "   -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
+         << "   -cleannsig nsig : Sets cleanner ThrNSig (default = 999999.) \n"
 	 << "   -outppf : Write the NTuple in PPF format (default: FITS) \n"
 	 << "   -noprstat : DO NOT PrintStat with ProcSampleCounter \n"
@@ -88,4 +89,5 @@
   int clean_wsz = 256;
   int clean_nbw = 5;
+  double clean_nsig = 999999.;
 
   // File names 
@@ -115,4 +117,8 @@
       sscanf(arg[ia+1],"%d,%d",  &clean_wsz, &clean_nbw);
     }    
+    else if (strcmp(arg[ia],"-cleannsig") == 0) {
+      if (ia == narg-1) Usage(true);  
+      clean_nsig = atof(arg[ia+1]); ia++;
+    }    
     else if (strcmp(arg[ia],"-range") == 0) {
       if (ia == narg-1) Usage(true);
@@ -127,4 +133,5 @@
 
     else if (strcmp(arg[ia],"-noprstat") == 0)  fgprstat = false;
+    else if (strcmp(arg[ia],"-prstat") == 0)  fgprstat = true;
     else if (strcmp(arg[ia],"-useseqbuff") == 0)  fgsegmented = false;
 
@@ -165,4 +172,5 @@
 	 << " - " << range_max << endl;
     cleaner.SetRange(range_min, range_max);
+    cleaner.SetCleanForMeanThrNSig(clean_nsig);
     cleaner.FillMeanSigNTuple(true);
 
