source: Sophya/trunk/SophyaLib/SkyT/specrespvector.cc@ 901

Last change on this file since 901 was 806, checked in by ansari, 25 years ago

Adaptation modifs TArray<T> - Reza 03/04/2000

File size: 4.1 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: specrespvector.cc,v 1.6 2000-04-03 17:42:39 ansari Exp $
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#include "fioarr.h"
25//----------------
26// Constructor --
27//----------------
28SpecRespVec::SpecRespVec()
29 : SpectralResponse()
30{
31}
32
33SpecRespVec::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;
40 _size = nu.NElts();
41 if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
42}
43
44SpecRespVec::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;
51 _numin = nu(0);
52 _numax = nu(nu.NElts()-1);
53 _size = nu.NElts();
54 if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
55}
56
57
58//--------------
59// Destructor --
60//--------------
61SpecRespVec::~SpecRespVec()
62{
63}
64
65// ---------------------------
66// -- Function Definitions --
67// ---------------------------
68
69
70
71
72double
73SpecRespVec::transmission(double nu) const
74{
75 if ( (nu < _numin) || (nu > _numax) ) return(0.);
76 double value = 0.;
77 int sizeVecOfNu = _vecOfNu.NElts();
78 if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
79 if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
80
81 for (int i=1; i<sizeVecOfNu; i++)
82 {
83 if(nu < _vecOfNu(i))
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
99void
100SpecRespVec::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}
110
111
112void
113ObjFileIO<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
130 // TVector<T> has Persistence Manager
131 s << dobj->getNuVec();
132 {
133 Vector& xv2 = dobj->getTNuVec();
134 cout << xv2 ;
135 FIO_TArray<double> vio2(&xv2);
136 vio2.Write(s);
137 }
138}
139
140void
141ObjFileIO<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 {
151 dobj= new SpecRespVec();
152 ownobj= true;
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
159 FIO_TArray<double> vio(&(dobj->getNuVec()));
160 vio.Read(s);
161 FIO_TArray<double> vio2(&(dobj->getTNuVec()));
162 vio2.Read(s);
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)
171template class ObjFileIO<SpecRespVec>;
172#endif
Note: See TracBrowser for help on using the repository browser.