/* Copyright 2018, UCAR/Unidata See COPYRIGHT file for copying and redistribution conditions. */ #include "config.h" #include #include #include #ifdef HAVE_HDF5_H #include #endif #include "netcdf.h" #include "netcdf_aux.h" #include "netcdf_filter.h" #undef TESTODDSIZE #undef DEBUG /* The C standard apparently defines all floating point constants as double; we rely on that in this code. */ #define DBLVAL 12345678.12345678 #define TEST_ID 32768 #define MAXERRS 8 #define MAXPARAMS 32 #define NPARAMS 14 static unsigned int baseline[NPARAMS]; static const char* testfile = NULL; #define MAXDIMS 8 #define DFALT_TESTFILE "tmp_misc.nc" #define spec "32768, -17b, 23ub, -25S, 27US, 77, 93U, 789f, 12345678.12345678d, -9223372036854775807L, 18446744073709551615UL" #ifdef TESTODDSIZE #define NDIMS 1 static size_t dimsize[NDIMS] = {4}; static size_t chunksize[NDIMS] = {3}; #else #define NDIMS 4 static size_t dimsize[NDIMS] = {4,4,4,4}; static size_t chunksize[NDIMS] = {4,4,4,4}; #endif static size_t ndims = NDIMS; static size_t totalproduct = 1; /* x-product over max dims */ static size_t actualproduct = 1; /* x-product over actualdims */ static size_t chunkproduct = 1; /* x-product over actual chunks */ static size_t pattern[MAXDIMS]; static int nerrs = 0; static int ncid, varid; static int dimids[MAXDIMS]; static size_t odom[MAXDIMS]; static float* array = NULL; static float* expected = NULL; static unsigned int filterid = 0; static size_t nparams = 0; static unsigned int params[MAXPARAMS]; /* Forward */ static int test_test1(void); static void init(int argc, char** argv); static void reset(void); static void odom_reset(void); static int odom_more(void); static int odom_next(void); static int odom_offset(void); static float expectedvalue(void); static void verifyparams(void); #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; } static void report(const char* msg, int lineno) { fprintf(stderr,"fail: line=%d %s\n",lineno,msg); exit(1); } #define CHECK(x) check(x,__LINE__) #define REPORT(x) report(x,__LINE__) static int verifychunks(void) { int i; int store = -1; size_t localchunks[MAXDIMS]; memset(localchunks,0,sizeof(localchunks)); CHECK(nc_inq_var_chunking(ncid, varid, &store, localchunks)); if(store != NC_CHUNKED) { fprintf(stderr,"bad chunk store\n"); return 0; } for(i=0;i 0) { params = (unsigned int*)malloc(sizeof(unsigned int)*nparams); if(params == NULL) return NC_ENOMEM; CHECK(nc_inq_var_filter(ncid,varid,&filterid,&nparams,params)); } if(filterid != TEST_ID) { fprintf(stderr,"open: test id mismatch: %d\n",filterid); free(params); return NC_EFILTER; } if(nparams != NPARAMS) { size_t i; fprintf(stderr,"nparams mismatch\n"); for(nerrs=0,i=0;i 0) return NC_EFILTER; /* Verify chunking */ if(!verifychunks()) return 0; fflush(stderr); return 1; } static int setchunking(void) { int store; store = NC_CHUNKED; CHECK(nc_def_var_chunking(ncid,varid,store,chunksize)); if(!verifychunks()) return NC_EINVAL; return NC_NOERR; } static void fill(void) { odom_reset(); if(1) { int i; if(actualproduct <= 1) abort(); for(i=0;i= MAXERRS) break; } } } else { odom_reset(); while(odom_more()) { int offset = odom_offset(); float expect = expectedvalue(); if(array[offset] != expect) { fprintf(stderr,"data mismatch: array[%d]=%f expected=%f\n", offset,array[offset],expect); errs++; if(errs >= MAXERRS) break; } odom_next(); } } if(errs == 0) fprintf(stderr,"no data errors\n"); return (errs == 0); } static void showparameters(void) { int i; fprintf(stderr,"test: nparams=%ld: params=",(unsigned long)nparams); for(i=0;i=0;i--) { odom[i] += 1; if(odom[i] < dimsize[i]) break; if(i == 0) return 0; /* leave the 0th entry if it overflows*/ odom[i] = 0; /* reset this position*/ } return 1; } static int odom_offset(void) { int i; int offset = 0; for(i=0;i 1) testfile = argv[1]; else testfile = DFALT_TESTFILE; /* Setup various variables */ totalproduct = 1; actualproduct = 1; chunkproduct = 1; for(i=0;i 0?1:0); }