| [601] | 1 | //-------------------------------------------------------------------------- | 
|---|
|  | 2 | // File and Version Information: | 
|---|
| [669] | 3 | //      $Id: radspecvector.cc,v 1.5 1999-11-29 16:59:11 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); | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 | //-------------- | 
|---|
|  | 45 | // Destructor -- | 
|---|
|  | 46 | //-------------- | 
|---|
|  | 47 | RadSpectraVec::~RadSpectraVec() | 
|---|
|  | 48 | { | 
|---|
|  | 49 | } | 
|---|
|  | 50 |  | 
|---|
|  | 51 | //              --------------------------- | 
|---|
|  | 52 | //              --  Function Definitions -- | 
|---|
|  | 53 | //              --------------------------- | 
|---|
|  | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 |  | 
|---|
|  | 57 |  | 
|---|
|  | 58 | double | 
|---|
|  | 59 | RadSpectraVec::flux(double nu) const | 
|---|
|  | 60 | { | 
|---|
|  | 61 | if ( (nu < _numin) || (nu > _numax) ) return(0.); | 
|---|
| [610] | 62 | double value = 0.; | 
|---|
| [601] | 63 | int sizeVecOfNu = _vecOfNu.NElts(); | 
|---|
| [610] | 64 | if(nu <=  _vecOfNu(0)) return _vecOfFDeNu(0); | 
|---|
| [601] | 65 | if(nu >=  _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1); | 
|---|
|  | 66 |  | 
|---|
|  | 67 | for (int i=1; i<sizeVecOfNu; i++) | 
|---|
|  | 68 | { | 
|---|
| [610] | 69 | if(nu < _vecOfNu(i)) | 
|---|
| [601] | 70 | { | 
|---|
|  | 71 | double up = _vecOfFDeNu(i) ; | 
|---|
|  | 72 | double down = _vecOfFDeNu(i-1); | 
|---|
|  | 73 | double xmin = _vecOfNu(i-1); | 
|---|
|  | 74 | double xmax = _vecOfNu(i); | 
|---|
|  | 75 | double a = ((up-down)/(xmax-xmin)); | 
|---|
|  | 76 | value = a*nu+(up-a*xmax); | 
|---|
|  | 77 | return value; | 
|---|
|  | 78 | } | 
|---|
|  | 79 | } | 
|---|
| [610] | 80 | return _vecOfFDeNu(sizeVecOfNu-1); | 
|---|
| [601] | 81 | } | 
|---|
|  | 82 |  | 
|---|
| [669] | 83 |  | 
|---|
|  | 84 |  | 
|---|
| [668] | 85 | void | 
|---|
| [669] | 86 | RadSpectraVec::Print(ostream& os) const | 
|---|
|  | 87 | { | 
|---|
|  | 88 | //  os << "RadSpectraVec::Print (" << typeid(*this).name() | 
|---|
|  | 89 | //     << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; | 
|---|
|  | 90 | os << "RadSpectraVec::Print  - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl; | 
|---|
|  | 91 | os << "MeanFreq= " << meanFreq() << "  Emission= " << flux(meanFreq()) << endl; | 
|---|
|  | 92 | os << "PeakFreq= " << peakFreq() << "  Emission= " << flux(peakFreq()) << endl; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | /* | 
|---|
|  | 97 | void | 
|---|
| [668] | 98 | RadSpectraVec::WriteSelf(POutPersist& s) | 
|---|
|  | 99 | { | 
|---|
|  | 100 | s.PutI4(this->NbElts()); | 
|---|
|  | 101 | for (int i=0; i< this->NbElts(); i++) | 
|---|
|  | 102 | { | 
|---|
|  | 103 | s.PutR8(this->getNuVec(i)); | 
|---|
|  | 104 | s.PutR8(this->getFNuVec(i)); | 
|---|
|  | 105 | } | 
|---|
|  | 106 | s.PutR8(this->minFreq()); | 
|---|
|  | 107 | s.PutR8(this->maxFreq()); | 
|---|
|  | 108 |  | 
|---|
|  | 109 | } | 
|---|
| [601] | 110 |  | 
|---|
|  | 111 | void | 
|---|
| [668] | 112 | RadSpectraVec::ReadSelf(PInPersist& s) | 
|---|
|  | 113 | { | 
|---|
|  | 114 | s.GetI4(_size); | 
|---|
|  | 115 |  | 
|---|
|  | 116 | _vecOfNu.ReSize(_size); | 
|---|
|  | 117 | _vecOfFDeNu.ReSize(_size); | 
|---|
|  | 118 | for (int i=0; i< _size; i++) | 
|---|
|  | 119 | { | 
|---|
|  | 120 | s.GetR8(_vecOfNu(i)); | 
|---|
|  | 121 | s.GetR8(_vecOfFDeNu(i)); | 
|---|
|  | 122 | } | 
|---|
|  | 123 | s.GetR8(_numin); | 
|---|
|  | 124 | s.GetR8(_numax); | 
|---|
|  | 125 | cout << "minFreq - maxFreq"<< endl; | 
|---|
|  | 126 | cout <<    _numin<< "-" <<  _numax << endl; | 
|---|
|  | 127 | } | 
|---|
| [669] | 128 | */ | 
|---|
| [668] | 129 |  | 
|---|
|  | 130 |  | 
|---|