source: Sophya/trunk/SophyaProg/PrgMap/extrap2sph.cc@ 1598

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

optimisation cmv 14/6/01

File size: 3.9 KB
Line 
1// Pour boucher les trous d'une sphere HEALPIX utilisant une autre sphere
2// cmv 13/6/01
3// extrap2sph -w sph143k05_e.fits sph143k05.fits sphred.fits sphout_2.fits
4// extrap2sph -m -1.e-30 -M +1.e-30 sph143k05.fits sphred.fits sphout_22.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<<"extrap2sph [-w sphinw.fits -m valmin -M valmax]"<<endl
19 <<" sphin.fits sphred.fits sphout.fits"<<endl
20 <<" -w sphinw.fits : input sphere weight (def=NULL)"<<endl
21 <<" -m minval : value to identify EMPTY pixel (def=-1.e30.)"<<endl
22 <<" -M maxval : value to identify EMPTY pixel (def=+1.e30)"<<endl
23 <<" condition for EMPTY pixel is (minval<val<maxval)"<<endl
24 <<" (bounds are excluded, used only if sphinw.fits==NULL)"<<endl
25 <<" sphin.fits : input sphere"<<endl
26 <<" sphred.fits : input reducted sphere"<<endl
27 <<" sphout.fits : output sphere"<<endl;
28}
29
30int main(int narg, char* arg[])
31{
32bool tstmin=false, tstmax=false;
33double valmin=-1.e30, valmax=+1.e30;
34char * fsphinw = NULL;
35int c;
36while((c = getopt(narg,arg,"hm:M:w:")) != -1) {
37 switch (c) {
38 case 'm' :
39 sscanf(optarg,"%lf",&valmin);
40 tstmin=true;
41 break;
42 case 'M' :
43 sscanf(optarg,"%lf",&valmax);
44 tstmax=true;
45 break;
46 case 'w' :
47 fsphinw = optarg;
48 break;
49 case 'h' :
50 default:
51 usage(); exit(1);
52 }
53}
54
55if(optind+2>=narg) {usage(); exit(1);}
56char * fsphin = arg[optind];
57char * fsphred = arg[optind+1];
58char * fsphout = arg[optind+2];
59
60cout<<"Input Sphere : "<<fsphin<<endl
61 <<"Input Weight Sphere : "<<fsphinw<<endl
62 <<"Input Reducted Sphere : "<<fsphred<<endl
63 <<"Output Sphere : "<<fsphout<<endl;
64if(!fsphinw)
65 cout<<"- test min("<<tstmin<<") : "<<valmin<<endl
66 <<" test max("<<tstmax<<") : "<<valmax<<endl
67 <<"Condition for EMPTY pixel is :\n ("<<valmin
68 <<" < sphere value < "<<valmax<<") bounds are excluded!"<<endl;
69
70// Lecture des spheres
71SphereHEALPix<r_8> sphin;
72{FitsInFile sfits(fsphin); sfits >> sphin;}
73int nlat = sphin.SizeIndex();
74cout<<"Opening Input Sphere :"<<endl
75 <<" Type of map : "<<sphin.TypeOfMap()<<endl
76 <<" Number of pixels : "<<sphin.NbPixels()<<endl
77 <<" Nlat : "<<sphin.SizeIndex()<<endl;
78
79SphereHEALPix<r_8> sphinw;
80if(fsphinw) {
81 FitsInFile sfits(fsphinw);
82 sfits >> sphinw;
83 cout<<"Opening Input Weight Sphere :"<<endl
84 <<" Type of map : "<<sphinw.TypeOfMap()<<endl
85 <<" Number of pixels : "<<sphinw.NbPixels()<<endl
86 <<" Nlat : "<<sphinw.SizeIndex()<<endl;
87 if(sphinw.SizeIndex()!=nlat) {
88 cout<<"Incompatible sphin sphinw"<<endl;
89 exit(2);
90 }
91}
92
93SphereHEALPix<r_8> sphred;
94{FitsInFile sfits(fsphred); sfits >> sphred;}
95cout<<"Opening Input Reducted Sphere :"<<endl
96 <<" Type of map : "<<sphred.TypeOfMap()<<endl
97 <<" Number of pixels : "<<sphred.NbPixels()<<endl
98 <<" Nlat : "<<sphred.SizeIndex()<<endl;
99
100// Filling hole for Output Sphere
101cout<<"...Filling hole for Output Sphere"<<endl;
102uint_4 n=0, n0=0;
103for(int_4 i=0;i<sphin.NbPixels();i++) {
104 if(fsphinw) {
105 if(sphinw(i)>0.) continue;
106 } else {
107 // Not Filled pixels ]valmin,valmax[
108 // Filled pixels ]-Infinity,valmin] or [valmax,+Infinity[
109 if(tstmin && sphin(i)<=valmin) continue;
110 if(tstmax && sphin(i)>=valmax) continue;
111 }
112 double theta,phi;
113 sphin.PixThetaPhi(i,theta,phi);
114 int_4 ir = sphred.PixIndexSph(theta,phi);
115 sphin(i) = sphred(ir);
116 n++; if(sphred(ir)!=0.) n0++;
117}
118cout<<" Number of pixels filled "
119 <<n<<" (not null values "<<n0<<")"<<endl;
120
121// Ecriture de la sphere
122{
123string dum = "rm -f "; dum += fsphout; system(dum.c_str());
124FitsOutFile sfits(fsphout);
125cout<<"Writing Output Sphere Fits file"<<endl;
126sfits<<sphin;
127}
128
129exit(0);
130}
Note: See TracBrowser for help on using the repository browser.