45 const EGS_Float *values) : n(0), own_data(true) {
50 EGS_InterpolatorFuncion func,
void *data) : n(0), own_data(true) {
55 EGS_Float *a, EGS_Float *b) : n(0), own_data(true) {
60 EGS_InterpolatorFuncion func,
void *data,
61 int nmax, EGS_Float accu) : n(0), own_data(true) {
65 void EGS_Interpolator::clear() {
66 if (n > 0 && own_data) {
77 void EGS_Interpolator::check(
int nbin, EGS_Float Xmin, EGS_Float Xmax) {
78 if (nbin < 2)
egsFatal(
"EGS_Interpolator::initialize: \n"
79 " attempt to initialize the interpolator with %d bins\n",nbin);
80 if (Xmin >= Xmax)
egsFatal(
"EGS_Interpolator::initialize: \n"
81 " Xmin must be > Xmax, I got Xmin=%g Xmax=%g\n",Xmin,Xmax);
85 const EGS_Float *values) {
86 check(nbin,Xmin,Xmax);
90 a =
new EGS_Float [nbin], b =
new EGS_Float [nbin];
95 EGS_Float dx = (xmax-xmin)/n;
98 for (
int j=0; j<n; j++) {
99 b[j] = (values[j+1]-values[j])*bx;
100 a[j] = values[j] - b[j]*(xmin + dx*j);
112 EGS_InterpolatorFuncion func,
void *data) {
113 EGS_Float *aux =
new EGS_Float [nbin];
114 EGS_Float dx = (Xmax - Xmin)/(nbin-1);
115 for (
int j=0; j<nbin; j++) {
116 aux[j] = func(Xmin + dx*j, data);
123 EGS_Float *A, EGS_Float *B) {
124 check(nbin,Xmin,Xmax);
130 EGS_Float dx = (xmax-xmin)/n;
135 fmin = a[0] + b[0]*xmin;
136 fmax = a[n-1]+b[n-1]*xmax;
140 EGS_InterpolatorFuncion func,
void *data,
141 int nmax, EGS_Float accu) {
142 check(nmax,Xmin,Xmax);
149 EGS_Float *tmp =
new EGS_Float [nnow];
151 EGS_Float ddx = (Xmax-Xmin)/(nnow-1);
152 for (j=0; j<nnow; j++) {
153 tmp[j] = func(Xmin + ddx*j, data);
155 for (EGS_I64 loopCount=0; loopCount<=
loopMax; ++loopCount) {
157 egsFatal(
"EGS_Interpolator::initialize: Too many iterations were required! Input may be invalid, or consider increasing loopMax.");
160 EGS_Float *tmp1 =
new EGS_Float [nnow-1];
161 for (j=0; j<nnow-1; j++) {
162 tmp1[j] = func(Xmin + ddx*(0.5+j),data);
165 for (j=0; j<nnow-1; j++) {
166 EGS_Float fint = 0.5*(tmp[j] + tmp[j+1]);
167 EGS_Float err = fabs(fint/tmp1[j]-1);
179 if (2*nnow-1 > nmax) {
184 EGS_Float *aux =
new EGS_Float [2*nnow-1];
187 for (j=1; j<nnow; j++) {
188 aux[i++] = tmp1[j-1];
195 ddx = (Xmax-Xmin)/(nnow-1);
const EGS_I64 loopMax
The maximum number of iterations for near-infinite loops.
Global egspp functions header file.
~EGS_Interpolator()
Destructor.
void initialize(int nbin, EGS_Float Xmin, EGS_Float Xmax, EGS_InterpolatorFuncion func, void *data)
Initialize the interpolator.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
EGS_Interpolator()
Create an empty (unitialized) interpolator.
void initialize(int nbin, EGS_Float Xmin, EGS_Float Xmax, const EGS_Float *values)
Initialize the interpolator.
EGS_Interpolator class header file.