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

Last change on this file since 1476 was 1476, checked in by ansari, 24 years ago

compil/portage SGI-CC - Reza 23/4/2001

File size: 5.0 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 "toi2map.h"
13#include "fitsspherehealpix.h"
14#include "timing.h"
15
16void usage(void);
17void usage(void) {
18 cout<<"tsttoi2map [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl
19 <<" [-a label_alpha] [-d label_delta] [-b label_bolomuv]"<<endl
20 <<" [-n nlat] [-G] fitsin fitsphout fitsphwout"<<endl;
21 return;
22}
23
24////////////////////////////////////////////////////////////////
25int main(int narg, char** arg) {
26
27TOIManager* mgr = TOIManager::getManager();
28
29//-- Decodage arguments
30int lp = 0, width = 8192;
31int nlat = 128; // npixel = 12 * nlat^2
32char *label_alpha = "alpha", *label_delta = "delta", *label_bolomuv = "boloMuV";
33bool coorgal=false;
34long sdeb,sfin;
35int c;
36while((c = getopt(narg,arg,"hGp:s:w:a:d:b:n:")) != -1) {
37 switch (c) {
38 case 's' :
39 sscanf(optarg,"%ld,%ld",&sdeb,&sfin);
40 cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
41 if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
42 else {cout<<"Bad sample interval "<<endl; exit(-2);}
43 break;
44 case 'w' :
45 sscanf(optarg,"%d",&width);
46 if(width<=0) width=8192;
47 cout<<"Data window size "<<width<<endl;
48 break;
49 case 'p' :
50 sscanf(optarg,"%d",&lp);
51 if(lp<0) lp=0;
52 break;
53 case 'a' :
54 label_alpha = optarg;
55 break;
56 case 'd' :
57 label_delta = optarg;
58 break;
59 case 'b' :
60 label_bolomuv = optarg;
61 break;
62 case 'n' :
63 sscanf(optarg,"%d",&nlat);
64 if(nlat<0) nlat=128;
65 break;
66 case 'G' :
67 coorgal = true;
68 break;
69 case 'h' :
70 usage(); exit(-1);
71 break;
72 default:
73 usage(); exit(-1);
74 }
75}
76if(optind+1>=narg) {usage(); exit(-2);}
77char * fitsin = arg[optind];
78string const fitsphout = arg[optind+1];
79string fitsphwout = "";
80if(optind+2<narg) fitsphwout = arg[optind+2];
81
82cout<<">>>> tsttoi2map:"<<endl
83 <<"Fits Infile(snum,alpha,delta,bolomuv)= "<<fitsin<<endl
84 <<" ...label_alpha "<<label_alpha<<" , label_delta "<<label_delta<<endl
85 <<" ...label_bolomuv "<<label_bolomuv<<endl
86 <<"Fits Sphere Healpix"<<fitsphout<<endl
87 <<" ...nlat "<<nlat<<endl
88 <<"Fits Sphere Healpix Error "<<fitsphwout<<endl;
89
90SophyaInit();
91InitTim();
92
93//--------------------------------------------------------------------
94try {
95//--------------------------------------------------------------------
96
97 // FITS reader
98 FITSTOIReader rfits(fitsin);
99 int ncol = rfits.getNOut();
100 cout<<"Number of columns in fits Infile : "<<ncol<<endl;
101 if(ncol<3) exit(-3);
102
103 // Creation de la sphere Healpix
104 SphereHEALPix<r_8>* sph = new SphereHEALPix<r_8>(nlat);
105 cout<<"SphereHEALPix: Type de map : "<<sph->TypeOfMap()<<endl
106 <<" Nombre de pixels : "<<sph->NbPixels()<<endl;
107
108 // Creation de la sphere de poids Healpix
109 SphereHEALPix<r_8>* wsph = NULL;
110 if(fitsphwout.size()>0) {
111 wsph = new SphereHEALPix<r_8>;
112 cout<<"SphereHEALPix Weight: Type de map : "<<wsph->TypeOfMap()<<endl
113 <<" Nombre de pixels : "<<wsph->NbPixels()<<endl;
114 }
115
116 // TOI Processor
117 TOI2Map toi2m(sph,wsph);
118 cout<<"TOI2Map created"<<endl;
119 toi2m.SetCoorGal(coorgal,2000.); // equinoxe de ref. 2000. (pour archtoi)
120
121 // Definition des tuyaux
122 TOISeqBuffered * toialphain = new TOISeqBuffered("toi_alpha_in",width);
123 if(lp) toialphain->setDebugLevel(1);
124 rfits.addOutput(label_alpha,toialphain);
125 toi2m.addInput("AlphaIn",toialphain);
126
127 TOISeqBuffered * toideltain = new TOISeqBuffered("toi_delta_in",width);
128 if(lp) toideltain->setDebugLevel(1);
129 rfits.addOutput(label_delta,toideltain);
130 toi2m.addInput("DeltaIn",toideltain);
131
132 TOISeqBuffered * toibolin = new TOISeqBuffered("toi_bolo_in",width);
133 if(lp) toibolin->setDebugLevel(1);
134 rfits.addOutput(label_bolomuv,toibolin);
135 toi2m.addInput("BoloIn",toibolin);
136
137 // Run
138 cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl;
139 rfits.PrintStatus(cout);
140
141 PrtTim("starting threads");
142 rfits.start();
143 toi2m.start();
144
145 if(lp>1)
146 for(int jjjj=0;jjjj<5;jjjj++) {
147 cout<<*toialphain;
148 cout<<*toibolin;
149 sleep(2);
150 }
151
152 mgr->joinAll();
153 PrtTim("End threads");
154
155 // Ecriture de la sphere Healpix sur fits
156 {
157 FitsOutFile sfits(fitsphout);
158 cout<<"tsttoi2map: Creating sphere fits file "<<fitsphout<<endl;
159 sfits << *sph;
160 }
161
162 // Ecriture de la sphere Healpix sur fits
163 if(wsph) {
164 FitsOutFile swfits(fitsphwout);
165 cout<<"tsttoi2map: Creating sphere weight fits file "<<fitsphwout<<endl;
166 swfits << *wsph;
167 }
168
169 // Nettoyage
170 delete sph;
171 if(wsph) delete wsph;
172
173//--------------------------------------------------------------------
174} catch (PThrowable & exc) {
175 cout<<"\ntsttoi2map: Catched Exception \n"<<(string)typeid(exc).name()
176 <<" - Msg= "<<exc.Msg()<<endl;
177} catch (const std::exception & sex) {
178 cout<<"\ntsttoi2map: Catched std::exception \n"
179 <<(string)typeid(sex).name()<<endl;
180} catch (...) {
181 cout<<"\ntsttoi2map: some other exception was caught ! "<<endl;
182}
183//--------------------------------------------------------------------
184
185exit(0);
186}
Note: See TracBrowser for help on using the repository browser.