1 | #include <typeinfo>
|
---|
2 | #include "sopnamsp.h"
|
---|
3 | #include "pmixer.h"
|
---|
4 |
|
---|
5 | /*!\ingroup PMixer
|
---|
6 | * \file tgrsr.cc
|
---|
7 | * \brief \b PROGRAM \b tgrsr <BR>
|
---|
8 | * Program to generate different type of RadSpectra
|
---|
9 | * and SpectralResponse in the form of RadSpectraVec and SpecRespVec
|
---|
10 | * in FITS format
|
---|
11 | */
|
---|
12 |
|
---|
13 |
|
---|
14 | // ------------- Main program --------------
|
---|
15 | int main(int narg, char* arg[])
|
---|
16 | {
|
---|
17 | #if !defined(SunOS) || !defined(__GNUG__)
|
---|
18 | // ca se plante sur Sun !
|
---|
19 | SophyaInit();
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | InitTim(); // Initializing the CPU timer
|
---|
23 |
|
---|
24 | if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) ) {
|
---|
25 | cout << " tgrsr : Generation of RadSpectraVec and SpecRespVec in FITS " << endl;
|
---|
26 | cout << " Usage: tgrsr 0/1 Params NPoints FitsFileName [ImageR4FITSName] [ppfname] " << endl;
|
---|
27 | cout << " 0 -> GaussianFilter T = A exp(((nu-nu0)/dnu)^2" << endl;
|
---|
28 | cout << " Params : A,Nu0,DNu,MinFreq,MaxFreq " << endl;
|
---|
29 | cout << " 1 -> PowerLawSpectra f = a ((nu-nu0)/dnu)^b " << endl;
|
---|
30 | cout << " Params : A,Nu0,dnu,b,MinFreq,MaxFreq " << endl;
|
---|
31 | exit(0);
|
---|
32 | }
|
---|
33 |
|
---|
34 | try {
|
---|
35 | int typ = 0;
|
---|
36 | typ = atoi(arg[1]);
|
---|
37 | int k, npt = 100;
|
---|
38 | npt = atoi(arg[3]);
|
---|
39 | if (npt < 5) npt = 5;
|
---|
40 | cout << " ---- tgrsr/Info: Type= " << typ << " NPoints= " << npt << endl;
|
---|
41 | Matrix mtx(2, npt);
|
---|
42 | ImageR4 img(npt, 2);
|
---|
43 |
|
---|
44 | char buff[256];
|
---|
45 | if (typ == 0) { // Generation de SpecRespVec from GaussianFilter
|
---|
46 | double a,nu0,dnu,fmin,fmax;
|
---|
47 | a = 1.0;
|
---|
48 | nu0 = 143.;
|
---|
49 | dnu = 10.;
|
---|
50 | fmin = 10.;
|
---|
51 | fmax = 1000.;
|
---|
52 | sscanf(arg[2],"%lg,%lg,%lg,%lg,%lg",&a,&nu0,&dnu,&fmin,&fmax);
|
---|
53 | cout << " GaussianFilter T = A exp(((nu-nu0)/dnu)^2" << endl;
|
---|
54 | sprintf(buff,"A=%g Nu0=%g DNu=%g FMin=%g FMax=%g",
|
---|
55 | a,nu0,dnu,fmin,fmax);
|
---|
56 | cout << "Decoded params: " << (string)buff << endl;
|
---|
57 | GaussianFilter sr(nu0, dnu, a, fmin, fmax);
|
---|
58 | cout << sr << endl;
|
---|
59 | cout << " Creating SpecRespVec() ... " << endl;
|
---|
60 | Vector v1(10);
|
---|
61 | Vector v2(10);
|
---|
62 | SpecRespVec srv(v1, v2, fmin, fmax);
|
---|
63 | Vector & nu = srv.getNuVec();
|
---|
64 | Vector & tnu = srv.getTNuVec();
|
---|
65 | nu.ReSize(npt);
|
---|
66 | tnu.ReSize(npt);
|
---|
67 | double freq;
|
---|
68 | double dfreq = (fmax-fmin)/(npt-3);
|
---|
69 | for(k=0; k<npt; k++) {
|
---|
70 | freq = fmin+(k-1)*dfreq;
|
---|
71 | nu(k) = freq;
|
---|
72 | tnu(k) = sr.transmission(freq);
|
---|
73 | // if ((k>10) && (k<25)) cout << " DBG - K = " << k <<
|
---|
74 | // " Nu= " << nu(k) << " Tnu= " << tnu(k) << endl;
|
---|
75 | mtx(0,k) = nu(k);
|
---|
76 | mtx(1,k) = tnu(k);
|
---|
77 | img(k,0) = nu(k);
|
---|
78 | img(k,1) = tnu(k);
|
---|
79 | }
|
---|
80 | if ((typ == 0) && (narg > 6)) { // Writing to ppf file
|
---|
81 | cout << "writing SpecRespVec(" << npt << ") to PPF file: "
|
---|
82 | << (string)(arg[6]) << endl;
|
---|
83 | cout << sr ;
|
---|
84 | cout << srv ;
|
---|
85 | {
|
---|
86 | POutPersist pos(arg[6]);
|
---|
87 | pos << srv;
|
---|
88 | }
|
---|
89 | PrtTim("End of ImageR4->PPF ");
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|
93 | else { // Generation de RadSpectraVec from PowerLawSpectra
|
---|
94 | double a,nu0,dnu,b,fmin,fmax;
|
---|
95 | a = 1.0;
|
---|
96 | nu0 = 143.;
|
---|
97 | b = 0.;
|
---|
98 | dnu = 10.;
|
---|
99 | fmin = 10.;
|
---|
100 | fmax = 1000.;
|
---|
101 | sscanf(arg[2],"%lg,%lg,%lg,%lg,%lg,%lg",&a,&nu0,&dnu,&b,&fmin,&fmax);
|
---|
102 | cout << " PowerLawSpectra f = a ((nu-nu0)/dnu)^b " << endl;
|
---|
103 | sprintf(buff,"A=%g Nu0=%g DNu=%g B=%g FMin=%g FMax=%g",
|
---|
104 | a,nu0,dnu,b,fmin,fmax);
|
---|
105 | cout << "Decoded params: " << (string)buff << endl;
|
---|
106 | PowerLawSpectra rs(a,b, nu0, dnu, fmin, fmax);
|
---|
107 | cout << rs << endl;
|
---|
108 | cout << " Creating RadSpectraVec() ... " << endl;
|
---|
109 | Vector v1(10);
|
---|
110 | Vector v2(10);
|
---|
111 | RadSpectraVec rsv(v1, v2, fmin, fmax);
|
---|
112 | Vector & nu = rsv.getNuVec();
|
---|
113 | Vector & fnu = rsv.getFNuVec();
|
---|
114 | nu.ReSize(npt);
|
---|
115 | fnu.ReSize(npt);
|
---|
116 | double freq;
|
---|
117 | double dfreq = (fmax-fmin)/(npt-3);
|
---|
118 | for(k=0; k<npt; k++) {
|
---|
119 | freq = fmin+(k-1)*dfreq;
|
---|
120 | nu(k) = freq;
|
---|
121 | fnu(k) = rs.flux(freq);
|
---|
122 | // if ((k>10) && (k<25)) cout << " DBG2 - K = " << k <<
|
---|
123 | // " Nu= " << nu(k) << " Fnu= " << fnu(k) << endl;
|
---|
124 | mtx(0,k) = nu(k);
|
---|
125 | mtx(1,k) = fnu(k);
|
---|
126 | img(k,0) = nu(k);
|
---|
127 | img(k,1) = fnu(k);
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | PrtTim("End of filling ");
|
---|
132 |
|
---|
133 | {
|
---|
134 | cout << "\n Writing Matrix NRows= " << mtx.NRows() << " NCols= "
|
---|
135 | << mtx.NCols() << " to FITS file: " << (string)(arg[4]) << endl;
|
---|
136 | FitsOutFile fios(arg[4]);
|
---|
137 | fios.firstImageOnPrimaryHeader(false); // use secondary header
|
---|
138 | DVList dvl;
|
---|
139 | if (typ == 0)
|
---|
140 | dvl["PDMTYPE"] = "FGRSPEC";
|
---|
141 | dvl.SetComment("PDMTYPE", "Planck Data Model Type");
|
---|
142 | dvl["SOPHYVER"] = SophyaVersion();
|
---|
143 | dvl.SetComment("SOPHYVER", "Sophya Version");
|
---|
144 | dvl["TGRSRKW"] = "Test Keyword from tgrsr.cc";
|
---|
145 | fios.DVListIntoPrimaryHeader(dvl);
|
---|
146 | fios << mtx ;
|
---|
147 | PrtTim("End of Matrix->FITS ");
|
---|
148 | }
|
---|
149 |
|
---|
150 | if (narg > 5) { // Writing ImageR4 fo FITS file
|
---|
151 | cout << "writing ImageR4(" << npt << ", 2) to FITS file: "
|
---|
152 | << (string)(arg[5]) << endl;
|
---|
153 | FitsOutFile fios(arg[5]);
|
---|
154 | fios.firstImageOnPrimaryHeader(true); // use primary header
|
---|
155 | fios << img ;
|
---|
156 | PrtTim("End of ImageR4->FITS ");
|
---|
157 | }
|
---|
158 | }
|
---|
159 | catch (PThrowable & exc) {
|
---|
160 | cerr << "tgrsr/Error Catched Exception " << (string)typeid(exc).name()
|
---|
161 | << " - Msg= " << exc.Msg() << endl;
|
---|
162 | }
|
---|
163 | catch (...) {
|
---|
164 | cerr << "tgrsr/Error some other exception was caught ! " << endl;
|
---|
165 | }
|
---|
166 |
|
---|
167 | cout << " ============ End of tgrsr program ======== " << endl;
|
---|
168 | return 0;
|
---|
169 | }
|
---|