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

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

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

File size: 9.0 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
[1530]29 <<" [-m vmin] [-M vmax] [-f flag]"<<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
[1810]46 <<" -I : sampleNum are implicit in fits files (def=no)"<<endl
[1516]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;
[1463]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
[1530]61bool tflg=false, tmin=false, tmax=false;
[1536]62r_8 vmin=-1.e30, vmax=1.e30; uint_8 badflg=0;
[1530]63char *label_coord1 = "coord1", *label_coord2 = "coord2"
64 , *label_bolomuv = "boloMuV";
[1809]65double equi=2000.;
66char *tcoorin="gdcdl", *tcoormap="g";
67string fitsphwout = "";
[1463]68long sdeb,sfin;
[1810]69bool snimplicit = false;
[2050]70bool fgprstat = true;
71int nbpointfiles = 0;
[1809]72int c;
[2050]73while((c = getopt(narg,arg,"hIp:s:w:a:d:b:n:i:o:m:M:f:e:N:")) != -1) {
[1463]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);
[1739]79 //else {cout<<"Bad sample interval "<<endl; exit(2);}
[1463]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' :
[1498]91 label_coord1 = optarg;
[1463]92 break;
93 case 'd' :
[1498]94 label_coord2 = optarg;
[1463]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;
[1516]103 case 'i' :
[1809]104 tcoorin=optarg;
[1516]105 break;
106 case 'o' :
[1809]107 tcoormap=optarg;
[1516]108 break;
[1809]109 case 'e' :
110 sscanf(optarg,"%lf",&equi);
111 break;
[1530]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' :
[1537]121 sscanf(optarg,"%ul",&badflg);
[1530]122 tflg = true;
123 break;
[2050]124 case 'N' :
125 nbpointfiles = atoi(optarg);
126 break;
[1810]127 case 'I' :
128 snimplicit = true;
129 break;
[1463]130 case 'h' :
[1516]131 default:
132 usage(); exit(1);
[1463]133 break;
134 }
135}
[1516]136if(optind+2>=narg) {usage(); exit(3);}
[1498]137
[1516]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];
[1463]142
143cout<<">>>> tsttoi2map:"<<endl
[1516]144 <<"Pipe Window Size "<<width<<endl
145 <<"Fits Infile Bolo "<<fitsin_bolo<<endl
146 <<" ...label_bolomuv "<<label_bolomuv<<endl;
[2050]147cout<<"Fits Infile Pointing "<<fitsin_point<<" NbFiles=" <<nbpointfiles<<endl
[1520]148 <<" ...label_coord1 "<<label_coord1<<endl
[1809]149 <<" ...label_coord2 "<<label_coord2<<endl
150 <<" ...... ctype="<<tcoorin<<endl;
[1516]151cout<<"Fits Healpix Sphere "<<fitsphout<<endl
[1530]152 <<" ...nlat "<<nlat<<endl;
[1809]153cout<<"Fits Healpix Weight Sphere "<<fitsphwout<<endl
154 <<" ...... ctype="<<tcoormap<<endl;
155cout<<"Equinoxe "<<equi<<" years"<<endl;
[1463]156
157SophyaInit();
158InitTim();
159
160//--------------------------------------------------------------------
161try {
162//--------------------------------------------------------------------
163
[1629]164
[1463]165 // FITS reader
[1498]166 FITSTOIReader rfitsb(fitsin_bolo);
[1810]167 if(snimplicit) rfitsb.setImplicitSN();
[1498]168 int ncolb = rfitsb.getNOut();
169 cout<<"Number of columns in fits Infile_bolo : "<<ncolb<<endl;
[1516]170 if(ncolb<1) exit(-4);
[1463]171
[2050]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
[1810]187 if(snimplicit) rfitsp.setImplicitSN();
[1498]188 int ncolp = rfitsp.getNOut();
189 cout<<"Number of columns in fits Infile_point : "<<ncolp<<endl;
[1516]190 if(ncolp<2) exit(-5);
[1498]191
[1463]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
[1530]195 <<" Nombre de pixels : "<<sph->NbPixels()<<endl
196 <<" Nlat : "<<sph->SizeIndex()<<endl;
[1463]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>;
[1530]202 cout<<"SphereHEALPix Weight Created"<<endl;
[1463]203 }
204
205 // TOI Processor
206 TOI2Map toi2m(sph,wsph);
207 cout<<"TOI2Map created"<<endl;
[1809]208 toi2m.SetEquinox(equi);
209 toi2m.SetCoorIn(tcoorin);
210 toi2m.SetCoorMap(tcoormap);
[1530]211 toi2m.SetTestFlag(tflg,badflg);
212 toi2m.SetTestMin(tmin,vmin);
213 toi2m.SetTestMax(tmax,vmax);
214 toi2m.Print(cout);
[1463]215
216 // Definition des tuyaux
[1723]217#ifdef TOISEQBUFFERED
218 cout<<">>>> Using TOISeqBuffered"<<endl;
[1498]219 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
[1723]220#else
221 cout<<">>>> Using TOISegmented"<<endl;
222 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
223#endif
[1516]224 // toicoord1in->setDebugLevel(1);
[1498]225 rfitsp.addOutput(label_coord1,toicoord1in);
226 toi2m.addInput("Coord1In",toicoord1in);
[1463]227
[1723]228#ifdef TOISEQBUFFERED
[1498]229 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
[1723]230#else
231 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
232#endif
[1516]233 // toicoord2in->setDebugLevel(1);
[1498]234 rfitsp.addOutput(label_coord2,toicoord2in);
235 toi2m.addInput("Coord2In",toicoord2in);
236
[1723]237#ifdef TOISEQBUFFERED
[1463]238 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
[1723]239#else
240 TOISegmented * toibolin = new TOISegmented("toi_bolo_in",width);
241#endif
[1516]242 // toibolin->setDebugLevel(1);
[1498]243 rfitsb.addOutput(label_bolomuv,toibolin);
[1463]244 toi2m.addInput("BoloIn",toibolin);
245
246 // Run
247 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
[1498]248 rfitsp.PrintStatus(cout);
249 rfitsb.PrintStatus(cout);
[1463]250
251 PrtTim("starting threads");
[1498]252 rfitsp.start();
253 rfitsb.start();
[1463]254 toi2m.start();
255
[1723]256 // if(lp>1)
257 // for(int jjjj=0;jjjj<5;jjjj++) {
258 // cout<<*toicoord1in;
259 // cout<<*toibolin;
260 // sleep(2);
261 // }
[1463]262
[2012]263 // Affichage de l'avancement des TOIProcessors
264 ProcSampleCounter<TOI2Map> stats(toi2m);
265 stats.InfoMessage() = "tsttoi2map/Info";
266 stats.PrintStats();
[1629]267
268 // Fin des traitements des TOIProcessors
[1463]269 mgr->joinAll();
270 PrtTim("End threads");
271
[1629]272
[1463]273 // Ecriture de la sphere Healpix sur fits
274 {
[1633]275 FitsOutFile sfits(fitsphout,FitsFile::clear);
[1463]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) {
[1633]282 FitsOutFile swfits(fitsphwout,FitsFile::clear);
[1463]283 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
284 swfits << *wsph;
285 }
286
287 // Nettoyage
[1629]288 cout << "tsttoi2map: cleanup " << endl;
[1463]289 delete sph;
290 if(wsph) delete wsph;
[1629]291 cout << "tsttoi2map: ----------- End of job -------------- " << endl;
[1463]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.