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
TimeSeriesTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Bernd Machenschalk, Jolien Creighton, Kipp Cannon
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/*
21 * Note that low-level sequence manipulation is tested in the Sequence
22 * verification code. The object here is mostly to test meta-data
23 * manipulation eg. epoch manipulation.
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28
29#include <lal/Date.h>
30#include <lal/LALDatatypes.h>
31#include <lal/Sequence.h>
32#include <lal/TimeSeries.h>
33#include <lal/Units.h>
34
36
37
39{
41
42 while(n--)
43 s->data->data[n] = rand() / (float) RAND_MAX;
44 return(s);
45}
46
47
49{
51
52 while(n--)
53 s->data->data[n] = n;
54 return(s);
55}
56
57
58static int cmp_real4(REAL4 *a, REAL4 *b, size_t n)
59{
60 REAL4 d;
61
62 while(n--) {
63 d = *a - *b;
64 if(d < 0.0)
65 return(-1);
66 if(d > 0.0)
67 return(+1);
68 }
69 return(0);
70}
71
72
73int main(void)
74{
77 int i;
78
79 /*
80 * Destroy
81 */
82
83 /* NULL pointer */
85
86 /* Incompletely/Incorrectly initialized structure */
87 x = XLALCalloc(1, sizeof(*x));
89 x = XLALCalloc(1, sizeof(*x));
90 x->data = XLALCalloc(1, sizeof(*x->data));
92
93 /*
94 * Create
95 */
96
97 /* try segfaulting on array access */
98 x = XLALCreateREAL4TimeSeries("blah", &gps_zero, 0.0, 1.0 / 1, &lalDimensionlessUnit, 1);
99 x->data->data[0] = 1.0;
100 if((x->f0 != 0.0) || (x->deltaT != 1.0) || (x->data->length != 1) || (x->data->data[0] != 1.0)) {
101 fprintf(stderr, "Create test 1 failed\n");
102 exit(1);
103 }
105
106 /*
107 * Cut
108 */
109
110 /* check metadata */
111 x = random_timeseries(1024);
112 y = XLALCutREAL4TimeSeries(x, 256, 512);
113 if((y->deltaT != x->deltaT) || (y->f0 != x->f0) || cmp_real4(x->data->data + 256, y->data->data, 512) || (XLALGPSDiff(&y->epoch, &x->epoch) != 256 * x->deltaT)) {
114 fprintf(stderr, "Cut test 1 failed\n");
115 exit(1);
116 }
119
120 /*
121 * Resize
122 */
123
124 /* check metadata */
125 a = sequential_timeseries(1024);
126 XLALResizeINT4TimeSeries(a, 256, 512);
127 for(i = 0; i < (int) a->data->length; i++)
128 if(a->data->data[i] != i + 256) {
129 fprintf(stderr, "Resize test 1a failed\n");
130 exit(1);
131 }
132 if((a->data->length != 512) || (XLALGPSDiff(&a->epoch, &gps_zero) != 256 * a->deltaT)) {
133 fprintf(stderr, "Resize test 1b failed\n");
134 exit(1);
135 }
137
138 /*
139 * Success
140 */
141
142 exit(0);
143}
#define fprintf
static int cmp_real4(REAL4 *a, REAL4 *b, size_t n)
int main(void)
static LIGOTimeGPS gps_zero
static REAL4TimeSeries * random_timeseries(size_t n)
static INT4TimeSeries * sequential_timeseries(size_t n)
#define LIGOTIMEGPSZERO
Zero-initializer for LIGOTimeGPS structs.
Definition: LALDatatypes.h:464
float REAL4
Single precision real floating-point number (4 bytes).
#define XLALCalloc(m, n)
Definition: LALMalloc.h:45
static const INT4 a
Definition: Random.c:79
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyINT4TimeSeries(INT4TimeSeries *series)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
INT4TimeSeries * XLALResizeINT4TimeSeries(INT4TimeSeries *series, int first, size_t length)
REAL4TimeSeries * XLALCutREAL4TimeSeries(const REAL4TimeSeries *series, size_t first, size_t length)
INT4TimeSeries * XLALCreateINT4TimeSeries(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 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
Difference between two GPS times as double.
Definition: XLALTime.c:157
Time series of INT4 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:530
INT4Sequence * data
The sequence of sampled data.
Definition: LALDatatypes.h:536
INT4 * data
Pointer to the data array.
Definition: LALDatatypes.h:114
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
Definition: LALDatatypes.h:570
REAL4Sequence * data
The sequence of sampled data.
Definition: LALDatatypes.h:576
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150