source: Sophya/trunk/SophyaProg/PrgMap/cl2map.cc@ 1441

Last change on this file since 1441 was 1441, checked in by ansari, 25 years ago

documentation PrgUtil (fichiers .cc) pour doxygen - Reza 14/3/2001

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