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

Last change on this file since 1809 was 1809, checked in by cmv, 24 years ago
  • map2toi et toi2map avec nouvelle interface sys coor et unites.
  • les modifs map2toi (LocalMap) de EA sont introduites + certains bugs corriges.

cmv 3/12/01

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