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

Last change on this file since 2437 was 2322, checked in by cmv, 23 years ago
  • passage xxstream.h en xxstream
  • compile avec gcc_3.2, gcc_2.96 et cxx En 3.2 le seek from ::end semble marcher (voir Eval/COS/pbseekios.cc)

rz+cmv 11/2/2003

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