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

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

Correction decodage sepFlagfile ds tsttoi2map.cc - Reza 18/6/2002

File size: 9.9 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] [-F sepFlagFileName]"<<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 <<" -c calibcoeff : Coefficient de calibration a appliquer (def=1.)"<<endl
47 <<" -I : sampleNum are implicit in fits files (def=no)"<<endl
48 <<" -F sepFlagFileName : separate flag file name for levelS"<<endl
49 <<" (FlagColName: Glitch PtSrc)"<<endl
50 <<" fitsin_point : fits file for pointing"<<endl
51 <<" fitsin_bolo : fits file for bolo values"<<endl
52 <<" fitsphout : fits file for output Healpix sphere"<<endl
53 <<" fitsphwout : fits file for output Healpix nFilled sphere (def=no)"<<endl;
54}
55
56////////////////////////////////////////////////////////////////
57int main(int narg, char** arg) {
58
59TOIManager* mgr = TOIManager::getManager();
60
61//-- Decodage arguments
62int lp = 0, width = 8192;
63int nlat = 128; // npixel = 12 * nlat^2
64bool tflg=false, tmin=false, tmax=false;
65r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
66char *label_coord1 = "coord1", *label_coord2 = "coord2"
67 , *label_bolomuv = "boloMuV";
68double equi=2000.;
69char *tcoorin="gdcdl", *tcoormap="g";
70string fitsphwout = "";
71long sdeb,sfin;
72bool snimplicit = false;
73bool fgprstat = true;
74int nbpointfiles = 0;
75double coeffcalib = 1.;
76string sepflagfile; // Fichier de flag separe / Level2 / Reza 18/6/2002
77bool sepflg = false; // " " " " " " "
78
79int c;
80while((c = getopt(narg,arg,"hIp:s:w:a:d:b:n:i:o:m:M:f:e:N:c:F:")) != -1) {
81 switch (c) {
82 case 's' :
83 sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
84 cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
85 if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
86 //else {cout<<"Bad sample interval "<<endl; exit(2);}
87 break;
88 case 'w' :
89 sscanf(optarg,"%d",&width);
90 if(width<=0) width=8192;
91 cout<<"Data window size "<<width<<endl;
92 break;
93 case 'p' :
94 sscanf(optarg,"%d",&lp);
95 if(lp<0) lp=0;
96 break;
97 case 'a' :
98 label_coord1 = optarg;
99 break;
100 case 'd' :
101 label_coord2 = optarg;
102 break;
103 case 'b' :
104 label_bolomuv = optarg;
105 break;
106 case 'n' :
107 sscanf(optarg,"%d",&nlat);
108 if(nlat<0) nlat=128;
109 break;
110 case 'i' :
111 tcoorin=optarg;
112 break;
113 case 'o' :
114 tcoormap=optarg;
115 break;
116 case 'e' :
117 sscanf(optarg,"%lf",&equi);
118 break;
119 case 'm' :
120 sscanf(optarg,"%lf",&vmin);
121 tmin = true;
122 break;
123 case 'M' :
124 sscanf(optarg,"%lf",&vmax);
125 tmax = true;
126 break;
127 case 'f' :
128 sscanf(optarg,"%ul",&badflg);
129 tflg = true;
130 break;
131 case 'N' :
132 nbpointfiles = atoi(optarg);
133 break;
134 case 'c' :
135 coeffcalib = atof(optarg);
136 break;
137 case 'I' :
138 snimplicit = true;
139 break;
140 case 'F' :
141 sepflagfile = optarg;
142 sepflg = true;
143 break;
144 case 'h' :
145 default:
146 usage(); exit(1);
147 break;
148 }
149}
150if(optind+2>=narg) {usage(); exit(3);}
151
152char * fitsin_point = arg[optind];
153char * fitsin_bolo = arg[optind+1];
154string const fitsphout = arg[optind+2];
155if(optind+3<narg) fitsphwout = arg[optind+3];
156
157cout<<">>>> tsttoi2map:"<<endl
158 <<"Pipe Window Size "<<width<<endl
159 <<"Fits Infile Bolo "<<fitsin_bolo<<endl
160 <<" ...label_bolomuv "<<label_bolomuv<<endl;
161cout<<"Fits Infile Pointing "<<fitsin_point<<" NbFiles=" <<nbpointfiles<<endl
162 <<" ...label_coord1 "<<label_coord1<<endl
163 <<" ...label_coord2 "<<label_coord2<<endl
164 <<" ...... ctype="<<tcoorin<<endl;
165cout<<"Fits Healpix Sphere "<<fitsphout<<endl
166 <<" ...nlat "<<nlat<<endl;
167cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl
168 <<" ...... ctype="<<tcoormap<<endl;
169cout<<"Equinoxe "<<equi<<" years"<<endl;
170cout<<"CoeffCalib "<<coeffcalib<<endl;
171
172SophyaInit();
173InitTim();
174
175//--------------------------------------------------------------------
176try {
177//--------------------------------------------------------------------
178
179
180 // FITS reader
181 FITSTOIReader rfitsb(fitsin_bolo);
182 if(snimplicit) rfitsb.setImplicitSN();
183 int ncolb = rfitsb.getNOut();
184 cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
185 if(ncolb<1) exit(-4);
186
187 if (sepflg) {
188 cout << " Setting separate flag file for InTOI_bolo File=" << sepflagfile
189 << " (Flags=FlgToiSpike, FlgToiSource)" << endl;
190 vector<FlagToiDef> flgcol;
191 flgcol.push_back(FlgToiSpike);
192 flgcol.push_back(FlgToiSource);
193 rfitsb.setFlagFile(sepflagfile, flgcol);
194 }
195 string pointfileI = fitsin_point;
196 MuTyV numf=0;
197 if(nbpointfiles > 0)
198 pointfileI += (string)numf + ".fits";
199 cout << " Creating FITSTOIReader for pointing file " << pointfileI << endl;
200 FITSTOIReader rfitsp(pointfileI);
201 if(nbpointfiles > 0)
202 for(int kff=1; kff<nbpointfiles; kff++) {
203 numf=kff;
204 pointfileI = fitsin_point;
205 pointfileI += (string)numf + ".fits";
206 cout << " pointing FITSTOIReader.addFile( " << pointfileI << " )" << endl;
207 rfitsp.addFile( pointfileI );
208 }
209
210 if(snimplicit) rfitsp.setImplicitSN();
211 int ncolp = rfitsp.getNOut();
212 cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
213 if(ncolp<2) exit(-5);
214
215 // Creation de la sphere Healpix
216 SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
217 cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
218 <<" Nombre de pixels : "<<sph->NbPixels()<<endl
219 <<" Nlat : "<<sph->SizeIndex()<<endl;
220
221 // Creation de la sphere de poids Healpix
222 SphereHEALPix<r_8>* wsph = NULL;
223 if(fitsphwout.size()>0) {
224 wsph = new SphereHEALPix<r_8>;
225 cout<<"SphereHEALPix Weight Created"<<endl;
226 }
227
228 // TOI Processor
229 TOI2Map toi2m(sph,wsph);
230 cout<<"TOI2Map created"<<endl;
231 toi2m.SetEquinox(equi);
232 toi2m.SetCoorIn(tcoorin);
233 toi2m.SetCoorMap(tcoormap);
234 toi2m.SetTestFlag(tflg,badflg);
235 toi2m.SetTestMin(tmin,vmin);
236 toi2m.SetTestMax(tmax,vmax);
237 toi2m.SetCalibrationFactor(coeffcalib);
238 toi2m.Print(cout);
239
240 // Definition des tuyaux
241#ifdef TOISEQBUFFERED
242 cout<<">>>> Using TOISeqBuffered"<<endl;
243 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
244#else
245 cout<<">>>> Using TOISegmented"<<endl;
246 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
247#endif
248 // toicoord1in->setDebugLevel(1);
249 rfitsp.addOutput(label_coord1,toicoord1in);
250 toi2m.addInput("Coord1In",toicoord1in);
251
252#ifdef TOISEQBUFFERED
253 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
254#else
255 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
256#endif
257 // toicoord2in->setDebugLevel(1);
258 rfitsp.addOutput(label_coord2,toicoord2in);
259 toi2m.addInput("Coord2In",toicoord2in);
260
261#ifdef TOISEQBUFFERED
262 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
263#else
264 TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
265#endif
266 // toibolin->setDebugLevel(1);
267 rfitsb.addOutput(label_bolomuv,toibolin);
268 toi2m.addInput("BoloIn",toibolin);
269
270 // Run
271 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
272 rfitsp.PrintStatus(cout);
273 rfitsb.PrintStatus(cout);
274
275 PrtTim("starting threads");
276 rfitsp.start();
277 rfitsb.start();
278 toi2m.start();
279
280 // if(lp>1)
281 // for(int jjjj=0;jjjj<5;jjjj++) {
282 // cout<<*toicoord1in;
283 // cout<<*toibolin;
284 // sleep(2);
285 // }
286
287 // Affichage de l'avancement des TOIProcessors
288 ProcSampleCounter<TOI2Map> stats(toi2m);
289 stats.InfoMessage() = "tsttoi2map/Info";
290 stats.PrintStats();
291
292 // Fin des traitements des TOIProcessors
293 mgr->joinAll();
294 PrtTim("End threads");
295
296
297 // Ecriture de la sphere Healpix sur fits
298 {
299 FitsOutFile sfits(fitsphout,FitsFile::clear);
300 cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
301 sfits << *sph;
302 }
303
304 // Ecriture de la sphere Healpix sur fits
305 if(wsph) {
306 FitsOutFile swfits(fitsphwout,FitsFile::clear);
307 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
308 swfits << *wsph;
309 }
310
311 // Nettoyage
312 cout << "tsttoi2map: cleanup " << endl;
313 delete sph;
314 if(wsph) delete wsph;
315 cout << "tsttoi2map: ----------- End of job -------------- " << endl;
316
317//--------------------------------------------------------------------
318} catch (PThrowable & exc) {
319 cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
320 <<" - Msg= "<<exc.Msg()<<endl;
321} catch (const std::exception & sex) {
322 cout<<"\ntsttoi2map: Catched std::exception \n"
323 <<(string)typeid(sex).name()<<endl;
324} catch (...) {
325 cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
326}
327//--------------------------------------------------------------------
328
329exit(0);
330}
Note: See TracBrowser for help on using the repository browser.