1 #include <lal/LALConfig.h>
3 #ifndef LAL_HDF5_ENABLED
4 int main(
void) {
return 77; }
10 #include <lal/LALStdlib.h>
11 #include <lal/AVFactories.h>
12 #include <lal/StringVector.h>
14 #include <lal/Units.h>
15 #include <lal/TimeSeries.h>
16 #include <lal/FrequencySeries.h>
17 #include <lal/H5FileIO.h>
19 #define FNAME "test.h5"
20 #define GROUP "path/to"
21 #define DSET "testdset"
27 #define NPTS (DIM0 * DIM1 * DIM2)
29 #define EPOCH { 123456789, 987654321 }
35 static int generate_int_data(
void)
37 return rand() % SHRT_MAX;
40 static float generate_float_data(
void)
42 return rand() / (RAND_MAX + 1.0);
45 static float complex generate_complex_data(
void)
47 return rand() / (RAND_MAX + 1.0) + I * rand() / (RAND_MAX + 1.0);
50 static char * generate_string_data(
void)
53 switch (rand() % 18) {
54 case 0: s =
"lorem";
break;
55 case 1: s =
"ipsum";
break;
56 case 2: s =
"dolor";
break;
57 case 3: s =
"sit";
break;
58 case 4: s =
"amet";
break;
59 case 5: s =
"consectetur";
break;
60 case 6: s =
"adipiscing";
break;
61 case 7: s =
"elit";
break;
62 case 8: s =
"sed";
break;
63 case 9: s =
"eiusmod";
break;
64 case 10: s =
"tempor";
break;
65 case 11: s =
"incididunt";
break;
66 case 12: s =
"ut";
break;
67 case 13: s =
"labore";
break;
68 case 14: s =
"et";
break;
69 case 15: s =
"dolore";
break;
70 case 16: s =
"magna";
break;
71 case 17: s =
"aliqua";
break;
73 fprintf(stderr,
"Cannot get here!");
79 #define DEFINE_WRITE_FUNCTION(type) \
80 static int write_ ## type (type *x) { \
83 XLALGPSTimeNow(&now); \
85 file = XLALH5FileOpen(FNAME, "w"); \
86 XLALH5FileAddLIGOTimeGPSAttribute(file, "creation_time_gps", &now); \
87 XLALH5FileAddScalarAttribute(file, "test_count", &count, LAL_U2_TYPE_CODE); \
88 group = XLALH5GroupOpen(file, GROUP); \
89 XLALH5FileAddStringAttribute(group, "test_data_type", #type); \
90 XLALH5FileWrite ## type (group, DSET, x); \
91 XLALH5FileClose(group); \
92 XLALH5FileClose(file); \
96 #define DEFINE_READ_FUNCTION(type) \
97 static type * read_ ## type (void) { \
101 LIGOTimeGPS creation_time; \
103 char t[sizeof(#type)]; \
104 file = XLALH5FileOpen(FNAME, "r"); \
105 XLALH5FileQueryLIGOTimeGPSAttributeValue(&creation_time, file, "creation_time_gps"); \
106 if (XLALGPSCmp(&creation_time, &now)) { \
107 fprintf(stderr, " FAIL\n"); \
110 XLALH5FileQueryScalarAttributeValue(&cnt, file, "test_count"); \
111 if (cnt != count) { \
112 fprintf(stderr, " FAIL\n"); \
115 group = XLALH5GroupOpen(file, GROUP); \
116 XLALH5FileQueryStringAttributeValue(t, sizeof(t), group, "test_data_type"); \
117 XLALH5FileClose(group); \
118 if (strcmp(t, #type)) { \
119 fprintf(stderr, " FAIL\n"); \
122 x = XLALH5FileRead ## type (file, GROUP "/" DSET); \
123 XLALH5FileClose(file); \
127 #define DEFINE_TEST_FUNCTION(type) \
128 static void test_ ## type (void) { \
131 fprintf(stderr, "Testing Read/Write of %s...", #type); \
132 orig = create_ ## type (); \
133 write_ ## type (orig); \
134 copy = read_ ## type (); \
135 if (compare_ ## type (orig, copy)) { \
136 fprintf(stderr, " FAIL\n"); \
139 XLALDestroy ## type (copy); \
140 XLALDestroy ## type (orig); \
141 fprintf(stderr, " PASS\n"); \
146 #define DEFINE_CREATE_VECTOR_FUNCTION(type) \
147 static type * create_ ## type (void) { \
150 v = XLALCreate ## type (NPTS); \
151 for (i = 0; i < NPTS; ++i) \
152 v->data[i] = GENERATE_DATA(); \
156 #define DEFINE_COMPARE_VECTOR_FUNCTION(type) \
157 static int compare_ ## type (type *v1, type *v2) { \
158 if (v1->length != v2->length) \
160 return memcmp(v1->data, v2->data, v1->length * sizeof(*v1->data)); \
168 for (i = 0; i < NPTS; ++i)
169 v->
data[i] = generate_string_data();
177 for (
size_t i = 0; i < v1->
length; ++i)
178 if (strcmp(v1->
data[i], v2->
data[i]) != 0)
185 #define DEFINE_CREATE_ARRAY_FUNCTION(type) \
186 static type * create_ ## type (void) { \
189 a = XLALCreate ## type ## L(NDIM, DIM0, DIM1, DIM2); \
190 for (i = 0; i < NPTS; ++i) \
191 a->data[i] = GENERATE_DATA(); \
195 #define DEFINE_COMPARE_ARRAY_FUNCTION(type) \
196 static int compare_ ## type (type *a1, type *a2) { \
197 size_t sz1 = 1, sz2 = 1, i; \
198 if (a1->dimLength->length != a2->dimLength->length) \
200 for (i = 0; i < a1->dimLength->length; ++i) { \
201 if (a1->dimLength->data[i] != a2->dimLength->data[i]) \
203 sz1 *= a1->dimLength->data[i]; \
204 sz2 *= a2->dimLength->data[i]; \
208 return memcmp(a1->data, a2->data, sz1 * sizeof(*a1->data)); \
213 #define DEFINE_CREATE_TIME_FREQUENCY_SERIES_FUNCTION(type) \
214 static type * create_ ## type (void) { \
217 s = XLALCreate ## type ("test_" #type, &epoch, 0.0, 0.1, &lalStrainUnit, NPTS); \
218 for (i = 0; i < NPTS; ++i) \
219 s->data->data[i] = GENERATE_DATA(); \
223 #define DEFINE_COMPARE_TIME_SERIES_FUNCTION(type) \
224 static int compare_ ## type (type *s1, type *s2) { \
226 if (s1->data->length != s2->data->length) \
228 if ((c = strcmp(s1->name, s2->name))) \
230 if ((c = (s1->deltaT > s2->deltaT) - (s1->deltaT < s2->deltaT))) \
232 if ((c = (s1->f0 > s2->f0) - (s1->f0 < s2->f0))) \
234 if (XLALUnitCompare(&s1->sampleUnits, &s2->sampleUnits)) \
236 return memcmp(s1->data->data, s2->data->data, s1->data->length * sizeof(*s1->data->data)); \
239 #define DEFINE_COMPARE_FREQUENCY_SERIES_FUNCTION(type) \
240 static int compare_ ## type (type *s1, type *s2) { \
242 if (s1->data->length != s2->data->length) \
244 if ((c = strcmp(s1->name, s2->name))) \
246 if ((c = (s1->deltaF > s2->deltaF) - (s1->deltaF < s2->deltaF))) \
248 if ((c = (s1->f0 > s2->f0) - (s1->f0 < s2->f0))) \
250 if (XLALUnitCompare(&s1->sampleUnits, &s2->sampleUnits)) \
252 return memcmp(s1->data->data, s2->data->data, s1->data->length * sizeof(*s1->data->data)); \
255 #define DEFINE_VECTOR_FUNCTIONS(type) \
256 DEFINE_WRITE_FUNCTION(type) \
257 DEFINE_READ_FUNCTION(type) \
258 DEFINE_COMPARE_VECTOR_FUNCTION(type) \
259 DEFINE_CREATE_VECTOR_FUNCTION(type) \
260 DEFINE_TEST_FUNCTION(type)
262 #define DEFINE_ARRAY_FUNCTIONS(type) \
263 DEFINE_WRITE_FUNCTION(type) \
264 DEFINE_READ_FUNCTION(type) \
265 DEFINE_COMPARE_ARRAY_FUNCTION(type) \
266 DEFINE_CREATE_ARRAY_FUNCTION(type) \
267 DEFINE_TEST_FUNCTION(type)
269 #define DEFINE_TIME_SERIES_FUNCTIONS(type) \
270 DEFINE_WRITE_FUNCTION(type) \
271 DEFINE_READ_FUNCTION(type) \
272 DEFINE_COMPARE_TIME_SERIES_FUNCTION(type) \
273 DEFINE_CREATE_TIME_FREQUENCY_SERIES_FUNCTION(type) \
274 DEFINE_TEST_FUNCTION(type)
276 #define DEFINE_FREQUENCY_SERIES_FUNCTIONS(type) \
277 DEFINE_WRITE_FUNCTION(type) \
278 DEFINE_READ_FUNCTION(type) \
279 DEFINE_COMPARE_FREQUENCY_SERIES_FUNCTION(type) \
280 DEFINE_CREATE_TIME_FREQUENCY_SERIES_FUNCTION(type) \
281 DEFINE_TEST_FUNCTION(type)
283 #define GENERATE_DATA generate_int_data
292 #define GENERATE_DATA generate_float_data
296 #define GENERATE_DATA generate_complex_data
301 #define StringVector LALStringVector
302 DEFINE_WRITE_FUNCTION(StringVector)
303 DEFINE_READ_FUNCTION(StringVector)
304 DEFINE_TEST_FUNCTION(StringVector)
306 #define GENERATE_DATA generate_int_data
314 #define GENERATE_DATA generate_float_data
318 #define GENERATE_DATA generate_complex_data
323 #define GENERATE_DATA generate_int_data
331 #define GENERATE_DATA generate_float_data
335 #define GENERATE_DATA generate_complex_data
340 #define GENERATE_DATA generate_float_data
344 #define GENERATE_DATA generate_complex_data
362 test_COMPLEX8Vector();
363 test_COMPLEX16Vector();
374 test_COMPLEX8Array();
375 test_COMPLEX16Array();
377 test_INT2TimeSeries();
378 test_INT4TimeSeries();
379 test_INT8TimeSeries();
380 test_UINT2TimeSeries();
381 test_UINT4TimeSeries();
382 test_UINT8TimeSeries();
383 test_REAL4TimeSeries();
384 test_REAL8TimeSeries();
385 test_COMPLEX8TimeSeries();
386 test_COMPLEX16TimeSeries();
388 test_REAL4FrequencySeries();
389 test_REAL8FrequencySeries();
390 test_COMPLEX8FrequencySeries();
391 test_COMPLEX16FrequencySeries();
void LALCheckMemoryLeaks(void)
uint16_t UINT2
Two-byte unsigned integer.
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
LALStringVector * XLALCreateEmptyStringVector(UINT4 length)
Create an empty string vector of the given length.
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that raises SIGABRT.
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
Sets the error handler to a new handler and returns the old handler.
Vector of type CHAR, see DATATYPE-Vector types for more details.
Multidimentional array of COMPLEX16, see DATATYPE-Array types for more details.
See DATATYPE-FrequencySeries types for documentation.
Time series of COMPLEX16 data, see DATATYPE-TimeSeries types for more details.
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
Multidimentional array of COMPLEX8, see DATATYPE-Array types for more details.
See DATATYPE-FrequencySeries types for documentation.
Time series of COMPLEX8 data, see DATATYPE-TimeSeries types for more details.
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
Multidimentional array of INT2, see DATATYPE-Array types for more details.
Time series of INT2 data, see DATATYPE-TimeSeries types for more details.
Vector of type INT2, see DATATYPE-Vector types for more details.
Multidimentional array of INT4, see DATATYPE-Array types for more details.
Time series of INT4 data, see DATATYPE-TimeSeries types for more details.
Vector of type INT4, see DATATYPE-Vector types for more details.
Multidimentional array of INT8, see DATATYPE-Array types for more details.
Time series of INT8 data, see DATATYPE-TimeSeries types for more details.
Vector of type INT8, see DATATYPE-Vector types for more details.
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
CHAR ** data
Pointer to the data array.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Multidimentional array of REAL4, see DATATYPE-Array types for more details.
See DATATYPE-FrequencySeries types for documentation.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
Vector of type REAL4, see DATATYPE-Vector types for more details.
Multidimentional array of REAL8, see DATATYPE-Array types for more details.
See DATATYPE-FrequencySeries types for documentation.
Time series of REAL8 data, see DATATYPE-TimeSeries types for more details.
Vector of type REAL8, see DATATYPE-Vector types for more details.
Multidimentional array of UINT2, see DATATYPE-Array types for more details.
Time series of UINT2 data, see DATATYPE-TimeSeries types for more details.
Vector of type UINT2, see DATATYPE-Vector types for more details.
Multidimentional array of UINT4, see DATATYPE-Array types for more details.
Time series of UINT4 data, see DATATYPE-TimeSeries types for more details.
Vector of type UINT4, see DATATYPE-Vector types for more details.
Multidimentional array of UINT8, see DATATYPE-Array types for more details.
Time series of UINT8 data, see DATATYPE-TimeSeries types for more details.
Vector of type UINT8, see DATATYPE-Vector types for more details.