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

Last change on this file since 1806 was 1760, checked in by aubourg, 24 years ago

salete de magique

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