| [1522] | 1 | // Creation d'une sphere de masque a partir d'une sphere de valeurs | 
|---|
|  | 2 | //         cmv 13/6/01 | 
|---|
| [1528] | 3 | // cremskfrsph -m 0.1 -v 1.,0. sph143k05_e.fits sphmskw.fits | 
|---|
|  | 4 | // cremskfrsph -n -m -1.e-30. -M 1.e-30. -v 1.,0. sph143k05.fits sphmsk.fits | 
|---|
| [1522] | 5 | #include "machdefs.h" | 
|---|
|  | 6 | #include <unistd.h> | 
|---|
|  | 7 | #include <stdexcept> | 
|---|
|  | 8 | #include <iostream.h> | 
|---|
|  | 9 | #include <stdio.h> | 
|---|
|  | 10 | #include <stdlib.h> | 
|---|
|  | 11 | #include "skymapinit.h" | 
|---|
|  | 12 | #include "skymap.h" | 
|---|
|  | 13 | #include "fitsspherehealpix.h" | 
|---|
|  | 14 |  | 
|---|
|  | 15 | void usage(); | 
|---|
|  | 16 | void usage() | 
|---|
|  | 17 | { | 
|---|
|  | 18 | cout<<"cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits"<<endl | 
|---|
|  | 19 | <<" -m min : min value"<<endl | 
|---|
|  | 20 | <<" -M max : max value"<<endl | 
|---|
| [1528] | 21 | <<"    condition for filling masque is : min<=sphere value<=max"<<endl | 
|---|
|  | 22 | <<"                                      (bounds are included)"<<endl | 
|---|
| [1522] | 23 | <<" -n : negate the condition"<<endl | 
|---|
|  | 24 | <<" -v valmsk,inimsk:"<<endl | 
|---|
|  | 25 | <<"    valmsk: value to be put into mask if ok (def=1.)"<<endl | 
|---|
|  | 26 | <<"    inimsk: initialisation value for the mask (def=0.)"<<endl; | 
|---|
|  | 27 | } | 
|---|
|  | 28 |  | 
|---|
|  | 29 |  | 
|---|
|  | 30 | int main(int narg, char* arg[]) | 
|---|
|  | 31 | { | 
|---|
|  | 32 | double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0.; | 
|---|
|  | 33 | bool tstmin=false,tstmax=false,negate=false; | 
|---|
|  | 34 | int c; | 
|---|
|  | 35 | while((c = getopt(narg,arg,"hnm:M:v:")) != -1) { | 
|---|
|  | 36 | switch (c) { | 
|---|
|  | 37 | case 'n' : | 
|---|
|  | 38 | negate = true; | 
|---|
|  | 39 | break; | 
|---|
|  | 40 | case 'm' : | 
|---|
|  | 41 | sscanf(optarg,"%lf",&vmin); | 
|---|
|  | 42 | tstmin = true; | 
|---|
|  | 43 | break; | 
|---|
|  | 44 | case 'M' : | 
|---|
|  | 45 | sscanf(optarg,"%lf",&vmax); | 
|---|
|  | 46 | tstmax = true; | 
|---|
|  | 47 | break; | 
|---|
|  | 48 | case 'v' : | 
|---|
|  | 49 | sscanf(optarg,"%lf,%lf",&vmask,&vmaskini); | 
|---|
|  | 50 | break; | 
|---|
|  | 51 | case 'h' : | 
|---|
|  | 52 | default: | 
|---|
|  | 53 | usage(); exit(1); | 
|---|
|  | 54 | } | 
|---|
|  | 55 | } | 
|---|
|  | 56 |  | 
|---|
|  | 57 | if(optind+1>=narg) {usage(); exit(1);} | 
|---|
|  | 58 | char * sphval = arg[optind]; | 
|---|
|  | 59 | char * sphmsk = arg[optind+1]; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | cout<<"Sphere values : "<<sphval<<endl | 
|---|
|  | 62 | <<"Sphere mask   : "<<sphmsk<<endl | 
|---|
| [1535] | 63 | <<"  ...min("<<tstmin<<") "<<vmin<<"  max("<<tstmax<<") "<<vmax<<endl | 
|---|
| [1522] | 64 | <<"  ...negate "<<negate<<endl | 
|---|
|  | 65 | <<"  ...mask set value "<<vmask<<endl | 
|---|
|  | 66 | <<"     mask init value "<<vmaskini<<endl; | 
|---|
|  | 67 | cout<<"Condition : "; | 
|---|
|  | 68 | if(negate) cout<<"!"; | 
|---|
| [1528] | 69 | cout<<"( "<<vmin<<" <= V <= "<<vmax<<" ) bounds are included"<<endl; | 
|---|
| [1522] | 70 |  | 
|---|
|  | 71 | // Lecture de la sphere Healpix des valeurs | 
|---|
|  | 72 | SphereHEALPix<r_8> sph; | 
|---|
|  | 73 | FitsInFile sfits(sphval); | 
|---|
|  | 74 | sfits >> sph; | 
|---|
|  | 75 | cout<<"Opening Sphere HEALPix for testing values :"<<endl | 
|---|
|  | 76 | <<"          Type of map : "<<sph.TypeOfMap()<<endl | 
|---|
|  | 77 | <<"     Number of pixels : "<<sph.NbPixels()<<endl | 
|---|
|  | 78 | <<"                 Nlat : "<<sph.SizeIndex()<<endl; | 
|---|
|  | 79 |  | 
|---|
|  | 80 | // Ouverture de la sphere Healpix pour le masque | 
|---|
|  | 81 | cout<<"Creating Mask Sphere"<<endl; | 
|---|
|  | 82 | SphereHEALPix<r_8> sphm(sph,false); | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // Filling Mask Sphere | 
|---|
|  | 85 | cout<<"Filling Mask"<<endl; | 
|---|
|  | 86 | uint_4 nmask = 0; | 
|---|
|  | 87 | for(int_4 i=0;i<sph.NbPixels();i++) { | 
|---|
|  | 88 | sphm(i) = vmaskini; | 
|---|
|  | 89 | r_8 v = sph(i); | 
|---|
|  | 90 | bool intoint = true; | 
|---|
|  | 91 | if(tstmin && v<vmin) intoint=false; | 
|---|
|  | 92 | if(tstmax && v>vmax) intoint=false; | 
|---|
|  | 93 | //                    [vmin , vmax] | 
|---|
|  | 94 | // intoint :   false  [    true   ]  false  (si tstmin && tstmax) | 
|---|
|  | 95 | // intoint :   false  [    true             (si tstmin && !tstmax) | 
|---|
|  | 96 | // intoint :               true   ]  false  (si !tstmin && tstmax) | 
|---|
|  | 97 | if(negate && intoint) continue; | 
|---|
|  | 98 | else if(!negate && !intoint) continue; | 
|---|
|  | 99 | sphm(i) = vmask; | 
|---|
|  | 100 | nmask++; | 
|---|
|  | 101 | } | 
|---|
|  | 102 | cout<<"    .... Number of values set in mask   : "<<nmask<<endl; | 
|---|
|  | 103 | cout<<"    .... Fraction of values set in mask : " | 
|---|
|  | 104 | <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl; | 
|---|
|  | 105 |  | 
|---|
|  | 106 | // Ecriture de la sphere Healpix sur fits | 
|---|
|  | 107 | { | 
|---|
|  | 108 | string dum = "rm -f "; dum += sphmsk; system(dum.c_str()); | 
|---|
|  | 109 | FitsOutFile swfits(sphmsk); | 
|---|
|  | 110 | cout<<"Writing Mask Sphere Fits file"<<endl; | 
|---|
|  | 111 | swfits<<sphm; | 
|---|
|  | 112 | } | 
|---|
|  | 113 |  | 
|---|
|  | 114 | exit(0); | 
|---|
|  | 115 | } | 
|---|