[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[806] | 3 | // $Id: specrespvector.cc,v 1.6 2000-04-03 17:42:39 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"
|
---|
[806] | 24 | #include "fioarr.h"
|
---|
[601] | 25 | //----------------
|
---|
| 26 | // Constructor --
|
---|
| 27 | //----------------
|
---|
[668] | 28 | SpecRespVec::SpecRespVec()
|
---|
| 29 | : SpectralResponse()
|
---|
| 30 | {
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[601] | 33 | SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
| 34 | : SpectralResponse(numin, numax)
|
---|
| 35 | {
|
---|
| 36 | if(nu.NElts() != fdenu.NElts())
|
---|
| 37 | throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
|
---|
| 38 | _vecOfNu = nu;
|
---|
| 39 | _vecOfFDeNu = fdenu;
|
---|
[669] | 40 | _size = nu.NElts();
|
---|
| 41 | if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu)
|
---|
| 45 | : SpectralResponse()
|
---|
| 46 | {
|
---|
| 47 | if(nu.NElts() != fdenu.NElts())
|
---|
| 48 | throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
|
---|
| 49 | _vecOfNu = nu;
|
---|
| 50 | _vecOfFDeNu = fdenu;
|
---|
[601] | 51 | _numin = nu(0);
|
---|
| 52 | _numax = nu(nu.NElts()-1);
|
---|
[668] | 53 | _size = nu.NElts();
|
---|
[601] | 54 | if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | //--------------
|
---|
| 59 | // Destructor --
|
---|
| 60 | //--------------
|
---|
| 61 | SpecRespVec::~SpecRespVec()
|
---|
| 62 | {
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | // ---------------------------
|
---|
| 66 | // -- Function Definitions --
|
---|
| 67 | // ---------------------------
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | double
|
---|
| 73 | SpecRespVec::transmission(double nu) const
|
---|
| 74 | {
|
---|
| 75 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
---|
[610] | 76 | double value = 0.;
|
---|
[601] | 77 | int sizeVecOfNu = _vecOfNu.NElts();
|
---|
[610] | 78 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
---|
[601] | 79 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
| 80 |
|
---|
| 81 | for (int i=1; i<sizeVecOfNu; i++)
|
---|
| 82 | {
|
---|
[610] | 83 | if(nu < _vecOfNu(i))
|
---|
[601] | 84 | {
|
---|
| 85 | double up = _vecOfFDeNu(i) ;
|
---|
| 86 | double down = _vecOfFDeNu(i-1);
|
---|
| 87 | double xmin = _vecOfNu(i-1);
|
---|
| 88 | double xmax = _vecOfNu(i);
|
---|
| 89 | double a = ((up-down)/(xmax-xmin));
|
---|
| 90 | value = a*nu+(up-a*xmax);
|
---|
| 91 | return value;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | return value;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | void
|
---|
| 100 | SpecRespVec::Print(ostream& os) const
|
---|
| 101 | {
|
---|
| 102 |
|
---|
| 103 | // os << "SpecRespVec::Print (" << typeid(*this).name()
|
---|
| 104 | //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 105 | os << "SpecRespVec ::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 106 | os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
|
---|
| 107 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
---|
| 108 |
|
---|
| 109 | }
|
---|
[668] | 110 |
|
---|
| 111 |
|
---|
| 112 | void
|
---|
| 113 | ObjFileIO<SpecRespVec>::WriteSelf(POutPersist& s) const
|
---|
| 114 | {
|
---|
| 115 | if(dobj == NULL)
|
---|
| 116 | {
|
---|
| 117 | cout << " ObjFileIO<SpecRespVec>::WriteSelf:: dobj= null " << endl;
|
---|
| 118 | return;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | int_4 version, nothing;
|
---|
| 122 | version = 1;
|
---|
| 123 | nothing = 0; // Reserved for future use
|
---|
| 124 | s.PutI4(version);
|
---|
| 125 | s.PutI4(nothing);
|
---|
| 126 |
|
---|
| 127 | s.PutR8(dobj->minFreq());
|
---|
| 128 | s.PutR8(dobj->maxFreq());
|
---|
| 129 |
|
---|
[669] | 130 | // TVector<T> has Persistence Manager
|
---|
| 131 | s << dobj->getNuVec();
|
---|
| 132 | {
|
---|
| 133 | Vector& xv2 = dobj->getTNuVec();
|
---|
| 134 | cout << xv2 ;
|
---|
[806] | 135 | FIO_TArray<double> vio2(&xv2);
|
---|
[669] | 136 | vio2.Write(s);
|
---|
| 137 | }
|
---|
[668] | 138 | }
|
---|
| 139 |
|
---|
| 140 | void
|
---|
| 141 | ObjFileIO<SpecRespVec>::ReadSelf(PInPersist& s)
|
---|
| 142 | {
|
---|
| 143 | int_4 version, nothing;
|
---|
| 144 | version = 1;
|
---|
| 145 | nothing = 0; // Reserved for future use
|
---|
| 146 | s.GetI4(version);
|
---|
| 147 | s.GetI4(nothing);
|
---|
| 148 |
|
---|
| 149 | if(dobj == NULL)
|
---|
| 150 | {
|
---|
[669] | 151 | dobj= new SpecRespVec();
|
---|
| 152 | ownobj= true;
|
---|
[668] | 153 | }
|
---|
| 154 | r_8 minf, maxf;
|
---|
| 155 | s.GetR8(minf);
|
---|
| 156 | s.GetR8(maxf);
|
---|
| 157 | dobj->setMinMaxFreq(minf, maxf);
|
---|
| 158 | // TVector<T> has Persistence Manager
|
---|
[806] | 159 | FIO_TArray<double> vio(&(dobj->getNuVec()));
|
---|
[669] | 160 | vio.Read(s);
|
---|
[806] | 161 | FIO_TArray<double> vio2(&(dobj->getTNuVec()));
|
---|
[669] | 162 | vio2.Read(s);
|
---|
[668] | 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 167 | #pragma define_template ObjFileIO<SpecRespVec>
|
---|
| 168 | #endif
|
---|
| 169 |
|
---|
| 170 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 171 | template class ObjFileIO<SpecRespVec>;
|
---|
| 172 | #endif
|
---|