| 1 | /*  ------------------------ Projet BAORadio -------------------- 
 | 
|---|
| 2 |   Programme de convolution avec le lobe d'un cube 3D (angles,freq) 
 | 
|---|
| 3 |     R. Ansari , C. Magneville - Juin 2010 
 | 
|---|
| 4 | 
 | 
|---|
| 5 |   Usage: applobe Diameter/Four2DRespTableFile In3DPPFName Out3DPPFName 
 | 
|---|
| 6 |                  [TargetBeamDoL] [ResmapleFactor=0.5,0.333...] 
 | 
|---|
| 7 | ---------------------------------------------------------------  */
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "sopnamsp.h"
 | 
|---|
| 10 | #include "machdefs.h"
 | 
|---|
| 11 | #include <math.h>
 | 
|---|
| 12 | #include <iostream>
 | 
|---|
| 13 | #include <typeinfo>
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "array.h"
 | 
|---|
| 16 | #include "histats.h"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "swfitsdtable.h"
 | 
|---|
| 19 | #include "fitshdtable.h"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "randr48.h"
 | 
|---|
| 22 | #include "vector3d.h"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | // #include "xastropack.h"     -- Pour faire les conversions de coordonnees celestes
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "radutil.h"
 | 
|---|
| 27 | #include "lobe.h"
 | 
|---|
| 28 | 
 | 
|---|
| 29 | // Pour l'initialisation des modules 
 | 
|---|
| 30 | #include "tarrinit.h"
 | 
|---|
| 31 | #include "histinit.h"
 | 
|---|
| 32 | #include "fiosinit.h"     
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include "timing.h"
 | 
|---|
| 35 | #include "ctimer.h"
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "cubedef.h"
 | 
|---|
| 38 | 
 | 
|---|
| 39 | //----------------------------------------------------------------------------
 | 
|---|
| 40 | //----------------------------------------------------------------------------   
 | 
|---|
| 41 | int main(int narg, char* arg[])
 | 
