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

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

Sophie: adding doc for Doxy doc

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