File: test_qfits.c

package info (click to toggle)
qfits 6.2.0-8
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 2,976 kB
  • ctags: 1,019
  • sloc: ansic: 11,631; sh: 8,330; makefile: 131
file content (660 lines) | stat: -rw-r--r-- 19,794 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/* $Id: test_qfits.c,v 1.15 2007/01/10 12:29:58 yjung Exp $
 *
 * This file is part of the ESO QFITS Library
 * Copyright (C) 2001-2004 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Author: yjung $
 * $Date: 2007/01/10 12:29:58 $
 * $Revision: 1.15 $
 * $Name: qfits-6_2_0 $
 */

/*-----------------------------------------------------------------------------
                                   Includes
 -----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>

#include "qfits_header.h"
#include "qfits_image.h"
#include "qfits_tools.h"
#include "qfits_rw.h"
#include "qfits_md5.h"
#include "qfits_memory.h"

/*-----------------------------------------------------------------------------
                                   Define
 -----------------------------------------------------------------------------*/

#define QFITSTEST1             "QFITS.fits"
#define QFITSTEST2             "QFITS_ext.fits"

#define REFSIG                "6569daba7b124febfa0cd7813f555774"

/*-----------------------------------------------------------------------------
                                   Functions
 -----------------------------------------------------------------------------*/

static float float_array_orig[] =
{
    1.0, 2.0, 0.0, -1.0, -2.0, 1e-4, -1e-4, 1e-6, -1e-6,
    1.2345678, 3.1415926535, 19.71
};

static int int_array_orig[] =
{
    -32768, -16384, -8192, -4096, -1023, 0,
     1023, 2048, 8191, 16387, 32767, 65536
};

static double double_array_orig[] =
{
    1.0, 2.0, 0.0, -1.0, -2.0, 1e-4, -1e-4, 1e-6, -1e-6,
    1.2345678, 3.1415926535, 19.71
};


/* Print out a comment */
static void say(char * fmt, ...)
{
    va_list ap ;
    fprintf(stdout, "qtest:\t\t");
    va_start(ap, fmt);
    vfprintf(stdout, fmt, ap);
    va_end(ap);
    fprintf(stdout, "\n");
}
 
/* Print out an error message */
static void fail(char * fmt, ...)
{
    va_list ap ;
    fprintf(stderr, "qtest: error: ");
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
    fprintf(stderr, "\n");
}

/*---------------------------------------------------------------------------
                                main
 ---------------------------------------------------------------------------*/

int test_qfits_header_sort(void)
{
    qfits_header    *    qh ;
    
    /* Create header */
    qh = qfits_header_new();
    qfits_header_append(qh, "EXTEND", "value", "comment", NULL);
    qfits_header_append(qh, "COMMENT", "value", "comment", NULL);
    qfits_header_append(qh, "TFORM", "value", "comment", NULL);
    qfits_header_append(qh, "BITPIX", "value", "comment", NULL);
    qfits_header_append(qh, "NAXIS", "value", "comment", NULL);
    qfits_header_append(qh, "NAXIS2", "value", "comment", NULL);
    qfits_header_append(qh, "NAXIS1", "value", "comment", NULL);

    /* Dump the header */
    qfits_header_dump(qh, NULL) ;

    /* Sort the header */
    qfits_header_sort(&qh) ;

    /* Dump the header */
    qfits_header_dump(qh, NULL) ;
    
    /* Destroy the header */
    qfits_header_destroy(qh) ;
    return 0 ;
}

