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

Last change on this file since 668 was 668, checked in by ansari, 26 years ago

Ajout de classes deleguees PPersist et correction integration - Sophie 29/11/99

File size: 3.6 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: specrespvector.cc,v 1.4 1999-11-29 14:16:09 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//----------------
25// Constructor --
26//----------------
27SpecRespVec::SpecRespVec()
28 : SpectralResponse()
29{
30}
31
32SpecRespVec::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);
41 _size = nu.NElts();
42 if(_vecOfNu.NElts() != _vecOfFDeNu.NElts()) cout << "vectors are not compatible" << exit;
43}
44
45
46//--------------
47// Destructor --
48//--------------
49SpecRespVec::~SpecRespVec()
50{
51}
52
53// ---------------------------
54// -- Function Definitions --
55// ---------------------------
56
57
58
59
60double
61SpecRespVec::transmission(double nu) const
62{
63 if ( (nu < _numin) || (nu > _numax) ) return(0.);
64 double value = 0.;
65 int sizeVecOfNu = _vecOfNu.NElts();
66 if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
67 if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
68
69 for (int i=1; i<sizeVecOfNu; i++)
70 {
71 if(nu < _vecOfNu(i))
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
87void
88SpecRespVec::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}
98
99
100void
101ObjFileIO<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
123void
124ObjFileIO<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)
155template class ObjFileIO<SpecRespVec>;
156#endif
Note: See TracBrowser for help on using the repository browser.