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

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

Flag : int_8 uint_8 cmv 15/6/01

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