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] [-i c,h] [-o c,h]"<<endl
|
---|
22 | <<" [-m vmin] [-M vmax] [-f flag]"<<endl
|
---|
23 | <<" fitsin_point fitsin_bolo fitsphout [fitsphwout]"<<endl
|
---|
24 | <<" -p lp : print level (def=0)"<<endl
|
---|
25 | <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
|
---|
26 | <<" -w data_window_size : window size for pipe (def=8192)"<<endl
|
---|
27 | <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
|
---|
28 | <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
|
---|
29 | <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
|
---|
30 | <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
|
---|
31 | <<" -n nlat : nlat for Healpix sphere (def=128)"<<endl
|
---|
32 | <<" -i c,h : coordIn caracteristics (c=G/E h=H/D/R) (def=G,D)"<<endl
|
---|
33 | <<" -o c,h : idem -i for coordOut"<<endl
|
---|
34 | <<" -m vmin : samples are good if sample value >= vmin"<<endl
|
---|
35 | <<" -M vmax : samples are good if sample value <= vmax"<<endl
|
---|
36 | <<" -f flag : samples are bad if match flag"<<endl
|
---|
37 | <<" fitsin_point : fits file for pointing"<<endl
|
---|
38 | <<" fitsin_bolo : fits file for bolo values"<<endl
|
---|
39 | <<" fitsphout : fits file for output Healpix sphere"<<endl
|
---|
40 | <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
|
---|
41 | }
|
---|
42 |
|
---|
43 | unsigned long typecoord(char typc=' ',char hd=' ');
|
---|
44 | unsigned long typecoord(char typc,char hd)
|
---|
45 | // typc : G=galactiques, E=equatoriales, autres=galactiques
|
---|
46 | // hd : H=heure, D=degre, R=radian, autres=(heure si typc==E, degre si typc==G)
|
---|
47 | {
|
---|
48 | if(typc!='G' && typc!='E') typc='G';
|
---|
49 | if(hd!='H' && hd!='D' && hd!='R') {if(typc=='E') hd='H'; else hd='D';}
|
---|
50 | unsigned long rc=TypCoordUndef;
|
---|
51 | if(typc=='G') rc |= TypCoordGal;
|
---|
52 | else rc |= TypCoordEq;
|
---|
53 | if(hd=='D') rc |= TypCoordDD;
|
---|
54 | else if(hd=='R') rc |= TypCoordRR;
|
---|
55 | else rc |= TypCoordHD;
|
---|
56 | return rc;
|
---|
57 | }
|
---|
58 |
|
---|
59 | ////////////////////////////////////////////////////////////////
|
---|
60 | int main(int narg, char** arg) {
|
---|
61 |
|
---|
62 | TOIManager* mgr = TOIManager::getManager();
|
---|
63 |
|
---|
64 | //-- Decodage arguments
|
---|
65 | int lp = 0, width = 8192;
|
---|
66 | int nlat = 128; // npixel = 12 * nlat^2
|
---|
67 | bool tflg=false, tmin=false, tmax=false;
|
---|
68 | r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
|
---|
69 | char *label_coord1 = "coord1", *label_coord2 = "coord2"
|
---|
70 | , *label_bolomuv = "boloMuV";
|
---|
71 | long sdeb,sfin;
|
---|
72 | string fitsphwout = "";
|
---|
73 | unsigned long tcoorin=typecoord(), tcoorout=typecoord();
|
---|
74 | int c; char t=' ',h=' ';
|
---|
75 | while((c = getopt(narg,arg,"hp:s:w:a:d:b:n:i:o:m:M:f:")) != -1) {
|
---|
76 | switch (c) {
|
---|
77 | case 's' :
|
---|
78 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
|
---|
79 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
|
---|
80 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
|
---|
81 | else {cout<<"Bad sample interval "<<endl; exit(2);}
|
---|
82 | break;
|
---|
83 | case 'w' :
|
---|
84 | sscanf(optarg,"%d",&width);
|
---|
85 | if(width<=0) width=8192;
|
---|
86 | cout<<"Data window size "<<width<<endl;
|
---|
87 | break;
|
---|
88 | case 'p' :
|
---|
89 | sscanf(optarg,"%d",&lp);
|
---|
90 | if(lp<0) lp=0;
|
---|
91 | break;
|
---|
92 | case 'a' :
|
---|
93 | label_coord1 = optarg;
|
---|
94 | break;
|
---|
95 | case 'd' :
|
---|
96 | label_coord2 = optarg;
|
---|
97 | break;
|
---|
98 | case 'b' :
|
---|
99 | label_bolomuv = optarg;
|
---|
100 | break;
|
---|
101 | case 'n' :
|
---|
102 | sscanf(optarg,"%d",&nlat);
|
---|
103 | if(nlat<0) nlat=128;
|
---|
104 | break;
|
---|
105 | case 'i' :
|
---|
106 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
107 | tcoorin=typecoord(t,h);
|
---|
108 | break;
|
---|
109 | case 'o' :
|
---|
110 | sscanf(optarg,"%c,%c",&t,&h);
|
---|
111 | tcoorout=typecoord(t,h);
|
---|
112 | break;
|
---|
113 | case 'm' :
|
---|
114 | sscanf(optarg,"%lf",&vmin);
|
---|
115 | tmin = true;
|
---|
116 | break;
|
---|
117 | case 'M' :
|
---|
118 | sscanf(optarg,"%lf",&vmax);
|
---|
119 | tmax = true;
|
---|
120 | break;
|
---|
121 | case 'f' :
|
---|
122 | sscanf(optarg,"%ul",&badflg);
|
---|
123 | tflg = true;
|
---|
124 | break;
|
---|
125 | case 'h' :
|
---|
126 | default:
|
---|
127 | usage(); exit(1);
|
---|
128 | break;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | if(optind+2>=narg) {usage(); exit(3);}
|
---|
132 |
|
---|
133 | char * fitsin_point = arg[optind];
|
---|
134 | char * fitsin_bolo = arg[optind+1];
|
---|
135 | string const fitsphout = arg[optind+2];
|
---|
136 | if(optind+3<narg) fitsphwout = arg[optind+3];
|
---|
137 |
|
---|
138 | cout<<">>>> tsttoi2map:"<<endl
|
---|
139 | <<"Pipe Window Size "<<width<<endl
|
---|
140 | <<"Fits Infile Bolo "<<fitsin_bolo<<endl
|
---|
141 | <<" ...label_bolomuv "<<label_bolomuv<<endl;
|
---|
142 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl
|
---|
143 | <<" ...label_coord1 "<<label_coord1<<endl
|
---|
144 | <<" ...label_coord2 "<<label_coord2<<endl;
|
---|
145 | cout<<"Fits Healpix Sphere "<<fitsphout<<endl
|
---|
146 | <<" ...nlat "<<nlat<<endl;
|
---|
147 | cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl;
|
---|
148 |
|
---|
149 | SophyaInit();
|
---|
150 | InitTim();
|
---|
151 |
|
---|
152 | //--------------------------------------------------------------------
|
---|
153 | try {
|
---|
154 | //--------------------------------------------------------------------
|
---|
155 |
|
---|
156 |
|
---|
157 | // FITS reader
|
---|
158 | FITSTOIReader rfitsb(fitsin_bolo);
|
---|
159 | int ncolb = rfitsb.getNOut();
|
---|
160 | cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
|
---|
161 | if(ncolb<1) exit(-4);
|
---|
162 |
|
---|
163 | FITSTOIReader rfitsp(fitsin_point);
|
---|
164 | int ncolp = rfitsp.getNOut();
|
---|
165 | cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
|
---|
166 | if(ncolp<2) exit(-5);
|
---|
167 |
|
---|
168 | // Creation de la sphere Healpix
|
---|
169 | SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
|
---|
170 | cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
|
---|
171 | <<" Nombre de pixels : "<<sph->NbPixels()<<endl
|
---|
172 | <<" Nlat : "<<sph->SizeIndex()<<endl;
|
---|
173 |
|
---|
174 | // Creation de la sphere de poids Healpix
|
---|
175 | SphereHEALPix<r_8>* wsph = NULL;
|
---|
176 | if(fitsphwout.size()>0) {
|
---|
177 | wsph = new SphereHEALPix<r_8>;
|
---|
178 | cout<<"SphereHEALPix Weight Created"<<endl;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // TOI Processor
|
---|
182 | TOI2Map toi2m(sph,wsph);
|
---|
183 | cout<<"TOI2Map created"<<endl;
|
---|
184 | toi2m.SetEquinox(2000.);
|
---|
185 | toi2m.SetCoorIn((TypAstroCoord) tcoorin);
|
---|
186 | toi2m.SetCoorOut((TypAstroCoord) tcoorout);
|
---|
187 | toi2m.SetTestFlag(tflg,badflg);
|
---|
188 | toi2m.SetTestMin(tmin,vmin);
|
---|
189 | toi2m.SetTestMax(tmax,vmax);
|
---|
190 | toi2m.Print(cout);
|
---|
191 |
|
---|
192 | // Definition des tuyaux
|
---|
193 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
|
---|
194 | // toicoord1in->setDebugLevel(1);
|
---|
195 | rfitsp.addOutput(label_coord1,toicoord1in);
|
---|
196 | toi2m.addInput("Coord1In",toicoord1in);
|
---|
197 |
|
---|
198 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
|
---|
199 | // toicoord2in->setDebugLevel(1);
|
---|
200 | rfitsp.addOutput(label_coord2,toicoord2in);
|
---|
201 | toi2m.addInput("Coord2In",toicoord2in);
|
---|
202 |
|
---|
203 | TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
|
---|
204 | // toibolin->setDebugLevel(1);
|
---|
205 | rfitsb.addOutput(label_bolomuv,toibolin);
|
---|
206 | toi2m.addInput("BoloIn",toibolin);
|
---|
207 |
|
---|
208 | // Run
|
---|
209 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
|
---|
210 | rfitsp.PrintStatus(cout);
|
---|
211 | rfitsb.PrintStatus(cout);
|
---|
212 |
|
---|
213 | PrtTim("starting threads");
|
---|
214 | rfitsp.start();
|
---|
215 | rfitsb.start();
|
---|
216 | toi2m.start();
|
---|
217 |
|
---|
218 | if(lp>1)
|
---|
219 | for(int jjjj=0;jjjj<5;jjjj++) {
|
---|
220 | cout<<*toicoord1in;
|
---|
221 | cout<<*toibolin;
|
---|
222 | sleep(2);
|
---|
223 | }
|
---|
224 |
|
---|
225 | // Affichage de l'avancement des TOIProcessors
|
---|
226 | ProcSampleCounter<FITSTOIReader> stats(rfitsb);
|
---|
227 | stats.InfoMessage() = "tsttoi2map/Info";
|
---|
228 | stats.PrintStats();
|
---|
229 |
|
---|
230 | // Fin des traitements des TOIProcessors
|
---|
231 | mgr->joinAll();
|
---|
232 | PrtTim("End threads");
|
---|
233 |
|
---|
234 |
|
---|
235 | // Ecriture de la sphere Healpix sur fits
|
---|
236 | {
|
---|
237 | FitsOutFile sfits(fitsphout,FitsFile::clear);
|
---|
238 | cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
|
---|
239 | sfits << *sph;
|
---|
240 | }
|
---|
241 |
|
---|
242 | // Ecriture de la sphere Healpix sur fits
|
---|
243 | if(wsph) {
|
---|
244 | FitsOutFile swfits(fitsphwout,FitsFile::clear);
|
---|
245 | cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
|
---|
246 | swfits << *wsph;
|
---|
247 | }
|
---|
248 |
|
---|
249 | // Nettoyage
|
---|
250 | cout << "tsttoi2map: cleanup " << endl;
|
---|
251 | delete sph;
|
---|
252 | if(wsph) delete wsph;
|
---|
253 | cout << "tsttoi2map: ----------- End of job -------------- " << endl;
|
---|
254 |
|
---|
255 | //--------------------------------------------------------------------
|
---|
256 | } catch (PThrowable & exc) {
|
---|
257 | cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
|
---|
258 | <<" - Msg= "<<exc.Msg()<<endl;
|
---|
259 | } catch (const std::exception & sex) {
|
---|
260 | cout<<"\ntsttoi2map: Catched std::exception \n"
|
---|
261 | <<(string)typeid(sex).name()<<endl;
|
---|
262 | } catch (...) {
|
---|
263 | cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
|
---|
264 | }
|
---|
265 | //--------------------------------------------------------------------
|
---|
266 |
|
---|
267 | exit(0);
|
---|
268 | }
|
---|