00001 #ifndef SPL_CLASS_HEADER
00002 #define SPL_CLASS_HEADER
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020
00021 #ifdef _STANDARD_C_PLUS_PLUS
00022 #include <vector>
00023 #include <algorithm>
00024 using namespace std;
00025 #else
00026 #include <vector.h>
00027 #include <algo.h>
00028 #endif
00029
00030
00031
00032 #include "Refstorage.hh"
00033 #include "Rangedimexc.hh"
00034
00035
00036
00037 namespace RazorBack {
00038
00039 class Spl_;
00040
00049 class Splstorage_
00050 {
00051 friend class Spl_;
00052
00053
00054 private:
00055
00056 vector<double> Xvec;
00057 vector<double> Yvec;
00058 vector<double> Y2vec;
00059 vector<double> Yintvec;
00060 unsigned int Len;
00061 bool Ev;
00062
00063
00064
00066 explicit Splstorage_(unsigned int N=2):
00067 Xvec(N), Yvec(N), Y2vec(N), Yintvec(N), Len(N), Ev(false) {}
00068
00074 void len(unsigned int L)
00075 {
00076 if (L>Len)
00077 {
00078
00079 int Increment=L-Len;
00080 Xvec.insert(Xvec.end(), Increment, 0.0);
00081 Yvec.insert(Yvec.end(), Increment, 0.0);
00082 Y2vec.insert(Y2vec.end(), Increment, 0.0);
00083 Yintvec.insert(Yintvec.end(), Increment, 0.0);
00084 }
00085 else
00086 {
00087
00088 Xvec.erase(Xvec.begin()+Len, Xvec.end());
00089 Yvec.erase(Yvec.begin()+Len, Yvec.end());
00090 Y2vec.erase(Y2vec.begin()+Len, Y2vec.end());
00091 Yintvec.erase(Yintvec.begin()+Len, Yintvec.end());
00092 }
00093 Len=L;
00094 }
00095
00097 void reset()
00098 {
00099 fill(Xvec.begin(), Xvec.end(), 0.0);
00100 fill(Yvec.begin(), Yvec.end(), 0.0);
00101 fill(Y2vec.begin(), Y2vec.end(), 0.0);
00102 fill(Yintvec.begin(), Yintvec.end(), 0.0);
00103 Ev=false;
00104 }
00105
00106 };
00107
00108
00114 class Spl_: protected Refstorage_<Splstorage_>
00115 {
00116
00117
00118 public:
00119
00121 explicit Spl_(unsigned int N=2):
00122 Refstorage_<Splstorage_>(new Splstorage_(N)) {}
00123
00125 unsigned int len() const { return data().Len; }
00126
00132 unsigned int len(unsigned int L);
00133
00135 void reset()
00136 {
00137 clone();
00138 data().reset();
00139 }
00140
00148 void add(unsigned int Idx, double x, double y);
00149
00162 void fit_spl(double yp1, bool Nat1, double ypn, bool Natn);
00163
00180 double eval_spl(double xi, double *Der1=NULL, double *Der2=NULL,
00181 double *Der3=NULL, double *Integ=NULL) const;
00182
00190 double integ_spl(double Low, double Up) const;
00191
00192 private:
00193
00194
00195 struct Datapoint_
00196 {
00197 double x, y;
00198 bool operator<(const Datapoint_& Rhs) const { return (x<Rhs.x); }
00199 };
00200
00201 bool check_data();
00202 double int_0x(double xi) const;
00203 double smallest_interval(double xi,
00204 unsigned int& kl, unsigned int& kh) const;
00205 };
00206
00207
00208 }
00209
00210
00211
00212 #endif