[761] | 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 | // 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 --------------
|
---|
| 24 | int 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] [ppfname] " << 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 | if ((typ == 0) && (narg > 6)) { // Writing to ppf file
|
---|
| 85 | cout << "writing SpecRespVec(" << npt << ") to PPF file: "
|
---|
| 86 | << (string)(arg[6]) << endl;
|
---|
| 87 | cout << sr ;
|
---|
| 88 | cout << srv ;
|
---|
| 89 | {
|
---|
| 90 | POutPersist pos(arg[6]);
|
---|
| 91 | pos << srv;
|
---|
| 92 | }
|
---|
| 93 | PrtTim("End of ImageR4->PPF ");
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | }
|
---|
| 97 | else { // Generation de RadSpectraVec from PowerLawSpectra
|
---|
| 98 | double a,nu0,dnu,b,fmin,fmax;
|
---|
| 99 | a = 1.0;
|
---|
| 100 | nu0 = 143.;
|
---|
| 101 | b = 0.;
|
---|
| 102 | dnu = 10.;
|
---|
| 103 | fmin = 10.;
|
---|
| 104 | fmax = 1000.;
|
---|
| 105 | sscanf(arg[2],"%lg,%lg,%lg,%lg,%lg,%lg",&a,&nu0,&dnu,&b,&fmin,&fmax);
|
---|
| 106 | cout << " PowerLawSpectra f = a ((nu-nu0)/dnu)^b " << endl;
|
---|
| 107 | sprintf(buff,"A=%g Nu0=%g DNu=%g B=%g FMin=%g FMax=%g",
|
---|
| 108 | a,nu0,dnu,b,fmin,fmax);
|
---|
| 109 | cout << "Decoded params: " << (string)buff << endl;
|
---|
| 110 | PowerLawSpectra rs(a,b, nu0, dnu, fmin, fmax);
|
---|
| 111 | cout << rs << endl;
|
---|
| 112 | cout << " Creating RadSpectraVec() ... " << endl;
|
---|
| 113 | Vector v1(10);
|
---|
| 114 | Vector v2(10);
|
---|
| 115 | RadSpectraVec rsv(v1, v2, fmin, fmax);
|
---|
| 116 | Vector & nu = rsv.getNuVec();
|
---|
| 117 | Vector & fnu = rsv.getFNuVec();
|
---|
| 118 | nu.ReSize(npt);
|
---|
| 119 | fnu.ReSize(npt);
|
---|
| 120 | double freq;
|
---|
| 121 | double dfreq = (fmax-fmin)/(npt-3);
|
---|
| 122 | for(k=0; k<npt; k++) {
|
---|
| 123 | freq = fmin+(k-1)*dfreq;
|
---|
| 124 | nu(k) = freq;
|
---|
| 125 | fnu(k) = rs.flux(freq);
|
---|
| 126 | // if ((k>10) && (k<25)) cout << " DBG2 - K = " << k <<
|
---|
| 127 | // " Nu= " << nu(k) << " Fnu= " << fnu(k) << endl;
|
---|
| 128 | mtx(0,k) = nu(k);
|
---|
| 129 | mtx(1,k) = fnu(k);
|
---|
| 130 | img(k,0) = nu(k);
|
---|
| 131 | img(k,1) = fnu(k);
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | PrtTim("End of filling ");
|
---|
| 136 |
|
---|
| 137 | FitsIoServer fios;
|
---|
| 138 | cout << "\n Writing Matrix NRows= " << mtx.NRows() << " NCols= "
|
---|
| 139 | << mtx.NCols() << " to FITS file: " << (string)(arg[4]) << endl;
|
---|
| 140 | fios.save(mtx, arg[4]);
|
---|
| 141 | PrtTim("End of Matrix->FITS ");
|
---|
| 142 |
|
---|
| 143 | if (narg > 5) { // Writing ImageR4 fo FITS file
|
---|
| 144 | cout << "wrting ImageR4(" << npt << ", 2) to FITS file: "
|
---|
| 145 | << (string)(arg[5]) << endl;
|
---|
| 146 | fios.save(img, arg[5]);
|
---|
| 147 | PrtTim("End of ImageR4->FITS ");
|
---|
| 148 | }
|
---|
| 149 | cout << " ============ End of tgrsr program ======== " << endl;
|
---|
| 150 | return 0;
|
---|
| 151 | }
|
---|