[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[668] | 3 | // $Id: specrespvector.cc,v 1.4 1999-11-29 14:16:09 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 "specrespvector.h"
|
---|
| 23 | #include "pexceptions.h"
|
---|
| 24 | //----------------
|
---|
| 25 | // Constructor --
|
---|
| 26 | //----------------
|
---|
[668] | 27 | SpecRespVec::SpecRespVec()
|
---|
| 28 | : SpectralResponse()
|
---|
| 29 | {
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[601] | 32 | SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
| 33 | : SpectralResponse(numin, numax)
|
---|
| 34 | {
|
---|
| 35 | if(nu.NElts() != fdenu.NElts())
|
---|
| 36 | throw SzMismatchError("SpecRespVec::SpecRespVec() - 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 | SpecRespVec::~SpecRespVec()
|
---|
| 50 | {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // ---------------------------
|
---|
| 54 | // -- Function Definitions --
|
---|
| 55 | // ---------------------------
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | double
|
---|
| 61 | SpecRespVec::transmission(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 | }
|
---|
| 82 | return value;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | void
|
---|
| 88 | SpecRespVec::Print(ostream& os) const
|
---|
| 89 | {
|
---|
| 90 |
|
---|
| 91 | // os << "SpecRespVec::Print (" << typeid(*this).name()
|
---|
| 92 | //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 93 | os << "SpecRespVec ::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 94 | os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
|
---|
| 95 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
---|
| 96 |
|
---|
| 97 | }
|
---|
[668] | 98 |
|
---|
| 99 |
|
---|
| 100 | void
|
---|
| 101 | ObjFileIO<SpecRespVec>::WriteSelf(POutPersist& s) const
|
---|
| 102 | {
|
---|
| 103 | if(dobj == NULL)
|
---|
| 104 | {
|
---|
| 105 | cout << " ObjFileIO<SpecRespVec>::WriteSelf:: dobj= null " << endl;
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | int_4 version, nothing;
|
---|
| 110 | version = 1;
|
---|
| 111 | nothing = 0; // Reserved for future use
|
---|
| 112 | s.PutI4(version);
|
---|
| 113 | s.PutI4(nothing);
|
---|
| 114 |
|
---|
| 115 | s.PutR8(dobj->minFreq());
|
---|
| 116 | s.PutR8(dobj->maxFreq());
|
---|
| 117 |
|
---|
| 118 | // TVector<T> has Persistence Manager
|
---|
| 119 | s << dobj->getNuVec();
|
---|
| 120 | s << dobj->getTNuVec();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | void
|
---|
| 124 | ObjFileIO<SpecRespVec>::ReadSelf(PInPersist& s)
|
---|
| 125 | {
|
---|
| 126 | int_4 version, nothing;
|
---|
| 127 | version = 1;
|
---|
| 128 | nothing = 0; // Reserved for future use
|
---|
| 129 | s.GetI4(version);
|
---|
| 130 | s.GetI4(nothing);
|
---|
| 131 |
|
---|
| 132 | if(dobj == NULL)
|
---|
| 133 | {
|
---|
| 134 | Vector v1(10);
|
---|
| 135 | Vector v2(10);
|
---|
| 136 | dobj= new SpecRespVec();
|
---|
| 137 | ownobj= true;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | r_8 minf, maxf;
|
---|
| 141 | s.GetR8(minf);
|
---|
| 142 | s.GetR8(maxf);
|
---|
| 143 | dobj->setMinMaxFreq(minf, maxf);
|
---|
| 144 | // TVector<T> has Persistence Manager
|
---|
| 145 | s >> dobj->getNuVec();
|
---|
| 146 | s >> dobj->getTNuVec();
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 151 | #pragma define_template ObjFileIO<SpecRespVec>
|
---|
| 152 | #endif
|
---|
| 153 |
|
---|
| 154 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 155 | template class ObjFileIO<SpecRespVec>;
|
---|
| 156 | #endif
|
---|