int test_qfits_filecreate(char * filename)
{
    qfits_header    *    qh ;
    FILE            *    out ;
    qfitsdumper            qd ;
    int                    i ;

    say("-----> Header creation");
    say("Creating blank header");
    qh = qfits_header_new();
    if (qh==NULL) {
        fail("qfits_header_new() failed");
        return 1 ;
    }
    say("Destroying blank header");
    /* Destroy header now */
    qfits_header_destroy(qh);

    /* Create minimal header (SIMPLE/END) */
    say("Creating minimal header");
    qh = qfits_header_default();
    if (qh==NULL) {
        fail("qfits_header_default() failed");
        return 1 ;
    }

    say("Inserting primary keywords");
    /* Insert XTENSION marker */
    qfits_header_add(qh, "EXTEND", "T", "xtension might be present", NULL);

    /* Insert a string */
    qfits_header_add(qh, "KEY01", "value01", "comment 01", NULL);
    /* Insert an int */
    qfits_header_add(qh, "KEY02", "2", "comment 02", NULL);
    /* Insert a double */
    qfits_header_add(qh, "KEY03", "3.0", "comment 03", NULL);
    /* Insert a complex */
    qfits_header_add(qh, "KEY04", "4.0 4.2", "comment 04", NULL);
    /* Insert a boolean */
    qfits_header_add(qh, "KEY05", "T", "comment 05", NULL);


    say("Inserting history keywords");
    /* Insert HISTORY keys */
    qfits_header_add(qh, "HISTORY", "1 history field", NULL, NULL);
    qfits_header_add(qh, "HISTORY", "2 history field", NULL, NULL);
    qfits_header_add(qh, "HISTORY", "3 history field", NULL, NULL);
    qfits_header_add(qh, "HISTORY", "4 history field", NULL, NULL);

    say("Inserting comment keywords");
    /* Insert COMMENT keys */
    qfits_header_add(qh, "COMMENT", "1 comment field", NULL, NULL);
    qfits_header_add(qh, "COMMENT", "2 comment field", NULL, NULL);
    qfits_header_add(qh, "COMMENT", "3 comment field", NULL, NULL);
    qfits_header_add(qh, "COMMENT", "4 comment field", NULL, NULL);

    say("Inserting hierarch keywords");
    /* Insert HIERARCH ESO keys in reverse DICB order */
    qfits_header_add(qh, "HIERARCH ESO NULL A", "0.0", "not DICB", NULL);
    qfits_header_add(qh, "HIERARCH ESO NULL B", "0.0", "not DICB", NULL);
    qfits_header_add(qh, "HIERARCH ESO NULL C", "0.0", "not DICB", NULL);

    qfits_header_add(qh, "PRO.A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "PRO.B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "PRO.C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "HIERARCH ESO LOG A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO LOG B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO LOG C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "INS.A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "INS.B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "INS.C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "HIERARCH ESO TEL A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO TEL B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO TEL C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "GEN.A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "GEN.B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "GEN.C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "HIERARCH ESO TPL A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO TPL B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "HIERARCH ESO TPL C", "0.0", "DICB compliant", NULL);

    qfits_header_add(qh, "OBS.A", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "OBS.B", "0.0", "DICB compliant", NULL);
    qfits_header_add(qh, "OBS.C", "0.0", "DICB compliant", NULL);

    say("Inserting mandatory keywords");
    /* Insert mandatory keys in reverse order */
    qfits_header_add(qh, "NAXIS2", "10", "NAXIS2 comment", NULL);
    qfits_header_add(qh, "NAXIS1", "11", "NAXIS1 comment", NULL);
    qfits_header_add(qh, "NAXIS",  "2", "NAXIS comment", NULL);
    qfits_header_add(qh, "BITPIX",  "-32", "BITPIX comment", NULL);

    /* Dump header to file */
    say("Opening file for output");
    out = fopen(filename, "w");
    if (out==NULL) {
        fail("cannot create test file");
        qfits_header_destroy(qh);
        return 1 ;
    }
    say("Dumping header to file");
    if (qfits_header_dump(qh, out)!=0) {
        fail("cannot dump header");
        qfits_header_destroy(qh);
        return 1 ;
    }
    say("Destroying built header");
    qfits_header_destroy(qh);
    fclose(out);

    say("-----> Dumping pixels");
    /* Allocate data segment and save it to FITS file */
    qd.fbuf = qfits_malloc(11 * 10 * sizeof(float));
    for (i=0 ; i<(11*10) ; i++) {
        qd.fbuf[i]=i*0.2 ;
    }

    qd.filename  = filename ;
    qd.npix      = 11 * 10 ;
    qd.ptype     = PTYPE_FLOAT ;
    qd.out_ptype = -32 ;

    if (qfits_pixdump(&qd)!=0) {
        fail("cannot save data to test file");
        qfits_free(qd.fbuf);
        return 1 ;
    }
    qfits_free(qd.fbuf);

    /* Zero-pad the output file */
    qfits_zeropad(filename);
    return 0 ;
}

