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

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

Ajout de classes deleguees PPersist et correction integration - Sophie 29/11/99

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