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

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

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

File size: 9.9 KB
RevLine 
[1723]1//#define TOISEQBUFFERED
2
[1463]3#include <unistd.h>
[1498]4#include <stdlib.h>
5#include <stdio.h>
[1463]6#include "toi.h"
7#include "toiprocessor.h"
8#include "fitstoirdr.h"
9#include "fitstoiwtr.h"
10#include "toimanager.h"
[1723]11#ifdef TOISEQBUFFERED
[1463]12#include "toiseqbuff.h"
[1723]13#else
14#include "toisegment.h"
15#endif
[1463]16
17#include "sambainit.h"
18#include "toi2map.h"
[1723]19#include "fitsspherehealpix.h"
[1463]20#include "timing.h"
21
[1760]22#include <stdexcept>
23
[1463]24void usage(void);
25void usage(void) {
26 cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
[1498]27 <<" [-a label_coord1] [-d label_coord2] [-b label_bolomuv]"<<endl
[1516]28 <<" [-n nlat] [-i c,h] [-o c,h]"<<endl
[2058]29 <<" [-m vmin] [-M vmax] [-f flag] [-F sepFlagFileName]"<<endl
[1516]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
[1809]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
[1530]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
[2050]45 <<" -N nbfiles : Number of fitsin_point files fitsin_point%d.fits 0..nb-1"<<endl
[2058]46 <<" -c calibcoeff : Coefficient de calibration a appliquer (def=1.)"<<endl
[1810]47 <<" -I : sampleNum are implicit in fits files (def=no)"<<endl
[2058]48 <<" -F sepFlagFileName : separate flag file name for levelS"<<endl
49 <<" (FlagColName: Glitch PtSrc)"<<endl
[1516]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;
[1463]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
[1530]64bool tflg=false, tmin=false, tmax=false;
[1536]65r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
[1530]66char *label_coord1 = "coord1", *label_coord2 = "coord2"
67 , *label_bolomuv = "boloMuV";
[1809]68double equi=2000.;
69char *tcoorin="gdcdl", *tcoormap="g";
70string fitsphwout = "";
[1463]71long sdeb,sfin;
[1810]72bool snimplicit = false;
[2050]73bool fgprstat = true;
74int nbpointfiles = 0;
[2058]75double coeffcalib = 1.;
76string sepflagfile; // Fichier de flag separe / Level2 / Reza 18/6/2002
77bool sepflg = false; // " " " " " " "
78
[1809]79int c;
[2058]80while((c = getopt(narg,arg,"hIp:s:w:a:d:b:n:i:o:m:M:f:e:N:c:F:")) != -1) {
[1463]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);
[1739]86 //else {cout<<"Bad sample interval "<<endl; exit(2);}
[1463]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' :
[1498]98 label_coord1 = optarg;
[1463]99 break;
100 case 'd' :
[1498]101 label_coord2 = optarg;
[1463]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;
[1516]110 case 'i' :
[1809]111 tcoorin=optarg;
[1516]112 break;
113 case 'o' :
[1809]114 tcoormap=optarg;
[1516]115 break;
[1809]116 case 'e' :
117 sscanf(optarg,"%lf",&equi);
118 break;
[1530]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' :
[1537]128 sscanf(optarg,"%ul",&badflg);
[1530]129 tflg = true;
130 break;
[2050]131 case 'N' :
132 nbpointfiles = atoi(optarg);
133 break;
[2058]134 case 'c' :
135 coeffcalib = atof(optarg);
136 break;
[1810]137 case 'I' :
138 snimplicit = true;
139 break;
[2058]140 case 'F' :
141 sepflagfile = optarg;
142 sepflg = true;
143 break;
[1463]144 case 'h' :
[1516]145 default:
146 usage(); exit(1);
[1463]147 break;
148 }
149}
[1516]150if(optind+2>=narg) {usage(); exit(3);}
[1498]151
[1516]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];
[1463]156
157cout<<">>>> tsttoi2map:"<<endl
[1516]158 <<"Pipe Window Size "<<width<<endl
159 <<"Fits Infile Bolo "<<fitsin_bolo<<endl
160 <<" ...label_bolomuv "<<label_bolomuv<<endl;
[2050]161cout<<"Fits Infile Pointing "<<fitsin_point<<" NbFiles=" <<nbpointfiles<<endl
[1520]162 <<" ...label_coord1 "<<label_coord1<<endl
[1809]163 <<" ...label_coord2 "<<label_coord2<<endl
164 <<" ...... ctype="<<tcoorin<<endl;
[1516]165cout<<"Fits Healpix Sphere "<<fitsphout<<endl
[1530]166 <<" ...nlat "<<nlat<<endl;
[1809]167cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl
168 <<" ...... ctype="<<tcoormap<<endl;
169cout<<"Equinoxe "<<equi<<" years"<<endl;
[2058]170cout<<"CoeffCalib "<<coeffcalib<<endl;
171
[1463]172SophyaInit();
173InitTim();
174
175//--------------------------------------------------------------------
176try {
177//--------------------------------------------------------------------
178
[1629]179
[1463]180 // FITS reader
[1498]181 FITSTOIReader rfitsb(fitsin_bolo);
[1810]182 if(snimplicit) rfitsb.setImplicitSN();
[1498]183 int ncolb = rfitsb.getNOut();
184 cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
[1516]185 if(ncolb<1) exit(-4);
[1463]186
[2058]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 }
[2050]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
[1810]210 if(snimplicit) rfitsp.setImplicitSN();
[1498]211 int ncolp = rfitsp.getNOut();
212 cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
[1516]213 if(ncolp<2) exit(-5);
[1498]214
[1463]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
[1530]218 <<" Nombre de pixels : "<<sph->NbPixels()<<endl
219 <<" Nlat : "<<sph->SizeIndex()<<endl;
[1463]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>;
[1530]225 cout<<"SphereHEALPix Weight Created"<<endl;
[1463]226 }
227
228 // TOI Processor
229 TOI2Map toi2m(sph,wsph);
230 cout<<"TOI2Map created"<<endl;
[1809]231 toi2m.SetEquinox(equi);
232 toi2m.SetCoorIn(tcoorin);
233 toi2m.SetCoorMap(tcoormap);
[1530]234 toi2m.SetTestFlag(tflg,badflg);
235 toi2m.SetTestMin(tmin,vmin);
236 toi2m.SetTestMax(tmax,vmax);
[2058]237 toi2m.SetCalibrationFactor(coeffcalib);
[1530]238 toi2m.Print(cout);
[1463]239
240 // Definition des tuyaux
[1723]241#ifdef TOISEQBUFFERED
242 cout<<">>>> Using TOISeqBuffered"<<endl;
[1498]243 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
[1723]244#else
245 cout<<">>>> Using TOISegmented"<<endl;
246 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
247#endif
[1516]248 // toicoord1in->setDebugLevel(1);
[1498]249 rfitsp.addOutput(label_coord1,toicoord1in);
250 toi2m.addInput("Coord1In",toicoord1in);
[1463]251
[1723]252#ifdef TOISEQBUFFERED
[1498]253 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
[1723]254#else
255 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
256#endif
[1516]257 // toicoord2in->setDebugLevel(1);
[1498]258 rfitsp.addOutput(label_coord2,toicoord2in);
259 toi2m.addInput("Coord2In",toicoord2in);
260
[1723]261#ifdef TOISEQBUFFERED
[1463]262 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
[1723]263#else
264 TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
265#endif
[1516]266 // toibolin->setDebugLevel(1);
[1498]267 rfitsb.addOutput(label_bolomuv,toibolin);
[1463]268 toi2m.addInput("BoloIn",toibolin);
269
270 // Run
271 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
[1498]272 rfitsp.PrintStatus(cout);
273 rfitsb.PrintStatus(cout);
[1463]274
275 PrtTim("starting threads");
[1498]276 rfitsp.start();
277 rfitsb.start();
[1463]278 toi2m.start();
279
[1723]280 // if(lp>1)
281 // for(int jjjj=0;jjjj<5;jjjj++) {
282 // cout<<*toicoord1in;
283 // cout<<*toibolin;
284 // sleep(2);
285 // }
[1463]286
[2012]287 // Affichage de l'avancement des TOIProcessors
288 ProcSampleCounter<TOI2Map> stats(toi2m);
289 stats.InfoMessage() = "tsttoi2map/Info";
290 stats.PrintStats();
[1629]291
292 // Fin des traitements des TOIProcessors
[1463]293 mgr->joinAll();
294 PrtTim("End threads");
295
[1629]296
[1463]297 // Ecriture de la sphere Healpix sur fits
298 {
[1633]299 FitsOutFile sfits(fitsphout,FitsFile::clear);
[1463]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) {
[1633]306 FitsOutFile swfits(fitsphwout,FitsFile::clear);
[1463]307 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
308 swfits << *wsph;
309 }
310
311 // Nettoyage
[1629]312 cout << "tsttoi2map: cleanup " << endl;
[1463]313 delete sph;
314 if(wsph) delete wsph;
[1629]315 cout << "tsttoi2map: ----------- End of job -------------- " << endl;
[1463]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.