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

Last change on this file since 3570 was 3512, checked in by ansari, 17 years ago

Correction,adaptation suite modifSphericalTransformServer , Reza 08/08/2008

File size: 6.6 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h" // Definitions specifiques SOPHYA
3
4#include <math.h>
5#include <iostream>
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
17/*!
18 \defgroup PrgMap PrgMap module
19 This module contains simple programs to perform various tasks
20 on spherical maps.
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>
26*/
27
28/*!
29 \ingroup PrgMap
30 \file cl2map.cc
31 \brief \b cl2map: generates spherical maps from power spectra (C(l))
32
33 \verbatim
34
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
56/* Nouvelle-Fonction */
57void 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"
67 << " [-fitsin] [-fitsout] [-autoinirand] InFileName OutFileName \n"
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 */
83template <class T>
84class _Cl2Map {
85public :
86static void BuildMap(string & infile, string & outfile, int msph, double beam,
87 bool fgfitsin, bool fgfitsout, bool fgair)
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 RandomGenerator rg;
118 if (fgair) {
119 cout << " Setting random number generator seed (using time) " << endl;
120 rg.AutoInit();
121 }
122 SphericalTransformServer<T> sphtr(rg);
123 sphtr.GenerateFromCl(sph, msph, clvec, beam);
124
125 cout << " Output map : NbPixels= " << sph.NbPixels() << " NSide= "
126 << sph.SizeIndex() << " Resolution= "
127 << sqrt(sph.PixSolAngle(0))/minute2rad << " Arcminutes " << endl;
128
129 if (fgfitsout) {
130 cout << "--- Writing map to Output FITS file " << outfile << endl;
131 string dum = "rm -f "; dum += outfile; system(dum.c_str());
132 FitsOutFile fio(outfile, FitsFile::clear);
133 fio << sph;
134 }
135 else {
136 cout << "--- Writing map to Output PPF file " << outfile << endl;
137 POutPersist ppo(outfile);
138 ppo << sph;
139 }
140}
141
142};
143
144/* Main-Program */
145int main(int narg, char *arg[])
146{
147 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
148
149 int msph = 128;
150 double beam = 0.;
151 string infile;
152 string outfile;
153 bool fgfitsin = false;
154 bool fgfitsout = false;
155 bool fginirand = false;
156 bool fgr4 = false;
157 cout << " cl2map : Decoding command line options ... " << endl;
158
159 int ko=1;
160 for (int k=1; k<narg; k++) {
161 if (strcmp(arg[k], "-msph") == 0) {
162 if (k == narg-1) Usage(true); // -msph est suivi d'un argument
163 msph = atoi(arg[k+1]); k++; // k++ pour sauter au suivant
164 }
165 else if (strcmp(arg[k], "-beam") == 0) {
166 if (k == narg-1) Usage(true); // -beam est suivi d'un argument
167 beam = atof(arg[k+1]); k++; // k++ pour sauter au suivant
168 }
169 else if (strcmp(arg[k], "-fitsin") == 0) {
170 fgfitsin = true;
171 }
172 else if (strcmp(arg[k], "-fitsout") == 0) {
173 fgfitsout = true;
174 }
175 else if (strcmp(arg[k], "-autoinirand") == 0) {
176 fginirand = true;
177 }
178 else if ((strcmp(arg[k], "-float") == 0) || (strcmp(arg[k], "-r4") == 0) ) {
179 fgr4 = true;
180 }
181
182 else { ko = k; break; } // Debut des noms
183 }
184
185 if ((narg-ko) < 2) Usage(true);
186 infile = arg[ko];
187 outfile = arg[ko+1];
188
189 // Bloc try de gestion des exception
190 try {
191 InitTim();
192 SophyaInit();
193 if (fgr4) {
194 cout << " Power spectrum C_l (r_4) --> SphereHEALPix<r_4> (float) " << endl;
195 _Cl2Map<r_4>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout, fginirand);
196 }
197 else {
198 cout << " Power spectrum C_l (r_8) --> SphereHEALPix<r_8> (double) " << endl;
199 _Cl2Map<r_8>::BuildMap(infile, outfile, msph, beam, fgfitsin, fgfitsout, fginirand);
200 }
201 }
202 catch (PThrowable & exc) { // Exceptions de SOPHYA
203 cerr << " cl2map: Catched Exception " << (string)typeid(exc).name()
204 << " - Msg= " << exc.Msg() << endl;
205 }
206 catch (...) { // Autres Exceptions
207 cerr << " cl2map: some other exception was caught ! " << endl;
208 }
209
210 PrtTim("End of cl2map ");
211 return(0);
212}
213
214
215
Note: See TracBrowser for help on using the repository browser.