source: Sophya/trunk/Cosmo/RadioBeam/repicon.cc@ 3932

Last change on this file since 3932 was 3932, checked in by ansari, 15 years ago

amelioration repicon.cc (decodage arguments) , Reza 23/12/2010

File size: 8.9 KB
Line 
1/* ------------------------ Projet BAORadio --------------------
2 Calcul de la reponse 2D (plan (u,v) d'un interferometre
3 R. Ansari , C. Magneville - Juin-Dec 2010
4
5 Usage: repicon [-parname value] configId OutPPFName
6--------------------------------------------------------------- */
7
8#include "machdefs.h"
9#include "sopnamsp.h"
10#include <iostream>
11#include <string>
12#include <math.h>
13
14#include <typeinfo>
15
16#include "mdish.h"
17#include "specpk.h"
18#include "interfconfigs.h"
19#include "radutil.h"
20
21#include "ntuple.h"
22#include "histinit.h"
23// #include "fiosinit.h"
24// #include "fitsioserver.h"
25
26#include "randr48.h"
27
28#include "timing.h"
29#include "ctimer.h"
30
31typedef DR48RandGen RandomGenerator ;
32
33// pour sauver la reponse mdresp et la config des dishes dans un fichier PPF
34void SaveDTVecDishesH2Resp(string& outfile, vector<Dish>& vdishes, Four2DRespTable& mdresp);
35
36// ---------------------------------------------------------------------
37// main program for computing interferometer response un (u,v) plane
38// R. Ansari - Avril-Juin 2010
39// ---------------------------------------------------------------------
40
41void Usage()
42{
43 cout << " Usage: repicon [-parname Value] configId OutPPFName \n"
44 << " configIds: f4x4,f8x8,f20x20, confA,confB,confC,confD, hex12,cross11, f3cyl,f8cyl,f3cylp,f8cylp \n"
45 << " f4x4 , f8x8 , f20x20 Filled array of nxn dishes \n"
46 << " confA , confB, confC, confD : semi-filled array of dishes \n"
47 << " hex12,cross11 : ASKAP like double hexagonal (12xD=12m), cross config (11xD=12m) \n"
48 << " f3cyl, f8cyl , f3cylp, f8cylp : filled array of non perfect/perfect of n cylinders \n"
49 << " [ -parname value] : -renmax -z -prt -D -lmax \n"
50 << " -renmax MaxValue (default : Do NOT renormalize 2D response value \n"
51 << " -z redshift (default=0.7) --> determines Lambda \n"
52 << " -D DishDiameter (default=5 m) \n"
53 << " -lmax array extension (default=100 m ) for response calculation kmax \n"
54 << " -rot ThetaMaxDeg,NTheta,PhiMaxDeg,NPhi (default NO-rotate/pointing -> 23,10,30,15 ) \n"
55 << " -prt PrtLev,PrtModulo (default=0,10) \n"
56 << endl;
57 return;
58}
59
60// ------------------ MAIN PROGRAM ------------------------------
61int main(int narg, const char* arg[])
62{
63 if (((narg>1)&&(strcmp(arg[1],"-h")==0))||(narg<3)) {
64 Usage();
65 return 1;
66 }
67 // make sure SOPHYA modules are initialized
68 SophyaInit();
69 // FitsIOServerInit();
70 InitTim();
71 //--- decoding command line arguments
72 string config = "f8x8" ;
73 string outfile = "repicon.ppf";
74 bool fgrenorm=false;
75 double rmax=1.;
76 double z_Redshift=0.7 ; // 21 cm at z=0.7 -> 0.357 m
77 int prtlev=0;
78 int prtmod=10;
79
80 double Ddish=5.;
81 bool fgDfixed=false;
82 double LMAX = 100.; // taille de la zone, pour calcul kmax
83 bool fgLMAXfixed=false;
84 double thetamxdeg=23.; // 23 degres : angle d'inclinaison de l'orbite terrestre
85 double phimxdeg=30.;
86 int nteta=10;
87 int nphi=15;
88 bool fgpoint=false;
89
90 int ka=1;
91 while (ka<(narg-1)) {
92 if (strcmp(arg[ka],"-renmax")==0) {
93 rmax=atof(arg[ka+1]); fgrenorm=true; ka+=2;
94 }
95 else if (strcmp(arg[ka],"-z")==0) {
96 z_Redshift=atof(arg[ka+1]); ka+=2;
97 }
98 else if (strcmp(arg[ka],"-D")==0) {
99 Ddish=atof(arg[ka+1]); fgDfixed=true; ka+=2;
100 }
101 else if (strcmp(arg[ka],"-lmax")==0) {
102 LMAX=atof(arg[ka+1]); fgLMAXfixed=true; ka+=2;
103 }
104 else if (strcmp(arg[ka],"-rot")==0) {
105 sscanf(arg[ka+1],"%lg,%d,%lg,%d",&thetamxdeg,&nteta,&phimxdeg,&nphi); fgpoint=true; ka+=2;
106 }
107 else if (strcmp(arg[ka],"-prt")==0) {
108 sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod); ka+=2;
109 }
110 else break;
111 }
112
113 if ((ka+1)>=narg) {
114 cout << " repicon / Argument error " << endl;
115 Usage();
116 return 2;
117 }
118
119 config = arg[ka];
120 outfile = arg[ka+1];
121 //-- end command line arguments
122
123 int rc = 1;
124 try { // exception handling try bloc at top level
125 cout << " ==== repicon.cc program , (u,v) plane response ==== " << endl;
126
127 double Eta=0.95;
128 double cylW=12.; // Largeur des cylindres
129 double cylRL=0.5; // Longeur des elements de reception le long du cylindre
130 double etaW=0.95; // Efficacite de couverture en largeur
131 double etaRL=0.9; // Efficacite de couverture le long du cylindre
132
133 int cnt=0;
134
135 vector<Dish> vdishes;
136 cout << " repicon[1] : creating dish vector/ MultiDish for configuration: " << config << endl;
137
138 if (config=="f4x4") {
139 vdishes=CreateFilledSqConfig(4,Ddish, Eta);
140 }
141 else if (config=="f8x8") {
142 vdishes=CreateFilledSqConfig(8,Ddish, Eta);
143 }
144 else if (config=="f20x20") {
145 vdishes=CreateFilledSqConfig(20,Ddish, Eta);
146 }
147 else if (config=="f3cyl") {
148 cylW=10.; cylRL=0.5;
149 vdishes=CreateFilledCylConfig(3, 128, cylW, cylRL, etaW, etaRL, true);
150 }
151 else if (config=="f3cylp") {
152 cylW=10.; cylRL=0.5;
153 vdishes=CreateFilledCylConfig(3, 128, cylW, cylRL, etaW, etaRL, false);
154 }
155 else if (config=="f8cyl") {
156 cylW=12.; cylRL=0.5;
157 vdishes=CreateFilledCylConfig(8, 192, cylW, cylRL, etaW, etaRL, true);
158 }
159 else if (config=="f8cylp") {
160 cylW=12.; cylRL=0.5;
161 vdishes=CreateFilledCylConfig(8, 192, cylW, cylRL, etaW, etaRL, false);
162 }
163 else if (config=="confA") {
164 vdishes=CreateConfigA(Ddish, Eta);
165 }
166 else if (config=="confB") {
167 vdishes=CreateConfigB(Ddish, Eta);
168 }
169 else if (config=="confC") {
170 vdishes=CreateConfigC(Ddish, Eta);
171 }
172 else if (config=="confD") {
173 vdishes=CreateConfigD(Ddish, Eta);
174 }
175 else if (config=="cross11") {
176 if (!fgDfixed) Ddish = 12.;
177 double base=20.;
178 Eta=0.95;
179 if (!fgLMAXfixed) LMAX = 250.;
180 vdishes=CreateCrossConfig(Ddish,base,Eta);
181 }
182 else if (config=="hex12") {
183 if (!fgDfixed) Ddish = 12.;
184 Eta=0.95;
185 if (!fgLMAXfixed) LMAX = 350.;
186 vdishes=CreateDoubleHexagonConfig(Ddish);
187 }
188 else {
189 cout << " NON valid configuration option -> exit" << endl;
190 return 99;
191 }
192
193 H21Conversions conv;
194 double LAMBDA=0.357 ; // 21 cm at z=0.7
195 conv.setRedshift(z_Redshift);
196 LAMBDA = conv.getLambda();
197
198 double Dol = LMAX/LAMBDA;
199 bool fgnoauto = true;
200 int NRX=200;
201 int NRY=200;
202
203 cout << " repicon[1] : Lambda=" << LAMBDA << " LMAX= " << LMAX << " NDishes=" << vdishes.size()
204 << " D-Dish=" << Ddish << " m." << endl;
205
206 MultiDish mdish(LAMBDA, LMAX, vdishes, fgnoauto);
207 mdish.SetPrtLevel(prtlev,prtmod);
208 mdish.SetRespHisNBins(NRX,NRY);
209
210 if (fgpoint) {
211 cout << " repicon[1.b] : activating pointing , ThetaMaxDeg=" << thetamxdeg << " NTheta=" << nteta
212 << " PhiMaxDeg= " << phimxdeg << " NPhi" << nphi << endl;
213 mdish.SetThetaPhiRange(Angle(thetamxdeg,Angle::Degree).ToRadian(),nteta,Angle(phimxdeg,Angle::Degree).ToRadian(), nphi);
214 }
215 cout << " repicon[2] : calling mdish.GetResponse() ..."<< endl;
216
217 Histo2D hrep = mdish.GetResponse();
218 PrtTim("Apres mdish.GetResponse()");
219
220 Four2DRespTable mdresp(hrep, Dol, LAMBDA);
221 if (fgrenorm) {
222 cout << " repicon[2.b] call to mdresp.renormalize(" << rmax << ")";
223 double omax=mdresp.renormalize(rmax);
224 cout << " Old Max=" << omax << endl;
225 }
226 cout << " repicon[3] : saving Four2DRespTable for config " << config << " to PPF file " << outfile << endl;
227 mdresp.writeToPPF(outfile);
228
229 string outfile2 = "hdt_"+outfile;
230 cout << " repicon[4] : saving H2D-response, multidish config to PPF file " << outfile2 << endl;
231 SaveDTVecDishesH2Resp(outfile2, vdishes, mdresp);
232
233 rc = 0;
234 } // End of try bloc
235 catch (PThrowable & exc) { // catching SOPHYA exceptions
236 cerr << " repicon.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
237 << "\n...exc.Msg= " << exc.Msg() << endl;
238 rc = 99;
239 }
240 catch (std::exception & e) { // catching standard C++ exceptions
241 cerr << " repicon.cc: Catched std::exception " << " - what()= " << e.what() << endl;
242 rc = 98;
243 }
244 catch (...) { // catching other exceptions
245 cerr << " repicon.cc: some other exception (...) was caught ! " << endl;
246 rc = 97;
247 }
248 PrtTim("End-repicon");
249 cout << " ==== End of repicon.cc program Rc= " << rc << endl;
250 return rc;
251}
252
253/*-- Nouvelle-Fonction --*/
254void SaveDTVecDishesH2Resp(string& outfile, vector<Dish>& vdishes, Four2DRespTable& mdresp)
255{
256 char* names[5]={"did","posx","posy","diam","diamy"};
257 NTuple ntvd(5,names,64,false);
258 r_4 xnt[10];
259 for(size_t i=0; i<vdishes.size(); i++) {
260 xnt[0]=vdishes[i].ReflectorId();
261 xnt[1]=vdishes[i].X;
262 xnt[2]=vdishes[i].Y;
263 if (vdishes[i].isCircular()) {
264 xnt[3]=vdishes[i].Diameter();
265 xnt[4]=0.;
266 }
267 else {
268 xnt[3]=vdishes[i].DiameterX();
269 xnt[4]=vdishes[i].DiameterY();
270 }
271 ntvd.Fill(xnt);
272 }
273 Histo2D h2rep=mdresp.GetResponse();
274 POutPersist po(outfile);
275 po << PPFNameTag("mdish") << ntvd;
276 po << PPFNameTag("h2rep") << h2rep;
277 return;
278}
279
Note: See TracBrowser for help on using the repository browser.