int check_key(qfits_header * qh, char * key, char * expval)
{
    char * val ;
    int    err=0 ;

    val = qfits_header_getstr(qh, key);
    if (val==NULL) {
        fail("missing key in header");
        err++ ;
    } else {
        val = qfits_pretty_string(val);
        if (strcmp(val, expval)) {
            fail("wrong value for key in header");
            err++ ;
        }
    }
    return err ;
}

int test_qfitsheader_read(char * filename)
{
    qfits_header    *    qh ;
    char            *    val ;
    int                    err ;
    int                    keytype ;

    err=0 ;
    say("-----> Header reading test");
    /* Read header from source */
    say("Reading header from file");
    qh = qfits_header_read(filename);
    if (qh==NULL) {
        fail("cannot read test file");
        return 1 ;
    }
    say("Querying mandatory keys");
    err += check_key(qh, "SIMPLE", "T");
    err += check_key(qh, "NAXIS", "2");
    err += check_key(qh, "NAXIS1", "11");
    err += check_key(qh, "NAXIS2", "10");
    err += check_key(qh, "BITPIX", "-32");

    say("Querying base keys");
    err += check_key(qh, "KEY01", "value01");
    err += check_key(qh, "KEY02", "2");
    err += check_key(qh, "KEY03", "3.0");
    err += check_key(qh, "KEY04", "4.0 4.2");
    err += check_key(qh, "KEY05", "T");

    say("Checking key types");
    val = qfits_header_getstr(qh, "KEY01");
    keytype = qfits_get_type(val);
    if (keytype!=QFITS_STRING) {
        printf("val=[%s] type is %d\n", val, keytype);
        fail("wrong identified type for KEY01 (string)");
        err++;
    }
    val = qfits_header_getstr(qh, "KEY02");
    keytype = qfits_get_type(val);
    if (keytype!=QFITS_INT) {
        fail("wrong identified type for KEY02 (int)");
        err++;
    }
    val = qfits_header_getstr(qh, "KEY03");
    keytype = qfits_get_type(val);
    if (keytype!=QFITS_FLOAT) {
        fail("wrong identified type for KEY03 (float)");
        err++;
    }
    val = qfits_header_getstr(qh, "KEY04");
    keytype = qfits_get_type(val);
    if (keytype!=QFITS_COMPLEX) {
        fail("wrong identified type for KEY04 (complex)");
        err++;
    }
    val = qfits_header_getstr(qh, "KEY05");
    keytype = qfits_get_type(val);
    if (keytype!=QFITS_BOOLEAN) {
        fail("wrong identified type for KEY05 (boolean)");
        err++;
    }

    say("Querying hierarch keys");
    err += check_key(qh, "HIERARCH ESO PRO A", "0.0");
    err += check_key(qh, "PRO.B", "0.0");
    err += check_key(qh, "pro.c", "0.0");

    err += check_key(qh, "ins.a", "0.0");
    err += check_key(qh, "ins.b", "0.0");
    err += check_key(qh, "ins.c", "0.0");

    err += check_key(qh, "gen.a", "0.0");
    err += check_key(qh, "gen.b", "0.0");
    err += check_key(qh, "gen.c", "0.0");

    err += check_key(qh, "obs.a", "0.0");
    err += check_key(qh, "obs.b", "0.0");
    err += check_key(qh, "obs.c", "0.0");

    err += check_key(qh, "tpl.a", "0.0");
    err += check_key(qh, "tpl.b", "0.0");
    err += check_key(qh, "tpl.c", "0.0");

    err += check_key(qh, "tel.a", "0.0");
    err += check_key(qh, "tel.b", "0.0");
    err += check_key(qh, "tel.c", "0.0");

    err += check_key(qh, "log.a", "0.0");
    err += check_key(qh, "log.b", "0.0");
    err += check_key(qh, "log.c", "0.0");

    err += check_key(qh, "null.a", "0.0");
    err += check_key(qh, "null.b", "0.0");
    err += check_key(qh, "null.c", "0.0");

    say("Removing keys");

    qfits_header_del(qh, "PRO.A");
    qfits_header_del(qh, "pro.b");
    qfits_header_del(qh, "HIERARCH ESO PRO C");

    if (qfits_header_getstr(qh, "HIERARCH ESO PRO A")!=NULL) 
        err ++ ;
    if (qfits_header_getstr(qh, "PRO.B")!=NULL) 
        err ++ ;
    if (qfits_header_getstr(qh, "pro.c")!=NULL) 
        err ++ ;

    say("Modifying keys");

    qfits_header_destroy(qh);
    return err ;
}

