| 1 | /*  ------------------------ Projet BAORadio -------------------- 
 | 
|---|
| 2 |   Programme de calcul du spectre de puissance de bruit pour 
 | 
|---|
| 3 |   un interferometre (spectre moyenne sur 3D -> P_noise(k) )
 | 
|---|
| 4 | 
 | 
|---|
| 5 |     R. Ansari , C. Magneville - Juin 2010 
 | 
|---|
| 6 | 
 | 
|---|
| 7 |   Usage:  pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName
 | 
|---|
| 8 |           -parname : -noise , -renmax , -scut , -ngen , -z , -prt 
 | 
|---|
| 9 | ---------------------------------------------------------------  */
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include "machdefs.h"
 | 
|---|
| 12 | #include "sopnamsp.h"
 | 
|---|
| 13 | #include <iostream>
 | 
|---|
| 14 | #include <string>
 | 
|---|
| 15 | #include <math.h>
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include <typeinfo>
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include "mdish.h"
 | 
|---|
| 20 | #include "specpk.h"
 | 
|---|
| 21 | #include "interfconfigs.h"
 | 
|---|
| 22 | #include "radutil.h"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "histinit.h"
 | 
|---|
| 25 | // #include "fiosinit.h"
 | 
|---|
| 26 | // #include "fitsioserver.h"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include "randr48.h"      
 | 
|---|
| 29 | 
 | 
|---|
| 30 | #include "timing.h"
 | 
|---|
| 31 | #include "ctimer.h"
 | 
|---|
| 32 | 
 | 
|---|
| 33 | typedef DR48RandGen RandomGenerator ;
 | 
|---|
| 34 | 
 | 
|---|
| 35 | // ---------------------------------------------------------------------
 | 
|---|
| 36 | // Test main 
 | 
|---|
| 37 | // R. Ansari  - Avril-Dec 2010 
 | 
|---|
| 38 | // ---------------------------------------------------------------------
 | 
|---|
| 39 | 
 | 
|---|
| 40 | void Usage() 
 | 
|---|
| 41 | {
 | 
|---|
| 42 |   cout << " Usage:  pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName \n" 
 | 
|---|
| 43 |        << "    -noise NoiseLevel (default=1.) \n"
 | 
|---|
| 44 |        << "    -renmax MaxValue (default : Do NOT renormalize 2D response value \n"   
 | 
|---|
| 45 |        << "    -scut SCutValue (default=100.) \n"
 | 
|---|
| 46 |        << "    -ngen NGen (default=1) number of noise fourier amp generations \n"
 | 
|---|
| 47 |        << "    -z redshift (default=0.7) \n"
 | 
|---|
| 48 |        << "    -prt PrtLev,PrtModulo (default=0,10) " << endl;
 | 
|---|
| 49 |   return;
 | 
|---|
| 50 | }
 | 
|---|
| 51 | 
 | 
|---|
| 52 | //-------------------------------------------------------------------------
 | 
|---|
| 53 | //      ------------------ MAIN PROGRAM ------------------------------
 | 
|---|
| 54 | //-------------------------------------------------------------------------
 | 
|---|
| 55 | int main(int narg, const char* arg[])
 | 
