| 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 GSMPPFDirectoryFileName GSMMapNumStart GSMMapNumEnd  Out3DPPFName  \n" | 
|---|
| 66 | << "  GSMPPFDirectoryFileName in form of Directory/gsmJJJJJ "  << endl; | 
|---|
| 67 | return 1; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | // decodage arguments | 
|---|
| 71 | string inpath = arg[1]; | 
|---|
| 72 | int numapstart = atoi(arg[2]); | 
|---|
| 73 | int numapend = atoi(arg[3]); | 
|---|
| 74 | string outname = arg[4]; | 
|---|
| 75 |  | 
|---|
| 76 | int rc = 91; | 
|---|
| 77 |  | 
|---|
| 78 | cout << " ====== gsm2cube :   Input GSM map path= " << inpath << " NumStart=" << numapstart | 
|---|
| 79 | << " End=" << numapend << " OutName=" << outname << endl; | 
|---|
| 80 | try { | 
|---|
| 81 | int nfreqgsm = numapend-numapstart+1; | 
|---|
| 82 | if (nfreqgsm!=NFreq) { | 
|---|
| 83 | cout << " gsm2cube/ERROR: (nfreqgsm=" << nfreqgsm << ") <> NFreq (=" << NFreq << ") -> exit 9" << endl; | 
|---|
| 84 | return 9; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | double tet0 = Angle(Theta0Degre,Angle::Degree).ToRadian(); | 
|---|
| 88 | double phi0 = Angle(Phi0Degre,Angle::Degree).ToRadian(); | 
|---|
| 89 | double dtet = Angle(ThetaSizeDegre,Angle::Degree).ToRadian()/(double)NTheta; | 
|---|
| 90 | double dphi = Angle(PhiSizeDegre,Angle::Degree).ToRadian()/(double)NPhi; | 
|---|
| 91 |  | 
|---|
| 92 | TArray<r_4> ocube(NPhi,NTheta,NFreq); | 
|---|
| 93 | double mjd2000 = MJDfrDate(1,1,2000);   // Modified Julian Date pour 1 Janvier 2000 | 
|---|
| 94 |  | 
|---|
| 95 | cout << "gsm2cube[1] Loop over input GSM spherical maps ... " << endl; | 
|---|
| 96 |  | 
|---|
| 97 | for(sa_size_t kf=0; kf<NFreq; kf++) { | 
|---|
| 98 | char mapname[512]; | 
|---|
| 99 | sprintf(mapname,"%s_%d.ppf",inpath.c_str(),(int)(kf+numapstart)); | 
|---|
| 100 | cout << kf << "- Reading GSM map from file " << mapname << " ... " ; | 
|---|
| 101 | PInPersist pin(mapname); | 
|---|
| 102 | SphereHEALPix<r_4> gsm; | 
|---|
| 103 | pin >> gsm; | 
|---|
| 104 | cout << " Freq=" << gsm.Info()["FMHz"] << " MHz " << endl; | 
|---|
| 105 | for (sa_size_t j=0; j<ocube.SizeY(); j++)  { | 
|---|
| 106 | for (sa_size_t i=0; i<ocube.SizeX(); i++)  { | 
|---|
| 107 | double theta = j*dtet+tet0; | 
|---|
| 108 | double phi = i*dphi+phi0; | 
|---|
| 109 | double ra, dec;  // Angle horaire (right ascension) [0...24], dec [-90 90] | 
|---|
| 110 | ra=Angle(phi).ToDegree()/360.*24.; | 
|---|
| 111 | dec=90-Angle(theta).ToDegree(); | 
|---|
| 112 | double glong, glat;  // Longitude et latitude galactique - en degres [0...360], [-90...90] | 
|---|
| 113 | EqtoGal(mjd2000,ra,dec,&glong,&glat); | 
|---|
| 114 | phi=Angle(glong,Angle::Degree).ToRadian(); | 
|---|
| 115 | theta=Angle(90-glat,Angle::Degree).ToRadian(); | 
|---|
| 116 | ocube(i,j,kf)=gsm(theta,phi); | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | double mean, sigma; | 
|---|
| 122 | MeanSigma(ocube, mean, sigma); | 
|---|
| 123 | cout << "gsm2cube[2] ocube : Mean=" << mean << " Sigma=" << sigma << " Sizes: " << endl; | 
|---|
| 124 | ocube.Show(); | 
|---|
| 125 |  | 
|---|
| 126 |  | 
|---|
| 127 | // On sauve le cube de sortie | 
|---|
| 128 | { | 
|---|
| 129 | cout << " gsm2cube[3]: Saving output cube to -> " << outname << endl; | 
|---|
| 130 | POutPersist poc(outname); | 
|---|
| 131 | poc << ocube; | 
|---|
| 132 | } | 
|---|
| 133 | rc = 0; | 
|---|
| 134 | } | 
|---|
| 135 | catch (PThrowable& exc) { | 
|---|
| 136 | cerr << " gsm2cube.cc catched Exception " << exc.Msg() << endl; | 
|---|
| 137 | rc = 77; | 
|---|
| 138 | } | 
|---|
| 139 | catch (std::exception& sex) { | 
|---|
| 140 | cerr << "\n gsm2cube.cc std::exception :" | 
|---|
| 141 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 142 | << sex.what() << endl; | 
|---|
| 143 | } | 
|---|
| 144 | catch (...) { | 
|---|
| 145 | cerr << " gsm2cube.cc catched unknown (...) exception  " << endl; | 
|---|
| 146 | rc = 78; | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 149 | cout << ">>>> gsm2cube ------- FIN ----------- Rc=" << rc << endl; | 
|---|
| 150 | return rc; | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|