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