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