File: tst_filter_avail.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,164 kB
  • sloc: ansic: 267,893; sh: 12,869; cpp: 5,822; yacc: 2,613; makefile: 1,813; lex: 1,216; xml: 173; awk: 2
file content (106 lines) | stat: -rw-r--r-- 2,153 bytes parent folder | download | duplicates (2)
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
/*
  Copyright 2018, UCAR/Unidata
  See COPYRIGHT file for copying and redistribution conditions.
*/

#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifdef USE_HDF5
#include <hdf5.h>
#endif

#include "netcdf.h"
#include "netcdf_aux.h"
#include "netcdf_filter.h"

#undef DEBUG

#define MAXPARAMS 32

#ifdef TESTNCZARR
#define DFALT_TESTFILE "file://tmp_filter_avail.file#mode=nczarr,file"
#else
#define DFALT_TESTFILE "tmp_filter_avail.nc"
#endif

static const char* testfile = NULL;
static int nerrs = 0;

static int ncid;

/* Forward */
static int test_test1(void);
static void init(int argc, char** argv);

#define ERRR do { \
fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
        __FILE__, __LINE__);                                \
nerrs++;\
} while (0)

static int
check(int err,int line)
{
    if(err != NC_NOERR) {
        fprintf(stderr,"fail (%d): %s\n",line,nc_strerror(err));
    }
    return NC_NOERR;
}

#define CHECK(x) check(x,__LINE__)

static int
test_test1(void)
{
    int stat = NC_NOERR;

    printf("test1: bzip2 availability\n");
    CHECK(nc_create(testfile,NC_NETCDF4|NC_CLOBBER,&ncid));
    CHECK(nc_enddef(ncid));
    switch (stat = nc_inq_filter_avail(ncid,H5Z_FILTER_BZIP2)) {
    case NC_NOERR: break;
    case NC_ENOFILTER: break;
    default: CHECK(stat); goto done;
    }
    if(stat == NC_ENOFILTER) {
	printf("*** FAIL: filter %d not available\n",H5Z_FILTER_BZIP2);
    } else {
	printf("*** PASS: filter %d available\n",H5Z_FILTER_BZIP2);
    }

    CHECK(nc_abort(ncid));
done:
    return stat;
}

/**************************************************/
/* Utilities */

static void
init(int argc, char** argv)
{
    /* get the testfile path */
    if(argc > 1)
        testfile = argv[1];
    else
        testfile = DFALT_TESTFILE;
}

/**************************************************/
int
main(int argc, char **argv)
{
#ifdef USE_HDF5
#ifdef DEBUG
    H5Eprint1(stderr);
    nc_set_log_level(1);
#endif
#endif
    init(argc,argv);
    if(test_test1() != NC_NOERR) ERRR;
    exit(nerrs > 0?1:0);
}