Index: trunk/SophyaProg/PrgMap/msksphere.cc
===================================================================
--- trunk/SophyaProg/PrgMap/msksphere.cc	(revision 1535)
+++ 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;