|---|
| 56 | {
 | 
|---|
| 57 |   if ( (narg<3)||((narg>1)&&(strcmp(arg[1],"-h")==0)) )  {
 | 
|---|
| 58 |     Usage();
 | 
|---|
| 59 |     return 1;
 | 
|---|
| 60 |   }
 | 
|---|
| 61 |   cout << " ==== pknoise.cc : interferometer noise power spectrum computation ==== " << endl;
 | 
|---|
| 62 |   // make sure SOPHYA modules are initialized 
 | 
|---|
| 63 |   SophyaInit();  
 | 
|---|
| 64 |   //  FitsIOServerInit();
 | 
|---|
| 65 |   InitTim();
 | 
|---|
| 66 |   //--- decoding command line arguments 
 | 
|---|
| 67 |   string tits="pknoise";
 | 
|---|
| 68 |   char cbuff[64];
 | 
|---|
| 69 |   bool fgresptbl=false;
 | 
|---|
| 70 |   double DIAMETRE=100.;
 | 
|---|
| 71 |   string resptblname;
 | 
|---|
| 72 |   double NoiseLevel=1.;
 | 
|---|
| 73 |   
 | 
|---|
| 74 |   bool fgrenorm=false;
 | 
|---|
| 75 |   double rmax=1.;
 | 
|---|
| 76 |   int NMAX = 1;
 | 
|---|
| 77 |   double SCut=0.;
 | 
|---|
| 78 |   double z_Redshift=0.7 ;  // 21 cm at z=0.7 -> 0.357 m  
 | 
|---|
| 79 |   int prtlev=0;
 | 
|---|
| 80 |   int prtmod=10;
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   int ka=1;
 | 
|---|
| 83 |   while (ka<(narg-1)) {
 | 
|---|
| 84 |     if (strcmp(arg[ka],"-noise")==0) {
 | 
|---|
| 85 |       NoiseLevel=atof(arg[ka+1]);
 | 
|---|
| 86 |       ka+=2;
 | 
|---|
| 87 |     }
 | 
|---|
| 88 |     else if (strcmp(arg[ka],"-renmax")==0) {
 | 
|---|
| 89 |       rmax=atof(arg[ka+1]);  fgrenorm=true;   ka+=2;
 | 
|---|
| 90 |     }
 | 
|---|
| 91 |     else if (strcmp(arg[ka],"-scut")==0) {
 | 
|---|
| 92 |       SCut=atof(arg[ka+1]);    ka+=2; 
 | 
|---|
| 93 |     }
 | 
|---|
| 94 |     else if (strcmp(arg[ka],"-ngen")==0) {
 | 
|---|
| 95 |       NMAX=atoi(arg[ka+1]);    ka+=2;
 | 
|---|
| 96 |     }
 | 
|---|
| 97 |     else if (strcmp(arg[ka],"-z")==0) {
 | 
|---|
| 98 |       z_Redshift=atof(arg[ka+1]);  ka+=2;
 | 
|---|
| 99 |     }
 | 
|---|
| 100 |     else if (strcmp(arg[ka],"-prt")==0) {
 | 
|---|
| 101 |       sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod);   ka+=2;
 | 
|---|
| 102 |     }
 | 
|---|
| 103 |     else break; 
 | 
|---|
| 104 |   }
 | 
|---|
| 105 | 
 | 
|---|
| 106 |   if ((ka+1)>=narg) {
 | 
|---|
| 107 |     cout << " pknoise / Argument error " << endl;
 | 
|---|
| 108 |     Usage();
 | 
|---|
| 109 |     return 2;
 | 
|---|
| 110 |   }
 | 
|---|
| 111 |   if (isdigit(*arg[ka])) {
 | 
|---|
| 112 |     fgresptbl=false;
 | 
|---|
| 113 |     DIAMETRE=atof(arg[ka]);
 | 
|---|
| 114 |     sprintf(cbuff,"pknoise_Dish(%g m)", DIAMETRE);
 | 
|---|
| 115 |   }
 | 
|---|
| 116 |   else { 
 | 
|---|
| 117 |     resptblname=arg[ka];
 | 
|---|
| 118 |     fgresptbl=true;
 | 
|---|
| 119 |     sprintf(cbuff,"pknoise_RespTblName=%s", arg[ka]);
 | 
|---|
| 120 |   }
 | 
|---|
| 121 |   tits=cbuff;
 | 
|---|
| 122 |   string outfile = arg[ka+1];  
 | 
|---|
| 123 |   if (outfile==".")  outfile = "pknoise.ppf";
 | 
|---|
| 124 |  //-- end command line arguments
 | 
|---|
| 125 |   
 | 
|---|
| 126 |   int rc = 1;  
 | 
