source: Sophya/trunk/SophyaProg/PMixer/tgsky.cc@ 931

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

Sophie: adapt to new class MapOperations

File size: 3.2 KB
RevLine 
[931]1#include "pmixer.h"
2#include "mapoperation.h"
[761]3
[928]4/*! \ingroup PMixer
[931]5 * \file tgsky.cc
[928]6 * \brief \b PROGRAM \b tgsky <BR>
7 * \l Program which generates different types of random skies
8 */
[931]9// ------------- Main program --------------
[761]10
11int main(int narg, char* arg[])
12{
13 double teta,phi;
14 double gmoy=0., gsig=0.;
15
[809]16 SophyaInit();
[761]17 InitTim(); // Initializing the CPU timer
18 if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) ) {
19 cout << " tgsky : Generation of random skies " << endl;
20 cout << " Usage: tgsky NSide TypSky Params FitsFileName [PPFName] " << endl;
21 cout << " - TypSky = 0 Params= m,sig , Gaussian(m,sig) " << endl;
22 cout << " - TypSky = 1 Params= m,sig , OOFNoise(sig) + m" << endl;
23 cout << " - TypSky = 2 Params= K,a,b,m K*cos(a*teta)*sin(b*phi)+m" << endl;
[905]24 cout << " - TypSky = 3 Params= theta,phi DIPOLE" << endl;
[761]25 exit(0);
26 }
27
28 int ns = atoi(arg[1]);
[856]29 SphereHEALPix<float> sph(ns);
[761]30
[856]31 cout << "Filling SphereHEALPix<float> NSide= " << ns
[761]32 << " NPixels= " << sph.NbPixels() << endl;
33
34 int typ = atoi(arg[2]);
35 double m,s,a,b,K;
[905]36 double Theta,Phi;
37 Theta = 0.;
38 Phi = 0.;
[761]39 m = 0.;
40 s = 1.;
41 a = b = 1.;
42 K = 1.;
[905]43 if ((typ < 0) || (typ > 3)) typ = 0;
[761]44 if (typ < 2) {
45 sscanf(arg[3],"%lg,%lg",&m,&s);
46 cout << " TypSky= " << typ << " m= " << m << " sig= " << s << endl;
47 if (typ == 1) cout << " ---> OOFNoise() " << endl;
48 else cout << " ---> NoiseGenerator() " << endl;
49 }
[905]50 else if(typ==2) {
[761]51 sscanf(arg[3],"%lg,%lg,%lg,%lg",&K,&a,&b,&m);
52 cout << " TypSky= " << typ << " K= " << m << " a= " << a << " b="
53 << b << " m= " << m << endl;
54 cout << " ---> K * cos(a*teta) * sin(b*teta) + m" << endl;
55 }
[905]56 else if(typ==3) {
57 sscanf(arg[3],"%lg,%lg",&Theta,&Phi);
58 cout << " TypSky= " << typ << " Theta= " << Theta << " phi= " << Phi ;
59 cout << " ---> DIPOLE " << endl;
60 }
[761]61
62 PrtTim("End of Init ");
63
64 if (typ == 2) {
65 for (int j=0;j<sph.NbPixels();j++) {
66 sph.PixThetaPhi(j,teta,phi);
67 sph(j)= K * cos(a*teta)*sin(b*phi) + m;
68 }
69 }
[905]70 else if(typ==3)
71 {
72 UnitVector vd(Theta,Phi);
73 UnitVector vc(Theta,Phi);
74 for(int i=0; i<sph.NbPixels(); i++)
75 {
76 double Thetar,Phir;
77 sph.PixThetaPhi(i,Thetar,Phir);
78 vc.SetThetaPhi(Thetar, Phir);
79 sph(i) += vd.Psc(vc);
80 }
81 }
82 else{
[761]83 NoiseGenerator * ng;
84 if (typ == 0) ng = new NoiseGenerator(s);
85 else ng = new OOFNoise(s);
86 for (int j=0;j<sph.NbPixels();j++) sph(j) = ng->Noise()+m;
87 delete ng;
88 }
89 PrtTim("End of Fill ");
90
91 // Computing mean and sigma on the sphere
[931]92 MeanSig(sph.DataBlock(), gmoy, gsig);
[856]93 cout << "SphereHEALPix<float> Mean= " << gmoy << " Sigma = " << gsig << endl;
[761]94 PrtTim("End of Mean-Sig ");
95
96 if (narg > 5) {
97 POutPersist s(arg[5]);
[856]98 FIO_SphereHEALPix<float> fiog(&sph) ;
[761]99 fiog.Write(s);
[856]100 cout << "SphereHEALPix<float> written to POutPersist file"
[761]101 << (string)(arg[5]) << endl;
102 PrtTim("End of WritePPF ");
103 }
104
105
106
107 FitsIoServer fios;
108 fios.save(sph, arg[4]);
[856]109 cout << "SphereHEALPix<float> written to FITS file " << (string)(arg[4]) << endl;
[761]110 PrtTim("End of WriteFITS ");
111
112 cout << " ============ End of tgsky program ======== " << endl;
113 return 0;
114}
115
Note: See TracBrowser for help on using the repository browser.