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

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

Pour boucher les trous dans les spheres Healpix

  • avec une sphere et sa sphere associee de poids
  • avec une sphere et une autre sphere (+ petite)

cmv 13/6/01

File size: 3.1 KB
RevLine 
[1526]1// Pour boucher les trous d'une sphere HEALPIX utilisant une autre sphere
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<<"extrap2sph [-w sphinw.fits -0 nulval]"<<endl
17 <<" sphin.fits sphred.fits sphout.fits"<<endl
18 <<" -w sphinw.fits : input sphere weight (def=NULL)"<<endl
19 <<" -0 nulval : value to identify empty pixel in sphin (def=0.)"<<endl
20 <<" (used if sphinw.fits==NULL)"<<endl
21 <<" sphin.fits : input sphere"<<endl
22 <<" sphred.fits : input reducted sphere"<<endl
23 <<" sphout.fits : output sphere"<<endl;
24}
25
26int main(int narg, char* arg[])
27{
28double nulval=0.;
29char * fsphinw = NULL;
30int c;
31while((c = getopt(narg,arg,"h0:w:")) != -1) {
32 switch (c) {
33 case '0' :
34 sscanf(optarg,"%lf",&nulval);
35 break;
36 case 'w' :
37 fsphinw = optarg;
38 break;
39 case 'h' :
40 default:
41 usage(); exit(1);
42 }
43}
44
45if(optind+2>=narg) {usage(); exit(1);}
46char * fsphin = arg[optind];
47char * fsphred = arg[optind+1];
48char * fsphout = arg[optind+2];
49
50cout<<"Sphere Input : "<<fsphin<<endl
51 <<"Weight Sphere Input : "<<fsphinw<<endl
52 <<"Reducted Sphere Input : "<<fsphred<<endl
53 <<"Sphere Output : "<<fsphout<<endl
54 <<"nulval : "<<nulval<<endl;
55
56// Lecture des spheres
57SphereHEALPix<r_8> sphin;
58{FitsInFile sfits(fsphin); sfits >> sphin;}
59int nlat = sphin.SizeIndex();
60cout<<"Opening Sphere Input :"<<endl
61 <<" Type of map : "<<sphin.TypeOfMap()<<endl
62 <<" Number of pixels : "<<sphin.NbPixels()<<endl
63 <<" Nlat : "<<sphin.SizeIndex()<<endl;
64
65SphereHEALPix<r_8> sphinw;
66if(fsphinw) {
67 FitsInFile sfits(fsphinw);
68 sfits >> sphinw;
69 cout<<"Opening Weight Sphere Input :"<<endl
70 <<" Type of map : "<<sphinw.TypeOfMap()<<endl
71 <<" Number of pixels : "<<sphinw.NbPixels()<<endl
72 <<" Nlat : "<<sphinw.SizeIndex()<<endl;
73 if(sphinw.SizeIndex()!=nlat) {
74 cout<<"Incompatible sphin sphinw"<<endl;
75 exit(2);
76 }
77}
78
79SphereHEALPix<r_8> sphred;
80{FitsInFile sfits(fsphred); sfits >> sphred;}
81cout<<"Opening Reducted Sphere Input :"<<endl
82 <<" Type of map : "<<sphred.TypeOfMap()<<endl
83 <<" Number of pixels : "<<sphred.NbPixels()<<endl
84 <<" Nlat : "<<sphred.SizeIndex()<<endl;
85
86// Creation de la sphere output
87cout<<"Creating Sphere for output"<<endl;
88SphereHEALPix<r_8> sphout(sphin,false);
89
90// Filling hole for Output Sphere
91cout<<"...Filling hole for Output Sphere"<<endl;
92uint_4 n=0;
93for(int_4 i=0;i<sphout.NbPixels();i++) {
94 if(fsphinw) {if(sphinw(i)>0.) continue;}
95 else {if(sphout(i)!=nulval) continue;}
96 double theta,phi;
97 sphout.PixThetaPhi(i,theta,phi);
98 int_4 ir = sphred.PixIndexSph(theta,phi);
99 sphout(i) = sphred(ir);
100 n++;
101}
102cout<<" Number of filled pixels "<<n<<endl;
103
104// Ecriture de la sphere
105{
106string dum = "rm -f "; dum += fsphout; system(dum.c_str());
107FitsOutFile sfits(fsphout);
108cout<<"Writing Output Sphere Fits file"<<endl;
109sfits<<sphout;
110}
111
112exit(0);
113}
Note: See TracBrowser for help on using the repository browser.