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 |
|
---|
16 | void usage(void);
|
---|
17 | void 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 |
|
---|
37 | unsigned long typecoord(char typc=' ',char hd=' ');
|
---|
38 | unsigned 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 | ////////////////////////////////////////////////////////////////
|
---|
53 | int main(int narg, char** arg) {
|
---|
54 |
|
---|
55 | TOIManager* mgr = TOIManager::getManager();
|
---|
56 |
|
---|
57 | //-- Decodage arguments
|
---|
58 | int lp = 0, width = 8192;
|
---|
59 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV";
|
---|
60 | long sdeb,sfin;
|
---|
61 | unsigned long tcoorin=typecoord(), tcoormap=typecoord();
|
---|
62 | int c; char t=' ',h=' ';
|
---|
63 | while((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 | }
|
---|
102 | if(optind+2>=narg) {usage(); exit(2);}
|
---|
103 | char * fitsin_point = arg[optind];
|
---|
104 | string const fitsphere = arg[optind+1];
|
---|
105 | char * fitsout = arg[optind+2];
|
---|
106 |
|
---|
107 | {
|
---|
108 | unsigned long tg,te,hd,dd;
|
---|
109 | cout<<">>>> tstmap2toi:"<<endl
|
---|
110 | <<"Pipe Window Size "<<width<<endl
|
---|
111 | <<"Fits OutFile "<<fitsout<<endl
|
---|
112 | <<" ...label_bolomuv "<<label_bolomuv<<endl;
|
---|
113 | tg = tcoorin&TypCoordGal; te = tcoorin&TypCoordEq;
|
---|
114 | hd = tcoorin&TypCoordHD; dd = tcoorin&TypCoordDD;
|
---|
115 | cout<<"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;
|
---|
119 | tg = tcoormap&TypCoordGal; te = tcoormap&TypCoordEq;
|
---|
120 | hd = tcoormap&TypCoordHD; dd = tcoormap&TypCoordDD;
|
---|
121 | cout<<"Fits Healpix Sphere "<<fitsphere<<endl
|
---|
122 | <<" ...... Gal="<<tg<<" Eq="<<te<<" hour="<<hd<<" deg="<<dd<<endl;
|
---|
123 | }
|
---|
124 |
|
---|
125 | SophyaInit();
|
---|
126 | InitTim();
|
---|
127 |
|
---|
128 | //--------------------------------------------------------------------
|
---|
129 | try {
|
---|
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 | // Affichage de l'avancement des TOIProcessors
|
---|
200 | ProcSampleCounter<FITSTOIReader> stats(rfits);
|
---|
201 | stats.InfoMessage() = "tstmap2toi/Info";
|
---|
202 | stats.PrintStats();
|
---|
203 |
|
---|
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 |
|
---|
219 | exit(0);
|
---|
220 | }
|
---|