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

Last change on this file since 4036 was 3238, checked in by ansari, 18 years ago

Ajout namespace SOPHYA ds les fichiers .cc au lieu de include sopnamsp.h en presence de DECL_TEMP_SPEC , cmv+reza 27/04/2007

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