Index: trunk/SophyaProg/PrgMap/cl2map.cc
===================================================================
--- trunk/SophyaProg/PrgMap/cl2map.cc	(revision 1624)
+++ trunk/SophyaProg/PrgMap/cl2map.cc	(revision 1626)
@@ -13,4 +13,10 @@
 #include "fitsspherehealpix.h"
 #include "fitstarray.h"
+
+/*!
+  \defgroup PrgMap PrgMap module
+  This module contains simple programs to perform various tasks
+  on spherical maps.
+*/
 
 /*!
Index: trunk/SophyaProg/PrgMap/cremskfrsph.cc
===================================================================
--- trunk/SophyaProg/PrgMap/cremskfrsph.cc	(revision 1624)
+++ trunk/SophyaProg/PrgMap/cremskfrsph.cc	(revision 1626)
@@ -13,4 +13,23 @@
 #include "fitsspherehealpix.h" 
 
+/*!
+  \ingroup PrgMap
+  \file cremskfrsph.cc
+  \brief \b cremskfrsph: Create a masked sphere from a sphere of datas
+  \verbatim
+csh> cremskfrsph -h
+cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits
+ -m min : min value
+ -M max : max value
+    condition for filling masque is: min<=sphere_value<=max
+          (fill mask with valmsk)     (bounds are included)
+ -n : negate the condition
+      (switch to: sphere_value<min || max<sphere_value)
+ -v valmsk,inimsk:
+    valmsk: value to be put into mask if ok (def=1.)
+    inimsk: initialisation value for the mask (def=0.)
+  \endverbatim
+*/
+
 void usage();
 void usage()
@@ -19,7 +38,8 @@
     <<" -m min : min value"<<endl
     <<" -M max : max value"<<endl
-    <<"    condition for filling masque is : min<=sphere value<=max"<<endl
-    <<"                                      (bounds are included)"<<endl
+    <<"    condition for filling masque is: min<=sphere_value<=max"<<endl
+    <<"          (fill mask with valmsk)     (bounds are included)"<<endl
     <<" -n : negate the condition"<<endl
+    <<"      (switch to: sphere_value<min || max<sphere_value)"<<endl
     <<" -v valmsk,inimsk:"<<endl
     <<"    valmsk: value to be put into mask if ok (def=1.)"<<endl
@@ -32,4 +52,5 @@
 double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0.;
 bool tstmin=false,tstmax=false,negate=false;
