58 #define TESTFILE "bzip2.nc"
67 static size_t dimsize = DIMSIZE;
68 static size_t chunksize = CHUNKSIZE;
69 static size_t actualdims = NDIMS;
71 static size_t actualproduct = 1;
72 static size_t chunkproduct = 1;
74 static size_t dims[NDIMS];
75 static size_t chunks[NDIMS];
79 static int ncid, varid;
80 static int dimids[NDIMS];
81 static float* array = NULL;
82 static float* expected = NULL;
83 static unsigned int filterid = 0;
84 static unsigned int* params = NULL;
87 static void init(
int argc,
char** argv);
88 static int test_bzip2(
void);
89 static int verifychunks(
void);
93 fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
94 __FILE__, __LINE__); \
99 check(
int err,
int line)
102 fprintf(stderr,
"fail (%d): %s\n",line,
nc_strerror(err));
109 #define CHECK(x) check(x,__LINE__)
121 size_t chunksizes[NDIMS];
122 memset(chunksizes,0,
sizeof(chunksizes));
126 fprintf(stderr,
"bad chunk store\n");
130 for(i=0;i<actualdims;i++) {
131 if(chunksizes[i] != chunks[i]) {
132 fprintf(stderr,
"bad chunk size: %d\n",i);
148 printf(
"data comparison: |array|=%ld\n",(
unsigned long)actualproduct);
149 for(i=0;i<actualproduct;i++) {
150 if(expected[i] != array[i]) {
151 printf(
"mismatch: array[%d]=%f expected[%d]=%f\n",
152 i,array[i],i,expected[i]);
159 printf(
"no data errors\n");
160 if(actualproduct <= 1)
172 unsigned int level = BZIP2_LEVEL;
175 printf(
"\n*** Testing API: bzip2 compression.\n");
178 memset(array,0,
sizeof(
float)*actualproduct);
187 for(i=0;i<actualdims;i++) {
189 snprintf(dimname,
sizeof(dimname),
"dim%d",i);
190 CHECK(
nc_def_dim(ncid, dimname, dims[i], &dimids[i]));
208 if(nparams != 1 || level != BZIP2_LEVEL) {
209 printf(
"test_filter: filter def/inq mismatch\n");
213 printf(
"show parameters for bzip2: level=%u\n",level);
215 printf(
"show chunks:");
216 for(i=0;i<actualdims;i++)
217 printf(
"%s%ld",(i==0?
" chunks=":
","),(
unsigned long)chunks[i]);
224 for(i=0;i<actualproduct;i++)
225 expected[i] = (
float)i;
234 printf(
"\n*** Testing API: bzip2 decompression.\n");
237 memset(array,0,
sizeof(
float)*actualproduct);
252 params = (
unsigned int*)malloc(
sizeof(
unsigned int)*nparams);
257 if(filterid != BZIP2_ID) {
258 printf(
"Bzip2 id mismatch: %d\n",filterid);
261 if(nparams != 1 && params != NULL && params[0] != BZIP2_LEVEL) {
262 printf(
"Compression parameter mismatch\n");
275 return (compare() ==
NC_NOERR ? 0 : 1);
282 init(
int argc,
char** argv)
288 for(i=0;i<NDIMS;i++) {
290 chunks[i] = chunksize;
292 actualproduct *= dims[i];
293 chunkproduct *= chunks[i];
297 array = (
float*)calloc(1,
sizeof(
float)*actualproduct);
298 expected = (
float*)calloc(1,
sizeof(
float)*actualproduct);
303 main(
int argc,
char **argv)
EXTERNL int nc_close(int ncid)
Close an open netCDF dataset.
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.
EXTERNL int nc_set_fill(int ncid, int fillmode, int *old_modep)
Change the fill-value mode to improve write performance.
EXTERNL int nc_enddef(int ncid)
Leave define mode.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
Open an existing netCDF file.
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
EXTERNL const char * nc_strerror(int ncerr)
Given an error number, return an error message.
EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp)
Find the ID of a variable, from the name.
EXTERNL int nc_put_var(int ncid, int varid, const void *op)
Write an entire variable with one call.
EXTERNL int nc_inq_var_filter_info(int ncid, int varid, unsigned int id, size_t *nparams, unsigned int *params)
Find the the param info about filter (if any) associated with a variable and with specified id.
EXTERNL int nc_inq_var_filter(int ncid, int varid, unsigned int *idp, size_t *nparams, unsigned int *params)
Find the first filter (if any) associated with a variable.
EXTERNL int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
Get the storage and (for chunked variables) the chunksizes of a variable.
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
int nc_get_var_float(int ncid, int varid, float *ip)
Read an entire variable in one call.
EXTERNL int nc_def_var_chunking(int ncid, int varid, int storage, const size_t *chunksizesp)
Define storage and, if chunked storage is used, chunking parameters for a variable.
Main header file for the C API.
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
#define NC_EFILTER
Filter operation failed.
#define NC_CLOBBER
Destroy existing file.
#define NC_FLOAT
single precision floating point number
#define NC_NOWRITE
Set read-only access for nc_open().
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_ESTORAGE
Can't specify both contiguous and chunking.
#define NC_NOFILL
Argument to nc_set_fill() to turn off filling of data.
#define NC_EINVAL
Invalid Argument.
#define NC_NOERR
No Error.
EXTERNL int nc_def_var_filter(int ncid, int varid, unsigned int id, size_t nparams, const unsigned int *parms)
Define a new variable filter Assumes HDF5 format using unsigned ints.
#define NC_EBADCHUNK
Bad chunksize.
#define NC_ENOFILTER
Filter not defined on variable.
#define NC_EBADDIM
Invalid dimension id or name.