[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 |
|
---|
| 13 | void usage();
|
---|
| 14 | void usage()
|
---|
| 15 | {
|
---|
| 16 | cout<<"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 |
|
---|
| 26 | int main(int narg, char* arg[])
|
---|
| 27 | {
|
---|
| 28 | double nulval=0.;
|
---|
| 29 | char * fsphinw = NULL;
|
---|
| 30 | int c;
|
---|
| 31 | while((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 |
|
---|
| 45 | if(optind+2>=narg) {usage(); exit(1);}
|
---|
| 46 | char * fsphin = arg[optind];
|
---|
| 47 | char * fsphred = arg[optind+1];
|
---|
| 48 | char * fsphout = arg[optind+2];
|
---|
| 49 |
|
---|
| 50 | cout<<"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
|
---|
| 57 | SphereHEALPix<r_8> sphin;
|
---|
| 58 | {FitsInFile sfits(fsphin); sfits >> sphin;}
|
---|
| 59 | int nlat = sphin.SizeIndex();
|
---|
| 60 | cout<<"Opening Sphere Input :"<<endl
|
---|
| 61 | <<" Type of map : "<<sphin.TypeOfMap()<<endl
|
---|
| 62 | <<" Number of pixels : "<<sphin.NbPixels()<<endl
|
---|
| 63 | <<" Nlat : "<<sphin.SizeIndex()<<endl;
|
---|
| 64 |
|
---|
| 65 | SphereHEALPix<r_8> sphinw;
|
---|
| 66 | if(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 |
|
---|
| 79 | SphereHEALPix<r_8> sphred;
|
---|
| 80 | {FitsInFile sfits(fsphred); sfits >> sphred;}
|
---|
| 81 | cout<<"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
|
---|
| 87 | cout<<"Creating Sphere for output"<<endl;
|
---|
| 88 | SphereHEALPix<r_8> sphout(sphin,false);
|
---|
| 89 |
|
---|
| 90 | // Filling hole for Output Sphere
|
---|
| 91 | cout<<"...Filling hole for Output Sphere"<<endl;
|
---|
| 92 | uint_4 n=0;
|
---|
| 93 | for(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 | }
|
---|
| 102 | cout<<" Number of filled pixels "<<n<<endl;
|
---|
| 103 |
|
---|
| 104 | // Ecriture de la sphere
|
---|
| 105 | {
|
---|
| 106 | string dum = "rm -f "; dum += fsphout; system(dum.c_str());
|
---|
| 107 | FitsOutFile sfits(fsphout);
|
---|
| 108 | cout<<"Writing Output Sphere Fits file"<<endl;
|
---|
| 109 | sfits<<sphout;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | exit(0);
|
---|
| 113 | }
|
---|