+string dum;
 int c;
 while((c = getopt(narg,arg,"hnm:M:v:")) != -1) {
@@ -59,16 +80,17 @@
 char * sphmsk = arg[optind+1];
 
+if(negate) dum = ".NOT."; else dum = "";
 cout<<"Sphere values : "<<sphval<<endl
     <<"Sphere mask   : "<<sphmsk<<endl
-    <<"  ...min("<<tstmin<<") "<<vmin<<"  max("<<tstmax<<") "<<vmax<<endl
+    <<"  ...min("<<tstmin<<") "<<vmin<<endl
+    <<"     max("<<tstmax<<") "<<vmax<<endl
     <<"  ...negate "<<negate<<endl
     <<"  ...mask set value "<<vmask<<endl
-    <<"     mask init value "<<vmaskini<<endl;
-cout<<"Condition : ";
-if(negate) cout<<"!";
-cout<<"( "<<vmin<<" <= V <= "<<vmax<<" ) bounds are included"<<endl;
+    <<"     mask init value "<<vmaskini<<endl
+    <<"Condition on data to set the mask: "
+    <<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
 
 // Lecture de la sphere Healpix des valeurs
-SphereHEALPix<r_8> sph;        
+SphereHEALPix<r_8> sph;
 FitsInFile sfits(sphval);
 sfits >> sph;
@@ -87,14 +109,9 @@
 for(int_4 i=0;i<sph.NbPixels();i++) {
   sphm(i) = vmaskini;
-  r_8 v = sph(i);
-  bool intoint = true;
-  if(tstmin && v<vmin) intoint=false;
-  if(tstmax && v>vmax) intoint=false;
-  //                    [vmin , vmax]
-  // intoint :   false  [    true   ]  false  (si tstmin && tstmax)
-  // intoint :   false  [    true             (si tstmin && !tstmax)
-  // intoint :               true   ]  false  (si !tstmin && tstmax)
-  if(negate && intoint) continue;
-  else if(!negate && !intoint) continue;
+
+  bool skp = (tstmin || tstmax) ? negate : false;
+  if((tstmin && sph(i)<vmin) || (tstmax && sph(i)>vmax)) skp = !negate;
+  if(skp) continue;   // Do nothing
+
   sphm(i) = vmask;
   nmask++;
@@ -106,5 +123,5 @@
 // Ecriture de la sphere Healpix sur fits
 {
-string dum = "rm -f "; dum += sphmsk; system(dum.c_str());
+dum = "rm -f "; dum += sphmsk; system(dum.c_str());
 FitsOutFile swfits(sphmsk);
 cout<<"Writing Mask Sphere Fits file"<<endl;
Index: trunk/SophyaProg/PrgMap/extrap2sph.cc
===================================================================
--- trunk/SophyaProg/PrgMap/extrap2sph.cc	(revision 1624)
+++ trunk/SophyaProg/PrgMap/extrap2sph.cc	(revision 1626)
@@ -1,3 +1,4 @@
-// Pour boucher les trous d'une sphere HEALPIX utilisant une autre sphere
+// Pour boucher les trous d'une sphere HEALPIX en utilisant
+// une autre sphere HEALPIX
 //             cmv 13/6/01
 // extrap2sph -w sph143k05_e.fits sph143k05.fits sphred.fits sphout_2.fits
@@ -13,14 +14,49 @@
 #include "fitsspherehealpix.h" 
 
+/*!
+  \ingroup PrgMap
+  \file extrap2sph.cc
+  \brief \b extrap2sph: Fill holes in a sphere of datas by using
+  an other sphere of datas.
+  A mask to define the place to be tested in the sphere might be given.
+  \verbatim
+csh> extrap2sph -h
+extrap2sph [-m valmin -M valmax -r rvalmin -R rvalmax]
+           [-w sphinw.fits] sphin.fits sphred.fits sphout.fits
+ -w sphinw.fits : input sphere  weight, if sphinw_value<=0. (def=NULL)
+                  if sphinw_value<=0. pixel has not to be filled
+ -m minval : min value to identify EMPTY pixel of sphin (def=no_test)
+ -M maxval : max value to identify EMPTY pixel of sphin (def=no_test)
+    condition for EMPTY pixel is (minval<=val<=maxval)
+ -n : negate the previous condition, condition for EMPTY pixel
+      becomes: (val<minval || maxval<val)
+ -r rminval : min value to identify GOOD pixel of sphred (def=no_test)
+ -R rmaxval : max value to identify GOOD pixel of sphred (def=no_test)
+    condition for GOOD pixel is (minval<=val<=maxval)
+ -n : negate the previous condition, condition for GOOD pixel
+      becomes: (val<minval || maxval<val)
+ sphin.fits   : input sphere
+ sphred.fits  : input reducted sphere
+ sphout.fits  : output sphere
+  \endverbatim
+*/
+
 void usage();
 void usage()
 {
-cout<<"extrap2sph [-w sphinw.fits -m valmin -M valmax]"<<endl
-    <<"           sphin.fits sphred.fits sphout.fits"<<endl
-    <<" -w sphinw.fits : input sphere  weight (def=NULL)"<<endl
-    <<" -m minval : value to identify EMPTY pixel (def=-1.e30.)"<<endl
-    <<" -M maxval : value to identify EMPTY pixel (def=+1.e30)"<<endl
-    <<"    condition for EMPTY pixel is (minval<val<maxval)"<<endl
-    <<"    (bounds are excluded, used only if sphinw.fits==NULL)"<<endl
+cout<<"extrap2sph [-m valmin -M valmax -r rvalmin -R rvalmax]"<<endl
+    <<"           [-w sphinw.fits] sphin.fits sphred.fits sphout.fits"<<endl
+    <<" -w sphinw.fits : input sphere  weight, if sphinw_value<=0. (def=NULL)"<<endl
+    <<"                  if sphinw_value<=0. pixel has not to be filled"<<endl
+    <<" -m minval : min value to identify EMPTY pixel of sphin (def=no_test)"<<endl
+    <<" -M maxval : max value to identify EMPTY pixel of sphin (def=no_test)"<<endl
+    <<"    condition for EMPTY pixel is (minval<=val<=maxval)"<<endl
+    <<" -n : negate the previous condition, condition for EMPTY pixel"<<endl
+    <<"      becomes: (val<minval || maxval<val)"<<endl
+    <<" -r rminval : min value to identify GOOD pixel of sphred (def=no_test)"<<endl
+    <<" -R rmaxval : max value to identify GOOD pixel of sphred (def=no_test)"<<endl
+    <<"    condition for GOOD pixel is (minval<=val<=maxval)"<<endl
+    <<" -n : negate the previous condition, condition for GOOD pixel"<<endl
+    <<"      becomes: (val<minval || maxval<val)"<<endl
     <<" sphin.fits   : input sphere"<<endl
     <<" sphred.fits  : input reducted sphere"<<endl
@@ -30,10 +66,18 @@
 int main(int narg, char* arg[])
 {
-bool tstmin=false, tstmax=false;
-double valmin=-1.e30, valmax=+1.e30;
+bool tstmin=false,  tstmax=false,  neg=false;
+bool rtstmin=false, rtstmax=false, rneg=false;
+double valmin=0., valmax=0., rvalmin=0., rvalmax=0.;
 char * fsphinw = NULL;
+string dum;
 int c;
-while((c = getopt(narg,arg,"hm:M:w:")) != -1) {
+while((c = getopt(narg,arg,"hnNm:M:r:R:w:")) != -1) {
   switch (c) {
+  case 'n' :
+    neg = true;
+    break;
+  case 'N' :
+    rneg = true;
+    break;
   case 'm' :
     sscanf(optarg,"%lf",&valmin);
@@ -43,4 +87,12 @@
     sscanf(optarg,"%lf",&valmax);
     tstmax=true;
+    break;
+  case 'r' :
+    sscanf(optarg,"%lf",&rvalmin);
+    rtstmin=true;
+    break;
+  case 'R' :
+    sscanf(optarg,"%lf",&rvalmax);
+    rtstmax=true;
     break;
   case 'w' :
@@ -54,7 +106,7 @@
 
 if(optind+2>=narg) {usage(); exit(1);}
-char * fsphin   = arg[optind];
+char * fsphin  = arg[optind];
 char * fsphred = arg[optind+1];
-char * fsphout  = arg[optind+2];
+char * fsphout = arg[optind+2];
 
 cout<<"Input Sphere          : "<<fsphin<<endl
@@ -62,9 +114,16 @@
     <<"Input Reducted Sphere : "<<fsphred<<endl
     <<"Output Sphere         : "<<fsphout<<endl;
-if(!fsphinw)
-  cout<<"- test min("<<tstmin<<") : "<<valmin<<endl
-      <<"  test max("<<tstmax<<") : "<<valmax<<endl
-      <<"Condition for EMPTY pixel is :\n    ("<<valmin
-      <<" < sphere value < "<<valmax<<") bounds are excluded!"<<endl;
+if(neg) dum = ".NOT."; else dum="";
+cout<<"- Sphere - test min("<<tstmin<<") : "<<valmin<<endl
+    <<"           test max("<<tstmax<<") : "<<valmax<<endl
+    <<"           negate("<<neg<<")"<<endl
+    <<"  - Condition for EMPTY pixel in Sphere is :"<<endl
+    <<"    "<<dum<<"( "<<valmin<<" <= V <= "<<valmax<<" )"<<endl;
+if(rneg) dum = ".NOT."; else dum="";
+cout<<"- Reducted Sphere - test min("<<rtstmin<<") : "<<rvalmin<<endl
+    <<"                    test max("<<rtstmax<<") : "<<rvalmax<<endl
+    <<"                    negate("<<rneg<<")"<<endl
+    <<"  - Condition for GOOD pixel in Reducted Sphere is :"<<endl
+    <<"    "<<dum<<"( "<<rvalmin<<" <= V <= "<<rvalmax<<" )"<<endl;
 
 // Lecture des spheres
@@ -102,15 +161,21 @@
 uint_4 n=0, n0=0;
 for(int_4 i=0;i<sphin.NbPixels();i++) {
-  if(fsphinw) {
-    if(sphinw(i)>0.) continue;
-  } else {
-    // Not Filled pixels ]valmin,valmax[
-    // Filled pixels ]-Infinity,valmin] or [valmax,+Infinity[
-    if(tstmin && sphin(i)<=valmin) continue;
-    if(tstmax && sphin(i)>=valmax) continue;
-  }
+  bool skp;
+  if(fsphinw) if(sphinw(i)<=0.) continue; // Pixel out of acceptance!
+
+  // Test if pixel of Sphere has to be extrapolated
+  skp = (tstmin || tstmax) ? neg : false;
+  if((tstmin && sphin(i)<valmin) || (tstmax && sphin(i)>valmax)) skp = !neg;
+  if(skp) continue;   // Do nothing
+
   double theta,phi;
   sphin.PixThetaPhi(i,theta,phi);
   int_4 ir = sphred.PixIndexSph(theta,phi);
+
+  // Test if pixel of Reducted Sphere is good
+  skp = (rtstmin || rtstmax) ? rneg : false;
+  if((rtstmin && sphred(i)<rvalmin) || (rtstmax && sphred(i)>rvalmax)) skp = !rneg;
+  if(skp) continue;   // Do nothing
+
   sphin(i) = sphred(ir);
   n++; if(sphred(ir)!=0.) n0++;
@@ -121,5 +186,5 @@
 // Ecriture de la sphere
 {
-string dum = "rm -f "; dum += fsphout; system(dum.c_str());
+dum = "rm -f "; dum += fsphout; system(dum.c_str());
 FitsOutFile sfits(fsphout);
 cout<<"Writing Output Sphere Fits file"<<endl;
Index: trunk/SophyaProg/PrgMap/extrapsph.cc
===================================================================
--- trunk/SophyaProg/PrgMap/extrapsph.cc	(revision 1624)
+++ trunk/SophyaProg/PrgMap/extrapsph.cc	(revision 1626)
@@ -1,4 +1,5 @@
-// Pour boucher les trous d'une sphere HEALPIX en clusterisant dans une sphere
-// plus petite             cmv 13/6/01
+// Pour boucher les trous d'une sphere HEALPIX en la clusterisant
+// dans une sphere plus petite puis en la re-extrapolant.
+//                    cmv 13/6/01
 // extrapsph -r 2 sph143k05.fits sph143k05_e.fits
 //                sphout.fits sphoutw.fits sphred.fits sphredw.fits
@@ -13,9 +14,28 @@
 #include "fitsspherehealpix.h" 
 
+/*!
+  \ingroup PrgMap
+  \file extrapsph.cc
+  \brief \b extrapsph: Fill holes in a sphere of datas by reducing
+  it size and re-extrapolating.
+  \verbatim
+csh> extrapsph -h
+extrapsph [-r reduc_factor] sphin.fits sphinw.fits
+          sphout.fits [sphout_w.fits sphred.fits sphred_w.fits]
+ -r reduc : reduction factor for clustering (must be 2^n, def=2)
+ sphin.fits    : input sphere
+ sphin_w.fits  : input sphere filling weight
+ sphout.fits   : output sphere
+ sphout_w.fits : output sphere filling weight
+ sphred.fits   : output reducted sphere
+ sphred_w.fits : output reducted sphere filling weight
+  \endverbatim
+*/
+
 void usage();
 void usage()
 {
-cout<<"extrapsph [-r reduc] sphin.fits sphinw.fits"<<endl
-    <<"                     sphout.fits [sphout_w.fits"
+cout<<"extrapsph [-r reduc_factor] sphin.fits sphinw.fits"<<endl
+    <<"          sphout.fits [sphout_w.fits"
     <<" sphred.fits sphred_w.fits]"<<endl
     <<" -r reduc : reduction factor for clustering (must be 2^n, def=2)"<<endl
@@ -31,4 +51,5 @@
 {
 int red=2;
+string dum;
 int c;
 while((c = getopt(narg,arg,"hr:")) != -1) {
@@ -122,4 +143,5 @@
   if(sphredw(ir)<=0.) continue;
   sphin(i)  = sphred(ir);
+  // On passe en negatif les pixels qui ont ete extrapoles
   sphinw(i) = -sphredw(ir);
   n++;
@@ -129,5 +151,5 @@
 // Ecriture des spheres
 {
-string dum = "rm -f "; dum += fsphout; system(dum.c_str());
+dum = "rm -f "; dum += fsphout; system(dum.c_str());
 FitsOutFile sfits(fsphout);
 cout<<"Writing Output Sphere Fits file"<<endl;
@@ -135,5 +157,5 @@
 }
 if(fsphoutw) {
-string dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
+dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
 FitsOutFile sfits(fsphoutw);
 cout<<"Writing Output Sphere Weight Fits file"<<endl;
@@ -141,5 +163,5 @@
 }
 if(fsphred) {
-string dum = "rm -f "; dum += fsphred; system(dum.c_str());
+dum = "rm -f "; dum += fsphred; system(dum.c_str());
 FitsOutFile sfits(fsphred);
 cout<<"Writing Reducted Sphere Fits file"<<endl;
@@ -147,5 +169,5 @@
 }
 if(fsphredw) {
-string dum = "rm -f "; dum += fsphredw; system(dum.c_str());
+dum = "rm -f "; dum += fsphredw; system(dum.c_str());
 FitsOutFile sfits(fsphredw);
 cout<<"Writing Reducted Sphere Weight Fits file"<<endl;
Index: trunk/SophyaProg/PrgMap/msksphere.cc
===================================================================
--- trunk/SophyaProg/PrgMap/msksphere.cc	(revision 1624)
+++ trunk/SophyaProg/PrgMap/msksphere.cc	(revision 1626)
@@ -11,18 +11,39 @@
 #include "fitsspherehealpix.h" 
 
+/*!
+  \ingroup PrgMap
+  \file msksphere.cc
+  \brief \b msksphere: mask a sphere of datas with a mask sphere.
+  \verbatim
+csh> msksphere -h
+msksphere [-m min -M max -v valmsk] sphval.fits sphmask.fits sphout.fits
+ sphval.fits : inpout sphere of datas where the pixels have to be masked
+ sphmask.fits : inpout masked sphere used to mask pixels
+ sphout.fits : output masked sphere of datas
+ -m min : min mask_sphere_value for MASKING the sphere pixel
+ -M max : max mask_sphere_value for MASKING the sphere pixel
+    condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)
+ -n : negate the previous condition, condition for MASKING sphere pixel
+      becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)
+ Default (no -m and -M): mask pixel if mask_sphere_value<0.
+ -v valmsk : set sphere value for masked pixels (def=0.)
+  \endverbatim
+*/
+
 void usage();
 void usage()
 {
-cout<<"msksphere [-m min -M max -v valmsk]"<<endl
-    <<"          sphval.fits sphmask.fits sphout.fits"<<endl
-    <<" -m min : min value"<<endl
-    <<" -M max : max value"<<endl
-    <<"        condition for masking is :"<<endl
-    <<"           mask_sphere_value <= min"<<endl
-    <<"        OR"<<endl
-    <<"           mask_sphere_value >= max"<<endl
-    <<"        (bounds are included)"<<endl
-    <<"        Default is mask_sphere_value <=0. (no -m and -M)"<<endl
-    <<" -v valmsk : set value for masked pixels (def=0.)"<<endl;
+cout<<"msksphere [-m min -M max -v valmsk]"
+    <<" sphval.fits sphmask.fits sphout.fits"<<endl
+    <<" sphval.fits : inpout sphere of datas where the pixels have to be masked"<<endl
+    <<" sphmask.fits : inpout masked sphere used to mask pixels"<<endl
+    <<" sphout.fits : output masked sphere of datas"<<endl
+    <<" -m min : min mask_sphere_value for MASKING the sphere pixel"<<endl
+    <<" -M max : max mask_sphere_value for MASKING the sphere pixel"<<endl
+    <<"    condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)"<<endl
+    <<" -n : negate the previous condition, condition for MASKING sphere pixel"<<endl
+    <<"      becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)"<<endl
+    <<" Default (no -m and -M): mask pixel if mask_sphere_value<0."<<endl
+    <<" -v valmsk : set sphere value for masked pixels (def=0.)"<<endl;
 }
 
@@ -30,8 +51,12 @@
 {
 double vmask=0.,vmin=-1.e30,vmax=1.e30;
-bool tstmin=false,tstmax=false;
+bool tstmin=false,tstmax=false,negate=false;
+string dum;
 int c;
-while((c = getopt(narg,arg,"hm:M:v:")) != -1) {
+while((c = getopt(narg,arg,"hnm:M:v:")) != -1) {
   switch (c) {
+  case 'n' :
+    negate = true;
+    break;
   case 'm' :
     sscanf(optarg,"%lf",&vmin);
@@ -56,11 +81,15 @@
 char * sphout = arg[optind+2];
 
+if(!tstmin && !tstmax) {tstmin=true; vmin=0.; negate=true;}
+
+if(negate) dum = ".NOT."; else dum="";
 cout<<"Sphere values : "<<sphval<<endl
     <<"Sphere mask   : "<<sphmsk<<endl
     <<"Sphere out    : "<<sphout<<endl
-    <<"  ...min("<<tstmin<<") "<<vmin<<"  max("<<tstmax<<") "<<vmax<<endl
+    <<"  ...min("<<tstmin<<") "<<vmin<<endl
+    <<"     max("<<tstmax<<") "<<vmax<<endl
     <<"  ...mask set value "<<vmask<<endl
-    <<"Condition for masking pixel is : "
-    <<"( Vmsk <= "<<vmin<<" OR Vmsk >= "<<vmax<<" ) bounds are included"<<endl;
+    <<"  Condition for masking pixel is :"<<endl
+    <<"    "<<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
 
 // Lecture de la sphere Healpix des valeurs
@@ -88,11 +117,11 @@
 uint_4 nmask = 0;
 for(int_4 i=0;i<sph.NbPixels();i++) {
-  r_8 v = msph(i);
-  bool masked=false;
-  if(tstmin && v<=vmin) {sph(i) = vmask; masked = true;}
-  if(tstmax && v>=vmax) {sph(i) = vmask; masked = true;}
-  if(!tstmin && !tstmax && v<=0.)
-                        {sph(i) = vmask; masked = true;}
-  if(masked) nmask++;
+
+  bool skp = (tstmin || tstmax) ? negate : false;
+  if((tstmin && msph(i)<vmin) || (tstmax && msph(i)>vmax)) skp = !negate;
+  if(skp) continue;   // Do nothing
+
+  sph(i) = vmask;
+  nmask++;
 }
 cout<<"    .... Number of values masked   : "<<nmask<<endl;
@@ -102,5 +131,5 @@
 // Ecriture de la sphere Healpix sur fits
 {
-string dum = "rm -f "; dum += sphout; system(dum.c_str());
+dum = "rm -f "; dum += sphout; system(dum.c_str());
 FitsOutFile sfits(sphout);
 cout<<"Writing Output Masked Sphere Fits file"<<endl;
