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