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

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

Ajout methode FITSTOIReader::setFlagFile() pour fichiers flag separes
de Level2 - 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
188 sepflagfile = optarg;
189 sepflg = true;
190 if (sepflg) {
191 cout << " Setting separate flag file for InTOI_bolo File=" << sepflagfile
192 << " (Flags=FlgToiSpike, FlgToiSource)" << endl;
193 vector<FlagToiDef> flgcol;
194 flgcol.push_back(FlgToiSpike);
195 flgcol.push_back(FlgToiSource);
196 rfitsb.setFlagFile(sepflagfile, flgcol);
197 }
[2050]198 string pointfileI = fitsin_point;
199 MuTyV numf=0;
200 if(nbpointfiles > 0)
201 pointfileI += (string)numf + ".fits";
202 cout << " Creating FITSTOIReader for pointing file " << pointfileI << endl;
203 FITSTOIReader rfitsp(pointfileI);
204 if(nbpointfiles > 0)
205 for(int kff=1; kff<nbpointfiles; kff++) {
206 numf=kff;
207 pointfileI = fitsin_point;
208 pointfileI += (string)numf + ".fits";
209 cout << " pointing FITSTOIReader.addFile( " << pointfileI << " )" << endl;
210 rfitsp.addFile( pointfileI );
211 }
212
[1810]213 if(snimplicit) rfitsp.setImplicitSN();
[1498]214 int ncolp = rfitsp.getNOut();
215 cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
[1516]216 if(ncolp<2) exit(-5);
[1498]217
[1463]218 // Creation de la sphere Healpix
219 SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
220 cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
[1530]221 <<" Nombre de pixels : "<<sph->NbPixels()<<endl
222 <<" Nlat : "<<sph->SizeIndex()<<endl;
[1463]223
224 // Creation de la sphere de poids Healpix
225 SphereHEALPix<r_8>* wsph = NULL;
226 if(fitsphwout.size()>0) {
227 wsph = new SphereHEALPix<r_8>;
[1530]228 cout<<"SphereHEALPix Weight Created"<<endl;
[1463]229 }
230
231 // TOI Processor
232 TOI2Map toi2m(sph,wsph);
233 cout<<"TOI2Map created"<<endl;
[1809]234 toi2m.SetEquinox(equi);
235 toi2m.SetCoorIn(tcoorin);
236 toi2m.SetCoorMap(tcoormap);
[1530]237 toi2m.SetTestFlag(tflg,badflg);
238 toi2m.SetTestMin(tmin,vmin);
239 toi2m.SetTestMax(tmax,vmax);
[2058]240 toi2m.SetCalibrationFactor(coeffcalib);
[1530]241 toi2m.Print(cout);
[1463]242
243 // Definition des tuyaux
[1723]244#ifdef TOISEQBUFFERED
245 cout<<">>>> Using TOISeqBuffered"<<endl;
[1498]246 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
[1723]247#else
248 cout<<">>>> Using TOISegmented"<<endl;
249 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
250#endif
[1516]251 // toicoord1in->setDebugLevel(1);
[1498]252 rfitsp.addOutput(label_coord1,toicoord1in);
253 toi2m.addInput("Coord1In",toicoord1in);
[1463]254
[1723]255#ifdef TOISEQBUFFERED
[1498]256 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
[1723]257#else
258 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
259#endif
[1516]260 // toicoord2in->setDebugLevel(1);
[1498]261 rfitsp.addOutput(label_coord2,toicoord2in);
262 toi2m.addInput("Coord2In",toicoord2in);
263
[1723]264#ifdef TOISEQBUFFERED
[1463]265 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
[1723]266#else
267 TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
268#endif
[1516]269 // toibolin->setDebugLevel(1);
[1498]270 rfitsb.addOutput(label_bolomuv,toibolin);
[1463]271 toi2m.addInput("BoloIn",toibolin);
272
273 // Run
274 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
[1498]275 rfitsp.PrintStatus(cout);
276 rfitsb.PrintStatus(cout);
[1463]277
278 PrtTim("starting threads");
[1498]279 rfitsp.start();
280 rfitsb.start();
[1463]281 toi2m.start();
282
[1723]283 // if(lp>1)
284 // for(int jjjj=0;jjjj<5;jjjj++) {
285 // cout<<*toicoord1in;
286 // cout<<*toibolin;
287 // sleep(2);
288 // }
[1463]289
[2012]290 // Affichage de l'avancement des TOIProcessors
291 ProcSampleCounter<TOI2Map> stats(toi2m);
292 stats.InfoMessage() = "tsttoi2map/Info";
293 stats.PrintStats();
[1629]294
295 // Fin des traitements des TOIProcessors
[1463]296 mgr->joinAll();
297 PrtTim("End threads");
298
[1629]299
[1463]300 // Ecriture de la sphere Healpix sur fits
301 {
[1633]302 FitsOutFile sfits(fitsphout,FitsFile::clear);
[1463]303 cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
304 sfits << *sph;
305 }
306
307 // Ecriture de la sphere Healpix sur fits
308 if(wsph) {
[1633]309 FitsOutFile swfits(fitsphwout,FitsFile::clear);
[1463]310 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
311 swfits << *wsph;
312 }
313
314 // Nettoyage
[1629]315 cout << "tsttoi2map: cleanup " << endl;
[1463]316 delete sph;
317 if(wsph) delete wsph;
[1629]318 cout << "tsttoi2map: ----------- End of job -------------- " << endl;
[1463]319
320//--------------------------------------------------------------------
321} catch (PThrowable & exc) {
322 cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
323 <<" - Msg= "<<exc.Msg()<<endl;
324} catch (const std::exception & sex) {
325 cout<<"\ntsttoi2map: Catched std::exception \n"
326 <<(string)typeid(sex).name()<<endl;
327} catch (...) {
328 cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
329}
330//--------------------------------------------------------------------
331
332exit(0);
333}
Note: See TracBrowser for help on using the repository browser.