|---|
| 127 |   try {  // exception handling try bloc at top level
 | 
|---|
| 128 |     cout << " pknoise[0] : Executing, output file= " << outfile << endl;  
 | 
|---|
| 129 |     POutPersist po(outfile);
 | 
|---|
| 130 | 
 | 
|---|
| 131 |     H21Conversions conv;
 | 
|---|
| 132 |     conv.setRedshift(z_Redshift);
 | 
|---|
| 133 |     double lambda = conv.getLambda();
 | 
|---|
| 134 | 
 | 
|---|
| 135 |     double Dol = DIAMETRE/lambda;
 | 
|---|
| 136 | 
 | 
|---|
| 137 |     Four2DResponse arep(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
 | 
|---|
| 138 |     Four2DResponse* arep_p=&arep;
 | 
|---|
| 139 |     Four2DRespTable resptbl;
 | 
|---|
| 140 |     if (fgresptbl) {
 | 
|---|
| 141 |       cout << "pknoise[1]: initializing Four2DRespTable from file" << resptblname << endl;
 | 
|---|
| 142 |       resptbl.readFromPPF(resptblname);
 | 
|---|
| 143 |       arep_p=&resptbl;
 | 
|---|
| 144 |       if (fgrenorm) {
 | 
|---|
| 145 |         cout << " pknoise[1.b] call to resptbl.renormalize(" << rmax << ")"; 
 | 
|---|
| 146 |         double omax=resptbl.renormalize(rmax);
 | 
|---|
| 147 |         cout << " ... Old Max=" << omax << endl;
 | 
|---|
| 148 |       }
 | 
|---|
| 149 |     }
 | 
|---|
| 150 |     else cout << " pknoise[1]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
 | 
|---|
| 151 |               << " DoL=" << DIAMETRE/lambda << " ) " << endl;
 | 
|---|
| 152 | 
 | 
|---|
| 153 |     
 | 
|---|
| 154 |     cout << " pknoise[2]: Instanciating object type Four3DPk  " << endl;
 | 
|---|
| 155 |     RandomGenerator rg;
 | 
|---|
| 156 |     Four3DPk m3d(rg);
 | 
|---|
| 157 |     m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI); 
 | 
|---|
| 158 |     m3d.SetPrtLevel(prtlev,prtmod);
 | 
|---|
| 159 | 
 | 
|---|
| 160 |     cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;
 | 
|---|
| 161 |     PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
 | 
|---|
| 162 |     pkn.SetPrtLevel(prtlev,prtmod);
 | 
|---|
| 163 |     HProf hpn = pkn.Compute();
 | 
|---|
| 164 |     po << hpn;
 | 
|---|
| 165 |  
 | 
|---|
| 166 |     rc = 0;
 | 
|---|
| 167 |   }  // End of try bloc 
 | 
|---|
| 168 |   catch (PThrowable & exc) {  // catching SOPHYA exceptions
 | 
|---|
| 169 |     cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name() 
 | 
|---|
| 170 |          << "\n...exc.Msg= " << exc.Msg() << endl;
 | 
|---|
| 171 |     rc = 99;
 | 
|---|
| 172 |   }
 | 
|---|
| 173 |   catch (std::exception & e) {  // catching standard C++ exceptions
 | 
|---|
| 174 |     cerr << " pknoise.cc: Catched std::exception "  << " - what()= " << e.what() << endl;
 | 
|---|
| 175 |     rc = 98;
 | 
|---|
| 176 |   }
 | 
|---|
| 177 |   catch (...) {  // catching other exceptions
 | 
|---|
| 178 |     cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
 | 
|---|
| 179 |     rc = 97;
 | 
|---|
| 180 |   }
 | 
|---|
| 181 |   PrtTim("End-pknoise");
 | 
|---|
| 182 |   cout << " ==== End of pknoise.cc program  Rc= " << rc << endl;
 | 
|---|
| 183 |   return rc;    
 | 
|---|
| 184 | }
 | 
|---|
| 185 | 
 | 
|---|
| 186 | 
 | 
|---|