|---|
| 42 | {
 | 
|---|
| 43 |   // Sophya modules initialization
 | 
|---|
| 44 |   TArrayInitiator  _inia;
 | 
|---|
| 45 |   HiStatsInitiator  _inih;
 | 
|---|
| 46 |   FitsIOServerInitiator  _inif;
 | 
|---|
| 47 |   //------- AU LIEU DE ------>  SophyaInit();  
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   InitTim();   // Initializing the CPU timer
 | 
|---|
| 50 |   Timer tm("applobe");
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   if (narg < 3) {
 | 
|---|
| 53 |     cout << "Usage: applobe Diameter/Four2DRespTableFile In3DPPFName Out3DPPFName " 
 | 
|---|
| 54 |          << "             [TargetBeamDoL] [ResmapleFactor=0.5,0.333...] \n" << endl;
 | 
|---|
| 55 |     return 1;
 | 
|---|
| 56 |   }
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   // decodage arguments 
 | 
|---|
| 59 |   bool fgresptbl=true;
 | 
|---|
| 60 |   double DIAMETRE=100.;
 | 
|---|
| 61 |   string resptblname;
 | 
|---|
| 62 |   if (isdigit(*arg[1])) {
 | 
|---|
| 63 |     fgresptbl=false;
 | 
|---|
| 64 |     DIAMETRE=atof(arg[1]);
 | 
|---|
| 65 |   }
 | 
|---|
| 66 |   else resptblname=arg[1];
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   string inname = arg[2];
 | 
|---|
| 69 |   string outname = arg[3];
 | 
|---|
| 70 |   bool fgcorrbeam=false;
 | 
|---|
| 71 |   double tbeamDoL=135;
 | 
|---|
| 72 |   if (narg>4) {
 | 
|---|
| 73 |     tbeamDoL=atof(arg[4]);
 | 
|---|
| 74 |     if (tbeamDoL>1)  fgcorrbeam=true;
 | 
|---|
| 75 |   }
 | 
|---|
| 76 |   bool fgresample=false;
 | 
|---|
| 77 |   double fresamp=1.;
 | 
|---|
| 78 |   if (narg>5) {
 | 
|---|
| 79 |     fresamp=atof(arg[5]);
 | 
|---|
| 80 |     if ((fabs(fresamp)>1.e-2)&&(fabs(fresamp-1.)>1.e-2))  fgresample=true; 
 | 
|---|
| 81 |   }
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   int rc = 91;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   cout << " ====== applobe :   Input skycube  name= " << inname << " OutName=" << outname;
 | 
|---|
| 86 |   bool fginmap=true;
 | 
|---|
| 87 |   try {
 | 
|---|
| 88 |     TArray<r_4> incube;
 | 
|---|
| 89 |     cout << "applobe[1]: reading input 3D map (cube) from file " << inname << endl;
 | 
|---|
| 90 |     {
 | 
|---|
| 91 |       PInPersist pin(inname);
 | 
|---|
| 92 |       pin >> incube;
 | 
|---|
| 93 |     }
 | 
|---|
| 94 |     incube.Show(); 
 | 
|---|
| 95 | 
 | 
|---|
| 96 |     double dxdeg = ThetaSizeDegre/(double)NTheta;
 | 
|---|
| 97 |     double dydeg = PhiSizeDegre/(double)NPhi;
 | 
|---|
| 98 |     double dx = DegreeToRadian(dxdeg);
 | 
|---|
| 99 |     double dy = DegreeToRadian(dydeg);
 | 
|---|
| 100 |     double dfreq = FreqSizeMHz/(double)NFreq;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |     cout << " X,Y map size in degrees , X/Phi=" << PhiSizeDegre << " Y/Theta=" << ThetaSizeDegre
 | 
|---|
| 103 |          << " \n dx=" << dxdeg << " dy=" << dydeg << " degres ( dx_rad=" << dx << " dy_rad=" << dy << ")" 
 | 
|---|
| 104 |          << " FreqSize=" << FreqSizeMHz << " dfreq=dz= " << dfreq << " MHz" << endl;
 | 
|---|
| 105 | 
 | 
|---|
| 106 |     double mean, sigma;
 | 
|---|
| 107 |     MeanSigma(incube, mean, sigma);
 | 
|---|
| 108 |     cout << " InCube 3D- : Mean=" << mean << " Sigma=" << sigma <<  endl;
 | 
|---|
| 109 | 
 | 
|---|
| 110 |     cout << "applobe[2]: creating Four2DResponse and BeamEffect objects..." << endl;
 | 
|---|
| 111 |     H21Conversions conv;
 | 
|---|
| 112 |     conv.setFrequency(Freq0MHz);
 | 
|---|
| 113 |     double lambda = conv.getLambda();
 | 
|---|
| 114 |     
 | 
|---|
| 115 |     Four2DResponse fresp(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
 | 
|---|
| 116 |     Four2DResponse* fresp_p=&fresp;
 | 
|---|
| 117 |     Four2DRespTable resptbl;
 | 
|---|
| 118 |     if (fgresptbl) {
 | 
|---|
| 119 |       cout << "applobe[2.b]: initializing Four2DRespTable from file" << resptblname << endl;
 | 
|---|
| 120 |       resptbl.readFromPPF(resptblname);
 | 
|---|
| 121 |       fresp_p=&resptbl;
 | 
|---|
| 122 |     }
 | 
|---|
| 123 |     else cout << " applobe[2.b]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
 | 
|---|
| 124 |               << " DoL=" << DIAMETRE/lambda << " ) " << endl;
 | 
|---|
| 125 |     BeamEffect beam(*fresp_p);
 | 
|---|
| 126 | 
 | 
|---|
| 127 |     if (fgcorrbeam) {
 | 
|---|
| 128 |       double DoL = tbeamDoL;
 | 
|---|
| 129 |       double tbeamarcmin = RadianToDegree(1.22/DoL)*60.;
 | 
|---|
| 130 |       int typcb = 2;
 | 
|---|
| 131 |       //      if (fgresptbl) typcb=22;
 | 
|---|
| 132 |       Four2DResponse tbeam(typcb, DoL, DoL );
 | 
|---|
| 133 |       cout << "applobe[3]: calling Correct2RefLobe() with target beam D/Lambda=" << DoL  
 | 
|---|
| 134 |            << " -> arcmin " << tbeamarcmin << " TypDishResp=" << typcb << endl;
 | 
|---|
| 135 |       beam.Correct2RefLobe(tbeam, incube, dx, dy, Freq0MHz, dfreq);
 | 
|---|
| 136 |     }
 | 
|---|
| 137 |     else {
 | 
|---|
| 138 |       cout << "applobe[3]: calling ApplyLobe3D() ... " << endl;
 | 
|---|
| 139 |       beam.ApplyLobe3D(incube, dx, dy, Freq0MHz, dfreq);
 | 
|---|
| 140 |     }
 | 
|---|
| 141 |     TArray< r_4 > outcube;
 | 
|---|
| 142 |     if (fgresample) {
 | 
|---|
| 143 |       cout << "applobe[4]: calling ReSample(incube," << fresamp << "," << ",1.) ... " << endl;
 | 
|---|
| 144 |       outcube.Share(beam.ReSample(incube, fresamp, fresamp, 1.));
 | 
|---|
| 145 |     }
 | 
|---|
| 146 |     else outcube.Share(incube);
 | 
|---|
| 147 | 
 | 
|---|
| 148 |     outcube.Show(); 
 | 
|---|
| 149 |     MeanSigma(outcube, mean, sigma);
 | 
|---|
| 150 |     cout << " OutCube 3D- : Mean=" << mean << " Sigma=" << sigma <<  endl;
 | 
|---|
| 151 | 
 | 
|---|
| 152 |     // On sauve le cube de sortie
 | 
|---|
| 153 |     {
 | 
|---|
| 154 |       cout << " applobe[5]: Saving output cube to -> " << outname << endl;
 | 
|---|
| 155 |       POutPersist poc(outname);
 | 
|---|
| 156 |       poc << outcube;
 | 
|---|
| 157 |     }
 | 
|---|
| 158 | 
 | 
|---|
| 159 |     rc = 0;
 | 
|---|
| 160 |   }
 | 
|---|
| 161 |   catch (PThrowable& exc) {
 | 
|---|
| 162 |     cerr << " applobe.cc catched SOPHYA Exception " << exc.Msg() << endl;
 | 
|---|
| 163 |     rc = 77;
 | 
|---|
| 164 |   }  
 | 
|---|
| 165 |   catch (std::exception& sex) {
 | 
|---|
| 166 |     cerr << "\n applobe.cc std::exception :" 
 | 
|---|
| 167 |          << (string)typeid(sex).name() << "\n msg= " 
 | 
|---|
| 168 |          << sex.what() << endl;
 | 
|---|
| 169 |   }
 | 
|---|
| 170 |   catch (...) {
 | 
|---|
| 171 |     cerr << " applobe.cc catched unknown (...) exception  " << endl; 
 | 
|---|
| 172 |     rc = 78; 
 | 
|---|
| 173 |   } 
 | 
|---|
| 174 | 
 | 
|---|
| 175 |   cout << ">>>> applobe[9] ------- FIN ----------- Rc=" << rc << endl;
 | 
|---|
| 176 |   return rc;
 | 
|---|
| 177 | }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | 
 | 
|---|