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