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

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

Re-shape de map2toi cmv 12/6/01

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