|
NetCDF
4.8.1
|
Go to the documentation of this file.
51 #include "netcdf_filter.h"
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]));
203 CHECK(nc_def_var_filter(ncid,varid,BZIP2_ID,1,&level));
207 CHECK(nc_inq_var_filter_info(ncid,varid,BZIP2_ID,&nparams,&level));
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);
249 CHECK(nc_inq_var_filter(ncid,varid,&filterid,&nparams,NULL));
252 params = (
unsigned int*)malloc(
sizeof(
unsigned int)*nparams);
255 CHECK(nc_inq_var_filter(ncid,varid,&filterid,&nparams,params));
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)
#define NC_NOERR
No Error.
#define NC_EINVAL
Invalid Argument.
#define NC_NOWRITE
Set read-only access for nc_open().
#define NC_FLOAT
single precision floating point number
#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_ENOFILTER
Filter not defined on 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.
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
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.
#define NC_EFILTER
Filter operation failed.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked,...
#define NC_EBADCHUNK
Bad chunksize.
EXTERNL int nc_put_var(int ncid, int varid, const void *op)
EXTERNL int nc_close(int ncid)
int nc_get_var_float(int ncid, int varid, float *ip)
EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp)
EXTERNL int nc_set_fill(int ncid, int fillmode, int *old_modep)
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
Open an existing netCDF file.
#define NC_ENOMEM
Memory allocation (malloc) failure.
EXTERNL const char * nc_strerror(int ncerr)
Given an error number, return an error message.
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
EXTERNL int nc_enddef(int ncid)
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
#define NC_EBADDIM
Invalid dimension id or name.
EXTERNL int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp)
#define NC_CLOBBER
Destroy existing file.