LAL  7.5.0.1-ec27e42
Interpolate.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Drew Keppel
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #ifndef _INTERPOLATE_H
21 #define _INTERPOLATE_H
22 
23 #include <lal/Date.h>
24 #include <lal/Sequence.h>
25 #include <lal/LALDatatypes.h>
26 
27 #include <lal/XLALGSL.h>
28 #include <gsl/gsl_errno.h>
29 #include <gsl/gsl_spline.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * \defgroup Interpolate_h Header Interpolate.h
37  * \ingroup lal_utilities
38  *
39  * \brief This header covers the routines for interpolation.
40  *
41  * ### Synopsis ###
42  *
43  * \code
44  * #include <lal/Interpolate.h>
45  * \endcode
46  *
47  * ### Description ###
48  *
49  * The routine <tt>LALSPolynomialInterpolation()</tt> computes the interpolated \f$y\f$
50  * value \c output at the \f$x\f$ value \c target by fitting a polynomial of
51  * order <tt>params.n-1</tt> to the data. The result \c output is of type
52  * \c SInterpolateOut, which contains the value <tt>output.y</tt> as well as
53  * an estimate of the error <tt>output.dy</tt>. The routine
54  * <tt>LALDPolynomialInterpolation()</tt> is the same but for double precision.
55  *
56  * ### Operating Instructions ###
57  *
58  * The following program fits a fourth-order polynomial to the five data points
59  * \f$\{(0,0),(1,1),(2,3),(3,4),(4,3)\}\f$, and interpolates the value at \f$x=2.4\f$.
60  *
61  * \code
62  * #include <lal/LALStdlib.h>
63  * #include <lal/Interpolate.h>
64  *
65  * int main ()
66  * {
67  * enum { ArraySize = 5 };
68  * static LALStatus status;
69  * REAL4 x[ArraySize] = {0,1,2,3,4};
70  * REAL4 y[ArraySize] = {0,1,3,4,3};
71  * REAL4 target = 2.4;
72  * SInterpolatePar intpar = {ArraySize, x, y};
73  * SInterpolateOut intout;
74  *
75  * LALSPolynomialInterpolation( &status, &intout, target, &intpar );
76  *
77  * return 0;
78  * }
79  * \endcode
80  *
81  * ### Algorithm ###
82  *
83  * This is an implementation of the Neville algroithm, see \c polint in
84  * Numerical Recipes \cite ptvf1992 .
85  *
86  */
87 /** @{ */
88 
89 /** \name Error Codes */
90 /** @{ */
91 #define INTERPOLATEH_ENULL 1 /**< Null pointer */
92 #define INTERPOLATEH_ESIZE 2 /**< Invalid size */
93 #define INTERPOLATEH_EZERO 4 /**< Zero divide */
94 /** @} */
95 
96 /** \cond DONT_DOXYGEN */
97 #define INTERPOLATEH_MSGENULL "Null pointer"
98 #define INTERPOLATEH_MSGESIZE "Invalid size"
99 #define INTERPOLATEH_MSGEZERO "Zero divide"
100 /** \endcond */
101 
102 /** These structures contain the output of the interpolation */
103 typedef struct
104 tagSInterpolateOut
105 {
106  REAL4 y; /**< The interpolated value */
107  REAL4 dy; /**< The estimated error in the interpolated value */
108 }
110 
111 /** These structures contain the output of the interpolation */
112 typedef struct
113 tagDInterpolateOut
114 {
115  REAL8 y; /**< The interpolated value */
116  REAL8 dy; /**< The estimated error in the interpolated value */
117 }
119 
120 /**
121  * These structures contain the interpolation parameters; These are the arrays
122  * of \c n domain values \f$x[0] \ldots x[n-1]\f$ and their
123  * corresponding values \f$y[0] \ldots y[n-1]\f$
124  */
125 typedef struct
126 tagSInterpolatePar
127 {
128  UINT4 n; /**< The number of points in the arrays to use in the interpolation */
129  REAL4 *x; /**< The array of domain values */
130  REAL4 *y; /**< The array of values to interpolate */
131 }
133 
134 /**
135  * These structures contain the interpolation parameters; These are the arrays
136  * of \c n domain values \f$x[0]\ldots x[n-1]\f$ and their
137  * corresponding values \f$y[0]\ldots y[n-1]\f$
138  */
139 typedef struct
140 tagDInterpolatePar
141 {
142  UINT4 n; /**< The number of points in the arrays to use in the interpolation */
143  REAL8 *x; /**< The array of domain values */
144  REAL8 *y; /**< The array of values to interpolate */
145 }
147 
148 /* ----- Interpolate.c ----- */
149 /** \see See \ref Interpolate_h for documentation */
150 void
152  LALStatus *status,
154  REAL4 target,
155  SInterpolatePar *params
156  );
157 
158 /** \see See \ref Interpolate_h for documentation */
159 void
161  LALStatus *status,
163  REAL8 target,
164  DInterpolatePar *params
165  );
166 
167 /** \see See \ref Interpolate_h for documentation */
168 REAL8
170  REAL8 *yout,
171  REAL8 xtarget,
172  REAL8 *y,
173  REAL8 *x,
174  UINT4 n
175  );
176 
177 int
179  REAL8Sequence *x_in, /* Assumed to be in ascending order */
180  REAL8Sequence *y_in,
181  REAL8Sequence *x_out,
182  REAL8Sequence *y_out, /* Modified in place */
183  UINT4 n_data_points,
184  const gsl_interp_type *itrp_type /* Can be NULL -- default it to cubic spline */
185  );
186 
187 int
189  REAL8TimeSeries *ts_in,
190  REAL8Sequence *y_in,
191  REAL8Sequence *t_in,
192  REAL8Sequence *t_out, /* If NULL, interpolate from dt and epoch of ts_in */
193  UINT4 n_data_points,
194  const gsl_interp_type *itrp_type
195  );
196 
197 /** @} */
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* _INTERPOLATE_H */
void LALDPolynomialInterpolation(LALStatus *status, DInterpolateOut *output, REAL8 target, DInterpolatePar *params)
Definition: Interpolate.c:115
int XLALREAL8TimeSeriesInterpolation(REAL8TimeSeries *ts_in, REAL8Sequence *y_in, REAL8Sequence *t_in, REAL8Sequence *t_out, UINT4 n_data_points, const gsl_interp_type *itrp_type)
Definition: Interpolate.c:282
void LALSPolynomialInterpolation(LALStatus *status, SInterpolateOut *output, REAL4 target, SInterpolatePar *params)
Definition: Interpolate.c:29
REAL8 XLALREAL8PolynomialInterpolation(REAL8 *yout, REAL8 xtarget, REAL8 *y, REAL8 *x, UINT4 n)
Definition: Interpolate.c:140
int XLALREAL8Interpolation(REAL8Sequence *x_in, REAL8Sequence *y_in, REAL8Sequence *x_out, REAL8Sequence *y_out, UINT4 n_data_points, const gsl_interp_type *itrp_type)
Definition: Interpolate.c:228
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
float REAL4
Single precision real floating-point number (4 bytes).
These structures contain the output of the interpolation.
Definition: Interpolate.h:114
REAL8 y
The interpolated value.
Definition: Interpolate.h:115
REAL8 dy
The estimated error in the interpolated value.
Definition: Interpolate.h:116
These structures contain the interpolation parameters; These are the arrays of n domain values and t...
Definition: Interpolate.h:141
REAL8 * y
The array of values to interpolate.
Definition: Interpolate.h:144
REAL8 * x
The array of domain values.
Definition: Interpolate.h:143
UINT4 n
The number of points in the arrays to use in the interpolation.
Definition: Interpolate.h:142
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:580
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
These structures contain the output of the interpolation.
Definition: Interpolate.h:105
REAL4 dy
The estimated error in the interpolated value.
Definition: Interpolate.h:107
REAL4 y
The interpolated value.
Definition: Interpolate.h:106
These structures contain the interpolation parameters; These are the arrays of n domain values and t...
Definition: Interpolate.h:127
REAL4 * x
The array of domain values.
Definition: Interpolate.h:129
UINT4 n
The number of points in the arrays to use in the interpolation.
Definition: Interpolate.h:128
REAL4 * y
The array of values to interpolate.
Definition: Interpolate.h:130
void output(int gps_sec, int output_type)
Definition: tconvert.c:440