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