[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[668] | 3 | // $Id: radspecvector.cc,v 1.4 1999-11-29 14:16:06 ansari Exp $
|
---|
[601] | 4 | //
|
---|
| 5 | // Description:
|
---|
| 6 | // Aim of the class: To give the energy density
|
---|
| 7 | // The unity used here is W/m^2/Hz/sr
|
---|
| 8 | //
|
---|
| 9 | // History (add to end):
|
---|
| 10 | // Sophie Oct, 1999 - creation
|
---|
| 11 | //
|
---|
| 12 | //------------------------------------------------------------------------
|
---|
| 13 |
|
---|
| 14 | //---------------
|
---|
| 15 | // C++ Headers --
|
---|
| 16 | //---------------
|
---|
| 17 | #include "machdefs.h"
|
---|
| 18 | #include <iostream.h>
|
---|
| 19 | #include <math.h>
|
---|
| 20 | // #include <typeinfo>
|
---|
| 21 |
|
---|
| 22 | #include "radspecvector.h"
|
---|
| 23 | #include "pexceptions.h"
|
---|
| 24 |
|
---|
| 25 | //----------------
|
---|
| 26 | // Constructor --
|
---|
| 27 | //----------------
|
---|
[668] | 28 | RadSpectraVec::RadSpectraVec()
|
---|
| 29 | {
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[601] | 32 | RadSpectraVec::RadSpectraVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
| 33 | : RadSpectra(numin, numax)
|
---|
| 34 | {
|
---|
| 35 | if(nu.NElts() != fdenu.NElts())
|
---|
| 36 | throw SzMismatchError("RadSpectraVec::RadSpectraVec() - Non equal vector sizes");
|
---|
| 37 | _vecOfNu = nu;
|
---|
| 38 | _vecOfFDeNu = fdenu;
|
---|
| 39 | _numin = nu(0);
|
---|
| 40 | _numax = nu(nu.NElts()-1);
|
---|
[668] | 41 | _size = nu.NElts();
|
---|
[601] | 42 | if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | //--------------
|
---|
| 47 | // Destructor --
|
---|
| 48 | //--------------
|
---|
| 49 | RadSpectraVec::~RadSpectraVec()
|
---|
| 50 | {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // ---------------------------
|
---|
| 54 | // -- Function Definitions --
|
---|
| 55 | // ---------------------------
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | double
|
---|
| 61 | RadSpectraVec::flux(double nu) const
|
---|
| 62 | {
|
---|
| 63 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
---|
[610] | 64 | double value = 0.;
|
---|
[601] | 65 | int sizeVecOfNu = _vecOfNu.NElts();
|
---|
[610] | 66 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
---|
[601] | 67 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
| 68 |
|
---|
| 69 | for (int i=1; i<sizeVecOfNu; i++)
|
---|
| 70 | {
|
---|
[610] | 71 | if(nu < _vecOfNu(i))
|
---|
[601] | 72 | {
|
---|
| 73 | double up = _vecOfFDeNu(i) ;
|
---|
| 74 | double down = _vecOfFDeNu(i-1);
|
---|
| 75 | double xmin = _vecOfNu(i-1);
|
---|
| 76 | double xmax = _vecOfNu(i);
|
---|
| 77 | double a = ((up-down)/(xmax-xmin));
|
---|
| 78 | value = a*nu+(up-a*xmax);
|
---|
| 79 | return value;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[610] | 82 | return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
[601] | 83 | }
|
---|
| 84 |
|
---|
[668] | 85 | void
|
---|
| 86 | RadSpectraVec::WriteSelf(POutPersist& s)
|
---|
| 87 | {
|
---|
| 88 | s.PutI4(this->NbElts());
|
---|
| 89 | for (int i=0; i< this->NbElts(); i++)
|
---|
| 90 | {
|
---|
| 91 | s.PutR8(this->getNuVec(i));
|
---|
| 92 | s.PutR8(this->getFNuVec(i));
|
---|
| 93 | }
|
---|
| 94 | s.PutR8(this->minFreq());
|
---|
| 95 | s.PutR8(this->maxFreq());
|
---|
| 96 |
|
---|
| 97 | }
|
---|
[601] | 98 |
|
---|
| 99 | void
|
---|
[668] | 100 | RadSpectraVec::ReadSelf(PInPersist& s)
|
---|
| 101 | {
|
---|
| 102 | s.GetI4(_size);
|
---|
| 103 |
|
---|
| 104 | _vecOfNu.ReSize(_size);
|
---|
| 105 | _vecOfFDeNu.ReSize(_size);
|
---|
| 106 | for (int i=0; i< _size; i++)
|
---|
| 107 | {
|
---|
| 108 | s.GetR8(_vecOfNu(i));
|
---|
| 109 | s.GetR8(_vecOfFDeNu(i));
|
---|
| 110 | }
|
---|
| 111 | s.GetR8(_numin);
|
---|
| 112 | s.GetR8(_numax);
|
---|
| 113 | cout << "minFreq - maxFreq"<< endl;
|
---|
| 114 | cout << _numin<< "-" << _numax << endl;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | void
|
---|
[601] | 120 | RadSpectraVec::Print(ostream& os) const
|
---|
| 121 | {
|
---|
| 122 | // os << "RadSpectraVec::Print (" << typeid(*this).name()
|
---|
| 123 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 124 | os << "RadSpectraVec::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 125 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
---|
| 126 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
---|
| 127 |
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|