1 | #ifndef CSPLINE_H_SEEN
|
---|
2 | #define CSPLINE_H_SEEN
|
---|
3 |
|
---|
4 | #include "machdefs.h"
|
---|
5 | #include "pexceptions.h"
|
---|
6 |
|
---|
7 | ///////////////////////////////////////////////////////////////////
|
---|
8 | // Class CSpline et CSpline2 selon Numerical Receipes (cmv 17/02/97)
|
---|
9 | ///////////////////////////////////////////////////////////////////
|
---|
10 | namespace SOPHYA {
|
---|
11 |
|
---|
12 | //! Spline fit to a set of points Y=f(X) (as in Numerical Receipes).
|
---|
13 | class CSpline {
|
---|
14 |
|
---|
15 | public:
|
---|
16 |
|
---|
17 | friend class CSpline2;
|
---|
18 |
|
---|
19 | enum { NaturalAll = 3, NoNatural = 0, Natural1 = 1, NaturalN = 2 };
|
---|
20 |
|
---|
21 | CSpline(int n,double* x,double* y,double yp1=0.,double ypn=0.
|
---|
22 | ,int natural=NaturalAll,bool order=true);
|
---|
23 |
|
---|
24 | CSpline(double yp1=0.,double ypn=0.,int natural=NaturalAll);
|
---|
25 |
|
---|
26 | virtual ~CSpline();
|
---|
27 |
|
---|
28 | void SetNewTab(int n,double* x,double* y
|
---|
29 | ,bool order=true,bool force=false);
|
---|
30 |
|
---|
31 | void SetBound1er(double yp1 = 0.,double yp2 = 0.);
|
---|
32 |
|
---|
33 | //! Pour changer le type de contraintes sur les derivees 2sd
|
---|
34 | inline void SetNaturalCSpline(int type = NaturalAll)
|
---|
35 | { Natural = type;}
|
---|
36 |
|
---|
37 | //! Pour liberer la place tampon qui ne sert que dans ComputeCSpline() et pas dans CSplineInt
|
---|
38 | inline void Free_Tmp()
|
---|
39 | { if(tmp != NULL) delete [] tmp; tmp=NULL;}
|
---|
40 |
|
---|
41 | void ComputeCSpline();
|
---|
42 |
|
---|
43 | double CSplineInt(double x);
|
---|
44 |
|
---|
45 | protected:
|
---|
46 |
|
---|
47 | void DelTab();
|
---|
48 |
|
---|
49 | // nombre d elements dans les tableaux X et Y
|
---|
50 | int Nel;
|
---|
51 | // true si les tableaux ont ete changes
|
---|
52 | // et qu il faut recalculer ComputeCSpline()
|
---|
53 | bool corrupt_Y2;
|
---|
54 | // true si les tableaux X,Y ont ete alloues
|
---|
55 | bool XY_Created;
|
---|
56 | // type de contraintes sur la derivee 2sd
|
---|
57 | int Natural;
|
---|
58 | // valeurs imposees de la derivee 1ere aux limites
|
---|
59 | double YP1, YPn;
|
---|
60 |
|
---|
61 | // tableaux rellement alloues si "order=true" ou seulement
|
---|
62 | // connectes aux tableaux externes si "order=false"
|
---|
63 | double* X;
|
---|
64 | double* Y;
|
---|
65 |
|
---|
66 | // tableau des coeff permettant l interpolation,
|
---|
67 | // remplis par ComputeCSpline()
|
---|
68 | double* Y2;
|
---|
69 |
|
---|
70 | // tableau tampon utilise dans ComputeCSpline()
|
---|
71 | double* tmp;
|
---|
72 | int_4* ind;
|
---|
73 |
|
---|
74 | };
|
---|
75 |
|
---|
76 |
|
---|
77 | ///////////////////////////////////////////////////////////////////
|
---|
78 | //! 2D Spline fit to a set of points Y=f(X1,X2) (as in Numerical Receipes).
|
---|
79 | class CSpline2 {
|
---|
80 |
|
---|
81 | public:
|
---|
82 | CSpline2(int n1,double* x1,int n2,double* x2,double* y
|
---|
83 | ,int natural=CSpline::NaturalAll,bool order=true);
|
---|
84 |
|
---|
85 | CSpline2(int natural=CSpline::NaturalAll);
|
---|
86 |
|
---|
87 | virtual ~CSpline2();
|
---|
88 |
|
---|
89 | void SetNewTab(int n1,double* x1,int n2,double* x2,double* y
|
---|
90 | ,bool order=true,bool force=false);
|
---|
91 |
|
---|
92 | //! Pour changer le type de contraintes sur les derivees 2sd
|
---|
93 | inline void SetNaturalCSpline(int type = CSpline::NaturalAll)
|
---|
94 | { Natural = type;}
|
---|
95 |
|
---|
96 | void ComputeCSpline();
|
---|
97 |
|
---|
98 | double CSplineInt(double x1,double x2);
|
---|
99 |
|
---|
100 | protected:
|
---|
101 | void DelTab();
|
---|
102 |
|
---|
103 | int Nel1, Nel2;
|
---|
104 | bool corrupt_Y2;
|
---|
105 | bool XY_Created;
|
---|
106 | int Natural;
|
---|
107 |
|
---|
108 | double* X1;
|
---|
109 | double* X2;
|
---|
110 | double* Y;
|
---|
111 | double* Y2;
|
---|
112 |
|
---|
113 | // nombre d elements alloues dans S
|
---|
114 | int Nel_S;
|
---|
115 | // tableau de CSpline pour interpolation selon X1
|
---|
116 | CSpline** S; // S[0->n2]
|
---|
117 | CSpline* Sint;
|
---|
118 |
|
---|
119 | // tableau tampon utilise dans CSplineInt()
|
---|
120 | double* tmp; // tmp[max(n1,n2)]
|
---|
121 | int_4* ind;
|
---|
122 |
|
---|
123 | };
|
---|
124 |
|
---|
125 | } // Fin du namespace
|
---|
126 |
|
---|
127 | #endif /* CSPLINE_H_SEEN */
|
---|