source: Sophya/trunk/SophyaProg/PrgMap/extrapsph.cc@ 1545

Last change on this file since 1545 was 1545, checked in by ansari, 24 years ago

compil/portage SGI-CC , Reza 18/6/2001

File size: 4.6 KB
RevLine 
[1526]1// Pour boucher les trous d'une sphere HEALPIX en clusterisant dans une sphere
2// plus petite cmv 13/6/01
[1528]3// extrapsph -r 2 sph143k05.fits sph143k05_e.fits
4// sphout.fits sphoutw.fits sphred.fits sphredw.fits
[1526]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<<"extrapsph [-r reduc] sphin.fits sphinw.fits"<<endl
19 <<" sphout.fits [sphout_w.fits"
20 <<" sphred.fits sphred_w.fits]"<<endl
[1528]21 <<" -r reduc : reduction factor for clustering (must be 2^n, def=2)"<<endl
22 <<" sphin.fits : input sphere"<<endl
23 <<" sphin_w.fits : input sphere filling weight"<<endl
24 <<" sphout.fits : output sphere"<<endl
25 <<" sphout_w.fits : output sphere filling weight"<<endl
26 <<" sphred.fits : output reducted sphere"<<endl
27 <<" sphred_w.fits : output reducted sphere filling weight"<<endl;
[1526]28}
29
30int main(int narg, char* arg[])
31{
32int red=2;
33int c;
34while((c = getopt(narg,arg,"hr:")) != -1) {
35 switch (c) {
36 case 'r' :
37 sscanf(optarg,"%d",&red);
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 * fsphinw = arg[optind+1];
48char * fsphout = arg[optind+2];
49char * fsphoutw = NULL;
50char * fsphred = NULL;
51char * fsphredw = NULL;
52if(optind+3<narg) fsphoutw = arg[optind+3];
53if(optind+4<narg) fsphred = arg[optind+4];
54if(optind+5<narg) fsphredw = arg[optind+5];
55
[1528]56cout<<"Input Sphere : "<<fsphin<<endl
57 <<"Input Weight Sphere : "<<fsphinw<<endl
58 <<"Output Sphere : "<<fsphout<<endl
59 <<"Output Weight Sphere : "<<fsphoutw<<endl
60 <<"Output Reducted Sphere : "<<fsphred<<endl
61 <<"Output Reducted Weight Sphere : "<<fsphredw<<endl
[1526]62 <<"Reduction : "<<red<<endl;
63
64// Lecture des spheres
65SphereHEALPix<r_8> sphin;
66{FitsInFile sfits(fsphin); sfits >> sphin;}
67int nlat = sphin.SizeIndex();
68int nlatr = nlat/red;
[1528]69cout<<"Opening Input Sphere :"<<endl
[1526]70 <<" Type of map : "<<sphin.TypeOfMap()<<endl
71 <<" Number of pixels : "<<sphin.NbPixels()<<endl
72 <<" Nlat : "<<sphin.SizeIndex()<<endl;
73
74SphereHEALPix<r_8> sphinw;
75{FitsInFile sfits(fsphinw); sfits >> sphinw;}
[1528]76cout<<"Opening Input Weight Sphere :"<<endl
[1526]77 <<" Type of map : "<<sphinw.TypeOfMap()<<endl
78 <<" Number of pixels : "<<sphinw.NbPixels()<<endl
79 <<" Nlat : "<<sphinw.SizeIndex()<<endl;
80if(sphinw.SizeIndex()!=nlat) {
81 cout<<"Incompatible sphin sphinw"<<endl;
82 exit(2);
83}
84
85// Creation des spheres reduites
86cout<<"Creating Reducted Spheres : nlatr = "<<nlatr<<endl;
87SphereHEALPix<r_8> sphred(nlatr);
88 sphred.SetPixels(0.);
89SphereHEALPix<r_8> sphredw(nlatr);
90 sphredw.SetPixels(0.);
[1528]91cout<<" Number of pixels : "<<sphred.NbPixels()<<endl
[1526]92 <<" Nlat : "<<sphred.SizeIndex()<<endl;
93
94// Filling reducted spheres
95cout<<"...Filling Reducted Spheres"<<endl;
[1528]96uint_4 n=0;
[1545]97int_4 i, ir;
98for(i=0;i<sphin.NbPixels();i++) {
[1526]99 if(sphinw(i)<=0.) continue;
100 double theta,phi;
101 sphin.PixThetaPhi(i,theta,phi);
[1545]102 ir = sphred.PixIndexSph(theta,phi);
[1526]103 sphred(ir) += sphin(i)*sphinw(i);
104 sphredw(ir) += sphinw(i);
[1528]105 n++;
[1526]106}
[1528]107cout<<" Input Sphere: Number of filled pixels "<<n<<endl;
[1526]108cout<<"...Computing Reducted Spheres"<<endl;
[1528]109n=0;
[1545]110for(ir=0;ir<sphred.NbPixels();ir++)
[1526]111 if(sphredw(ir) > 0.) {sphred(ir) /= sphredw(ir); n++;}
[1528]112cout<<" Reducted Sphere: Number of pixels filled "<<n<<endl;
[1526]113
114// Filling hole for Output Spheres
115cout<<"...Filling hole for Output Spheres"<<endl;
116n=0;
[1545]117for(i=0;i<sphin.NbPixels();i++) {
[1528]118 if(sphinw(i)>0.) continue;
[1526]119 double theta,phi;
[1528]120 sphin.PixThetaPhi(i,theta,phi);
[1526]121 int_4 ir = sphred.PixIndexSph(theta,phi);
122 if(sphredw(ir)<=0.) continue;
[1528]123 sphin(i) = sphred(ir);
124 sphinw(i) = -sphredw(ir);
[1526]125 n++;
126}
[1528]127cout<<" Output Sphere: Number of pixels filled "<<n<<endl;
[1526]128
129// Ecriture des spheres
130{
131string dum = "rm -f "; dum += fsphout; system(dum.c_str());
132FitsOutFile sfits(fsphout);
133cout<<"Writing Output Sphere Fits file"<<endl;
[1528]134sfits<<sphin;
[1526]135}
136if(fsphoutw) {
137string dum = "rm -f "; dum += fsphoutw; system(dum.c_str());
138FitsOutFile sfits(fsphoutw);
139cout<<"Writing Output Sphere Weight Fits file"<<endl;
[1528]140sfits<<sphinw;
[1526]141}
142if(fsphred) {
143string dum = "rm -f "; dum += fsphred; system(dum.c_str());
144FitsOutFile sfits(fsphred);
145cout<<"Writing Reducted Sphere Fits file"<<endl;
146sfits<<sphred;
147}
148if(fsphredw) {
149string dum = "rm -f "; dum += fsphredw; system(dum.c_str());
150FitsOutFile sfits(fsphredw);
151cout<<"Writing Reducted Sphere Weight Fits file"<<endl;
152sfits<<sphredw;
153}
154
155exit(0);
156}
Note: See TracBrowser for help on using the repository browser.