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

Last change on this file since 2873 was 2873, checked in by ansari, 20 years ago

Portage/compilation sur AIX-XlC (regatta): Ajout qualification de nom pour instanciation explicite de template + correction petit bug - Reza 3 Jan 2006

File size: 4.6 KB
RevLine 
[601]1//--------------------------------------------------------------------------
2// File and Version Information:
[2873]3// $Id: specrespvector.cc,v 1.12 2006-01-03 14:29:37 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//---------------
[2615]17#include "sopnamsp.h"
[601]18#include "machdefs.h"
[2322]19#include <iostream>
[601]20#include <math.h>
21// #include <typeinfo>
22
23#include "specrespvector.h"
24#include "pexceptions.h"
[806]25#include "fioarr.h"
[601]26//----------------
27// Constructor --
28//----------------
[909]29/*!
30 * \class SOPHYA::SpecRespVec
[927]31 \ingroup SkyT
[909]32 One may also want to defined the filter of a detector by two vectors:
33 one for the frequencies and one for the corresponding transmission values.
34 In this case on should use the SpecRespVec class !
35*/
[668]36SpecRespVec::SpecRespVec()
37 : SpectralResponse()
38{
39}
40
[909]41/*! Constructor:
42 \param nu vector of the frequencies
43 \param fdenu vector of the corresponding transmission values of the filter
44*/
[601]45SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
46 : SpectralResponse(numin, numax)
47{
48 if(nu.NElts() != fdenu.NElts())
49 throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
50 _vecOfNu = nu;
51 _vecOfFDeNu = fdenu;
[669]52 _size = nu.NElts();
53}
54
55SpecRespVec::SpecRespVec(Vector const & nu, Vector const & fdenu)
56 : SpectralResponse()
57{
58 if(nu.NElts() != fdenu.NElts())
59 throw SzMismatchError("SpecRespVec::SpecRespVec() - Non equal vector sizes");
60 _vecOfNu = nu;
61 _vecOfFDeNu = fdenu;
[601]62 _numin = nu(0);
63 _numax = nu(nu.NElts()-1);
[668]64 _size = nu.NElts();
[601]65}
66
67
68//--------------
69// Destructor --
70//--------------
71SpecRespVec::~SpecRespVec()
72{
73}
74
75// ---------------------------
76// -- Function Definitions --
77// ---------------------------
78
79
80
[909]81/*! The transmission function extrapolates the transmission values for the
82 frequencies that are not present in the nu vector <BR>
83 given at the instanciation of the class.
84*/
[601]85double
86SpecRespVec::transmission(double nu) const
87{
88 if ( (nu < _numin) || (nu > _numax) ) return(0.);
[610]89 double value = 0.;
[601]90 int sizeVecOfNu = _vecOfNu.NElts();
[610]91 if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
[601]92 if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
93
94 for (int i=1; i<sizeVecOfNu; i++)
95 {
[610]96 if(nu < _vecOfNu(i))
[601]97 {
98 double up = _vecOfFDeNu(i) ;
99 double down = _vecOfFDeNu(i-1);
100 double xmin = _vecOfNu(i-1);
101 double xmax = _vecOfNu(i);
102 double a = ((up-down)/(xmax-xmin));
103 value = a*nu+(up-a*xmax);
104 return value;
105 }
106 }
107 return value;
108}
109
110
111
112void
113SpecRespVec::Print(ostream& os) const
114{
115
116 // os << "SpecRespVec::Print (" << typeid(*this).name()
117 //<< ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
118 os << "SpecRespVec ::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
119 os << "MeanFreq= " << meanFreq() << " Transmission= " << transmission(meanFreq()) << endl;
120 os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
121
122}
[668]123
124
[2344]125DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
[668]126void
127ObjFileIO<SpecRespVec>::WriteSelf(POutPersist& s) const
128{
129 if(dobj == NULL)
130 {
131 cout << " ObjFileIO<SpecRespVec>::WriteSelf:: dobj= null " << endl;
132 return;
133 }
134
135 int_4 version, nothing;
136 version = 1;
137 nothing = 0; // Reserved for future use
138 s.PutI4(version);
139 s.PutI4(nothing);
140
141 s.PutR8(dobj->minFreq());
142 s.PutR8(dobj->maxFreq());
143
[669]144 // TVector<T> has Persistence Manager
145 s << dobj->getNuVec();
146 {
147 Vector& xv2 = dobj->getTNuVec();
148 cout << xv2 ;
[806]149 FIO_TArray<double> vio2(&xv2);
[669]150 vio2.Write(s);
151 }
[668]152}
153
[2344]154DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
[668]155void
156ObjFileIO<SpecRespVec>::ReadSelf(PInPersist& s)
157{
158 int_4 version, nothing;
159 version = 1;
160 nothing = 0; // Reserved for future use
161 s.GetI4(version);
162 s.GetI4(nothing);
163
164 if(dobj == NULL)
165 {
[669]166 dobj= new SpecRespVec();
167 ownobj= true;
[668]168 }
169 r_8 minf, maxf;
170 s.GetR8(minf);
171 s.GetR8(maxf);
172 dobj->setMinMaxFreq(minf, maxf);
173 // TVector<T> has Persistence Manager
[806]174 FIO_TArray<double> vio(&(dobj->getNuVec()));
[669]175 vio.Read(s);
[806]176 FIO_TArray<double> vio2(&(dobj->getTNuVec()));
[669]177 vio2.Read(s);
[668]178}
179
180
181#ifdef __CXX_PRAGMA_TEMPLATES__
182#pragma define_template ObjFileIO<SpecRespVec>
183#endif
184
185#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
[2873]186template class SOPHYA::ObjFileIO<SpecRespVec>;
[668]187#endif
Note: See TracBrowser for help on using the repository browser.