| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [1427] | 2 | #include "machdefs.h"    // Definitions specifiques SOPHYA | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include <math.h> | 
|---|
| [2322] | 5 | #include <iostream> | 
|---|
| [1427] | 6 |  | 
|---|
|  | 7 | #include "nbmath.h" | 
|---|
|  | 8 | #include "timing.h" | 
|---|
|  | 9 |  | 
|---|
|  | 10 | #include "array.h" | 
|---|
|  | 11 | #include "skymap.h" | 
|---|
|  | 12 | #include "samba.h" | 
|---|
|  | 13 | #include "sambainit.h" | 
|---|
|  | 14 | #include "fitsspherehealpix.h" | 
|---|
|  | 15 | #include "fitstarray.h" | 
|---|
|  | 16 |  | 
|---|
| [3613] | 17 | #include "randr48.h" | 
|---|
|  | 18 |  | 
|---|
| [1441] | 19 | /*! | 
|---|
| [1626] | 20 | \defgroup PrgMap PrgMap module | 
|---|
|  | 21 | This module contains simple programs to perform various tasks | 
|---|
|  | 22 | on spherical maps. | 
|---|
| [3091] | 23 | <UL> | 
|---|
|  | 24 | <LI> prjsmap : Molleweide and sinus projection of sky maps (prjsmap.cc) | 
|---|
|  | 25 | <LI> map2cl : Computes power spectra (C(l)) on spherical maps (map2cl.cc) | 
|---|
|  | 26 | <LI> cl2map : generates spherical maps from power spectra (C(l)) (cl2map.cc) | 
|---|
|  | 27 | </UL> | 
|---|
| [1626] | 28 | */ | 
|---|
|  | 29 |  | 
|---|
|  | 30 | /*! | 
|---|
| [1607] | 31 | \ingroup PrgMap | 
|---|
| [1441] | 32 | \file cl2map.cc | 
|---|
|  | 33 | \brief \b cl2map: generates spherical maps from power spectra (C(l)) | 
|---|
| [1427] | 34 |  | 
|---|
| [1441] | 35 | \verbatim | 
|---|
| [1427] | 36 |  | 
|---|
| [1441] | 37 | csh> cl2map -h | 
|---|
|  | 38 | SOPHYA Version  1.1 Revision 0 (V_Fev2001) -- Mar  9 2001 15:45:31 cxx | 
|---|
|  | 39 |  | 
|---|
|  | 40 | cl2map : Spherical harmonics synthesis - Power spectrum C_l -> HEALPix map | 
|---|
|  | 41 | Usage: cl2map [-float/-r4] [-msph pixp] [-beam fwhm] | 
|---|
|  | 42 | [-fitsin] [-fitsout] [-autoinirand] InFileName OutFileName | 
|---|
|  | 43 | -float (-r4): single precision C_l and map (default = double) | 
|---|
|  | 44 | -msph pix: Spherical map pixelization parameter | 
|---|
|  | 45 | nside=2^n for HEALPix - default=128 | 
|---|
|  | 46 | lmax = 2^n  default=128 | 
|---|
|  | 47 | -beam fwhm : Beam moothing (in l-space) FWHM in arcmin, default=0 | 
|---|
|  | 48 | -fitsout: Select the FITS format for the output map (default PPF format) | 
|---|
|  | 49 | -fitsin : Select the FITS format for the input vector (default PPF format) | 
|---|
|  | 50 | -autoinirand : Automtatic random number generator initialization | 
|---|
|  | 51 | InFileName : Input file name containing the C_l vector | 
|---|
|  | 52 | OutFileName : Output file name (HEALPix map) | 
|---|
|  | 53 |  | 
|---|
|  | 54 | \endverbatim | 
|---|
|  | 55 | */ | 
|---|
|  | 56 |  | 
|---|
|  | 57 |  | 
|---|
| [1427] | 58 | /* Nouvelle-Fonction */ | 
|---|
|  | 59 | void Usage(bool fgerr) | 
|---|
|  | 60 | { | 
|---|
|  | 61 | cout << endl; | 
|---|
|  | 62 | if (fgerr) { | 
|---|
|  | 63 | cout << " cl2map : Argument Error ! cl2map -h for usage " << endl; | 
|---|
|  | 64 | exit(1); | 
|---|
|  | 65 | } | 
|---|
|  | 66 | else { | 
|---|
|  | 67 | cout << " cl2map : Spherical harmonics synthesis - Power spectrum C_l -> HEALPix map \n" | 
|---|
|  | 68 | << " Usage: cl2map [-float/-r4] [-msph pixp] [-beam fwhm] \n" | 
|---|
| [1430] | 69 | << "        [-fitsin] [-fitsout] [-autoinirand] InFileName OutFileName \n" | 
|---|
| [1427] | 70 | << "   -float (-r4): single precision C_l and map (default = double) \n" | 
|---|
|  | 71 | << "   -msph pix: Spherical map pixelization parameter \n" | 
|---|
|  | 72 | << "              nside=2^n for HEALPix - default=128 \n" | 
|---|
|  | 73 | << "                lmax = 2^n  default=128 \n" | 
|---|
|  | 74 | << "   -beam fwhm : Beam moothing (in l-space) FWHM in arcmin, default=0 \n" | 
|---|
|  | 75 | << "   -fitsout: Select the FITS format for the output map (default PPF format) \n" | 
|---|
|  | 76 | << "   -fitsin : Select the FITS format for the input vector (default PPF format) \n" | 
|---|
|  | 77 | << "   -autoinirand : Automtatic random number generator initialization \n" | 
|---|
|  | 78 | << "   InFileName : Input file name containing the C_l vector \n" | 
|---|
|  | 79 | << "   OutFileName : Output file name (HEALPix map) \n" << endl; | 
|---|
|  | 80 | exit(0); | 
|---|
|  | 81 | } | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | /* Nouvelle-Classe */ | 
|---|
|  | 85 | template <class T> | 
|---|
|  | 86 | class _Cl2Map { | 
|---|
|  | 87 | public : | 
|---|
|  | 88 | static void BuildMap(string & infile, string & outfile, int msph, double beam, | 
|---|
| [3512] | 89 | bool fgfitsin, bool fgfitsout, bool fgair) | 
|---|
| [1427] | 90 | { | 
|---|
|  | 91 | double deg2rad =  M_PI/180.; | 
|---|
|  | 92 | double minute2rad =  M_PI/(180.*60.); | 
|---|
|  | 93 |  | 
|---|
|  | 94 | TArray<T> cla; | 
|---|
|  | 95 | SphereHEALPix<T> sph; | 
|---|
|  | 96 | if (fgfitsin) { | 
|---|
|  | 97 | cout << "--- Reading Input FITS file " << infile << endl; | 
|---|
|  | 98 | FitsInFile fii(infile); | 
|---|
|  | 99 | fii >> cla; | 
|---|
|  | 100 | } | 
|---|
|  | 101 | else { | 
|---|
|  | 102 | cout << "--- Reading Input PPF file " << infile << endl; | 
|---|
|  | 103 | PInPersist ppi(infile); | 
|---|
|  | 104 | ppi >> cla; | 
|---|
|  | 105 | } | 
|---|
|  | 106 | TVector<T> clvec(cla); | 
|---|
|  | 107 | cout << " Input vector : " ; | 
|---|
|  | 108 | clvec.Show(); | 
|---|
|  | 109 | T min, max; | 
|---|
|  | 110 | double mean, sigma; | 
|---|
|  | 111 | clvec.MinMax(min, max); | 
|---|
|  | 112 | MeanSigma(clvec, mean, sigma); | 
|---|
|  | 113 | cout << " C_l.Min= " << min << " C_l.Max= " << max | 
|---|
|  | 114 | << " C_l.Mean= " << mean << " C_l.Sigma= " << sigma << endl; | 
|---|
|  | 115 |  | 
|---|
|  | 116 | cout << "--- Calling  GenerateFromCl() (beam= " << beam | 
|---|
|  | 117 | << "' msph= " << msph << ") beam=" << beam*minute2rad << " rad" << endl; | 
|---|
|  | 118 | // on cree la carte | 
|---|
| [3613] | 119 | ThSDR48RandGen rg; | 
|---|
| [3512] | 120 | if (fgair) { | 
|---|
|  | 121 | cout << " Setting random number generator seed (using time) " << endl; | 
|---|
|  | 122 | rg.AutoInit(); | 
|---|
|  | 123 | } | 
|---|
|  | 124 | SphericalTransformServer<T> sphtr(rg); | 
|---|
|  | 125 | sphtr.GenerateFromCl(sph, msph, clvec, beam); | 
|---|
| [1427] | 126 |  | 
|---|
|  | 127 | cout << " Output map : NbPixels= " <<  sph.NbPixels() << " NSide= " | 
|---|
|  | 128 | << sph.SizeIndex() << " Resolution= " | 
|---|
|  | 129 | << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl; | 
|---|
|  | 130 |  | 
|---|
|  | 131 | if (fgfitsout) { | 
|---|
| [1535] | 132 | cout << "--- Writing map to Output FITS file " << outfile << endl; | 
|---|
|  | 133 | string dum = "rm -f "; dum += outfile; system(dum.c_str()); | 
|---|
| [1841] | 134 | FitsOutFile fio(outfile, FitsFile::clear); | 
|---|
| [1427] | 135 | fio << sph; | 
|---|
|  | 136 | } | 
|---|
|  | 137 | else { | 
|---|
|  | 138 | cout << "--- Writing map to Output PPF file " << outfile << endl; | 
|---|
|  | 139 | POutPersist ppo(outfile); | 
|---|
|  | 140 | ppo << sph; | 
|---|
|  | 141 | } | 
|---|
|  | 142 | } | 
|---|
|  | 143 |  | 
|---|
|  | 144 | }; | 
|---|
|  | 145 |  | 
|---|
|  | 146 | /* Main-Program */ | 
|---|
|  | 147 | int main(int narg, char *arg[]) | 
|---|
|  | 148 | { | 
|---|
|  | 149 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false); | 
|---|
|  | 150 |  | 
|---|
|  | 151 | int msph = 128; | 
|---|
|  | 152 | double beam = 0.; | 
|---|
|  | 153 | string infile; | 
|---|
|  | 154 | string outfile; | 
|---|
|  | 155 | bool fgfitsin = false; | 
|---|
|  | 156 | bool fgfitsout = false; | 
|---|
|  | 157 | bool fginirand = false; | 
|---|
|  | 158 | bool fgr4 = false; | 
|---|
|  | 159 | cout << " cl2map : Decoding command line options ... " << endl; | 
|---|
|  | 160 |  | 
|---|
|  | 161 | int ko=1; | 
|---|
|  | 162 | for (int k=1; k<narg; k++)   { | 
|---|
|  | 163 | if (strcmp(arg[k], "-msph") == 0)  { | 
|---|
|  | 164 | if (k == narg-1) Usage(true);  // -msph est suivi d'un argument | 
|---|
|  | 165 | msph = atoi(arg[k+1]);  k++;       // k++ pour sauter au suivant | 
|---|
|  | 166 | } | 
|---|
|  | 167 | else if (strcmp(arg[k], "-beam") == 0)  { | 
|---|
|  | 168 | if (k == narg-1) Usage(true);  // -beam est suivi d'un argument | 
|---|
|  | 169 | beam = atof(arg[k+1]);  k++;       // k++ pour sauter au suivant | 
|---|
|  | 170 | } | 
|---|
|  | 171 | else if (strcmp(arg[k], "-fitsin") == 0) { | 
|---|
|  | 172 | fgfitsin = true; | 
|---|
|  | 173 | } | 
|---|
|  | 174 | else if (strcmp(arg[k], "-fitsout") == 0) { | 
|---|
|  | 175 | fgfitsout = true; | 
|---|
|  | 176 | } | 
|---|
|  | 177 | else if (strcmp(arg[k], "-autoinirand") == 0) { | 
|---|
|  | 178 | fginirand = true; | 
|---|
|  | 179 | } | 
|---|
|  | 180 | else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) { | 
|---|
|  | 181 | fgr4 = true; | 
|---|
|  | 182 | } | 
|---|
|  | 183 |  | 
|---|
|  | 184 | else { ko = k; break; }  // Debut des noms | 
|---|
|  | 185 | } | 
|---|
|  | 186 |  | 
|---|
| [1441] | 187 | if ((narg-ko) < 2)  Usage(true); | 
|---|
| [1427] | 188 | infile = arg[ko]; | 
|---|
|  | 189 | outfile = arg[ko+1]; | 
|---|
|  | 190 |  | 
|---|
|  | 191 | // Bloc try de gestion des exception | 
|---|
|  | 192 | try { | 
|---|
|  | 193 | InitTim(); | 
|---|
|  | 194 | SophyaInit(); | 
|---|
|  | 195 | if (fgr4) { | 
|---|
|  | 196 | cout << " Power spectrum C_l (r_4) --> SphereHEALPix<r_4> (float) " << endl; | 
|---|
| [3512] | 197 | _Cl2Map<r_4>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout, fginirand); | 
|---|
| [1427] | 198 | } | 
|---|
|  | 199 | else { | 
|---|
|  | 200 | cout << " Power spectrum C_l (r_8) --> SphereHEALPix<r_8> (double) " << endl; | 
|---|
| [3512] | 201 | _Cl2Map<r_8>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout, fginirand); | 
|---|
| [1427] | 202 | } | 
|---|
|  | 203 | } | 
|---|
|  | 204 | catch (PThrowable & exc) {   // Exceptions de SOPHYA | 
|---|
|  | 205 | cerr << " cl2map: Catched Exception " << (string)typeid(exc).name() | 
|---|
|  | 206 | << " - Msg= " << exc.Msg() << endl; | 
|---|
|  | 207 | } | 
|---|
|  | 208 | catch (...) {    // Autres Exceptions | 
|---|
|  | 209 | cerr << " cl2map: some other exception was caught ! " << endl; | 
|---|
|  | 210 | } | 
|---|
|  | 211 |  | 
|---|
|  | 212 | PrtTim("End of cl2map "); | 
|---|
|  | 213 | return(0); | 
|---|
|  | 214 | } | 
|---|
|  | 215 |  | 
|---|
|  | 216 |  | 
|---|
|  | 217 |  | 
|---|