int test_qfitsheader_browse(char * filename)
{
    qfits_header    *    qh ;
    char key[80], val[80], com[80] ;
    int     i ;
    int  err ;

    say("-----> Header browsing test");
    /* Read header from source */
    say("Reading header from file");
    qh = qfits_header_read(filename);
    if (qh==NULL) {
        fail("cannot read test file");
        return 1 ;
    }

    err=0 ;
    for (i=0 ; i<qh->n ; i++) {
        if (qfits_header_getitem(qh, i, key, val, com, NULL)!=0) {
            fail("cannot read header item");
            err++ ;
        }
    }
    qfits_header_destroy(qh);
    return err ;
}


int test_qfitsdata_load(char * filename)
{
    qfitsloader    ql ;
    int    i ;
    int    err ;
    float diff ;

    err=0 ;
    say("-----> Data loading test");
    ql.filename    = filename ;
    ql.xtnum    = 0 ;
    ql.pnum        = 0 ;
    ql.ptype    = PTYPE_FLOAT ;
    ql.map      = 1 ;

    say("Initializing loader");
    if (qfitsloader_init(&ql)!=0) {
        fail("cannot initialize loader on test file");
        return 1 ;
    }
    if (ql.lx != 11) {
        fail("wrong size in X");
        err++ ;
    }
    if (ql.ly != 10) {
        fail("wrong size in Y");
        err++ ;
    }

    say("Loading pixel buffer");
    if (qfits_loadpix(&ql)!=0) {
        fail("cannot load data from test file");
        return 1 ;
    }

    for (i=0 ; i<(11*10) ; i++) {
        diff = ql.fbuf[i] - (float)i * 0.2 ;
        if (diff>1e-4) {
            fail("diff in pix value");
            err++ ;
        }
    }
    qfits_free(ql.fbuf);
    return err ;

}

