source: Sophya/trunk/SophyaProg/PrgMap/cremskfrsph.cc@ 1528

Last change on this file since 1528 was 1528, checked in by cmv, 24 years ago

optimisation cmv 14/6/01

File size: 3.3 KB
Line 
1// Creation d'une sphere de masque a partir d'une sphere de valeurs
2// cmv 13/6/01
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
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
15void usage();
16void usage()
17{
18cout<<"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
21 <<" condition for filling masque is : min<=sphere value<=max"<<endl
22 <<" (bounds are included)"<<endl
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
30int main(int narg, char* arg[])
31{
32double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0.;
33bool tstmin=false,tstmax=false,negate=false;
34int c;
35while((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
57if(optind+1>=narg) {usage(); exit(1);}
58char * sphval = arg[optind];
59char * sphmsk = arg[optind+1];
60
61cout<<"Sphere values : "<<sphval<<endl
62 <<"Sphere mask : "<<sphmsk<<endl
63 <<" ...min "<<vmin<<" max "<<vmax<<endl
64 <<" ...negate "<<negate<<endl
65 <<" ...mask set value "<<vmask<<endl
66 <<" mask init value "<<vmaskini<<endl;
67cout<<"Condition : ";
68if(negate) cout<<"!";
69cout<<"( "<<vmin<<" <= V <= "<<vmax<<" ) bounds are included"<<endl;
70
71// Lecture de la sphere Healpix des valeurs
72SphereHEALPix<r_8> sph;
73FitsInFile sfits(sphval);
74sfits >> sph;
75cout<<"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
81cout<<"Creating Mask Sphere"<<endl;
82SphereHEALPix<r_8> sphm(sph,false);
83
84// Filling Mask Sphere
85cout<<"Filling Mask"<<endl;
86uint_4 nmask = 0;
87for(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}
102cout<<" .... Number of values set in mask : "<<nmask<<endl;
103cout<<" .... Fraction of values set in mask : "
104 <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
105
106// Ecriture de la sphere Healpix sur fits
107{
108string dum = "rm -f "; dum += sphmsk; system(dum.c_str());
109FitsOutFile swfits(sphmsk);
110cout<<"Writing Mask Sphere Fits file"<<endl;
111swfits<<sphm;
112}
113
114exit(0);
115}
Note: See TracBrowser for help on using the repository browser.