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

Last change on this file since 1803 was 1760, checked in by aubourg, 24 years ago

salete de magique

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