int test_qfits_filecreate_ext(char * filename)
{
    qfits_header*    qh ;
    qfitsdumper        qd ;
    FILE        *    out ;
    const char  *    sig ;

    say("-----> File with multiple extensions");
    /* Create minimal FITS header for main */
    say("Creating default header");
    qh = qfits_header_default() ;
    if (qh==NULL) {
        fail("cannot create default header");
        return 1 ;
    }
    qfits_header_add(qh, "BITPIX", "8", "no data in main section", NULL);
    qfits_header_add(qh, "NAXIS", "0", "no data in main section", NULL);
    qfits_header_add(qh, "EXTEND", "T", "Extensions are present", NULL);

    say("Dumping header to test file");
    out = fopen(filename, "w");
    if (out==NULL) {
        fail("cannot create test file");
        qfits_header_destroy(qh);
        return 1 ;
    }
    qfits_header_dump(qh, out);
    fclose(out);
    qfits_header_destroy(qh);

    say("Creating first extension with float pixels");
    qh = qfits_header_new();
    if (qh==NULL) {
        fail("cannot create extension header 1");
        return 1 ;
    }
    qfits_header_append(qh, "XTENSION", "T", "Ext 1", NULL);
    qfits_header_append(qh, "BITPIX", "-32", "bpp", NULL);
    qfits_header_append(qh, "NAXIS", "2", "axes", NULL);
    qfits_header_append(qh, "NAXIS1", "6", "size in x", NULL);
    qfits_header_append(qh, "NAXIS2", "2", "size in y", NULL);
    qfits_header_append(qh, "END", NULL, NULL, NULL);

    say("Dumping ext header 1 to test file");
    out = fopen(filename, "a");
    if (out==NULL) {
        fail("cannot append to test file");
        qfits_header_destroy(qh);
        return 1 ;
    }
    qfits_header_dump(qh, out);
    fclose(out);
    qfits_header_destroy(qh);

    say("Dumping float array");

    qd.filename = filename ;
    qd.npix      = 12 ;
    qd.ptype     = PTYPE_FLOAT ;
    qd.out_ptype = -32 ;
    qd.fbuf         = float_array_orig ;

    if (qfits_pixdump(&qd)!=0) {
        fail("cannot save data to test file");
        qfits_free(qd.fbuf);
        return 1 ;
    }
    /* Zero-pad the output file */
    qfits_zeropad(filename);

    say("Creating second extension with int pixels");
    qh = qfits_header_new();
    if (qh==NULL) {
        fail("cannot create extension header 1");
        return 1 ;
    }
    qfits_header_append(qh, "XTENSION", "T", "Ext 1", NULL);
    qfits_header_append(qh, "BITPIX", "32", "bpp", NULL);
    qfits_header_append(qh, "NAXIS", "2", "axes", NULL);
    qfits_header_append(qh, "NAXIS1", "6", "size in x", NULL);
    qfits_header_append(qh, "NAXIS2", "2", "size in y", NULL);
    qfits_header_append(qh, "END", NULL, NULL, NULL);

    say("Dumping ext header 2 to test file");
    out = fopen(filename, "a");
    if (out==NULL) {
        fail("cannot append to test file");
        qfits_header_destroy(qh);
        return 1 ;
    }
    qfits_header_dump(qh, out);
    fclose(out);
    qfits_header_destroy(qh);

    say("Dumping int array");

    qd.filename = filename ;
    qd.npix      = 12 ;
    qd.ptype     = PTYPE_INT ;
    qd.out_ptype = 32 ;
    qd.ibuf         = int_array_orig ;

    if (qfits_pixdump(&qd)!=0) {
        fail("cannot save data to test file");
        qfits_free(qd.fbuf);
        return 1 ;
    }
    /* Zero-pad the output file */
    qfits_zeropad(filename);

    say("Creating third extension with double pixels");
    qh = qfits_header_new();
    if (qh==NULL) {
        fail("cannot create extension header 3");
        return 1 ;
    }
    qfits_header_append(qh, "XTENSION", "T", "Ext 1", NULL);
    qfits_header_append(qh, "BITPIX", "-64", "bpp", NULL);
    qfits_header_append(qh, "NAXIS", "2", "axes", NULL);
    qfits_header_append(qh, "NAXIS1", "6", "size in x", NULL);
    qfits_header_append(qh, "NAXIS2", "2", "size in y", NULL);
    qfits_header_append(qh, "END", NULL, NULL, NULL);

    say("Dumping ext header 3 to test file");
    out = fopen(filename, "a");
    if (out==NULL) {
        fail("cannot append to test file");
        qfits_header_destroy(qh);
        return 1 ;
    }
    qfits_header_dump(qh, out);
    fclose(out);
    qfits_header_destroy(qh);

    say("Dumping double array");

    qd.filename = filename ;
    qd.npix      = 12 ;
    qd.ptype     = PTYPE_DOUBLE ;
    qd.out_ptype = -64 ;
    qd.dbuf         = double_array_orig ;

    if (qfits_pixdump(&qd)!=0) {
        fail("cannot save data to test file");
        qfits_free(qd.fbuf);
        return 1 ;
    }
    /* Zero-pad the output file */
    qfits_zeropad(filename);

    /* Get MD5 for the test file */
    sig = qfits_datamd5(filename);
    if (strcmp(sig, REFSIG)) {
        fail("test file signature does not match");
        return 1 ;
    }
    say("File DATAMD5 signature is Ok");

    return 0 ;
}

int main(int argc, char * argv[])
{
    int    err ;

    err=0 ;

    /* Test on simple FITS file */
    err += test_qfits_header_sort();
    err += test_qfits_filecreate(QFITSTEST1);
    err += test_qfitsheader_read(QFITSTEST1);
    err += test_qfitsheader_browse(QFITSTEST1);
    err += test_qfitsdata_load(QFITSTEST1);
    remove(QFITSTEST1);

    /* Test on FITS file with extensions */
    err += test_qfits_filecreate_ext(QFITSTEST2);
    remove(QFITSTEST2);

    fprintf(stderr, "total error(s): %d\n", err);
    return err ;
}