source: Sophya/trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc@ 2050

Last change on this file since 2050 was 2050, checked in by ansari, 23 years ago

Modifs lecture multiple fichiers de pointage - Reza 10/6/2002

File size: 9.0 KB
Line 
1//#define TOISEQBUFFERED
2
3#include <unistd.h>
4#include <stdlib.h>
5#include <stdio.h>
6#include "toi.h"
7#include "toiprocessor.h"
8#include "fitstoirdr.h"
9#include "fitstoiwtr.h"
10#include "toimanager.h"
11#ifdef TOISEQBUFFERED
12#include "toiseqbuff.h"
13#else
14#include "toisegment.h"
15#endif
16
17#include "sambainit.h"
18#include "toi2map.h"
19#include "fitsspherehealpix.h"
20#include "timing.h"
21
22#include <stdexcept>
23
24void usage(void);
25void usage(void) {
26 cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
27 <<" [-a label_coord1] [-d label_coord2] [-b label_bolomuv]"<<endl
28 <<" [-n nlat] [-i c,h] [-o c,h]"<<endl
29 <<" [-m vmin] [-M vmax] [-f flag]"<<endl
30 <<" fitsin_point fitsin_bolo fitsphout [fitsphwout]"<<endl
31 <<" -p lp : print level (def=0)"<<endl
32 <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
33 <<" -w data_window_size : window size for pipe (def=8192)"<<endl
34 <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
35 <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
36 <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
37 <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
38 <<" -n nlat : nlat for Healpix sphere (def=128)"<<endl
39 <<" -i cin : coordIn caracteristics (def=\"gdcdl\")"<<endl
40 <<" -o cmap : idem -i for coordMap (def=\"g\")"<<endl
41 <<" -e equi : equinoxe en annee (def=2000.)"<<endl
42 <<" -m vmin : samples are good if sample value >= vmin"<<endl
43 <<" -M vmax : samples are good if sample value <= vmax"<<endl
44 <<" -f flag : samples are bad if match flag"<<endl
45 <<" -N nbfiles : Number of fitsin_point files fitsin_point%d.fits 0..nb-1"<<endl
46 <<" -I : sampleNum are implicit in fits files (def=no)"<<endl
47 <<" fitsin_point : fits file for pointing"<<endl
48 <<" fitsin_bolo : fits file for bolo values"<<endl
49 <<" fitsphout : fits file for output Healpix sphere"<<endl
50 <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
51}
52
53////////////////////////////////////////////////////////////////
54int main(int narg, char** arg) {
55
56TOIManager* mgr = TOIManager::getManager();
57
58//-- Decodage arguments
59int lp = 0, width = 8192;
60int nlat = 128; // npixel = 12 * nlat^2
61bool tflg=false, tmin=false, tmax=false;
62r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
63char *label_coord1 = "coord1", *label_coord2 = "coord2"
64 , *label_bolomuv = "boloMuV";
65double equi=2000.;
66char *tcoorin="gdcdl", *tcoormap="g";
67string fitsphwout = "";
68long sdeb,sfin;
69bool snimplicit = false;
70bool fgprstat = true;
71int nbpointfiles = 0;
72int c;
73while((c = getopt(narg,arg,"hIp:s:w:a:d:b:n:i:o:m:M:f:e:N:")) != -1) {
74 switch (c) {
75 case 's' :
76 sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
77 cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
78 if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
79 //else {cout<<"Bad sample interval "<<endl; exit(2);}
80 break;
81 case 'w' :
82 sscanf(optarg,"%d",&width);
83 if(width<=0) width=8192;
84 cout<<"Data window size "<<width<<endl;
85 break;
86 case 'p' :
87 sscanf(optarg,"%d",&lp);
88 if(lp<0) lp=0;
89 break;
90 case 'a' :
91 label_coord1 = optarg;
92 break;
93 case 'd' :
94 label_coord2 = optarg;
95 break;
96 case 'b' :
97 label_bolomuv = optarg;
98 break;
99 case 'n' :
100 sscanf(optarg,"%d",&nlat);
101 if(nlat<0) nlat=128;
102 break;
103 case 'i' :
104 tcoorin=optarg;
105 break;
106 case 'o' :
107 tcoormap=optarg;
108 break;
109 case 'e' :
110 sscanf(optarg,"%lf",&equi);
111 break;
112 case 'm' :
113 sscanf(optarg,"%lf",&vmin);
114 tmin = true;
115 break;
116 case 'M' :
117 sscanf(optarg,"%lf",&vmax);
118 tmax = true;
119 break;
120 case 'f' :
121 sscanf(optarg,"%ul",&badflg);
122 tflg = true;
123 break;
124 case 'N' :
125 nbpointfiles = atoi(optarg);
126 break;
127 case 'I' :
128 snimplicit = true;
129 break;
130 case 'h' :
131 default:
132 usage(); exit(1);
133 break;
134 }
135}
136if(optind+2>=narg) {usage(); exit(3);}
137
138char * fitsin_point = arg[optind];
139char * fitsin_bolo = arg[optind+1];
140string const fitsphout = arg[optind+2];
141if(optind+3<narg) fitsphwout = arg[optind+3];
142
143cout<<">>>> tsttoi2map:"<<endl
144 <<"Pipe Window Size "<<width<<endl
145 <<"Fits Infile Bolo "<<fitsin_bolo<<endl
146 <<" ...label_bolomuv "<<label_bolomuv<<endl;
147cout<<"Fits Infile Pointing "<<fitsin_point<<" NbFiles=" <<nbpointfiles<<endl
148 <<" ...label_coord1 "<<label_coord1<<endl
149 <<" ...label_coord2 "<<label_coord2<<endl
150 <<" ...... ctype="<<tcoorin<<endl;
151cout<<"Fits Healpix Sphere "<<fitsphout<<endl
152 <<" ...nlat "<<nlat<<endl;
153cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl
154 <<" ...... ctype="<<tcoormap<<endl;
155cout<<"Equinoxe "<<equi<<" years"<<endl;
156
157SophyaInit();
158InitTim();
159
160//--------------------------------------------------------------------
161try {
162//--------------------------------------------------------------------
163
164
165 // FITS reader
166 FITSTOIReader rfitsb(fitsin_bolo);
167 if(snimplicit) rfitsb.setImplicitSN();
168 int ncolb = rfitsb.getNOut();
169 cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
170 if(ncolb<1) exit(-4);
171
172 string pointfileI = fitsin_point;
173 MuTyV numf=0;
174 if(nbpointfiles > 0)
175 pointfileI += (string)numf + ".fits";
176 cout << " Creating FITSTOIReader for pointing file " << pointfileI << endl;
177 FITSTOIReader rfitsp(pointfileI);
178 if(nbpointfiles > 0)
179 for(int kff=1; kff<nbpointfiles; kff++) {
180 numf=kff;
181 pointfileI = fitsin_point;
182 pointfileI += (string)numf + ".fits";
183 cout << " pointing FITSTOIReader.addFile( " << pointfileI << " )" << endl;
184 rfitsp.addFile( pointfileI );
185 }
186
187 if(snimplicit) rfitsp.setImplicitSN();
188 int ncolp = rfitsp.getNOut();
189 cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
190 if(ncolp<2) exit(-5);
191
192 // Creation de la sphere Healpix
193 SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
194 cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
195 <<" Nombre de pixels : "<<sph->NbPixels()<<endl
196 <<" Nlat : "<<sph->SizeIndex()<<endl;
197
198 // Creation de la sphere de poids Healpix
199 SphereHEALPix<r_8>* wsph = NULL;
200 if(fitsphwout.size()>0) {
201 wsph = new SphereHEALPix<r_8>;
202 cout<<"SphereHEALPix Weight Created"<<endl;
203 }
204
205 // TOI Processor
206 TOI2Map toi2m(sph,wsph);
207 cout<<"TOI2Map created"<<endl;
208 toi2m.SetEquinox(equi);
209 toi2m.SetCoorIn(tcoorin);
210 toi2m.SetCoorMap(tcoormap);
211 toi2m.SetTestFlag(tflg,badflg);
212 toi2m.SetTestMin(tmin,vmin);
213 toi2m.SetTestMax(tmax,vmax);
214 toi2m.Print(cout);
215
216 // Definition des tuyaux
217#ifdef TOISEQBUFFERED
218 cout<<">>>> Using TOISeqBuffered"<<endl;
219 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
220#else
221 cout<<">>>> Using TOISegmented"<<endl;
222 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
223#endif
224 // toicoord1in->setDebugLevel(1);
225 rfitsp.addOutput(label_coord1,toicoord1in);
226 toi2m.addInput("Coord1In",toicoord1in);
227
228#ifdef TOISEQBUFFERED
229 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
230#else
231 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
232#endif
233 // toicoord2in->setDebugLevel(1);
234 rfitsp.addOutput(label_coord2,toicoord2in);
235 toi2m.addInput("Coord2In",toicoord2in);
236
237#ifdef TOISEQBUFFERED
238 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
239#else
240 TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
241#endif
242 // toibolin->setDebugLevel(1);
243 rfitsb.addOutput(label_bolomuv,toibolin);
244 toi2m.addInput("BoloIn",toibolin);
245
246 // Run
247 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
248 rfitsp.PrintStatus(cout);
249 rfitsb.PrintStatus(cout);
250
251 PrtTim("starting threads");
252 rfitsp.start();
253 rfitsb.start();
254 toi2m.start();
255
256 // if(lp>1)
257 // for(int jjjj=0;jjjj<5;jjjj++) {
258 // cout<<*toicoord1in;
259 // cout<<*toibolin;
260 // sleep(2);
261 // }
262
263 // Affichage de l'avancement des TOIProcessors
264 ProcSampleCounter<TOI2Map> stats(toi2m);
265 stats.InfoMessage() = "tsttoi2map/Info";
266 stats.PrintStats();
267
268 // Fin des traitements des TOIProcessors
269 mgr->joinAll();
270 PrtTim("End threads");
271
272
273 // Ecriture de la sphere Healpix sur fits
274 {
275 FitsOutFile sfits(fitsphout,FitsFile::clear);
276 cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
277 sfits << *sph;
278 }
279
280 // Ecriture de la sphere Healpix sur fits
281 if(wsph) {
282 FitsOutFile swfits(fitsphwout,FitsFile::clear);
283 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
284 swfits << *wsph;
285 }
286
287 // Nettoyage
288 cout << "tsttoi2map: cleanup " << endl;
289 delete sph;
290 if(wsph) delete wsph;
291 cout << "tsttoi2map: ----------- End of job -------------- " << endl;
292
293//--------------------------------------------------------------------
294} catch (PThrowable & exc) {
295 cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
296 <<" - Msg= "<<exc.Msg()<<endl;
297} catch (const std::exception & sex) {
298 cout<<"\ntsttoi2map: Catched std::exception \n"
299 <<(string)typeid(sex).name()<<endl;
300} catch (...) {
301 cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
302}
303//--------------------------------------------------------------------
304
305exit(0);
306}
Note: See TracBrowser for help on using the repository browser.