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

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

Ajout cl2map.cc et map2cl.cc (Synthese et decomposition en harm spherique) - Reza 1/3/2001

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