1 | #include <unistd.h>
|
---|
2 | #include <stdexcept>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <stdio.h>
|
---|
5 | #include "toi.h"
|
---|
6 | #include "toiprocessor.h"
|
---|
7 | #include "fitstoirdr.h"
|
---|
8 | #include "fitstoiwtr.h"
|
---|
9 | #include "toimanager.h"
|
---|
10 | #include "toiseqbuff.h"
|
---|
11 |
|
---|
12 | #include "sambainit.h"
|
---|
13 | #include "toi2map.h"
|
---|
14 | #include "fitsspherehealpix.h"
|
---|
15 | #include "timing.h"
|
---|
16 |
|
---|
17 | void usage(void);
|
---|
18 | void usage(void) {
|
---|
19 | cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
|
---|
20 | <<" [-a label_coord1] [-d label_coord2] [-b label_bolomuv]"<<endl
|
---|
21 | <<" [-n nlat] coord_ini coord_fin fitsin_bolo fitsin_point fitsphout fitsphwout"<<endl
|
---|
22 | <<" coord_ini[_fin] = G for Galactic coordinates"<<endl
|
---|
23 | <<" = Q for equatorial coordinates"<<endl
|
---|
24 | <<" coord1 = alpha or longitude ; coord2 = delta or latitude"<<endl;
|
---|
25 | return;
|
---|
26 | }
|
---|
27 |
|
---|
28 | ////////////////////////////////////////////////////////////////
|
---|
29 | int main(int narg, char** arg) {
|
---|
30 |
|
---|
31 | TOIManager* mgr = TOIManager::getManager();
|
---|
32 |
|
---|
33 | //-- Decodage arguments
|
---|
34 | int lp = 0, width = 8192;
|
---|
35 | int nlat = 128; // npixel = 12 * nlat^2
|
---|
36 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
|
---|
37 | long sdeb,sfin;
|
---|
38 | int c;
|
---|
39 | while((c = getopt(narg,arg,"hGp:s:w:a:d:b:n:")) != -1) {
|
---|
40 | switch (c) {
|
---|
41 | case 's' :
|
---|
42 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
|
---|
43 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
|
---|
44 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
|
---|
45 | else {cout<<"Bad sample interval "<<endl; exit(-2);}
|
---|
46 | break;
|
---|
47 | case 'w' :
|
---|
48 | sscanf(optarg,"%d",&width);
|
---|
49 | if(width<=0) width=8192;
|
---|
50 | cout<<"Data window size "<<width<<endl;
|
---|
51 | break;
|
---|
52 | case 'p' :
|
---|
53 | sscanf(optarg,"%d",&lp);
|
---|
54 | if(lp<0) lp=0;
|
---|
55 | break;
|
---|
56 | case 'a' :
|
---|
57 | label_coord1 = optarg;
|
---|
58 | break;
|
---|
59 | case 'd' :
|
---|
60 | label_coord2 = optarg;
|
---|
61 | break;
|
---|
62 | case 'b' :
|
---|
63 | label_bolomuv = optarg;
|
---|
64 | break;
|
---|
65 | case 'n' :
|
---|
66 | sscanf(optarg,"%d",&nlat);
|
---|
67 | if(nlat<0) nlat=128;
|
---|
68 | break;
|
---|
69 | case 'h' :
|
---|
70 | usage(); exit(-1);
|
---|
71 | break;
|
---|
72 | default:
|
---|
73 | usage(); exit(-1);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | if(optind+3>=narg) {usage(); exit(-2);}
|
---|
77 | bool mcoorgal=true;
|
---|
78 | bool fcoorgal=true;
|
---|
79 |
|
---|
80 | if ( strcmp(arg[optind],"Q") == 0) mcoorgal=false;
|
---|
81 | if ( strcmp(arg[optind+1],"Q") == 0) fcoorgal=false;
|
---|
82 |
|
---|
83 | char * fitsin_bolo = arg[optind+2];
|
---|
84 | char * fitsin_point = arg[optind+3];
|
---|
85 | string const fitsphout = arg[optind+4];
|
---|
86 | string fitsphwout = "";
|
---|
87 | if(optind+5<narg) fitsphwout = arg[optind+5];
|
---|
88 |
|
---|
89 | cout<<">>>> tsttoi2map:"<<endl
|
---|
90 | <<"Fits Infile(snum,bolomuv)= "<<fitsin_bolo<<endl
|
---|
91 | <<"Fits Infile(snum,coord1,coord2)= "<<fitsin_point<<endl
|
---|
92 | <<" ...label_coord1 "<<label_coord1<<" , label_coord2 "<<label_coord2<<endl
|
---|
93 | <<" with coordinates Gal "<<mcoorgal<<endl
|
---|
94 | <<" ...label_bolomuv "<<label_bolomuv<<endl
|
---|
95 | <<"Fits Sphere Healpix"<<fitsphout<<endl
|
---|
96 | <<" ...nlat "<<nlat<<endl
|
---|
97 | <<" with coordinates Gal "<<fcoorgal<<endl
|
---|
98 | <<"Fits Sphere Healpix Error "<<fitsphwout<<endl;
|
---|
99 |
|
---|
100 | SophyaInit();
|
---|
101 | InitTim();
|
---|
102 |
|
---|
103 | //--------------------------------------------------------------------
|
---|
104 | try {
|
---|
105 | //--------------------------------------------------------------------
|
---|
106 |
|
---|
107 | // FITS reader
|
---|
108 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
109 | int ncolb = rfitsb.getNOut();
|
---|
110 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
111 | if(ncolb<1) exit(-3);
|
---|
112 |
|
---|
113 | FITSTOIReader rfitsp(fitsin_point);
|
---|
114 | int ncolp = rfitsp.getNOut();
|
---|
115 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
116 | if(ncolp<2) exit(-3);
|
---|
117 |
|
---|
118 | // Creation de la sphere Healpix
|
---|
119 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
120 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
121 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl;
|
---|
122 |
|
---|
123 | // Creation de la sphere de poids Healpix
|
---|
124 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
125 | if(fitsphwout.size()>0) {
|
---|
126 | wsph = new SphereHEALPix<r_8>;
|
---|
127 | cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
|
---|
128 | <<" Nombre de pixels : "<<wsph->NbPixels()<<endl;
|
---|
129 | }
|
---|
130 |
|
---|
131 | // TOI Processor
|
---|
132 | TOI2Map toi2m(sph,wsph);
|
---|
133 | cout<<"TOI2Map created"<<endl;
|
---|
134 | toi2m.SetCoorGal(mcoorgal,fcoorgal,2000.); // equinoxe de ref. 2000. (pour archtoi)
|
---|
135 |
|
---|
136 | // Definition des tuyaux
|
---|
137 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
138 | if(lp) toicoord1in->setDebugLevel(1);
|
---|
139 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
140 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
141 |
|
---|
142 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
143 | if(lp) toicoord2in->setDebugLevel(1);
|
---|
144 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
145 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
146 |
|
---|
147 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
148 | if(lp) toibolin->setDebugLevel(1);
|
---|
149 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
150 | toi2m.addInput("BoloIn",toibolin);
|
---|
151 |
|
---|
152 | // Run
|
---|
153 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
154 | rfitsp.PrintStatus(cout);
|
---|
155 | rfitsb.PrintStatus(cout);
|
---|
156 |
|
---|
157 | PrtTim("starting threads");
|
---|
158 | rfitsp.start();
|
---|
159 | rfitsb.start();
|
---|
160 | toi2m.start();
|
---|
161 |
|
---|
162 | if(lp>1)
|
---|
163 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
164 | cout<<*toicoord1in;
|
---|
165 | cout<<*toibolin;
|
---|
166 | sleep(2);
|
---|
167 | }
|
---|
168 |
|
---|
169 | mgr->joinAll();
|
---|
170 | PrtTim("End threads");
|
---|
171 |
|
---|
172 | // Ecriture de la sphere Healpix sur fits
|
---|
173 | {
|
---|
174 | FitsOutFile sfits(fitsphout);
|
---|
175 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
176 | sfits << *sph;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // Ecriture de la sphere Healpix sur fits
|
---|
180 | if(wsph) {
|
---|
181 | FitsOutFile swfits(fitsphwout);
|
---|
182 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
183 | swfits << *wsph;
|
---|
184 | }
|
---|
185 |
|
---|
186 | // Nettoyage
|
---|
187 | delete sph;
|
---|
188 | if(wsph) delete wsph;
|
---|
189 |
|
---|
190 | //--------------------------------------------------------------------
|
---|
191 | } catch (PThrowable & exc) {
|
---|
192 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
193 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
194 | } catch (const std::exception & sex) {
|
---|
195 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
196 | <<(string)typeid(sex).name()<<endl;
|
---|
197 | } catch (...) {
|
---|
198 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
199 | }
|
---|
200 | //--------------------------------------------------------------------
|
---|
201 |
|
---|
202 | exit(0);
|
---|
203 | }
|
---|