| [3825] | 1 | /*  ------------------------ Projet BAORadio -------------------- 
 | 
|---|
 | 2 |   Programme d'extraction d'une partie de carte synchrotron 
 | 
|---|
 | 3 |   (HASLAM @ 400 MHz) et fabrication d'un cube 3D (angles,fre) 
 | 
|---|
 | 4 |     R. Ansari , C. Magneville - Juin 2010 
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Usage: syncube InFitsName Out3DPPFName [Out2DMapName] 
 | 
|---|
 | 7 | ---------------------------------------------------------------  */
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #include "sopnamsp.h"
 | 
|---|
 | 10 | #include "machdefs.h"
 | 
|---|
 | 11 | #include <math.h>
 | 
|---|
 | 12 | #include <iostream>
 | 
|---|
 | 13 | #include <typeinfo>
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | #include "tvector.h"
 | 
|---|
 | 16 | #include "srandgen.h"
 | 
|---|
 | 17 | #include "fioarr.h"
 | 
|---|
 | 18 | #include "sopemtx.h"
 | 
|---|
 | 19 | #include "pexceptions.h"
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | #include "randr48.h"
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | #include "tvector.h"        // Pour l'utilisation des classes TArray, TMatrix , TVector
 | 
|---|
 | 24 | #include "matharr.h"
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | /*
 | 
|---|
 | 27 | #include "spherehealpix.h"   // Pour les cartes spheriques pixelisees au format HEALPix 
 | 
|---|
 | 28 | #include "spherethetaphi.h"   // Pour les cartes spheriques pixelisees au format Theta-Phi 
 | 
|---|
 | 29 | #include "localmap.h"         // Pour les cartes locales 
 | 
|---|
 | 30 | #include "mapoperation.h"         // Pour les cartes locales 
 | 
|---|
 | 31 | */
 | 
|---|
 | 32 | #include "skymap.h"
 | 
|---|
 | 33 | #include "mapoperation.h"         // Pour les cartes locales 
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | #include "fitsspherehealpix.h"   // Pour les I/O fits de HEALPix
 | 
|---|
 | 36 | #include "fitsspherethetaphi.h"   // Pour les I/O fits de SphereThetaPhi
 | 
|---|
 | 37 | #include "fitslocalmap.h"         // Pour les I/O fits de LocalMap<T> 
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #include "xastropack.h"     // Pour faire les conversions de coordonnees celestes
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | // Pour l'initialisation des modules 
 | 
|---|
 | 42 | #include "tarrinit.h"
 | 
|---|
 | 43 | #include "skymapinit.h"     
 | 
|---|
 | 44 | #include "fiosinit.h"     
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | #include "timing.h"
 | 
|---|
 | 47 | #include "ctimer.h"
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | #include "cubedef.h"
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | //----------------------------------------------------------------------------
 | 
|---|
 | 52 | //----------------------------------------------------------------------------   
 | 
|---|
 | 53 | int main(int narg, char* arg[])
 | 
