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

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

creation sphere mask a partir sphere valeurs cmv 13/6/01

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