Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FITSFileIOTest.c
Go to the documentation of this file.
1//
2// Copyright (C) 2016 Karl Wette
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#include <config.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <errno.h>
24#include <string.h>
25#include <math.h>
26#include <limits.h>
27#include <float.h>
28
29#include <lal/FITSFileIO.h>
30#include <lal/LALPulsarVCSInfo.h>
31#include <lal/LALString.h>
32#include <lal/StringVector.h>
33#include <lal/Date.h>
34#include <lal/UserInput.h>
35#include <lal/GSLHelpers.h>
36
37#if !defined(HAVE_LIBCFITSIO)
38
39int main( void )
40{
41 fprintf( stderr, "CFITSIO library is not available; skipping test\n" );
42 return 77;
43}
44
45#else // defined(HAVE_LIBCFITSIO)
46
47const CHAR *longstring_ref = \
48 "This is a long string #1. This is a long string #2. " \
49 "This is a long string #3. This is a long string #4. " \
50 "This is a long string #5. This is a long string #6. " \
51 "This is a long string #7. This is a long string #8. " \
52 "This is a long string #9. This is a long string #10." ;
53
54typedef struct {
55 INT4 n;
56 REAL4 v;
57 CHAR desc[4];
58 UINT8 idx;
59} TestSubRecord;
60
61typedef struct {
62 INT4 index;
63 BOOLEAN flag;
64 CHAR name[8];
66 struct {
67 REAL4 sky;
68 REAL8 freq;
69 REAL8 fkdot[5];
70 } pos;
71 REAL8 values[2];
72 COMPLEX8 phasef;
74 REAL4 *array;
75 const TestSubRecord *sub;
76} TestRecord;
77
78REAL4 testarray[3][1824] = { { 0 }, { 0 }, { 0 } };
79
80const TestSubRecord testsub[3][2] = {
81 { { .n = 0, .v = 1.23, .desc = "A1", .idx = 3 }, { .n = 1, .v = 2.34, .desc = "X9", .idx = LAL_UINT8_MAX >> 0 } },
82 { { .n = 0, .v = 3.45, .desc = "B3", .idx = 7 }, { .n = 1, .v = 4.56, .desc = "Y7", .idx = LAL_UINT8_MAX >> 1 } },
83 { { .n = 0, .v = 5.67, .desc = "C5", .idx = 11 }, { .n = 1, .v = 6.78, .desc = "Z5", .idx = LAL_UINT8_MAX >> 5 } },
84};
85
86const TestRecord testtable[3] = {
87 {
88 .index = 3, .flag = 1, .name = "CasA", .epoch = {123456789, 5}, .pos = {.sky = 5.4321, .freq = 100.999, .fkdot = {1e-9, 5e-20}}, .values = {13.24, 43.234},
89 .phasef = crectf( 1.2, 3.4 ), .phase = crect( 4.5, 0.2 ), .array = testarray[0], .sub = testsub[0]
90 },
91 {
92 .index = 2, .flag = 0, .name = "Vela", .epoch = {452456245, 9}, .pos = {.sky = 34.454, .freq = 1345.34, .fkdot = {2e-8, 6e-21}}, .values = {14.35, 94.128},
93 .phasef = crectf( 3.6, 9.3 ), .phase = crect( 8.3, 4.0 ), .array = testarray[1], .sub = testsub[1]
94 },
95 {
96 .index = 1, .flag = 1, .name = "Crab", .epoch = {467846774, 4}, .pos = {.sky = 64.244, .freq = 15.6463, .fkdot = {4e-6, 0}}, .values = {153.4, 3.0900},
97 .phasef = crectf( 6.7, 4.4 ), .phase = crect( 5.6, 6.3 ), .array = testarray[2], .sub = testsub[2]
98 },
99};
100
101int main( int argc, char *argv[] )
102{
103
104 // Initialise test array data
105 for ( size_t i = 0; i < XLAL_NUM_ELEM( testarray ); ++i ) {
106 for ( size_t j = 0; j < XLAL_NUM_ELEM( testarray[0] ); ++j ) {
107 testarray[i][j] = LAL_PI * i - LAL_E * j;
108 }
109 }
110
111 // Create a dummy user enviroment and command line, for testing XLALFITSFileWriteUVarCmdLine()
112 struct uvar_type {
113 INT4 dummy;
114 } uvar_struct = { .dummy = 0 };
115 struct uvar_type *const uvar = &uvar_struct;
116 XLAL_CHECK_MAIN( XLALRegisterUvarMember( dummy, INT4, 0, OPTIONAL, "Dummy option" ) == XLAL_SUCCESS, XLAL_EFUNC );
117 BOOLEAN should_exit = 0;
118 XLAL_CHECK_MAIN( argc > 0, XLAL_ESYS );
119 char *my_argv[] = { argv[0], XLALStringDuplicate( "--dummy=3" ) };
121 XLAL_CHECK_MAIN( !should_exit, XLAL_EFAILED );
122 XLALFree( my_argv[1] );
123
124 // Write an example FITS file
125 {
126 FITSFile *file = XLALFITSFileOpenWrite( "FITSFileIOTest.fits" );
127 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC );
130 XLAL_CHECK_MAIN( XLALFITSHeaderWriteComment( file, "%s\n%s", "This is a test comment", longstring_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
131 fprintf( stderr, "PASSED: opened 'FITSFileIOTest.fits' for writing\n" );
132
133 XLAL_CHECK_MAIN( XLALFITSHeaderWriteBOOLEAN( file, "testbool", 1, "This is a test BOOLEAN" ) == XLAL_SUCCESS, XLAL_EFUNC );
134 fprintf( stderr, "PASSED: wrote a BOOLEAN\n" );
135
136 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT2( file, "testushrt", 1234, "This is a test UINT2" ) == XLAL_SUCCESS, XLAL_EFUNC );
137 fprintf( stderr, "PASSED: wrote a UINT2\n" );
138
139 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT4( file, "testuint [m]", 34567, "This is a test UINT4" ) == XLAL_SUCCESS, XLAL_EFUNC );
140 fprintf( stderr, "PASSED: wrote a UINT4\n" );
141
142 XLAL_CHECK_MAIN( XLALFITSHeaderWriteUINT8( file, "testuint2", LAL_UINT8_MAX >> 1, "This is a test UINT8" ) == XLAL_SUCCESS, XLAL_EFUNC );
143 fprintf( stderr, "PASSED: wrote a UINT8\n" );
144
145 XLAL_CHECK_MAIN( XLALFITSHeaderWriteINT2( file, "testshrt", -1234, "This is a test INT2" ) == XLAL_SUCCESS, XLAL_EFUNC );
146 fprintf( stderr, "PASSED: wrote a INT2\n" );
147
148 XLAL_CHECK_MAIN( XLALFITSHeaderWriteINT4( file, "testint [s]", -2345, "This is a test INT4" ) == XLAL_SUCCESS, XLAL_EFUNC );
149 fprintf( stderr, "PASSED: wrote a INT4\n" );
150
151 XLAL_CHECK_MAIN( XLALFITSHeaderWriteINT8( file, "testint2", LAL_INT4_MAX + 6789, "This is a test INT8" ) == XLAL_SUCCESS, XLAL_EFUNC );
152 fprintf( stderr, "PASSED: wrote a INT8\n" );
153
154 XLAL_CHECK_MAIN( XLALFITSHeaderWriteREAL4( file, "testflt", LAL_PI, "This is a test REAL4" ) == XLAL_SUCCESS, XLAL_EFUNC );
155 fprintf( stderr, "PASSED: wrote a REAL4\n" );
156
157 XLAL_CHECK_MAIN( XLALFITSHeaderWriteREAL8( file, "testdbl [Hz]", LAL_E, "This is a test REAL8" ) == XLAL_SUCCESS, XLAL_EFUNC );
158 fprintf( stderr, "PASSED: wrote a REAL8\n" );
159
160 XLAL_CHECK_MAIN( XLALFITSHeaderWriteCOMPLEX8( file, "testcmp", crectf( LAL_PI_2, LAL_PI_4 ), "This is a test COMPLEX8" ) == XLAL_SUCCESS, XLAL_EFUNC );
161 fprintf( stderr, "PASSED: wrote a COMPLEX8\n" );
162
163 XLAL_CHECK_MAIN( XLALFITSHeaderWriteCOMPLEX16( file, "testdblcmp", crect( LAL_LOG2E, LAL_LOG10E ), "This is a test COMPLEX16" ) == XLAL_SUCCESS, XLAL_EFUNC );
164 fprintf( stderr, "PASSED: wrote a COMPLEX16\n" );
165
166 XLAL_CHECK_MAIN( XLALFITSHeaderWriteString( file, "teststr", "This is a short string", "This is a test string" ) == XLAL_SUCCESS, XLAL_EFUNC );
167 fprintf( stderr, "PASSED: wrote a string\n" );
168
169 XLAL_CHECK_MAIN( XLALFITSHeaderWriteString( file, "longstring", longstring_ref, "This is a long test string" ) == XLAL_SUCCESS, XLAL_EFUNC );
170 fprintf( stderr, "PASSED: wrote a long string\n" );
171
172 LALStringVector *testsv = XLALCreateStringVector( "abc", "def", "ghij", NULL );
173 XLAL_CHECK_MAIN( testsv != NULL, XLAL_EFUNC );
174 XLAL_CHECK_MAIN( XLALFITSHeaderWriteStringVector( file, "testsv", testsv, "These are test string vector entries" ) == XLAL_SUCCESS, XLAL_EFUNC );
175 XLALDestroyStringVector( testsv );
176 fprintf( stderr, "PASSED: wrote a string vector\n" );
177
178 LIGOTimeGPS ref_time = { 987654321, 123456789 };
179 XLAL_CHECK_MAIN( XLALFITSHeaderWriteGPSTime( file, "date-obs", &ref_time, "This is the reference time" ) == XLAL_SUCCESS, XLAL_EFUNC );
180 fprintf( stderr, "PASSED: wrote a GPS time\n" );
181
182 {
183 const size_t dims[4] = {1, 2, 3, 4};
184 XLAL_CHECK_MAIN( XLALFITSArrayOpenWrite( file, "array1", XLAL_NUM_ELEM( dims ), dims, "This is a test INT4 array" ) == XLAL_SUCCESS, XLAL_EFUNC );
185 size_t idx[4];
186 for ( idx[0] = 0; idx[0] < dims[0]; ++idx[0] ) {
187 for ( idx[1] = 0; idx[1] < dims[1]; ++idx[1] ) {
188 for ( idx[2] = 0; idx[2] < dims[2]; ++idx[2] ) {
189 for ( idx[3] = 0; idx[3] < dims[3]; ++idx[3] ) {
190 const INT4 value = idx[0] + 2 * idx[1] + 3 * idx[2] + 4 * idx[3];
192 }
193 }
194 }
195 }
196 }
197 fprintf( stderr, "PASSED: wrote a INT4 array\n" );
198
199 XLAL_CHECK_MAIN( XLALFITSArrayOpenWrite2( file, "array2", 2, 2, "This is a test UINT8 array" ) == XLAL_SUCCESS, XLAL_EFUNC );
200 for ( size_t i = 0; i < 2; ++i ) {
201 for ( size_t j = 0; j < 2; ++j ) {
202 const size_t idx[] = { i, j };
203 const UINT8 value = LAL_UINT8_MAX >> ( 1 + i + j );
205 }
206 }
207 fprintf( stderr, "PASSED: wrote a UINT8 array\n" );
208
209 XLAL_CHECK_MAIN( XLALFITSArrayOpenWrite1( file, "array3", 14, "This is a test REAL4 array" ) == XLAL_SUCCESS, XLAL_EFUNC );
210 for ( size_t i = 0; i < 14; ++i ) {
211 const size_t idx[] = { i };
212 const REAL4 value = 21 + 0.5 * i;
214 }
215 fprintf( stderr, "PASSED: wrote a REAL4 array\n" );
216
217 {
218 const size_t m = 2, n = 3;
219 gsl_matrix *GAMAT( elems, m, n );
220 for ( size_t i = 0; i < m; ++i ) {
221 for ( size_t j = 0; j < n; ++j ) {
222 const double value = 7.0 + 2.5 * i + 3.0 * j;
223 gsl_matrix_set( elems, i, j, value );
224 }
225 }
226 XLAL_CHECK_MAIN( XLALFITSArrayOpenWrite2( file, "array4", m, n, "This is a test REAL8 array" ) == XLAL_SUCCESS, XLAL_EFUNC );
228 GFMAT( elems );
229 }
230 fprintf( stderr, "PASSED: wrote a gsl_matrix\n" );
231
232 XLAL_CHECK_MAIN( XLALFITSTableOpenWrite( file, "table1", "This is a test table" ) == XLAL_SUCCESS, XLAL_EFUNC );
233 {
234 XLAL_FITS_TABLE_COLUMN_BEGIN( TestRecord );
247 {
248 XLAL_FITS_TABLE_COLUMN_PTR_STRUCT_BEGIN( sub, TestSubRecord, 2 );
257 }
258 }
259 for ( size_t i = 0; i < XLAL_NUM_ELEM( testtable ); ++i ) {
261 }
262 fprintf( stderr, "PASSED: wrote a table\n" );
263
264 XLAL_CHECK_MAIN( XLALFITSHeaderWriteComment( file, "%s", "This is another test comment" ) == XLAL_SUCCESS, XLAL_EFUNC );
268 XLAL_CHECK_MAIN( XLALFITSFileWriteHistory( file, "%s\n%s", "This is a test history", longstring_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
269 fprintf( stderr, "PASSED: HDU seeking in write mode\n" );
270
272 fprintf( stderr, "PASSED: closed 'FITSFileIOTest.fits'\n" );
273 }
274 fprintf( stderr, "\n" );
275 fflush( stderr );
276
277 // Read the example FITS file and check data is consistent
278 // - Data is read in reverse order to check HDU seeking
279 {
280 FITSFile *file = XLALFITSFileOpenRead( "FITSFileIOTest.fits" );
281 XLAL_CHECK_MAIN( file != NULL, XLAL_EFUNC );
282 fprintf( stderr, "PASSED: opened 'FITSFileIOTest.fits' for reading\n" );
283
284 {
285 UINT8 nrows = LAL_UINT8_MAX;
287 XLAL_CHECK_MAIN( nrows == XLAL_NUM_ELEM( testtable ), XLAL_EFAILED );
288 {
289 XLAL_FITS_TABLE_COLUMN_BEGIN( TestRecord );
292 {
293 int errnum = 0;
296 }
297 {
298 int errnum = 0;
301 }
306 {
307 int errnum = 0;
308 XLAL_TRY_SILENT( XLAL_FITS_TABLE_COLUMN_ADD_NAMED( file, REAL8, pos.fkdot[0], "wrong" ), errnum );
310 }
317 {
318 XLAL_FITS_TABLE_COLUMN_PTR_STRUCT_BEGIN( sub, TestSubRecord, 2 );
319 for ( size_t s = 0; s < 2; ++s ) {
320 char col_name[32];
321 snprintf( col_name, sizeof( col_name ), "n%zu", s + 1 );
323 snprintf( col_name, sizeof( col_name ), "v%zu", s + 1 );
325 snprintf( col_name, sizeof( col_name ), "desc%zu", s + 1 );
327 snprintf( col_name, sizeof( col_name ), "idx%zu", s + 1 );
329 }
330 }
331 }
332 TestRecord XLAL_INIT_DECL( record );
333 REAL4 XLAL_INIT_DECL( record_array, [XLAL_NUM_ELEM( testarray[0] )] );
334 record.array = record_array;
335 TestSubRecord XLAL_INIT_DECL( record_sub, [2] );
336 record.sub = record_sub;
337 size_t i = 0;
338 while ( nrows > 0 ) {
340 XLAL_CHECK_MAIN( nrows == XLAL_NUM_ELEM( testtable ) - i - 1, XLAL_EFAILED );
341 XLAL_CHECK_MAIN( record.index == testtable[i].index, XLAL_EFAILED );
342 XLAL_CHECK_MAIN( record.flag == testtable[i].flag, XLAL_EFAILED );
343 XLAL_CHECK_MAIN( strcmp( record.name, testtable[i].name ) == 0, XLAL_EFAILED );
344 XLAL_CHECK_MAIN( XLALGPSCmp( &record.epoch, &testtable[i].epoch ) == 0, XLAL_EFAILED );
345 XLAL_CHECK_MAIN( record.pos.sky == testtable[i].pos.sky, XLAL_EFAILED );
346 XLAL_CHECK_MAIN( record.pos.freq == testtable[i].pos.freq, XLAL_EFAILED );
347 for ( size_t j = 0; j < XLAL_NUM_ELEM( record.pos.fkdot ); ++j ) {
348 XLAL_CHECK_MAIN( record.pos.fkdot[j] == testtable[i].pos.fkdot[j], XLAL_EFAILED );
349 }
350 for ( size_t j = 0; j < XLAL_NUM_ELEM( record.values ); ++j ) {
351 XLAL_CHECK_MAIN( record.values[j] == testtable[i].values[j], XLAL_EFAILED );
352 }
353 XLAL_CHECK_MAIN( record.phasef == testtable[i].phasef, XLAL_EFAILED );
354 XLAL_CHECK_MAIN( record.phase == testtable[i].phase, XLAL_EFAILED );
355 for ( size_t j = 0; j < XLAL_NUM_ELEM( testarray[0] ); ++j ) {
356 XLAL_CHECK_MAIN( record.array[j] == testtable[i].array[j], XLAL_EFAILED );
357 }
358 for ( size_t s = 0; s < 2; ++s ) {
359 XLAL_CHECK_MAIN( record.sub[s].n == testtable[i].sub[s].n, XLAL_EFAILED );
360 XLAL_CHECK_MAIN( record.sub[s].v == testtable[i].sub[s].v, XLAL_EFAILED );
361 XLAL_CHECK_MAIN( strcmp( record.sub[s].desc, testtable[i].sub[s].desc ) == 0, XLAL_EFAILED );
362 XLAL_CHECK_MAIN( record.sub[s].idx == testtable[i].sub[s].idx, XLAL_EFAILED );
363 }
364 ++i;
365 }
366 XLAL_CHECK_MAIN( i == XLAL_NUM_ELEM( testtable ), XLAL_EFAILED );
368 XLAL_CHECK_MAIN( nrows == 0, XLAL_EFAILED );
370 }
371 fprintf( stderr, "PASSED: read and verified a table\n" );
372
373 {
374 size_t m = 0, n = 0;
377 XLAL_CHECK_MAIN( n == 3, XLAL_EFAILED );
378 gsl_matrix *elems = NULL;
380 for ( size_t i = 0; i < m; ++i ) {
381 for ( size_t j = 0; j < n; ++j ) {
382 const double value_ref = 7.0 + 2.5 * i + 3.0 * j;
383 double value = gsl_matrix_get( elems, i, j );
384 XLAL_CHECK_MAIN( value == value_ref, XLAL_EFAILED, "value[%zu,%zu] = %g != %g", i, j, value, value_ref );
385 }
386 }
387 GFMAT( elems );
388 }
389 fprintf( stderr, "PASSED: read and verified a gsl_matrix\n" );
390
391 {
392 size_t dim = 0;
394 XLAL_CHECK_MAIN( dim == 14, XLAL_EFAILED );
395 for ( size_t i = 0; i < dim; ++i ) {
396 const size_t idx[] = { i };
397 const REAL4 value_ref = 21 + 0.5 * i;
398 REAL4 value = 0;
400 XLAL_CHECK_MAIN( value == value_ref, XLAL_EFAILED, "value[%zu] = %g != %g", i, value, value_ref );
401 }
402 }
403 fprintf( stderr, "PASSED: read and verified a REAL4 array\n" );
404
405 {
406 size_t dim_i = 0, dim_j = 0;
407 XLAL_CHECK_MAIN( XLALFITSArrayOpenRead2( file, "array2", &dim_i, &dim_j ) == XLAL_SUCCESS, XLAL_EFUNC );
408 XLAL_CHECK_MAIN( dim_i == 2, XLAL_EFAILED );
409 XLAL_CHECK_MAIN( dim_j == 2, XLAL_EFAILED );
410 for ( size_t i = 0; i < dim_i; ++i ) {
411 for ( size_t j = 0; j < dim_j; ++j ) {
412 const size_t idx[] = { i, j };
413 const UINT8 value_ref = LAL_UINT8_MAX >> ( 1 + i + j );
414 UINT8 value = 0;
416 XLAL_CHECK_MAIN( value == value_ref, XLAL_EFAILED, "value[%zu,%zu] = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT, i, j, value, value_ref );
417 }
418 }
419 }
420 fprintf( stderr, "PASSED: read and verified a UINT8 array\n" );
421
422 {
423 size_t ndim, dims[FFIO_MAX];
424 XLAL_CHECK_MAIN( XLALFITSArrayOpenRead( file, "array1", &ndim, dims ) == XLAL_SUCCESS, XLAL_EFUNC );
425 XLAL_CHECK_MAIN( ndim == 4, XLAL_EFAILED );
426 size_t idx[4];
427 for ( idx[0] = 0; idx[0] < dims[0]; ++idx[0] ) {
428 for ( idx[1] = 0; idx[1] < dims[1]; ++idx[1] ) {
429 for ( idx[2] = 0; idx[2] < dims[2]; ++idx[2] ) {
430 for ( idx[3] = 0; idx[3] < dims[3]; ++idx[3] ) {
431 const INT4 value_ref = idx[0] + 2 * idx[1] + 3 * idx[2] + 4 * idx[3];
432 INT4 value = 0;
434 XLAL_CHECK_MAIN( value == value_ref, XLAL_EFAILED, "value[%zu,%zu,%zu,%zu] = %i != %i", idx[0], idx[1], idx[2], idx[3], value, value_ref );
435 }
436 }
437 }
438 }
439 }
440 fprintf( stderr, "PASSED: read and verified a INT4 array\n" );
441
443
444 {
445 BOOLEAN testbool;
447 XLAL_CHECK_MAIN( testbool, XLAL_EFAILED, "testbool is not true" );
448 }
449 fprintf( stderr, "PASSED: read and verified a BOOLEAN\n" );
450
451 {
452 const UINT2 testushrt_ref = 1234;
453 UINT2 testushrt;
454 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT2( file, "testushrt", &testushrt ) == XLAL_SUCCESS, XLAL_EFUNC );
455 XLAL_CHECK_MAIN( testushrt == testushrt_ref, XLAL_EFAILED, "testushrt = %i != %i", testushrt, testushrt_ref );
456 }
457 fprintf( stderr, "PASSED: read and verified a UINT2\n" );
458
459 {
460 const UINT4 testuint_ref = 34567;
461 UINT4 testuint;
462 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT4( file, "testuint", &testuint ) == XLAL_SUCCESS, XLAL_EFUNC );
463 XLAL_CHECK_MAIN( testuint == testuint_ref, XLAL_EFAILED, "testuint = %i != %i", testuint, testuint_ref );
464 }
465 fprintf( stderr, "PASSED: read and verified a UINT4\n" );
466
467 {
468 UINT4 testuint2_too_small;
469 int errnum = 0;
470 XLAL_TRY_SILENT( XLALFITSHeaderReadUINT4( file, "testuint2", &testuint2_too_small ), errnum );
472 }
473 {
474 const UINT8 testuint2_ref = LAL_UINT8_MAX >> 1;
475 UINT8 testuint2;
476 XLAL_CHECK_MAIN( XLALFITSHeaderReadUINT8( file, "testuint2", &testuint2 ) == XLAL_SUCCESS, XLAL_EFUNC );
477 XLAL_CHECK_MAIN( testuint2 == testuint2_ref, XLAL_EFAILED, "testuint = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT, testuint2, testuint2_ref );
478 }
479 fprintf( stderr, "PASSED: read and verified a UINT8\n" );
480
481 {
482 const INT2 testshrt_ref = -1234;
483 INT2 testshrt;
484 XLAL_CHECK_MAIN( XLALFITSHeaderReadINT2( file, "testshrt", &testshrt ) == XLAL_SUCCESS, XLAL_EFUNC );
485 XLAL_CHECK_MAIN( testshrt == testshrt_ref, XLAL_EFAILED, "testshrt = %i != %i", testshrt, testshrt_ref );
486 }
487 fprintf( stderr, "PASSED: read and verified a INT2\n" );
488
489 {
490 const INT4 testint_ref = -2345;
491 INT4 testint;
493 XLAL_CHECK_MAIN( testint == testint_ref, XLAL_EFAILED, "testint = %i != %i", testint, testint_ref );
494 }
495 fprintf( stderr, "PASSED: read and verified a INT4\n" );
496
497 {
498 INT4 testint2_too_small;
499 int errnum = 0;
500 XLAL_TRY_SILENT( XLALFITSHeaderReadINT4( file, "testint2", &testint2_too_small ), errnum );
502 }
503 {
504 const INT8 testint2_ref = LAL_INT4_MAX + 6789;
505 INT8 testint2;
506 XLAL_CHECK_MAIN( XLALFITSHeaderReadINT8( file, "testint2", &testint2 ) == XLAL_SUCCESS, XLAL_EFUNC );
507 XLAL_CHECK_MAIN( testint2 == testint2_ref, XLAL_EFAILED, "testint = %" LAL_INT8_FORMAT " != %" LAL_INT8_FORMAT, testint2, testint2_ref );
508 }
509 fprintf( stderr, "PASSED: read and verified a INT8\n" );
510
511 {
512 const REAL4 testflt_ref = LAL_PI;
513 REAL4 testflt;
515 const REAL4 err = fabsf( testflt - testflt_ref ), err_tol = 5 * FLT_EPSILON;
516 XLAL_CHECK_MAIN( err < err_tol, XLAL_EFAILED, "|testflt - testflt_ref| = |%0.*g - %0.*g| = %0.*g >= %0.*g",
517 FLT_DIG, testflt, FLT_DIG, testflt_ref, FLT_DIG, err, FLT_DIG, err_tol );
518 }
519 fprintf( stderr, "PASSED: read and verified a REAL4\n" );
520
521 {
522 const REAL8 testdbl_ref = LAL_E;
523 REAL8 testdbl;
524 XLAL_CHECK_MAIN( XLALFITSHeaderReadREAL8( file, "testdbl", &testdbl ) == XLAL_SUCCESS, XLAL_EFUNC );
525 const REAL8 err = fabs( testdbl - testdbl_ref ), err_tol = 5 * DBL_EPSILON;
526 XLAL_CHECK_MAIN( err < err_tol, XLAL_EFAILED, "|testdbl - testdbl_ref| = |%0.*g - %0.*g| = %0.*g >= %0.*g",
527 DBL_DIG, testdbl, DBL_DIG, testdbl_ref, DBL_DIG, err, DBL_DIG, err_tol );
528 }
529 fprintf( stderr, "PASSED: read and verified a REAL8\n" );
530
531 {
532 const COMPLEX8 testcmp_ref = crectf( LAL_PI_2, LAL_PI_4 );
533 COMPLEX8 testcmp;
534 XLAL_CHECK_MAIN( XLALFITSHeaderReadCOMPLEX8( file, "testcmp", &testcmp ) == XLAL_SUCCESS, XLAL_EFUNC );
535 const REAL4 err = cabsf( testcmp - testcmp_ref ), err_tol = 5 * FLT_EPSILON;
536 XLAL_CHECK_MAIN( err < err_tol, XLAL_EFAILED, "|testcmp - testcmp_ref| = |(%0.*g,%0.*g) - (%0.*g,%0.*g)| = %0.*g >= %0.*g",
537 FLT_DIG, crealf( testcmp ), FLT_DIG, cimagf( testcmp ), FLT_DIG, crealf( testcmp_ref ), FLT_DIG, cimagf( testcmp_ref ), FLT_DIG, err, FLT_DIG, err_tol );
538 }
539 fprintf( stderr, "PASSED: read and verified a COMPLEX8\n" );
540
541 {
542 const COMPLEX16 testdblcmp_ref = crect( LAL_LOG2E, LAL_LOG10E );
543 COMPLEX16 testdblcmp;
544 XLAL_CHECK_MAIN( XLALFITSHeaderReadCOMPLEX16( file, "testdblcmp", &testdblcmp ) == XLAL_SUCCESS, XLAL_EFUNC );
545 const REAL8 err = cabs( testdblcmp - testdblcmp_ref ), err_tol = 5 * DBL_EPSILON;
546 XLAL_CHECK_MAIN( err < err_tol, XLAL_EFAILED, "|testdblcmp - testdblcmp_ref| = |(%0.*g,%0.*g) - (%0.*g,%0.*g)| = %0.*g >= %0.*g",
547 DBL_DIG, creal( testdblcmp ), DBL_DIG, cimag( testdblcmp ), DBL_DIG, creal( testdblcmp_ref ), DBL_DIG, cimag( testdblcmp_ref ), DBL_DIG, err, DBL_DIG, err_tol );
548 }
549 fprintf( stderr, "PASSED: read and verified a COMPLEX16\n" );
550
551 {
552 const CHAR *teststr_ref = "This is a short string";
553 CHAR *teststr = NULL;
554 XLAL_CHECK_MAIN( XLALFITSHeaderReadString( file, "teststr", &teststr ) == XLAL_SUCCESS, XLAL_EFUNC );
555 XLAL_CHECK_MAIN( strcmp( teststr, teststr_ref ) == 0, XLAL_EFAILED, "teststr = '%s' != '%s'", teststr, teststr_ref );
556 XLALFree( teststr );
557 }
558 fprintf( stderr, "PASSED: read and verified a string\n" );
559
560 {
561 CHAR *longstring = NULL;
562 XLAL_CHECK_MAIN( XLALFITSHeaderReadString( file, "longstring", &longstring ) == XLAL_SUCCESS, XLAL_EFUNC );
563 XLAL_CHECK_MAIN( strcmp( longstring, longstring_ref ) == 0, XLAL_EFAILED, "longstring = '%s' != '%s'", longstring, longstring_ref );
564 XLALFree( longstring );
565 }
566 fprintf( stderr, "PASSED: read and verified a long string\n" );
567
568 {
569 LALStringVector *testsv = NULL;
570 XLAL_CHECK_MAIN( XLALFITSHeaderReadStringVector( file, "testsv", &testsv ) == XLAL_SUCCESS, XLAL_EFUNC );
571 XLAL_CHECK_MAIN( testsv->length == 3, XLAL_EFAILED, "testsv->length = %u != 3", testsv->length );
572 XLAL_CHECK_MAIN( strcmp( testsv->data[0], "abc" ) == 0, XLAL_EFAILED, "testsv->data[0] = '%s' != 'abc'", testsv->data[0] );
573 XLAL_CHECK_MAIN( strcmp( testsv->data[1], "def" ) == 0, XLAL_EFAILED, "testsv->data[1] = '%s' != 'def'", testsv->data[1] );
574 XLAL_CHECK_MAIN( strcmp( testsv->data[2], "ghij" ) == 0, XLAL_EFAILED, "testsv->data[2] = '%s' != 'ghij'", testsv->data[2] );
575 XLALDestroyStringVector( testsv );
576 }
577 fprintf( stderr, "PASSED: read and verified a string vector\n" );
578
579 {
580 LIGOTimeGPS ref_time = LIGOTIMEGPSZERO;
581 XLAL_CHECK_MAIN( XLALFITSHeaderReadGPSTime( file, "date-obs", &ref_time ) == XLAL_SUCCESS, XLAL_EFUNC );
582 XLAL_CHECK_MAIN( ref_time.gpsSeconds == 987654321 && ref_time.gpsNanoSeconds == 123456789, XLAL_EFAILED,
583 "ref_time = %" LAL_GPS_FORMAT " != 987654321.123456789", LAL_GPS_PRINT( ref_time ) );
584 }
585 fprintf( stderr, "PASSED: read and verified a GPS time\n" );
586
587 {
588 const struct {
589 BOOLEAN exists;
590 const CHAR *key;
591 } keys[] = { { 1, "date-obs" }, { 1, "testdbl" }, { 0, "banana" }, { 1, "longstring" } };
592 for ( size_t i = 0; i < XLAL_NUM_ELEM( keys ); ++i ) {
593 BOOLEAN exists = 0;
594 XLAL_CHECK_MAIN( XLALFITSHeaderQueryKeyExists( file, keys[i].key, &exists ) == XLAL_SUCCESS, XLAL_EFUNC );
595 XLAL_CHECK_MAIN( exists == keys[i].exists, XLAL_EFAILED, "Failed to query key '%s': %i != %i", keys[i].key, exists, keys[i].exists );
596 }
597 }
598 fprintf( stderr, "PASSED: HDU key queries in read mode\n" );
599
600 XLAL_CHECK_MAIN( XLALFITSFileSeekNamedHDU( file, "table1" ) == XLAL_SUCCESS, XLAL_EFUNC );
601 XLAL_CHECK_MAIN( XLALFITSFileSeekNamedHDU( file, "array3" ) == XLAL_SUCCESS, XLAL_EFUNC );
602 XLAL_CHECK_MAIN( XLALFITSFileSeekNamedHDU( file, "array1" ) == XLAL_SUCCESS, XLAL_EFUNC );
603 fprintf( stderr, "PASSED: HDU seeking in read mode\n" );
604
605 XLALFITSFileClose( file );
606 fprintf( stderr, "PASSED: closed 'FITSFileIOTest.fits'\n" );
607 }
608 fprintf( stderr, "\n" );
609 fflush( stderr );
610
611 // Cleanup
612 XLALDestroyUserVars();
613 LALCheckMemoryLeaks();
614
615 return EXIT_SUCCESS;
616
617}
618
619#endif // !defined(HAVE_LIBCFITSIO)
620
621// Local Variables:
622// c-file-style: "linux"
623// c-basic-offset: 2
624// End:
int XLALFITSArrayReadINT4(FITSFile UNUSED *file, const size_t UNUSED idx[], INT4 UNUSED *elem)
Definition: FITSFileIO.c:1975
int XLALFITSArrayOpenWrite1(FITSFile UNUSED *file, const CHAR UNUSED *name, const size_t UNUSED dim0, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1680
int XLALFITSHeaderWriteUINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, const UINT4 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:762
int XLALFITSArrayOpenWrite(FITSFile UNUSED *file, const CHAR UNUSED *name, const size_t UNUSED ndim, const size_t UNUSED dims[], const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1587
int XLALFITSFileSeekNamedHDU(FITSFile UNUSED *file, const CHAR UNUSED *name)
Definition: FITSFileIO.c:400
int XLALFITSTableWriteRow(FITSFile UNUSED *file, const void UNUSED *record)
Definition: FITSFileIO.c:2550
int XLALFITSHeaderWriteStringVector(FITSFile UNUSED *file, const CHAR UNUSED *key, const LALStringVector UNUSED *values, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1412
int XLALFITSFileSeekPrimaryHDU(FITSFile UNUSED *file)
Definition: FITSFileIO.c:378
int XLALFITSHeaderWriteGPSTime(FITSFile UNUSED *file, const CHAR UNUSED *key, const LIGOTimeGPS UNUSED *value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1494
int XLALFITSHeaderWriteBOOLEAN(FITSFile UNUSED *file, const CHAR UNUSED *key, const BOOLEAN UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:635
int XLALFITSTableReadRow(FITSFile UNUSED *file, void UNUSED *record, UINT8 UNUSED *rem_nrows)
Definition: FITSFileIO.c:2621
int XLALFITSArrayReadGSLMatrix(FITSFile UNUSED *file, const size_t UNUSED idx[], gsl_matrix UNUSED **elems)
Definition: FITSFileIO.c:2118
int XLALFITSHeaderReadINT2(FITSFile UNUSED *file, const CHAR UNUSED *key, INT2 UNUSED *value)
Definition: FITSFileIO.c:928
int XLALFITSHeaderReadBOOLEAN(FITSFile UNUSED *file, const CHAR UNUSED *key, BOOLEAN UNUSED *value)
Definition: FITSFileIO.c:668
int XLALFITSHeaderReadREAL4(FITSFile UNUSED *file, const CHAR UNUSED *key, REAL4 UNUSED *value)
Definition: FITSFileIO.c:1123
FITSFile * XLALFITSFileOpenWrite(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:263
int XLALFITSArrayWriteUINT8(FITSFile UNUSED *file, const size_t UNUSED idx[], const UINT8 UNUSED elem)
Definition: FITSFileIO.c:1906
int XLALFITSArrayOpenRead2(FITSFile UNUSED *file, const CHAR UNUSED *name, size_t UNUSED *dim0, size_t UNUSED *dim1)
Definition: FITSFileIO.c:1723
int XLALFITSHeaderReadINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, INT8 UNUSED *value)
Definition: FITSFileIO.c:1059
int XLALFITSHeaderWriteComment(FITSFile UNUSED *file, const CHAR UNUSED *format,...)
Definition: FITSFileIO.c:601
int XLALFITSFileWriteVCSInfo(FITSFile UNUSED *file, const LALVCSInfoList UNUSED vcs_list)
Definition: FITSFileIO.c:466
int XLALFITSFileWriteUVarCmdLine(FITSFile UNUSED *file)
Definition: FITSFileIO.c:508
int XLALFITSArrayOpenRead(FITSFile UNUSED *file, const CHAR UNUSED *name, size_t UNUSED *ndim, size_t UNUSED dims[])
Definition: FITSFileIO.c:1634
int XLALFITSHeaderWriteINT2(FITSFile UNUSED *file, const CHAR UNUSED *key, const INT2 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:893
int XLALFITSHeaderWriteCOMPLEX16(FITSFile UNUSED *file, const CHAR UNUSED *key, const COMPLEX16 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1275
int XLALFITSTableOpenWrite(FITSFile UNUSED *file, const CHAR UNUSED *name, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:2162
int XLALFITSHeaderWriteUINT2(FITSFile UNUSED *file, const CHAR UNUSED *key, const UINT2 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:697
int XLALFITSArrayWriteREAL4(FITSFile UNUSED *file, const size_t UNUSED idx[], const REAL4 UNUSED elem)
Definition: FITSFileIO.c:2016
FITSFile * XLALFITSFileOpenRead(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:320
int XLALFITSHeaderWriteINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, const INT8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1023
int XLALFITSArrayReadREAL4(FITSFile UNUSED *file, const size_t UNUSED idx[], REAL4 UNUSED *elem)
Definition: FITSFileIO.c:2029
int XLALFITSHeaderReadINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, INT4 UNUSED *value)
Definition: FITSFileIO.c:993
int XLALFITSArrayOpenRead1(FITSFile UNUSED *file, const CHAR UNUSED *name, size_t UNUSED *dim0)
Definition: FITSFileIO.c:1693
int XLALFITSArrayOpenWrite2(FITSFile UNUSED *file, const CHAR UNUSED *name, const size_t UNUSED dim0, const size_t UNUSED dim1, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1710
int XLALFITSHeaderWriteUINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, const UINT8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:827
int XLALFITSHeaderReadUINT2(FITSFile UNUSED *file, const CHAR UNUSED *key, UINT2 UNUSED *value)
Definition: FITSFileIO.c:732
void XLALFITSFileClose(FITSFile UNUSED *file)
Definition: FITSFileIO.c:245
int XLALFITSArrayWriteGSLMatrix(FITSFile UNUSED *file, const size_t UNUSED idx[], const gsl_matrix UNUSED *elems)
Definition: FITSFileIO.c:2070
int XLALFITSHeaderWriteINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, const INT4 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:958
int XLALFITSHeaderWriteREAL4(FITSFile UNUSED *file, const CHAR UNUSED *key, const REAL4 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1089
int XLALFITSHeaderWriteREAL8(FITSFile UNUSED *file, const CHAR UNUSED *key, const REAL8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1150
int XLALFITSHeaderReadUINT8(FITSFile UNUSED *file, const CHAR UNUSED *key, UINT8 UNUSED *value)
Definition: FITSFileIO.c:863
int XLALFITSHeaderWriteCOMPLEX8(FITSFile UNUSED *file, const CHAR UNUSED *key, const COMPLEX8 UNUSED value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1211
int XLALFITSArrayWriteINT4(FITSFile UNUSED *file, const size_t UNUSED idx[], const INT4 UNUSED elem)
Definition: FITSFileIO.c:1962
int XLALFITSArrayReadUINT8(FITSFile UNUSED *file, const size_t UNUSED idx[], UINT8 UNUSED *elem)
Definition: FITSFileIO.c:1920
int XLALFITSHeaderReadUINT4(FITSFile UNUSED *file, const CHAR UNUSED *key, UINT4 UNUSED *value)
Definition: FITSFileIO.c:797
int XLALFITSTableOpenRead(FITSFile UNUSED *file, const CHAR UNUSED *name, UINT8 UNUSED *nrows)
Definition: FITSFileIO.c:2198
int XLALFITSHeaderWriteString(FITSFile UNUSED *file, const CHAR UNUSED *key, const CHAR UNUSED *value, const CHAR UNUSED *comment)
Definition: FITSFileIO.c:1339
int XLALFITSFileWriteHistory(FITSFile UNUSED *file, const CHAR UNUSED *format,...)
Definition: FITSFileIO.c:429
int main(void)
#define LAL_INT4_MAX
int j
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
const char * name
Definition: SearchTiming.c:93
INT4 dummy
Definition: SinCosLUT.i:123
#define fprintf
double e
#define XLAL_FITS_TABLE_COLUMN_ADD_PTR_ARRAY(file, type, length, field)
Definition: FITSFileIO.h:261
#define XLAL_FITS_TABLE_COLUMN_BEGIN(record_type)
Definition: FITSFileIO.h:239
#define XLAL_FITS_TABLE_COLUMN_ADD_NAMED(file, type, field, col_name)
Definition: FITSFileIO.h:246
#define XLAL_FITS_TABLE_COLUMN_ADD_PTR_STRUCT_NAMED(file, index, type, field, col_name)
Definition: FITSFileIO.h:278
#define XLAL_FITS_TABLE_COLUMN_PTR_STRUCT_BEGIN(field, ptr_record_type, length)
Definition: FITSFileIO.h:273
#define XLAL_FITS_TABLE_COLUMN_ADD_PTR_STRUCT_ARRAY_NAMED(file, index, type, field, col_name)
Definition: FITSFileIO.h:281
#define XLAL_FITS_TABLE_COLUMN_ADD_ARRAY(file, type, field)
Definition: FITSFileIO.h:249
#define FFIO_MAX
Maximum possible number of FITS array dimensions, and FITS table columns.
Definition: FITSFileIO.h:49
#define XLAL_FITS_TABLE_COLUMN_ADD(file, type, field)
Definition: FITSFileIO.h:243
#define XLAL_FITS_TABLE_COLUMN_ADD_PTR_ARRAY_NAMED(file, type, length, field, col_name)
Definition: FITSFileIO.h:264
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
#define XLAL_FITS_TABLE_COLUMN_ADD_ARRAY_NAMED(file, type, field, col_name)
Definition: FITSFileIO.h:252
#define LAL_E
#define LAL_PI
#define LAL_UINT8_MAX
#define crect(re, im)
unsigned char BOOLEAN
#define XLAL_NUM_ELEM(x)
uint64_t UINT8
double complex COMPLEX16
double REAL8
#define XLAL_INIT_DECL(var,...)
int16_t INT2
int64_t INT8
#define crectf(re, im)
uint16_t UINT2
char CHAR
uint32_t UINT4
float complex COMPLEX8
int32_t INT4
float REAL4
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
static const INT4 m
static const INT4 a
void XLALDestroyStringVector(LALStringVector *vect)
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
#define XLALRegisterUvarMember(name, type, option, category,...)
#define XLAL_TRY_SILENT(statement, errnum)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_ERANGE
XLAL_EFUNC
XLAL_EIO
XLAL_ESYS
XLAL_EFAILED
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
pos
n
def phase(point, coeffs, params, ignoreintcheck=False)
desc
UserInput_t uvar_struct
Definition: sw_inj_frames.c:93
enum @1 epoch