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

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

salete de magique

File size: 7.5 KB
Line 
1//#define TOISEQBUFFERED
2
3#include <unistd.h>
4#include "toi.h"
5#include "toiprocessor.h"
6#include "fitstoirdr.h"
7#include "fitstoiwtr.h"
8#include "toimanager.h"
9#ifdef TOISEQBUFFERED
10#include "toiseqbuff.h"
11#else
12#include "toisegment.h"
13#endif
14
15#include "sambainit.h"
16#include "map2toi.h"
17#include "fitsspherehealpix.h"
18#include "timing.h"
19
20#include <stdexcept>
21
22
23void usage(void);
24void usage(void) {
25 cout<<"tstmap2toi [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
26 <<" [-a label_coord1In] [-d label_coord2In] [-b label_bolomuv]"<<endl
27 <<" [-i c,h] [-m c,h]"<<endl
28 <<" fitsin_point fitsphere fitsout"<<endl
29 <<" -p lp : print level (def=0)"<<endl
30 <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl
31 <<" -w data_window_size : window size for pipe (def=8192)"<<endl
32 <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl
33 <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl
34 <<" coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl
35 <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl
36 <<" -i c,h : coordIn caracteristics (c=G/E h=H/D) (def=G,D)"<<endl
37 <<" -m c,h : idem -i for Sphere"<<endl
38 <<" fitsin_point : fits file for pointing"<<endl
39 <<" fitsphere : fits file for input Healpix sphere"<<endl
40 <<" fitsout : fits file for output"<<endl;
41 return;
42}
43
44unsigned long typecoord(char typc=' ',char hd=' ');
45unsigned long typecoord(char typc,char hd)
46// typc : G=galactiques, E=equatoriales, autres=galactiques
47// hd : H=heure, D=degre, autres=(heure si typc==E, degre si typc==G)
48{
49 if(typc!='G' && typc!='E') typc='G';
50 if(hd!='H' && hd!='D') {if(typc=='E') hd='H'; else hd='D';}
51 unsigned long rc=TypCoordUndef;
52 if(typc=='G') rc |= TypCoordGal;
53 else rc |= TypCoordEq;
54 if(hd=='D') rc |= TypCoordDD;
55 else rc |= TypCoordHD;
56 return rc;
57}
58
59////////////////////////////////////////////////////////////////
60int main(int narg, char** arg) {
61
62TOIManager* mgr = TOIManager::getManager();
63
64//-- Decodage arguments
65int lp = 0, width = 8192;
66char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
67long sdeb,sfin;
68unsigned long tcoorin=typecoord(), tcoormap=typecoord();
69int c; char t=' ',h=' ';
70while((c = getopt(narg,arg,"hp:s:w:a:d:b:i:m:")) != -1) {
71 switch (c) {
72 case 's' :
73 sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
74 cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
75 if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
76 else {cout<<"Bad sample interval "<<endl; exit(1);}
77 break;
78 case 'w' :
79 sscanf(optarg,"%d",&width);
80 if(width<=0) width=8192;
81 cout<<"Data window size "<<width<<endl;
82 break;
83 case 'p' :
84 sscanf(optarg,"%d",&lp);
85 if(lp<0) lp=0;
86 break;
87 case 'a' :
88 label_coord1 = optarg;
89 break;
90 case 'd' :
91 label_coord2 = optarg;
92 break;
93 case 'b' :
94 label_bolomuv = optarg;
95 break;
96 case 'i' :
97 sscanf(optarg,"%c,%c",&t,&h);
98 tcoorin=typecoord(t,h);
99 break;
100 case 'm' :
101 sscanf(optarg,"%c,%c",&t,&h);
102 tcoormap=typecoord(t,h);
103 break;
104 case 'h' :
105 default:
106 usage(); exit(1);
107 }
108}
109if(optind+2>=narg) {usage(); exit(2);}
110char * fitsin_point = arg[optind];
111string const fitsphere = arg[optind+1];
112char * fitsout = arg[optind+2];
113
114{
115unsigned long tg,te,hd,dd;
116cout<<">>>> tstmap2toi:"<<endl
117 <<"Pipe Window Size "<<width<<endl
118 <<"Fits OutFile "<<fitsout<<endl
119 <<" ...label_bolomuv "<<label_bolomuv<<endl;
120tg = tcoorin&TypCoordGal; te = tcoorin&TypCoordEq;
121hd = tcoorin&TypCoordHD; dd = tcoorin&TypCoordDD;
122cout<<"Fits Infile Pointing "<<fitsin_point<<endl
123 <<" ...label_coord1 "<<label_coord1<<endl
124 <<" ...label_coord2 "<<label_coord2<<endl
125 <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
126tg = tcoormap&TypCoordGal; te = tcoormap&TypCoordEq;
127hd = tcoormap&TypCoordHD; dd = tcoormap&TypCoordDD;
128cout<<"Fits Healpix Sphere "<<fitsphere<<endl
129 <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
130}
131
132SophyaInit();
133InitTim();
134
135//--------------------------------------------------------------------
136try {
137//--------------------------------------------------------------------
138
139 // FITS reader et writer
140 FITSTOIReader rfits(fitsin_point);
141 int ncol = rfits.getNOut();
142 cout<<"Number of columns in fits Infile Pointing : "<<ncol<<endl;
143 if(ncol<2) exit(3);
144
145 FITSTOIWriter wfits(fitsout);
146 //wfits.setOutFlags(true);
147 cout << "fits reader and writer created"<<endl;
148
149 // Lecture de la sphere Healpix
150 SphereHEALPix<r_8> sph;
151 FitsInFile sfits(fitsphere);
152 sfits >> sph;
153 cout<<"SphereHEALPix: Type de map : "<<sph.TypeOfMap()<<endl
154 <<" Nombre de pixels : "<<sph.NbPixels()<<endl;
155
156 // TOI Processor
157 Map2TOI m2toi(sph);
158 cout<<"Map2TOI created"<<endl;
159 m2toi.SetEquinox(2000.);
160 m2toi.SetCoorIn((TypAstroCoord) tcoorin);
161 m2toi.SetCoorMap((TypAstroCoord) tcoormap);
162 m2toi.Print(cout);
163
164 // Definition des tuyaux
165#ifdef TOISEQBUFFERED
166 cout<<">>>> Using TOISeqBuffered"<<endl;
167 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
168#else
169 cout<<">>>> Using TOISegmented"<<endl;
170 TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width);
171#endif
172 // toicoord1in->setDebugLevel(1);
173 rfits.addOutput(label_coord1,toicoord1in);
174 m2toi.addInput("Coord1In",toicoord1in);
175
176#ifdef TOISEQBUFFERED
177 TOISeqBuffered * toicoord1out = new TOISeqBuffered("toi_coord1_out",width);
178#else
179 TOISegmented * toicoord1out = new TOISegmented("toi_coord1_out",width);
180#endif
181 m2toi.addOutput("Coord1Out",toicoord1out);
182 wfits.addInput(label_coord1,toicoord1out);
183
184#ifdef TOISEQBUFFERED
185 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
186#else
187 TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width);
188#endif
189 // toicoord2in->setDebugLevel(1);
190 rfits.addOutput(label_coord2,toicoord2in);
191 m2toi.addInput("Coord2In",toicoord2in);
192
193#ifdef TOISEQBUFFERED
194 TOISeqBuffered * toicoord2out = new TOISeqBuffered("toi_coord2_out",width);
195#else
196 TOISegmented * toicoord2out = new TOISegmented("toi_coord2_out",width);
197#endif
198 m2toi.addOutput("Coord2Out",toicoord2out);
199 wfits.addInput(label_coord2,toicoord2out);
200
201#ifdef TOISEQBUFFERED
202 TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width);
203#else
204 TOISegmented * toibolout = new TOISegmented("toi_bolo_out",width);
205#endif
206 // toibolout->setDebugLevel(1);
207 m2toi.addOutput("BoloOut",toibolout);
208 wfits.addInput(label_bolomuv,toibolout);
209
210 // Run
211 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
212 rfits.PrintStatus(cout);
213 cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
214 wfits.PrintStatus(cout);
215
216 PrtTim("starting threads");
217 rfits.start();
218 m2toi.start();
219 wfits.start();
220
221 if(lp>1)
222 for(int jjjj=0;jjjj<5;jjjj++) {
223 cout<<*toicoord1in;
224 cout<<*toibolout;
225 sleep(2);
226 }
227
228 // Affichage de l'avancement des TOIProcessors
229 //ProcSampleCounter<FITSTOIReader> stats(rfits);
230 //stats.InfoMessage() = "tstmap2toi/Info";
231 //stats.PrintStats();
232
233 mgr->joinAll();
234 PrtTim("End threads");
235
236//--------------------------------------------------------------------
237} catch (PThrowable & exc) {
238 cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name()
239 <<" - Msg= "<<exc.Msg()<<endl;
240} catch (const std::exception & sex) {
241 cout<<"\ntstmap2toi: Catched std::exception \n"
242 <<(string)typeid(sex).name()<<endl;
243} catch (...) {
244 cout<<"\ntstmap2toi: some other exception was caught ! "<<endl;
245}
246//--------------------------------------------------------------------
247
248exit(0);
249}
Note: See TracBrowser for help on using the repository browser.