source: Sophya/trunk/SophyaLib/SkyT/tgrsr.cc@ 611

Last change on this file since 611 was 611, checked in by ansari, 26 years ago

prog creation de RadSpectraVec et SpectralResponseVec en FITS - Reza 21/11/99

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