mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
d2316f866c
Primary Fixes: * Add a whole variable optimization -- used in the rare case that nc_get/put_vara covers the whole of a variable and the variable has a single chunk. * Fix chunking error when stride causes whole chunks to be skipped. * Fix some memory leaks * Add test cases * Add one performance test to nczarr_test/. This uses the timer utils from unit_test: timer_utils.[ch]. * Move ncdumpchunks utility from ncdump to nczarr_test Misc. Other Changes: * Make check for aws libraries conditional on --enable-nczarr-s3 * Remove all but one bm tests from nczarr_test until they are working. * Remove another dependency on HDF5 from supposedly non-HDF5 specific code; specifically hdf5_log_hdf5. * Make the BAIL2 macro be hdf5 specific and replace elsewhere with an HDF5 independent equivalent. * Move hdf5cache.c to libsrc4/nc4cache.c because it is used by nczarr. * Modify unit_tests so that some of them are run even if using Windows. * Misc. small bug fixes and refactors and memory leaks. * Rename some conflicting tests for cmake. * Attempted to make nc_perf work with cmake and failed.
78 lines
2.3 KiB
C
78 lines
2.3 KiB
C
/* This is part of the netCDF package. Copyright 2018 University
|
|
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file for
|
|
conditions of use. See www.unidata.ucar.edu for more info.
|
|
|
|
Create a chunkable test file for nccopy to test chunking.
|
|
*/
|
|
|
|
#include "ut_includes.h"
|
|
#include "test_nczarr_utils.h"
|
|
|
|
#define DEBUG
|
|
|
|
static int ret = NC_NOERR;
|
|
#define FILE_NAME "tst_chunks3.nc"
|
|
|
|
#define VAR_RANK 7
|
|
#define IVAR_NAME "ivar"
|
|
#define FVAR_NAME "fvar"
|
|
#define NVALS 45360 /* 7 * 4 * 2 * 3 * 5 * 6 * 9 */
|
|
|
|
/* Make trackable ERR macro replacement */
|
|
static int lerr(int stat, const char* file, int lineno) {
|
|
fflush(stdout); /* Make sure our stdout is synced with stderr. */
|
|
err++;
|
|
fprintf(stderr, "Sorry! Unexpected result(%d), %s, line: %d\n",ret,file,lineno);
|
|
fflush(stderr); \
|
|
return 2; \
|
|
}
|
|
#define LERR lerr(ret,__FILE__,__LINE__)
|
|
|
|
static const char *dim_names[VAR_RANK] = {"dim0", "dim1", "dim2", "dim3", "dim4", "dim5", "dim6"};
|
|
static const size_t dim_lens[VAR_RANK] = {7, 4, 2, 3, 5, 6, 9};
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
/* file metadata */
|
|
int mode = NC_CLOBBER|NC_NETCDF4;
|
|
int ncid;
|
|
int ivarid, fvarid;
|
|
int ivar_dims[VAR_RANK];
|
|
int fvar_dims[VAR_RANK];
|
|
int ivar_data[NVALS];
|
|
float fvar_data[NVALS];
|
|
int r, i;
|
|
char* file_name = FILE_NAME;
|
|
|
|
printf("*** Creating chunkable test file %s...\n", file_name);
|
|
|
|
if ((ret=nc_create(FILE_NAME, mode, &ncid))) LERR;
|
|
for(r = 0; r < VAR_RANK; r++) {
|
|
if ((ret=nc_def_dim(ncid, dim_names[r], dim_lens[r], &ivar_dims[r]))) LERR;
|
|
fvar_dims[VAR_RANK - 1 - r] = ivar_dims[r];
|
|
}
|
|
if ((ret=nc_def_var(ncid, IVAR_NAME, NC_INT, VAR_RANK, ivar_dims, &ivarid))) LERR;
|
|
|
|
/* fvar is unchanged */
|
|
if ((ret=nc_def_var(ncid, FVAR_NAME, NC_FLOAT, VAR_RANK, fvar_dims, &fvarid))) LERR;
|
|
if ((ret=nc_enddef (ncid))) LERR;
|
|
|
|
/* Fill in the data */
|
|
for(i=0; i < NVALS; i++) {
|
|
ivar_data[i] = i;
|
|
}
|
|
if ((ret=nc_put_var(ncid, ivarid, ivar_data))) LERR;
|
|
|
|
/* fvar is unchanged */
|
|
for(i=0; i < NVALS; i++) {
|
|
fvar_data[i] = NVALS - i;
|
|
}
|
|
if ((ret=nc_put_var(ncid, fvarid, fvar_data))) LERR;
|
|
|
|
if ((ret=nc_close(ncid))) LERR;
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
}
|