Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
CSInterpolateTest.c
Go to the documentation of this file.
1
2#include <math.h>
3#include <stdio.h>
4
5#include <gsl/gsl_spline.h>
6
7#include <lal/TimeSeries.h>
8#include <lal/Units.h>
9#include <lal/Interpolate.h>
10
11int main(void) {
12 size_t len=100;
13 double dt=0.02;
14 double drift=0.0;
15 REAL8Sequence *sample_time = XLALCreateREAL8Sequence(len);
16 size_t i=0;
17 sample_time->data[0] = dt*i;
18 for(i=1; i<len; i++) {
19 sample_time->data[i] = dt*i+drift;
20 drift += 1e-3;
21 }
22
23 double frequency = 20.0 / 2 / 3.14159;
24
25 //FILE* fref = fopen( "fref.txt", "w" );
27 for(i=0; i<len; i++) {
28 fcn->data[i] = sin( sample_time->data[i] * frequency );
29 //fprintf( fref, "%f %f\n", sample_time->data[i], fcn->data[i] );
30 }
31 //fclose(fref);
32
33 LIGOTimeGPS ep = {0, 0};
34
35 REAL8TimeSeries *ts = XLALCreateREAL8TimeSeries("intrp test", &ep, 0.0, dt*0.9, &lalDimensionlessUnit, len);
36
37 int ret = XLALREAL8TimeSeriesInterpolation(ts, fcn, sample_time, NULL, len, gsl_interp_cspline);
38
39 REAL8 start = XLALGPSGetREAL8(&ts->epoch);
40 REAL8 tolerance = 1e-6;
41 //FILE* fout = fopen( "fout.txt", "w" );
42 for(i=0; i<ts->data->length; i++) {
43 REAL8 t = ts->deltaT * i + start;
44 REAL8 fcnval = sin(frequency*t);
45 REAL8 diff = fabs(ts->data->data[i] - fcnval);
46 //fprintf( fout, "%f %f %f\n", t, fcnval, ts->data->data[i] );
47 if (diff > tolerance) {
48 fprintf(stderr, "%f %g\n", t, diff);
49 return -1;
50 }
51 }
52 //fclose(fout);
53
54 return ret;
55}
int main(void)
#define fprintf
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
double REAL8
Double precision real floating-point number (8 bytes).
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalDimensionlessUnit
dimensionless units
Definition: UnitDefs.c:156
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
Returns the GPS time as a REAL8.
Definition: XLALTime.c:91
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:580
REAL8Sequence * data
The sequence of sampled data.
Definition: LALDatatypes.h:586
REAL8 deltaT
The time step between samples of the time series in seconds.
Definition: LALDatatypes.h:583
LIGOTimeGPS epoch
The start time of the time series.
Definition: LALDatatypes.h:582
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158