| 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 | inline void SetNaturalCSpline(int type = NaturalAll)
|
|---|
| 34 | { Natural = type;}
|
|---|
| 35 |
|
|---|
| 36 | inline void Free_Tmp()
|
|---|
| 37 | { if(tmp != NULL) delete [] tmp; tmp=NULL;}
|
|---|
| 38 |
|
|---|
| 39 | void ComputeCSpline();
|
|---|
| 40 |
|
|---|
| 41 | double CSplineInt(double x);
|
|---|
| 42 |
|
|---|
| 43 | protected:
|
|---|
| 44 |
|
|---|
| 45 | void DelTab();
|
|---|
| 46 |
|
|---|
| 47 | // nombre d elements dans les tableaux X et Y
|
|---|
| 48 | int Nel;
|
|---|
| 49 | // true si les tableaux ont ete changes
|
|---|
| 50 | // et qu il faut recalculer ComputeCSpline()
|
|---|
| 51 | bool corrupt_Y2;
|
|---|
| 52 | // true si les tableaux X,Y ont ete alloues
|
|---|
| 53 | bool XY_Created;
|
|---|
| 54 | // type de contraintes sur la derivee 2sd
|
|---|
| 55 | int Natural;
|
|---|
| 56 | // valeurs imposees de la derivee 1ere aux limites
|
|---|
| 57 | double YP1, YPn;
|
|---|
| 58 |
|
|---|
| 59 | // tableaux rellement alloues si "order=true" ou seulement
|
|---|
| 60 | // connectes aux tableaux externes si "order=false"
|
|---|
| 61 | double* X;
|
|---|
| 62 | double* Y;
|
|---|
| 63 |
|
|---|
| 64 | // tableau des coeff permettant l interpolation,
|
|---|
| 65 | // remplis par ComputeCSpline()
|
|---|
| 66 | double* Y2;
|
|---|
| 67 |
|
|---|
| 68 | // tableau tampon utilise dans ComputeCSpline()
|
|---|
| 69 | double* tmp;
|
|---|
| 70 | int_4* ind;
|
|---|
| 71 |
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | ///////////////////////////////////////////////////////////////////
|
|---|
| 76 | //! 2D Spline fit to a set of points Y=f(X1,X2) (as in Numerical Receipes).
|
|---|
| 77 | class CSpline2 {
|
|---|
| 78 |
|
|---|
| 79 | public:
|
|---|
| 80 | CSpline2(int n1,double* x1,int n2,double* x2,double* y
|
|---|
| 81 | ,int natural=CSpline::NaturalAll,bool order=true);
|
|---|
| 82 |
|
|---|
| 83 | CSpline2(int natural=CSpline::NaturalAll);
|
|---|
| 84 |
|
|---|
| 85 | virtual ~CSpline2();
|
|---|
| 86 |
|
|---|
| 87 | void SetNewTab(int n1,double* x1,int n2,double* x2,double* y
|
|---|
| 88 | ,bool order=true,bool force=false);
|
|---|
| 89 |
|
|---|
| 90 | inline void SetNaturalCSpline(int type = CSpline::NaturalAll)
|
|---|
| 91 | { Natural = type;}
|
|---|
| 92 |
|
|---|
| 93 | void ComputeCSpline();
|
|---|
| 94 |
|
|---|
| 95 | double CSplineInt(double x1,double x2);
|
|---|
| 96 |
|
|---|
| 97 | protected:
|
|---|
| 98 | void DelTab();
|
|---|
| 99 |
|
|---|
| 100 | int Nel1, Nel2;
|
|---|
| 101 | bool corrupt_Y2;
|
|---|
| 102 | bool XY_Created;
|
|---|
| 103 | int Natural;
|
|---|
| 104 |
|
|---|
| 105 | double* X1;
|
|---|
| 106 | double* X2;
|
|---|
| 107 | double* Y;
|
|---|
| 108 | double* Y2;
|
|---|
| 109 |
|
|---|
| 110 | // nombre d elements alloues dans S
|
|---|
| 111 | int Nel_S;
|
|---|
| 112 | // tableau de CSpline pour interpolation selon X1
|
|---|
| 113 | CSpline** S; // S[0->n2]
|
|---|
| 114 | CSpline* Sint;
|
|---|
| 115 |
|
|---|
| 116 | // tableau tampon utilise dans CSplineInt()
|
|---|
| 117 | double* tmp; // tmp[max(n1,n2)]
|
|---|
| 118 | int_4* ind;
|
|---|
| 119 |
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | } // Fin du namespace
|
|---|
| 123 |
|
|---|
| 124 | #endif /* CSPLINE_H_SEEN */
|
|---|