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

Last change on this file since 1676 was 1651, checked in by cmv, 24 years ago

intro print avec ProcSampleCounter cmv 17/9/01

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