source: Sophya/trunk/SophyaLib/SkyT/radspecvector.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.0 KB
Line 
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: radspecvector.cc,v 1.4 1999-11-29 14:16:06 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 "radspecvector.h"
23#include "pexceptions.h"
24
25//----------------
26// Constructor --
27//----------------
28RadSpectraVec::RadSpectraVec()
29{
30}
31
32RadSpectraVec::RadSpectraVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
33 : RadSpectra(numin, numax)
34{
35 if(nu.NElts() != fdenu.NElts())
36 throw SzMismatchError("RadSpectraVec::RadSpectraVec() - 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//--------------
49RadSpectraVec::~RadSpectraVec()
50{
51}
52
53// ---------------------------
54// -- Function Definitions --
55// ---------------------------
56
57
58
59
60double
61RadSpectraVec::flux(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 _vecOfFDeNu(sizeVecOfNu-1);
83}
84
85void
86RadSpectraVec::WriteSelf(POutPersist& s)
87{
88 s.PutI4(this->NbElts());
89 for (int i=0; i< this->NbElts(); i++)
90 {
91 s.PutR8(this->getNuVec(i));
92 s.PutR8(this->getFNuVec(i));
93 }
94 s.PutR8(this->minFreq());
95 s.PutR8(this->maxFreq());
96
97}
98
99void
100RadSpectraVec::ReadSelf(PInPersist& s)
101{
102 s.GetI4(_size);
103
104 _vecOfNu.ReSize(_size);
105 _vecOfFDeNu.ReSize(_size);
106 for (int i=0; i< _size; i++)
107 {
108 s.GetR8(_vecOfNu(i));
109 s.GetR8(_vecOfFDeNu(i));
110 }
111 s.GetR8(_numin);
112 s.GetR8(_numax);
113 cout << "minFreq - maxFreq"<< endl;
114 cout << _numin<< "-" << _numax << endl;
115}
116
117
118
119void
120RadSpectraVec::Print(ostream& os) const
121{
122 // os << "RadSpectraVec::Print (" << typeid(*this).name()
123 // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
124 os << "RadSpectraVec::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
125 os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
126 os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
127
128}
129
130
Note: See TracBrowser for help on using the repository browser.