Chris@0: /* Chris@0: copyright (C) 2012 I. Irigaray, M. Rocamora Chris@0: Chris@0: This program is free software: you can redistribute it and/or modify Chris@0: it under the terms of the GNU General Public License as published by Chris@0: the Free Software Foundation, either version 3 of the License, or Chris@0: (at your option) any later version. Chris@0: Chris@0: This program is distributed in the hope that it will be useful, Chris@0: but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: GNU General Public License for more details. Chris@0: Chris@0: You should have received a copy of the GNU General Public License Chris@0: along with this program. If not, see . Chris@8: */ Chris@0: Chris@0: Chris@0: #include "FChTransformUtils.h" Chris@29: Chris@29: #define _USE_MATH_DEFINES Chris@29: Chris@0: #include Chris@0: Chris@14: void Chris@14: Utils::cumtrapz(const double *x, const double *y, int N, double *accum) Chris@0: /*Trapezoidal Integrator: 1/2(b-a)(F(a)+F(b))*/ Chris@0: { Chris@8: accum[0]=0.0; Chris@10: for (int i = 1; i < N; i++) { Chris@8: accum[i]=accum[i-1]+0.5*(x[i]-x[i-1])*(y[i]+y[i-1]); Chris@8: } Chris@0: } Chris@0: Chris@0: Chris@14: void Chris@14: Utils::interp1(const double *x1, const double *y1, int N1, const double *x2, double *y2, int N2){ Chris@0: /*1-D linear interpolation*/ Chris@0: Chris@10: for (int i = 0; i < N2; i++) { Chris@8: /*Smaller or equal than the smallest, or larger or equal than the largest.*/ Chris@8: if ( x2[i] <= x1[0] ) { Chris@8: y2[i] = y1[0]; Chris@8: } else if ( x2[i] >= x1[N1-1] ) { Chris@8: y2[i] = y1[N1-1]; Chris@8: } else { Chris@8: /*Search every value of x2 in x1*/ Chris@10: int j = 1; Chris@10: int salir = 0; Chris@8: while ((j