source: Sophya/trunk/SophyaProg/PMixer/tgrsr.cc@ 930

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

Sophie: adapt to new MapOperations class

File size: 4.3 KB
RevLine 
[930]1#include "pmixer.h"
[761]2
[930]3/*!\ingroup PMixer
4 * \file tgrsr.cc
[928]5 * \brief \b PROGRAM \b tgrsr <BR>
[930]6 * Program to generate different type of RadSpectra
7 * and SpectralResponse in the form of RadSpectraVec and SpecRespVec
8 * in FITS format
9 */
[928]10
[761]11
12// ------------- Main program --------------
13int main(int narg, char* arg[])
14{
[809]15 SophyaInit();
[761]16 InitTim(); // Initializing the CPU timer
17
18 if ((narg < 5) || ((narg>1) && (strcmp(arg[1],"-h") == 0)) ) {
19 cout << " tgrsr : Generation of RadSpectraVec and SpecRespVec in FITS " << endl;
20 cout << " Usage: tgrsr 0/1 Params NPoints FitsFileName [ImageR4FITSName] [ppfname] " << endl;
21 cout << " 0 -> GaussianFilter T = A exp(((nu-nu0)/dnu)^2" << endl;
22 cout << " Params : A,Nu0,DNu,MinFreq,MaxFreq " << endl;
23 cout << " 1 -> PowerLawSpectra f = a ((nu-nu0)/dnu)^b " << endl;
24 cout << " Params : A,Nu0,dnu,b,MinFreq,MaxFreq " << endl;
25 exit(0);
26 }
27
28 int typ = 0;
29 typ = atoi(arg[1]);
30 int k, npt = 100;
31 npt = atoi(arg[3]);
32 if (npt < 5) npt = 5;
33 cout << " ---- tgrsr/Info: Type= " << typ << " NPoints= " << npt << endl;
34 Matrix mtx(2, npt);
35 ImageR4 img(npt, 2);
36
37 char buff[256];
38 if (typ == 0) { // Generation de SpecRespVec from GaussianFilter
39 double a,nu0,dnu,fmin,fmax;
40 a = 1.0;
41 nu0 = 143.;
42 dnu = 10.;
43 fmin = 10.;
44 fmax = 1000.;
45 sscanf(arg[2],"%lg,%lg,%lg,%lg,%lg",&a,&nu0,&dnu,&fmin,&fmax);
46 cout << " GaussianFilter T = A exp(((nu-nu0)/dnu)^2" << endl;
47 sprintf(buff,"A=%g Nu0=%g DNu=%g FMin=%g FMax=%g",
48 a,nu0,dnu,fmin,fmax);
49 cout << "Decoded params: " << (string)buff << endl;
50 GaussianFilter sr(nu0, dnu, a, fmin, fmax);
51 cout << sr << endl;
52 cout << " Creating SpecRespVec() ... " << endl;
53 Vector v1(10);
54 Vector v2(10);
55 SpecRespVec srv(v1, v2, fmin, fmax);
56 Vector & nu = srv.getNuVec();
57 Vector & tnu = srv.getTNuVec();
58 nu.ReSize(npt);
59 tnu.ReSize(npt);
60 double freq;
61 double dfreq = (fmax-fmin)/(npt-3);
62 for(k=0; k<npt; k++) {
63 freq = fmin+(k-1)*dfreq;
64 nu(k) = freq;
65 tnu(k) = sr.transmission(freq);
66 // if ((k>10) && (k<25)) cout << " DBG - K = " << k <<
67 // " Nu= " << nu(k) << " Tnu= " << tnu(k) << endl;
68 mtx(0,k) = nu(k);
69 mtx(1,k) = tnu(k);
70 img(k,0) = nu(k);
71 img(k,1) = tnu(k);
72 }
73 if ((typ == 0) && (narg > 6)) { // Writing to ppf file
74 cout << "writing SpecRespVec(" << npt << ") to PPF file: "
75 << (string)(arg[6]) << endl;
76 cout << sr ;
77 cout << srv ;
78 {
79 POutPersist pos(arg[6]);
80 pos << srv;
81 }
82 PrtTim("End of ImageR4->PPF ");
83 }
84
85 }
86 else { // Generation de RadSpectraVec from PowerLawSpectra
87 double a,nu0,dnu,b,fmin,fmax;
88 a = 1.0;
89 nu0 = 143.;
90 b = 0.;
91 dnu = 10.;
92 fmin = 10.;
93 fmax = 1000.;
94 sscanf(arg[2],"%lg,%lg,%lg,%lg,%lg,%lg",&a,&nu0,&dnu,&b,&fmin,&fmax);
95 cout << " PowerLawSpectra f = a ((nu-nu0)/dnu)^b " << endl;
96 sprintf(buff,"A=%g Nu0=%g DNu=%g B=%g FMin=%g FMax=%g",
97 a,nu0,dnu,b,fmin,fmax);
98 cout << "Decoded params: " << (string)buff << endl;
99 PowerLawSpectra rs(a,b, nu0, dnu, fmin, fmax);
100 cout << rs << endl;
101 cout << " Creating RadSpectraVec() ... " << endl;
102 Vector v1(10);
103 Vector v2(10);
104 RadSpectraVec rsv(v1, v2, fmin, fmax);
105 Vector & nu = rsv.getNuVec();
106 Vector & fnu = rsv.getFNuVec();
107 nu.ReSize(npt);
108 fnu.ReSize(npt);
109 double freq;
110 double dfreq = (fmax-fmin)/(npt-3);
111 for(k=0; k<npt; k++) {
112 freq = fmin+(k-1)*dfreq;
113 nu(k) = freq;
114 fnu(k) = rs.flux(freq);
115 // if ((k>10) && (k<25)) cout << " DBG2 - K = " << k <<
116 // " Nu= " << nu(k) << " Fnu= " << fnu(k) << endl;
117 mtx(0,k) = nu(k);
118 mtx(1,k) = fnu(k);
119 img(k,0) = nu(k);
120 img(k,1) = fnu(k);
121 }
122 }
123
124 PrtTim("End of filling ");
125
126 FitsIoServer fios;
127 cout << "\n Writing Matrix NRows= " << mtx.NRows() << " NCols= "
128 << mtx.NCols() << " to FITS file: " << (string)(arg[4]) << endl;
129 fios.save(mtx, arg[4]);
130 PrtTim("End of Matrix->FITS ");
131
132 if (narg > 5) { // Writing ImageR4 fo FITS file
133 cout << "wrting ImageR4(" << npt << ", 2) to FITS file: "
134 << (string)(arg[5]) << endl;
135 fios.save(img, arg[5]);
136 PrtTim("End of ImageR4->FITS ");
137 }
138 cout << " ============ End of tgrsr program ======== " << endl;
139 return 0;
140}
Note: See TracBrowser for help on using the repository browser.