|---|
 | 54 | {
 | 
|---|
 | 55 |   // Sophya modules initialization
 | 
|---|
 | 56 |   TArrayInitiator  _inia;
 | 
|---|
 | 57 |   SkyMapInitiator  _inis;
 | 
|---|
 | 58 |   FitsIOServerInitiator  _inif;
 | 
|---|
 | 59 |   //------- AU LIEU DE ------>  SophyaInit();  
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   InitTim();   // Initializing the CPU timer
 | 
|---|
 | 62 |   Timer tm("gsm2cube");
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |   if (narg < 5) {
 | 
|---|
 | 65 |     cout << "Usage: gsm2cube GSMPPFDirectory GSMMapNumStart GSMMapNumEnd  Out3DPPFName  \n" << endl;
 | 
|---|
 | 66 |     return 1;
 | 
|---|
 | 67 |   }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   // decodage arguments 
 | 
|---|
 | 70 |   string inpath = arg[1];
 | 
|---|
 | 71 |   int numapstart = atoi(arg[2]);
 | 
|---|
 | 72 |   int numapend = atoi(arg[3]);
 | 
|---|
 | 73 |   string outname = arg[4];
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |   int rc = 91;
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   cout << " ====== gsm2cube :   Input GSM map path= " << inpath << " NumStart=" << numapstart 
 | 
|---|
 | 78 |        << " End=" << numapend << " OutName=" << outname << endl;
 | 
|---|
 | 79 |   try {
 | 
|---|
 | 80 |     int nfreqgsm = numapend-numapstart+1;
 | 
|---|
 | 81 |     if (nfreqgsm!=NFreq) {
 | 
|---|
 | 82 |       cout << " gsm2cube/ERROR: (nfreqgsm=" << nfreqgsm << ") <> NFreq (=" << NFreq << ") -> exit 9" << endl;
 | 
|---|
 | 83 |       return 9;
 | 
|---|
 | 84 |     }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |     double tet0 = Angle(Theta0Degre,Angle::Degree).ToRadian();
 | 
|---|
 | 87 |     double phi0 = Angle(Phi0Degre,Angle::Degree).ToRadian();
 | 
|---|
 | 88 |     double dtet = Angle(ThetaSizeDegre,Angle::Degree).ToRadian()/(double)NTheta;
 | 
|---|
 | 89 |     double dphi = Angle(PhiSizeDegre,Angle::Degree).ToRadian()/(double)NPhi;
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |     TArray<r_4> ocube(NPhi,NTheta,NFreq);
 | 
|---|
 | 92 |     double mjd2000 = MJDfrDate(1,1,2000);   // Modified Julian Date pour 1 Janvier 2000
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 |     cout << "gsm2cube[1] Loop over input GSM spherical maps ... " << endl;
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |     for(sa_size_t kf=0; kf<NFreq; kf++) {
 | 
|---|
 | 97 |       char mapname[512];
 | 
|---|
 | 98 |       sprintf(mapname,"%s/gsm820948_%d.ppf",inpath.c_str(),(int)(kf+numapstart));
 | 
|---|
 | 99 |       cout << kf << "- Reading GSM map from file " << mapname << " ... " ;
 | 
|---|
 | 100 |       PInPersist pin(mapname);
 | 
|---|
 | 101 |       SphereHEALPix<r_4> gsm;
 | 
|---|
 | 102 |       pin >> gsm;
 | 
|---|
 | 103 |       cout << " Freq=" << gsm.Info()["FMHz"] << " MHz " << endl;
 | 
|---|
 | 104 |       for (sa_size_t j=0; j<ocube.SizeY(); j++)  {
 | 
|---|
 | 105 |         for (sa_size_t i=0; i<ocube.SizeX(); i++)  {
 | 
|---|
 | 106 |           double theta = j*dtet+tet0;
 | 
|---|
 | 107 |           double phi = i*dphi+phi0;
 | 
|---|
 | 108 |           double ra, dec;  // Angle horaire (right ascension) [0...24], dec [-90 90]
 | 
|---|
 | 109 |           ra=Angle(phi).ToDegree()/360.*24.;
 | 
|---|
 | 110 |           dec=90-Angle(theta).ToDegree();
 | 
|---|
 | 111 |           double glong, glat;  // Longitude et latitude galactique - en degres [0...360], [-90...90]
 | 
|---|
 | 112 |           EqtoGal(mjd2000,ra,dec,&glong,&glat);
 | 
|---|
 | 113 |           phi=Angle(glong,Angle::Degree).ToRadian();
 | 
|---|
 | 114 |           theta=Angle(90-glat,Angle::Degree).ToRadian();
 | 
|---|
 | 115 |           ocube(i,j,kf)=gsm(theta,phi);
 | 
|---|
 | 116 |         }
 | 
|---|
 | 117 |       }
 | 
|---|
 | 118 |     }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 |     double mean, sigma;
 | 
|---|
 | 121 |     MeanSigma(ocube, mean, sigma);
 | 
|---|
 | 122 |     cout << "gsm2cube[2] ocube : Mean=" << mean << " Sigma=" << sigma << " Sizes: " << endl;
 | 
|---|
 | 123 |     ocube.Show(); 
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 |     
 | 
|---|
 | 126 |     // On sauve le cube de sortie
 | 
|---|
 | 127 |     {
 | 
|---|
 | 128 |       cout << " gsm2cube[3]: Saving output cube to -> " << outname << endl;
 | 
|---|
 | 129 |       POutPersist poc(outname);
 | 
|---|
 | 130 |       poc << ocube;
 | 
|---|
 | 131 |     }
 | 
|---|
 | 132 |     rc = 0;
 | 
|---|
 | 133 |   }
 | 
|---|
 | 134 |   catch (PThrowable& exc) {
 | 
|---|
 | 135 |     cerr << " gsm2cube.cc catched Exception " << exc.Msg() << endl;
 | 
|---|
 | 136 |     rc = 77;
 | 
|---|
 | 137 |   }  
 | 
|---|
 | 138 |   catch (std::exception& sex) {
 | 
|---|
 | 139 |     cerr << "\n gsm2cube.cc std::exception :" 
 | 
|---|
 | 140 |          << (string)typeid(sex).name() << "\n msg= " 
 | 
|---|
 | 141 |          << sex.what() << endl;
 | 
|---|
 | 142 |   }
 | 
|---|
 | 143 |   catch (...) {
 | 
|---|
 | 144 |     cerr << " gsm2cube.cc catched unknown (...) exception  " << endl; 
 | 
|---|
 | 145 |     rc = 78; 
 | 
|---|
 | 146 |   } 
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 |   cout << ">>>> gsm2cube ------- FIN ----------- Rc=" << rc << endl;
 | 
|---|
 | 149 |   return rc;
 | 
|---|
 | 150 | }
 | 
|---|
 | 151 | 
 | 
|---|
 | 152 | 
 | 
|---|