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

Last change on this file since 1536 was 1530, checked in by cmv, 24 years ago

ameliorations et + de possibilites cmv 14/6/01

File size: 6.7 KB
Line 
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
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;
34 return;
35}
36
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
52////////////////////////////////////////////////////////////////
53int main(int narg, char** arg) {
54
55TOIManager* mgr = TOIManager::getManager();
56
57//-- Decodage arguments
58int lp = 0, width = 8192;
59char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
60long sdeb,sfin;
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) {
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);
69 else {cout<<"Bad sample interval "<<endl; exit(1);}
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' :
81 label_coord1 = optarg;
82 break;
83 case 'd' :
84 label_coord2 = optarg;
85 break;
86 case 'b' :
87 label_bolomuv = optarg;
88 break;
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;
97 case 'h' :
98 default:
99 usage(); exit(1);
100 }
101}
102if(optind+2>=narg) {usage(); exit(2);}
103char * fitsin_point = arg[optind];
104string const fitsphere = arg[optind+1];
105char * fitsout = arg[optind+2];
106
107{
108unsigned long tg,te,hd,dd;
109cout<<">>>> tstmap2toi:"<<endl
110 <<"Pipe Window Size "<<width<<endl
111 <<"Fits OutFile "<<fitsout<<endl
112 <<" ...label_bolomuv "<<label_bolomuv<<endl;
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}
124
125SophyaInit();
126InitTim();
127
128//--------------------------------------------------------------------
129try {
130//--------------------------------------------------------------------
131
132 // FITS reader et writer
133 FITSTOIReader rfits(fitsin_point);
134 int ncol = rfits.getNOut();
135 cout<<"Number of columns in fits Infile Pointing : "<<ncol<<endl;
136 if(ncol<2) exit(3);
137
138 FITSTOIWriter wfits(fitsout);
139 //wfits.setOutFlags(true);
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;
152 m2toi.SetEquinox(2000.);
153 m2toi.SetCoorIn((TypAstroCoord) tcoorin);
154 m2toi.SetCoorMap((TypAstroCoord) tcoormap);
155 m2toi.Print(cout);
156
157 // Definition des tuyaux
158 TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width);
159 // toicoord1in->setDebugLevel(1);
160 rfits.addOutput(label_coord1,toicoord1in);
161 m2toi.addInput("Coord1In",toicoord1in);
162
163 TOISeqBuffered * toicoord1out = new TOISeqBuffered("toi_coord1_out",width);
164 m2toi.addOutput("Coord1Out",toicoord1out);
165 wfits.addInput(label_coord1,toicoord1out);
166
167 TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width);
168 // toicoord2in->setDebugLevel(1);
169 rfits.addOutput(label_coord2,toicoord2in);
170 m2toi.addInput("Coord2In",toicoord2in);
171
172 TOISeqBuffered * toicoord2out = new TOISeqBuffered("toi_coord2_out",width);
173 m2toi.addOutput("Coord2Out",toicoord2out);
174 wfits.addInput(label_coord2,toicoord2out);
175
176 TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width);
177 // toibolout->setDebugLevel(1);
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++) {
194 cout<<*toicoord1in;
195 cout<<*toibolout;
196 sleep(2);
197 }
198
199 mgr->joinAll();
200 PrtTim("End threads");
201
202//--------------------------------------------------------------------
203} catch (PThrowable & exc) {
204 cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name()
205 <<" - Msg= "<<exc.Msg()<<endl;
206} catch (const std::exception & sex) {
207 cout<<"\ntstmap2toi: Catched std::exception \n"
208 <<(string)typeid(sex).name()<<endl;
209} catch (...) {
210 cout<<"\ntstmap2toi: some other exception was caught ! "<<endl;
211}
212//--------------------------------------------------------------------
213
214exit(0);
215}
Note: See TracBrowser for help on using the repository browser.