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