[3930] | 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 Diameter/Four2DRespTableFile OutPPFName
|
---|
| 8 | [NGen=1] [S2Cut=100.] [z_redshift=0.7]
|
---|
| 9 | --------------------------------------------------------------- */
|
---|
| 10 |
|
---|
[3756] | 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"
|
---|
[3792] | 21 | #include "interfconfigs.h"
|
---|
[3930] | 22 | #include "radutil.h"
|
---|
[3792] | 23 |
|
---|
[3756] | 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 | // ---------------------------------------------------------------------
|
---|
[3930] | 36 | // Test main
|
---|
| 37 | // R. Ansari - Avril-Dec 2010
|
---|
[3756] | 38 | // ---------------------------------------------------------------------
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
[3769] | 42 | //-------------------------------------------------------------------------
|
---|
| 43 | // ------------------ MAIN PROGRAM ------------------------------
|
---|
| 44 | //-------------------------------------------------------------------------
|
---|
[3756] | 45 | int main(int narg, const char* arg[])
|
---|
| 46 | {
|
---|
[3930] | 47 | if ( (narg<3)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
|
---|
| 48 | cout << " Usage: pknoise Diameter/Four2DRespTableFile OutPPFName [RenormalizeMax]\n"
|
---|
| 49 | << " [NGen=1] [S2Cut=100.] [z_redshift=0.7] [PrtLev,PrtModulo=0,10]" << endl;
|
---|
[3756] | 50 | return 1;
|
---|
| 51 | }
|
---|
[3930] | 52 | cout << " ==== pknoise.cc : interferometer noise power spectrum computation ==== " << endl;
|
---|
[3756] | 53 | // make sure SOPHYA modules are initialized
|
---|
| 54 | SophyaInit();
|
---|
| 55 | // FitsIOServerInit();
|
---|
| 56 | InitTim();
|
---|
| 57 | //--- decoding command line arguments
|
---|
[3930] | 58 | string tits="pknoise";
|
---|
| 59 | char cbuff[64];
|
---|
| 60 | bool fgresptbl=false;
|
---|
| 61 | double DIAMETRE=100.;
|
---|
| 62 | string resptblname;
|
---|
| 63 | if (isdigit(*arg[1])) {
|
---|
| 64 | fgresptbl=false;
|
---|
| 65 | DIAMETRE=atof(arg[1]);
|
---|
| 66 | sprintf(cbuff,"pknoise_Dish(%g m)", DIAMETRE);
|
---|
| 67 | }
|
---|
| 68 | else {
|
---|
| 69 | resptblname=arg[1];
|
---|
| 70 | fgresptbl=true;
|
---|
| 71 | sprintf(cbuff,"pknoise_RespTblName=%s", arg[1]);
|
---|
| 72 | }
|
---|
| 73 | tits=cbuff;
|
---|
| 74 | string outfile = arg[2];
|
---|
[3756] | 75 | if (outfile==".") outfile = "pknoise.ppf";
|
---|
[3930] | 76 | bool fgrenorm=false;
|
---|
| 77 | double rmax=1.;
|
---|
| 78 | if (narg>3) {
|
---|
| 79 | rmax=atof(arg[3]);
|
---|
| 80 | fgrenorm=true;
|
---|
| 81 | }
|
---|
[3756] | 82 | int NMAX = 1;
|
---|
[3930] | 83 | if (narg>4) NMAX = atoi(arg[4]);
|
---|
[3756] | 84 | double SCut=0.;
|
---|
[3930] | 85 | if (narg>5) SCut = atof(arg[5]);
|
---|
| 86 | double z_Redshift=0.7 ; // 21 cm at z=0.7 -> 0.357 m
|
---|
| 87 | if (narg>6) z_Redshift = atof(arg[6]);
|
---|
| 88 | int prtlev=0;
|
---|
| 89 | int prtmod=10;
|
---|
| 90 | if (narg>7) sscanf(arg[7],"%d,%d",&prtlev,&prtmod);
|
---|
[3756] | 91 | //-- end command line arguments
|
---|
| 92 |
|
---|
| 93 | int rc = 1;
|
---|
| 94 | try { // exception handling try bloc at top level
|
---|
[3930] | 95 | cout << " pknoise[0] : Executing, output file= " << outfile << endl;
|
---|
[3756] | 96 | POutPersist po(outfile);
|
---|
| 97 |
|
---|
[3930] | 98 | H21Conversions conv;
|
---|
| 99 | conv.setRedshift(z_Redshift);
|
---|
| 100 | double lambda = conv.getLambda();
|
---|
[3756] | 101 |
|
---|
[3930] | 102 | double Dol = DIAMETRE/lambda;
|
---|
[3756] | 103 |
|
---|
[3930] | 104 | Four2DResponse arep(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
|
---|
| 105 | Four2DResponse* arep_p=&arep;
|
---|
| 106 | Four2DRespTable resptbl;
|
---|
| 107 | if (fgresptbl) {
|
---|
| 108 | cout << "pknoise[1]: initializing Four2DRespTable from file" << resptblname << endl;
|
---|
| 109 | resptbl.readFromPPF(resptblname);
|
---|
| 110 | arep_p=&resptbl;
|
---|
| 111 | if (fgrenorm) {
|
---|
| 112 | cout << " pknoise[1.b] call to resptbl.renormalize(" << rmax << ")";
|
---|
| 113 | double omax=resptbl.renormalize(rmax);
|
---|
| 114 | cout << " ... Old Max=" << omax << endl;
|
---|
| 115 | }
|
---|
[3769] | 116 | }
|
---|
[3930] | 117 | else cout << " pknoise[1]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
|
---|
| 118 | << " DoL=" << DIAMETRE/lambda << " ) " << endl;
|
---|
[3769] | 119 |
|
---|
[3756] | 120 |
|
---|
[3930] | 121 | cout << " pknoise[2]: Instanciating object type Four3DPk " << endl;
|
---|
[3756] | 122 | RandomGenerator rg;
|
---|
| 123 | Four3DPk m3d(rg);
|
---|
| 124 | m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI);
|
---|
[3930] | 125 | m3d.SetPrtLevel(prtlev,prtmod);
|
---|
[3756] | 126 |
|
---|
[3930] | 127 | cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;
|
---|
| 128 | PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
|
---|
| 129 | pkn.SetPrtLevel(prtlev,prtmod);
|
---|
| 130 | HProf hpn = pkn.Compute();
|
---|
| 131 | po << hpn;
|
---|
| 132 |
|
---|
[3756] | 133 | rc = 0;
|
---|
| 134 | } // End of try bloc
|
---|
| 135 | catch (PThrowable & exc) { // catching SOPHYA exceptions
|
---|
| 136 | cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
| 137 | << "\n...exc.Msg= " << exc.Msg() << endl;
|
---|
| 138 | rc = 99;
|
---|
| 139 | }
|
---|
| 140 | catch (std::exception & e) { // catching standard C++ exceptions
|
---|
| 141 | cerr << " pknoise.cc: Catched std::exception " << " - what()= " << e.what() << endl;
|
---|
| 142 | rc = 98;
|
---|
| 143 | }
|
---|
| 144 | catch (...) { // catching other exceptions
|
---|
| 145 | cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
|
---|
| 146 | rc = 97;
|
---|
| 147 | }
|
---|
| 148 | PrtTim("End-pknoise");
|
---|
| 149 | cout << " ==== End of pknoise.cc program Rc= " << rc << endl;
|
---|
| 150 | return rc;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 |
|
---|