source: Sophya/trunk/SophyaProg/Tests/tspm.cc@ 945

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

Adapatation a SphereHEALPix, correction tsttmatrix.cc tsttvector.cc - Reza 10/4/2000

File size: 3.7 KB
Line 
1#include <iostream.h>
2#include "skymapinit.h"
3#include "skymap.h"
4
5#include "tod.h"
6#include "timing.h"
7
8template <class T>
9void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
10{
11 gmoy=0.;
12 gsig = 0.;
13 double valok;
14 for(int k=0; k<map.NbPixels(); k++) {
15 valok = map(k);
16 gmoy += valok; gsig += valok*valok;
17 }
18 gmoy /= (double)map.NbPixels();
19 gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
20 if (gsig >= 0.) gsig = sqrt(gsig);
21}
22
23int main(int narg, char* arg[])
24{
25 double teta,phi;
26 double gmoy, gsig;
27
28 SophyaInit();
29 InitTim(); // Initializing the CPU timer
30 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
31 cout << " tspm [HEALPix_M=32] [M_TetaPhi=64] : Spherical Map Test " << endl;
32 exit(0);
33 }
34
35 int m=32;
36 if (narg >1) m = atoi(arg[1]);
37 cout << " ===== HEALPix Spherical Map Test M= " << m << endl;
38
39 SphereHEALPix<double> sph(m);
40
41 cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
42 for (int j=0;j<sph.NbPixels();j++)
43 {
44 sph.PixThetaPhi(j,teta,phi);
45 sph(j)= 0.2* cos(3.*teta)*sin(8*phi);
46 }
47 PrtTim("End of Fill ");
48
49 // Computing mean and sigma on the sphere
50 MeanSig(sph, gmoy, gsig);
51 cout << "SphereHEALPix<double> Mean= " << gmoy << " Sigma = " << gsig << endl;
52 PrtTim("End of Mean-Sig ");
53
54// Writing to a PPF file
55 {
56 POutPersist s("sphg.ppf");
57 FIO_SphereHEALPix<double> fiog(&sph) ;
58 fiog.Write(s);
59 cout << "SphereHEALPix<double> written to sphg.ppf " << endl;
60 }
61
62 // Reading from the file
63 {
64 FIO_SphereHEALPix<double> fiog("sphg.ppf");
65 SphereHEALPix<double> sph2 = fiog;
66 PrtTim("End of Write/Read ");
67
68 cout << " Spherical map from file sphg.ppf NPixels= " << sph2.NbPixels() << endl;
69
70 int ndiff = 0;
71 for(int k=0; k<sph2.NbPixels(); k++) {
72// if ((sph2(k)-sph(k)) > 1.e-49) {
73 if ( sph2(k) != sph(k) ) {
74 ndiff++;
75 if (ndiff < 20) cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
76 }
77 }
78 MeanSig(sph, gmoy, gsig);
79 cout << "SphMapFromFile Mean= " << gmoy << " Sigma = " << gsig << endl;
80 cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
81 PrtTim("End of Mean-Sig ");
82 }
83
84
85 int mt=64;
86 if (narg > 2) mt = atoi(arg[2]);
87 cout << "\n ===== ThetaPhi Spherical Map Test MT= " << mt << endl;
88
89 SphereThetaPhi<float> spht(m);
90
91 cout << "Filling spherical map NPixels= " << spht.NbPixels() << endl;
92 for (int j=0;j<spht.NbPixels();j++)
93 {
94 spht.PixThetaPhi(j,teta,phi);
95 spht(j)= 0.5* cos(5.*teta)*sin(10.*phi);
96 }
97 PrtTim("End of Fill ");
98
99 // Computing mean and sigma on the sphere
100 MeanSig(spht, gmoy, gsig);
101 cout << "SphereThetaPhi<float> Mean= " << gmoy << " Sigma = " << gsig << endl;
102 PrtTim("End of Mean-Sig ");
103
104// Writing to a PPF file
105 {
106 POutPersist s("spht.ppf");
107 FIO_SphereThetaPhi<float> fiog(spht) ;
108 fiog.Write(s);
109 cout << "SphereThetaPhi<float> written to spht.ppf " << endl;
110 }
111
112 // Reading from the file
113 {
114 FIO_SphereThetaPhi<float> fiog("spht.ppf");
115 SphereThetaPhi<float> sph2 = fiog;
116 PrtTim("End of Write/Read ");
117
118 cout << " Spherical map from file sph.ppf NPixels= " << sph2.NbPixels() << endl;
119
120 int ndiff = 0;
121 for(int k=0; k<sph2.NbPixels(); k++) {
122// if ((sph2(k)-sph(k)) > 1.e-49) {
123 if ( sph2(k) != spht(k) ) {
124 ndiff++;
125 if (ndiff < 20) cout << "!!!Diff: K= " << k << " SPH2= " << sph2(k) << " SPH= " << sph(k) << endl;
126 }
127 }
128 MeanSig(sph, gmoy, gsig);
129 cout << "SphMapFromFile Mean= " << gmoy << " Sigma = " << gsig << endl;
130 cout << " NDiff = " << ndiff << " (should be zero = 0) " << endl;
131 PrtTim("End of Mean-Sig ");
132 }
133
134 cout << " ===== Fin de TSPM_Test ======== " << endl;
135 return 0;
136}
Note: See TracBrowser for help on using the repository browser.