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

Last change on this file since 1730 was 1723, checked in by cmv, 24 years ago

TOIsegmented remplace TOISeqBuffered cmv 27/10/01

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