mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
Merge branch 'ejh_fill_value_string_unidata' of https://github.com/NetCDF-World-Domination-Council/netcdf-c into ejh_batch
This commit is contained in:
commit
e0577cb251
@ -41,6 +41,7 @@
|
||||
#define ONE_TWENTY_EIGHT_MEG (SIXTEEN_MEG * 8)
|
||||
#define TEST_VAL_42 42
|
||||
#define BAD_NAME "dd//d/ "
|
||||
#define NUM_CLASSIC_TYPES 6
|
||||
#define NUM_NETCDF_TYPES 12
|
||||
/** \} */
|
||||
|
||||
|
@ -2289,6 +2289,55 @@ var_exists(hid_t grpid, char *name, nc_bool_t *exists)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Convert a coordinate variable HDF5 dataset into one that
|
||||
* is not a coordinate variable. This happens during renaming of vars
|
||||
* and dims. This function removes the HDF5 NAME and CLASS attributes
|
||||
* associated with dimension scales, and also the NC_DIMID_ATT_NAME
|
||||
* attribute which may be present, and, if it does, holds the dimid of
|
||||
* the coordinate variable.
|
||||
*
|
||||
* @param hdf_datasetid The HDF5 dataset ID of the coordinate variable dataset.
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @return ::NC_EHDFERR HDF5 error.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
remove_coord_atts(hid_t hdf_datasetid)
|
||||
{
|
||||
htri_t attr_exists;
|
||||
|
||||
/* If the variable dataset has an optional NC_DIMID_ATT_NAME
|
||||
* attribute, delete it. */
|
||||
if ((attr_exists = H5Aexists(hdf_datasetid, NC_DIMID_ATT_NAME)) < 0)
|
||||
return NC_EHDFERR;
|
||||
if (attr_exists)
|
||||
{
|
||||
if (H5Adelete(hdf_datasetid, NC_DIMID_ATT_NAME) < 0)
|
||||
return NC_EHDFERR;
|
||||
}
|
||||
|
||||
/* (We could do a better job here and verify that the attributes are
|
||||
* really dimension scale 'CLASS' & 'NAME' attributes, but that would be
|
||||
* poking about in the HDF5 DimScale internal data) */
|
||||
if ((attr_exists = H5Aexists(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME)) < 0)
|
||||
return NC_EHDFERR;
|
||||
if (attr_exists)
|
||||
{
|
||||
if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_CLASS_ATT_NAME) < 0)
|
||||
return NC_EHDFERR;
|
||||
}
|
||||
if ((attr_exists = H5Aexists(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME)) < 0)
|
||||
return NC_EHDFERR;
|
||||
if (attr_exists)
|
||||
{
|
||||
if (H5Adelete(hdf_datasetid, HDF5_DIMSCALE_NAME_ATT_NAME) < 0)
|
||||
return NC_EHDFERR;
|
||||
}
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This function writes a variable. The principle difficulty
|
||||
* comes from the possibility that this is a coordinate variable, and
|
||||
@ -2301,7 +2350,7 @@ var_exists(hid_t grpid, char *name, nc_bool_t *exists)
|
||||
*
|
||||
* @returns NC_NOERR No error.
|
||||
* @returns NC_EHDFERR HDF5 returned an error.
|
||||
* @author Ed Hartnett
|
||||
* @author Ed Hartnett, Quincey Koziol
|
||||
*/
|
||||
static int
|
||||
write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
|
||||
@ -2402,25 +2451,8 @@ write_var(NC_VAR_INFO_T *var, NC_GRP_INFO_T *grp, nc_bool_t write_dimid)
|
||||
* for making a dataset not a scale. -QAK) */
|
||||
if (var->created)
|
||||
{
|
||||
htri_t attr_exists;
|
||||
|
||||
/* (We could do a better job here and verify that the attributes are
|
||||
* really dimension scale 'CLASS' & 'NAME' attributes, but that would be
|
||||
* poking about in the HDF5 DimScale internal data) */
|
||||
if ((attr_exists = H5Aexists(var->hdf_datasetid, "CLASS")) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
if (attr_exists)
|
||||
{
|
||||
if (H5Adelete(var->hdf_datasetid, "CLASS") < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
}
|
||||
if ((attr_exists = H5Aexists(var->hdf_datasetid, "NAME")) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
if (attr_exists)
|
||||
{
|
||||
if (H5Adelete(var->hdf_datasetid, "NAME") < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
}
|
||||
if ((retval = remove_coord_atts(var->hdf_datasetid)))
|
||||
BAIL(retval);
|
||||
}
|
||||
|
||||
if (var->dimscale_attached)
|
||||
|
@ -265,11 +265,7 @@ check_chunksizes(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, const size_t *chunksize
|
||||
else
|
||||
dprod = (double)type_len;
|
||||
for (d = 0; d < var->ndims; d++)
|
||||
{
|
||||
if (chunksizes[d] < 1)
|
||||
return NC_EINVAL;
|
||||
dprod *= (double) chunksizes[d];
|
||||
}
|
||||
dprod *= (double)chunksizes[d];
|
||||
|
||||
if (dprod > (double) NC_MAX_UINT)
|
||||
return NC_EBADCHUNK;
|
||||
@ -410,7 +406,8 @@ nc4_find_default_chunksizes2(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
* @returns ::NC_ENOMEM Out of memory.
|
||||
* @author Dennis Heimbigner
|
||||
*/
|
||||
int nc4_vararray_add(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
int
|
||||
nc4_vararray_add(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
{
|
||||
NC_VAR_INFO_T **vp = NULL;
|
||||
|
||||
@ -431,11 +428,10 @@ int nc4_vararray_add(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var)
|
||||
grp->vars.nalloc += NC_ARRAY_GROWBY;
|
||||
}
|
||||
|
||||
if(var != NULL) {
|
||||
assert(var->varid == grp->vars.nelems);
|
||||
grp->vars.value[grp->vars.nelems] = var;
|
||||
grp->vars.nelems++;
|
||||
}
|
||||
assert(var->varid == grp->vars.nelems);
|
||||
grp->vars.value[grp->vars.nelems] = var;
|
||||
grp->vars.nelems++;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
@ -885,19 +881,18 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
|
||||
{
|
||||
if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (*(char **)var->fill_value) {
|
||||
assert(*(char **)var->fill_value);
|
||||
if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
|
||||
return NC_ENOMEM;
|
||||
|
||||
if (!(fill_valuep = calloc(1, sizeof(char *))))
|
||||
return NC_ENOMEM;
|
||||
|
||||
if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
|
||||
{
|
||||
free(fill_valuep);
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
|
||||
{
|
||||
free(*(char **)fill_valuep);
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
assert(var->type_info->size);
|
||||
memcpy(fill_valuep, var->fill_value, var->type_info->size);
|
||||
}
|
||||
@ -906,15 +901,13 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
|
||||
{
|
||||
if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (!(fill_valuep = calloc(1, sizeof(char *))))
|
||||
if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
|
||||
return NC_ENOMEM;
|
||||
|
||||
if ((retval = nc4_get_default_fill_value(var->type_info, (char **)fill_valuep)))
|
||||
{
|
||||
free(fill_valuep);
|
||||
free(*(char **)fill_valuep);
|
||||
return retval;
|
||||
} else {
|
||||
free(fill_valuep);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1013,7 +1006,7 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
|
||||
return NC_EINVAL;
|
||||
|
||||
/* Valid deflate level? */
|
||||
if (deflate && deflate_level)
|
||||
if (deflate)
|
||||
{
|
||||
if (*deflate)
|
||||
if (*deflate_level < NC_MIN_DEFLATE_LEVEL ||
|
||||
@ -1104,7 +1097,16 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
|
||||
if (no_fill)
|
||||
{
|
||||
if (*no_fill)
|
||||
{
|
||||
/* NC_STRING types may not turn off fill mode. It's disallowed
|
||||
* by HDF5 and will cause a HDF5 error later. */
|
||||
if (*no_fill)
|
||||
if (var->type_info->nc_typeid == NC_STRING)
|
||||
return NC_EINVAL;
|
||||
|
||||
/* Set the no-fill mode. */
|
||||
var->no_fill = NC_TRUE;
|
||||
}
|
||||
else
|
||||
var->no_fill = NC_FALSE;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
See COPYRIGHT file for conditions of use.
|
||||
|
||||
Test netcdf-4 variables.
|
||||
$Id: tst_chunks.c,v 1.3 2010/01/21 16:00:18 ed Exp $
|
||||
Ed Hartnett
|
||||
*/
|
||||
|
||||
#include <nc_tests.h>
|
||||
@ -24,7 +24,6 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
printf("\n*** Testing netcdf-4 variable chunking.\n");
|
||||
printf("**** testing that fixed vars with filter end up being chunked, with good sizes...");
|
||||
{
|
||||
@ -287,45 +286,86 @@ main(int argc, char **argv)
|
||||
if (nc_abort(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing different chunksizes on an unlimited dimension with existing data...");
|
||||
printf("**** testing cache size smaller than chunk size...");
|
||||
{
|
||||
#define D_UNLIM "unlimited_dim"
|
||||
#define V_UNLIM_ONE "unlimited_var_one"
|
||||
#define V_UNLIM_TWO "unlimited_var_two"
|
||||
int ncid;
|
||||
int unlim_dimid;
|
||||
int first_unlim_varid;
|
||||
int second_unlim_varid;
|
||||
size_t first_chunks[1];
|
||||
size_t second_chunks[1];
|
||||
size_t start[1], count[1];
|
||||
unsigned short first_data[2] = {0, 1}, second_data[3] = {2, 3, 4};
|
||||
#define NDIM2 2
|
||||
#define DIM_X_LEN 10000
|
||||
#define DIM_Y_LEN 10000
|
||||
#define DIM_NAME_X_CACHE_CHUNK "Height"
|
||||
#define DIM_NAME_Y_CACHE_CHUNK "Width"
|
||||
#define VAR_NAME_CACHE_CHUNK "House_Size"
|
||||
#define VAR_NAME_CACHE_CHUNK_2 "Boat_Size"
|
||||
#define VAR_NAME_CACHE_CHUNK_3 "Deck_Size"
|
||||
|
||||
/* Create a netcdf4 file with 1 dimension. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, D_UNLIM, NC_UNLIMITED, &unlim_dimid)) ERR;
|
||||
int ncid;
|
||||
int dimid[NDIM2];
|
||||
int varid, varid2, varid3;
|
||||
size_t chunks[NDIM2] = {100, 100};
|
||||
size_t chunks_big[NDIM2] = {DIM_X_LEN, DIM_Y_LEN};
|
||||
size_t chunks_in[NDIM2];
|
||||
int contiguous;
|
||||
size_t cache_size = 16;
|
||||
size_t cache_nelems = 1;
|
||||
float cache_preemption = 0.5;
|
||||
size_t cache_size_in;
|
||||
size_t cache_nelems_in;
|
||||
float cache_preemption_in;
|
||||
|
||||
/* Add one var with one chunksize */
|
||||
if (nc_def_var(ncid, V_UNLIM_ONE, NC_USHORT, NDIMS1, &unlim_dimid, &first_unlim_varid)) ERR;
|
||||
first_chunks[0] = 2;
|
||||
if (nc_def_var_chunking(ncid, first_unlim_varid, NC_CHUNKED, first_chunks)) ERR;
|
||||
/* Create a netcdf-4 file with two dimensions. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_X_CACHE_CHUNK, DIM_X_LEN, &dimid[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_Y_CACHE_CHUNK, DIM_Y_LEN, &dimid[1])) ERR;
|
||||
|
||||
/* Add a record to the first variable. */
|
||||
start[0] = 0;
|
||||
count[0] = 1;
|
||||
if (nc_put_vara(ncid, first_unlim_varid, start, count, first_data)) ERR;
|
||||
/* Add vars. */
|
||||
if (nc_def_var(ncid, VAR_NAME_CACHE_CHUNK, NC_INT64, NDIM2, dimid, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_CACHE_CHUNK_2, NC_INT64, NDIM2, dimid, &varid2)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_CACHE_CHUNK_3, NC_INT64, NDIM2, dimid, &varid3)) ERR;
|
||||
|
||||
/* Add second var with second chunksize */
|
||||
if (nc_def_var(ncid, V_UNLIM_TWO, NC_USHORT, NDIMS1, &unlim_dimid, &second_unlim_varid)) ERR;
|
||||
second_chunks[0] = 3;
|
||||
if (nc_def_var_chunking(ncid, second_unlim_varid, NC_CHUNKED, second_chunks)) ERR;
|
||||
/* Set the var cache. */
|
||||
if (nc_set_var_chunk_cache(ncid, varid, cache_size, cache_nelems,
|
||||
cache_preemption)) ERR;
|
||||
|
||||
/* Add a record to the second variable. */
|
||||
start[0] = 0;
|
||||
count[0] = 2;
|
||||
if (nc_put_vara(ncid, second_unlim_varid, start, count, second_data)) ERR;
|
||||
/* Set the chunking. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CHUNKED, chunks)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid, &contiguous, chunks_in)) ERR;
|
||||
if (contiguous || chunks_in[0] != chunks[0] || chunks_in[1] != chunks[1]) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid2, NC_CHUNKED, chunks)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid2, &contiguous, chunks_in)) ERR;
|
||||
if (contiguous || chunks_in[0] != chunks[0] || chunks_in[1] != chunks[1]) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid3, NC_CHUNKED, chunks_big)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid3, &contiguous, chunks_in)) ERR;
|
||||
if (contiguous || chunks_in[0] != chunks_big[0] || chunks_in[1] != chunks_big[1]) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
/* Get the var cache values. */
|
||||
if (nc_get_var_chunk_cache(ncid, varid, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in)) ERR;
|
||||
if (cache_size_in != cache_size || cache_nelems_in != cache_nelems ||
|
||||
cache_preemption_in != cache_preemption) ERR;
|
||||
if (nc_get_var_chunk_cache(ncid, varid2, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in)) ERR;
|
||||
if (cache_size_in != CHUNK_CACHE_SIZE || cache_nelems_in != CHUNK_CACHE_NELEMS ||
|
||||
cache_preemption_in != CHUNK_CACHE_PREEMPTION) ERR;
|
||||
|
||||
/* The cache_size has been increased due to larger chunksizes
|
||||
* for varid3. */
|
||||
if (nc_get_var_chunk_cache(ncid, varid3, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in)) ERR;
|
||||
if (cache_nelems_in != CHUNK_CACHE_NELEMS ||
|
||||
cache_preemption_in != CHUNK_CACHE_PREEMPTION) ERR;
|
||||
/* printf("cache_size_in %ld\n", cache_size_in); */
|
||||
#ifndef USE_PARALLEL
|
||||
/* THe cache size does not change under parallel. Not sure why. */
|
||||
if (cache_size_in <= CHUNK_CACHE_SIZE) ERR;
|
||||
#endif
|
||||
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
|
@ -68,7 +68,7 @@ check_file(int ncid, char *var0_name, char *var1_name, char *dim_name)
|
||||
|
||||
/* printf("checking for vars %s and %s, dim %s\n", var0_name, var1_name, */
|
||||
/* dim_name); */
|
||||
|
||||
|
||||
/* Check vars. Ids will change because of rename. */
|
||||
if (nc_inq_varid(ncid, var0_name, &varid)) ERR;
|
||||
if (nc_inq_varid(ncid, var1_name, &var2id)) ERR;
|
||||
@ -76,7 +76,7 @@ check_file(int ncid, char *var0_name, char *var1_name, char *dim_name)
|
||||
/* Check dim. */
|
||||
if (nc_inq_dimid(ncid, dim_name, &dimid)) ERR;
|
||||
if (dimid != 0) ERR;
|
||||
|
||||
|
||||
/* Check the lats. */
|
||||
if (nc_get_var_int(ncid, varid, lats_in)) ERR;
|
||||
for (ii = 0; ii < DIM_LEN; ii++)
|
||||
@ -99,7 +99,7 @@ check_charlies_file(char *file, char *dim_name, char *var_name)
|
||||
{
|
||||
int ncid;
|
||||
int varid, dimid;
|
||||
|
||||
|
||||
if (nc_open(file, 0, &ncid)) ERR;
|
||||
if (nc_inq_varid(ncid, var_name, &varid)) ERR;
|
||||
if (nc_inq_dimid(ncid, dim_name, &dimid)) ERR;
|
||||
@ -114,7 +114,7 @@ int
|
||||
check_charlies_no_enddef_file(int ncid, char *dim_name, char *var_name)
|
||||
{
|
||||
int varid, dimid;
|
||||
|
||||
|
||||
if (nc_inq_varid(ncid, var_name, &varid)) ERR;
|
||||
if (nc_inq_dimid(ncid, dim_name, &dimid)) ERR;
|
||||
if (varid || dimid) ERR;
|
||||
@ -131,6 +131,7 @@ main(int argc, char **argv)
|
||||
int format;
|
||||
|
||||
fprintf(stderr,"*** Testing netcdf rename bugs and fixes.\n");
|
||||
/* nc_set_log_level(5); */
|
||||
|
||||
for (format = 0; format < NUM_FORMATS; format++)
|
||||
{
|
||||
@ -170,7 +171,7 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Reopen the file and check. */
|
||||
if (check_charlies_file(CHARLIE_TEST_FILE, LONGITUDE, LONGITUDE)) ERR;
|
||||
if (check_charlies_file(CHARLIE_TEST_FILE, LONGITUDE, LONGITUDE)) ERR;
|
||||
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
@ -199,7 +200,7 @@ main(int argc, char **argv)
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (check_charlies_no_enddef_file(ncid, LONGITUDE, LON)) ERR;
|
||||
|
||||
|
||||
/* Rename the variable. This will remove the (as yet
|
||||
* unwritten) dimscale-only dataset "longitude" and rename
|
||||
* the extisting dataset "lon" to "longitude". Variable
|
||||
@ -262,7 +263,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
int ncid, varid, var2id;
|
||||
int dimid;
|
||||
|
||||
|
||||
if (nc_set_default_format(formats[format], NULL)) ERR;
|
||||
if (nc_create(file_names[format], 0, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR;
|
||||
@ -272,7 +273,7 @@ main(int argc, char **argv)
|
||||
/* Now rename the dim. */
|
||||
if (nc_rename_dim(ncid, dimid, TAL)) ERR;
|
||||
if (nc_rename_var(ncid, varid, TAL)) ERR;
|
||||
|
||||
|
||||
if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */
|
||||
if (nc_put_var_int(ncid, varid, lats)) ERR;
|
||||
if (nc_put_var_float(ncid, var2id, rh)) ERR;
|
||||
@ -289,7 +290,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
int ncid, varid, var2id;
|
||||
int dimid;
|
||||
|
||||
|
||||
if (nc_set_default_format(formats[format], NULL)) ERR;
|
||||
if (nc_create(file_names[format], 0, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR;
|
||||
@ -301,7 +302,7 @@ main(int argc, char **argv)
|
||||
if (nc_rename_var(ncid, varid, TAL2)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, TAL)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
|
||||
|
||||
if (nc_put_var_int(ncid, varid, lats)) ERR;
|
||||
if (nc_put_var_float(ncid, var2id, rh)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
@ -316,7 +317,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
int ncid, varid, var2id;
|
||||
int dimid;
|
||||
|
||||
|
||||
/* This will create a HDF5 file with two datasets, RH, and
|
||||
* LAT. LAT is a dimscale. RH points to dimscale LAT. Life is
|
||||
* so simple. */
|
||||
@ -363,7 +364,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
int ncid, varid, var2id;
|
||||
int dimid;
|
||||
|
||||
|
||||
if (nc_set_default_format(formats[format], NULL)) ERR;
|
||||
if (nc_create(file_names[format], 0, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR;
|
||||
@ -376,7 +377,7 @@ main(int argc, char **argv)
|
||||
if (nc_rename_dim(ncid, dimid, TAL)) ERR;
|
||||
if (nc_rename_var(ncid, varid, TAL)) ERR;
|
||||
if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */
|
||||
|
||||
|
||||
if (nc_put_var_int(ncid, varid, lats)) ERR;
|
||||
if (nc_put_var_float(ncid, var2id, rh)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
@ -387,7 +388,7 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
|
||||
printf("*** testing renaming after enddef for %s...", fmt_names[format]);
|
||||
{
|
||||
/* Create a file with datasets LAT, RH. LAT is a dimscale. RH
|
||||
@ -456,7 +457,7 @@ main(int argc, char **argv)
|
||||
if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR;
|
||||
if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR;
|
||||
if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_get_var_int(ncid, varid, lats_in)) ERR;
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
Test netcdf-4 string types.
|
||||
|
||||
$Id: tst_strings.c,v 1.34 2010/05/25 13:53:04 ed Exp $
|
||||
Ed Hartnett
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <nc_tests.h>
|
||||
#include "err_macros.h"
|
||||
|
||||
#define TEST_NAME "tst_strings"
|
||||
#define FILE_NAME "tst_strings.nc"
|
||||
#define DIM_LEN 9
|
||||
#define ATT_NAME "measure_for_measure_att"
|
||||
@ -243,7 +244,7 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
printf("*** testing long string variable...");
|
||||
printf("*** testing string variables with fill values...");
|
||||
{
|
||||
#define VAR_NAME2 "empty"
|
||||
#define ATT_NAME2 "empty"
|
||||
@ -256,7 +257,6 @@ main(int argc, char **argv)
|
||||
char var_name[NC_MAX_NAME + 1];
|
||||
int var_natts, var_ndims;
|
||||
int ncid, varid, i, dimids[NDIMS], varid2;
|
||||
char *data_in[DHR_LEN];
|
||||
char *data[DHR_LEN] = {
|
||||
"All human beings are born free and equal in dignity and rights. "
|
||||
"They are endowed with reason and "
|
||||
@ -426,56 +426,177 @@ main(int argc, char **argv)
|
||||
"any of the rights and freedoms set forth herein."
|
||||
};
|
||||
char *empty_string[] = {""};
|
||||
char *my_string_fill[] = {"fill_string"};
|
||||
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
#define NUM_DIM_COMBOS 4
|
||||
int dim_combo;
|
||||
|
||||
/* Create an array of strings for the Universal Declaraion of Human Rights. */
|
||||
if (nc_def_dim(ncid, DIM_NAME1, DHR_LEN, dimids)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME1, NC_STRING, NDIMS, dimids, &varid)) ERR;
|
||||
for (dim_combo = 0; dim_combo < NUM_DIM_COMBOS; dim_combo++)
|
||||
{
|
||||
char filename[NC_MAX_NAME + 1];
|
||||
int dim_len = dim_combo ? NC_UNLIMITED : DHR_LEN;
|
||||
int expected_unlimdimid = dim_combo ? 0 : -1;
|
||||
char *default_fill = ((char *)"");
|
||||
char **string_fillp = dim_combo == 3 ? my_string_fill : &default_fill;
|
||||
char *data_in;
|
||||
|
||||
/* Create a scalar variable for the empty string. */
|
||||
if (nc_def_var(ncid, VAR_NAME2, NC_STRING, 0, NULL, &varid2)) ERR;
|
||||
sprintf(filename, "%s_dim_combo_%d.nc", TEST_NAME, dim_combo);
|
||||
if (nc_create(filename, NC_NETCDF4, &ncid)) ERR;
|
||||
|
||||
/* Check some stuff. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
|
||||
var_dimids, &var_natts)) ERR;
|
||||
if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
|
||||
var_dimids[0] != dimids[0]) ERR;
|
||||
/* Create an array of strings for the Universal Declaraion of Human Rights. */
|
||||
if (nc_def_dim(ncid, DIM_NAME1, dim_len, dimids)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME1, NC_STRING, NDIMS, dimids, &varid)) ERR;
|
||||
|
||||
/* Write the universal declaraion of human rights. */
|
||||
if (nc_put_var(ncid, varid, data)) ERR;
|
||||
/* Create a scalar variable for the empty string. */
|
||||
if (nc_def_var(ncid, VAR_NAME2, NC_STRING, 0, NULL, &varid2)) ERR;
|
||||
if (dim_combo == 3)
|
||||
if (nc_put_att(ncid, varid, _FillValue, NC_STRING, 1, my_string_fill)) ERR;
|
||||
|
||||
/* Write an empty string with an empty attribute. */
|
||||
if (nc_put_var(ncid, varid2, empty_string)) ERR;
|
||||
if (nc_put_att(ncid, varid2, ATT_NAME2, NC_STRING, 0, empty_string)) ERR;
|
||||
/* Check some stuff. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != expected_unlimdimid) ERR;
|
||||
if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
|
||||
var_dimids, &var_natts)) ERR;
|
||||
if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
|
||||
var_dimids[0] != dimids[0]) ERR;
|
||||
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
/* Write the universal declaraion of human rights. */
|
||||
if (dim_combo)
|
||||
{
|
||||
size_t start[NDIMS], count[NDIMS] = {1};
|
||||
int counter = 1;
|
||||
|
||||
/* Write one record at a time. */
|
||||
for (start[0] = 0; start[0] < DHR_LEN; start[0]++)
|
||||
{
|
||||
size_t new_start[NDIMS];
|
||||
size_t *my_startp = start;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != -1) ERR;
|
||||
/* For dim_combo 2 or 3 skip every other record. */
|
||||
new_start[0] = start[0] + counter++;
|
||||
if (dim_combo >= 2)
|
||||
my_startp = new_start;
|
||||
|
||||
/* Check declaration. */
|
||||
if (nc_inq_varid(ncid, VAR_NAME1, &varid)) ERR;
|
||||
if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
|
||||
var_dimids, &var_natts)) ERR;
|
||||
if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
|
||||
var_dimids[0] != dimids[0]) ERR;
|
||||
if (nc_get_var(ncid, varid, data_in)) ERR;
|
||||
for (i = 0; i < DHR_LEN; i++)
|
||||
if (strcmp(data_in[i], data[i])) ERR;
|
||||
if (nc_free_string(DHR_LEN, data_in)) ERR;
|
||||
/* Write a record. */
|
||||
nc_put_vara_string(ncid, varid, my_startp, count, (const char **)&data[start[0]]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Write all records at once. */
|
||||
if (nc_put_var(ncid, varid, data)) ERR;
|
||||
}
|
||||
|
||||
/* Check the empty var and att. */
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
if (nc_get_var(ncid, varid, data_in)) ERR;
|
||||
if (strcmp(data_in[0], empty_string[0])) ERR;
|
||||
if (nc_free_string(1, data_in)) ERR;
|
||||
if (nc_get_att(ncid, varid, ATT_NAME2, NULL)) ERR;
|
||||
/* Write an empty string with an empty attribute. */
|
||||
if (nc_put_var(ncid, varid2, empty_string)) ERR;
|
||||
if (nc_put_att(ncid, varid2, ATT_NAME2, NC_STRING, 0, empty_string)) ERR;
|
||||
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
if (nc_open(filename, NC_NOWRITE, &ncid)) ERR;
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS || nvars != 2 || natts != 0 || unlimdimid != expected_unlimdimid) ERR;
|
||||
|
||||
/* Check declaration. */
|
||||
if (nc_inq_varid(ncid, VAR_NAME1, &varid)) ERR;
|
||||
if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims, var_dimids,
|
||||
&var_natts)) ERR;
|
||||
if (var_type != NC_STRING || strcmp(var_name, VAR_NAME1) || var_ndims != NDIMS ||
|
||||
var_dimids[0] != dimids[0]) ERR;
|
||||
|
||||
/* Check fill value stuff. */
|
||||
{
|
||||
int no_fill;
|
||||
char *fill_value_in[1];
|
||||
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, (char **)fill_value_in)) ERR;
|
||||
if (no_fill) ERR;
|
||||
if (strcmp(fill_value_in[0], *string_fillp)) ERR;
|
||||
if (nc_free_string(1, fill_value_in)) ERR;
|
||||
}
|
||||
|
||||
if (dim_combo < 2)
|
||||
{
|
||||
char *data_in[DHR_LEN];
|
||||
|
||||
/* Get the data in one read of the entire var. */
|
||||
if (nc_get_var(ncid, varid, data_in)) ERR;
|
||||
for (i = 0; i < DHR_LEN; i++)
|
||||
if (strcmp(data_in[i], data[i])) ERR;
|
||||
if (nc_free_string(DHR_LEN, data_in)) ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *data_in;
|
||||
size_t start[NDIMS], count[NDIMS] = {1};
|
||||
int my_count = 0;
|
||||
|
||||
/* Get the data one record at a time. Every other record,
|
||||
* starting with the first, is a fill value. */
|
||||
for (start[0] = 0; start[0] < DHR_LEN; start[0]++)
|
||||
{
|
||||
if (nc_get_vara(ncid, varid, start, count, &data_in)) ERR;
|
||||
if (start[0] % 2)
|
||||
{
|
||||
if (strcmp(data_in, data[my_count++])) ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(data_in, *string_fillp)) ERR;
|
||||
}
|
||||
if (nc_free_string(1, &data_in)) ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check the empty var and att. */
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
if (nc_get_var(ncid, varid, &data_in)) ERR;
|
||||
if (strcmp(data_in, empty_string[0])) ERR;
|
||||
if (nc_free_string(1, &data_in)) ERR;
|
||||
if (nc_get_att(ncid, varid, ATT_NAME2, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
} /* next dim_combo */
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
printf("*** Testing a file that causes ncdump problems...");
|
||||
{
|
||||
#define NUM_DIMS 2
|
||||
#define DIM_0_NAME "dim_0"
|
||||
#define DIM_1_NAME "dim_1"
|
||||
#define DIM_1_LEN 2
|
||||
#define FILE_NAME_NCDUMP "tst_strings_ncdump_problem.nc"
|
||||
#define VAR_NAME_NCDUMP "var_string"
|
||||
int ncid, varid, dimid[NUM_DIMS];
|
||||
char *string_data[] = {"x"};
|
||||
int t;
|
||||
|
||||
/* Create a file. */
|
||||
if (nc_create(FILE_NAME_NCDUMP, NC_NETCDF4, &ncid)) ERR;
|
||||
|
||||
/* Create dims. */
|
||||
if (nc_def_dim(ncid, DIM_0_NAME, NC_UNLIMITED, &dimid[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM_1_NAME, DIM_1_LEN, &dimid[1])) ERR;
|
||||
|
||||
/* Create a var. */
|
||||
if (nc_def_var(ncid, VAR_NAME_NCDUMP, NC_STRING, NUM_DIMS, dimid, &varid)) ERR;
|
||||
|
||||
/* Check that you can't turn off fill mode for NC_STRING variables. */
|
||||
if (nc_def_var_fill(ncid, varid, NC_NOFILL, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* End define mode. */
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
|
||||
/* Write to each var. */
|
||||
for (t = 0; t < 1; t++)
|
||||
{
|
||||
size_t start[NUM_DIMS] = {1, 0};
|
||||
size_t count[NUM_DIMS] = {1, 1};
|
||||
|
||||
if (nc_put_vara_string(ncid, varid, start, count, (const char **)string_data)) ERR;
|
||||
}
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
@ -81,8 +81,9 @@ create_4D_example(char *file_name, int cmode)
|
||||
write our data. */
|
||||
size_t start[NDIMS_EX], count[NDIMS_EX];
|
||||
|
||||
/* Program variables to hold the data we will write out. We will only
|
||||
need enough space to hold one timestep of data; one record. */
|
||||
/* Program variables to hold the data we will write out. We will
|
||||
only need enough space to hold one timestep of data; one
|
||||
record. */
|
||||
float pres_out[NLVL][NLAT][NLON];
|
||||
float temp_out[NLVL][NLAT][NLON];
|
||||
|
||||
@ -1050,47 +1051,70 @@ main(int argc, char **argv)
|
||||
#define DIM7_LEN 2
|
||||
#define DIM7_NAME "dim_7_from_Indiana"
|
||||
#define VAR7_NAME "var_7_from_Idaho"
|
||||
#define VAR8_NAME "var_8_from_Outer_Space"
|
||||
#define VAR9_NAME "var_9_from_Inner_Space"
|
||||
#define VAR10_NAME "var_10_from_Im_Out_Of_Ideas"
|
||||
#define NDIMS 1
|
||||
|
||||
printf("*** testing fill values...");
|
||||
{
|
||||
int dimids[NDIMS], dimids_in[NDIMS];
|
||||
size_t index[NDIMS];
|
||||
int varid, ndims, natts;
|
||||
int varid, varid2, varid3, varid4, ndims, natts;
|
||||
nc_type xtype_in;
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
int shuffle_in, deflate_in, deflate_level_in;
|
||||
int checksum_in, no_fill;
|
||||
unsigned short ushort_data = 42, ushort_data_in, fill_value_in;
|
||||
unsigned short my_fill_value = 999;
|
||||
unsigned short my_fill_value2 = 111;
|
||||
|
||||
/* Create a netcdf-4 file with one dim and 1 NC_USHORT var. */
|
||||
/* Create a netcdf-4 file with one dim and some NC_USHORT vars. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids,
|
||||
&varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR8_NAME, NC_USHORT, NDIMS, dimids, &varid2)) ERR;
|
||||
if (nc_def_var(ncid, VAR9_NAME, NC_USHORT, NDIMS, dimids, &varid3)) ERR;
|
||||
if (nc_put_att(ncid, varid3, _FillValue, NC_USHORT, 1, &my_fill_value2)) ERR;
|
||||
if (nc_def_var(ncid, VAR10_NAME, NC_USHORT, NDIMS, dimids, &varid4)) ERR;
|
||||
if (nc_put_att(ncid, varid4, _FillValue, NC_USHORT, 1, &my_fill_value2)) ERR;
|
||||
|
||||
/* Check stuff. */
|
||||
if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims,
|
||||
dimids_in, &natts)) ERR;
|
||||
if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in,
|
||||
&natts)) ERR;
|
||||
if (strcmp(name_in, VAR7_NAME) || xtype_in != NC_USHORT ||
|
||||
ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR;
|
||||
if (nc_inq_var_deflate(ncid, 0, &shuffle_in, &deflate_in,
|
||||
&deflate_level_in)) ERR;
|
||||
&deflate_level_in)) ERR;
|
||||
if (shuffle_in != NC_NOSHUFFLE || deflate_in) ERR;
|
||||
if (nc_inq_var_fletcher32(ncid, 0, &checksum_in)) ERR;
|
||||
if (checksum_in != NC_NOCHECKSUM) ERR;
|
||||
if (nc_inq_var_fill(ncid, 0, &no_fill, &fill_value_in)) ERR;
|
||||
if (no_fill || fill_value_in != NC_FILL_USHORT) ERR;
|
||||
|
||||
/* Set a fill value for the second and forth variable. This will
|
||||
* overwrite the existing fill value attribute for varid4. */
|
||||
if (nc_def_var_fill(ncid, varid2, 0, &my_fill_value)) ERR;
|
||||
if (nc_def_var_fill(ncid, varid4, 0, &my_fill_value)) ERR;
|
||||
|
||||
/* Write the second of two values. */
|
||||
index[0] = 1;
|
||||
if (nc_put_var1_ushort(ncid, 0, index, &ushort_data)) ERR;
|
||||
if (nc_put_var1_ushort(ncid, varid2, index, &ushort_data)) ERR;
|
||||
if (nc_put_var1_ushort(ncid, varid3, index, &ushort_data)) ERR;
|
||||
if (nc_put_var1_ushort(ncid, varid4, index, &ushort_data)) ERR;
|
||||
|
||||
/* Get the first value, and make sure we get the default fill
|
||||
* value for USHORT. */
|
||||
/* Get the first value, and make sure we get the correct fill
|
||||
* values. */
|
||||
index[0] = 0;
|
||||
if (nc_get_var1_ushort(ncid, 0, index, &ushort_data_in)) ERR;
|
||||
if (ushort_data_in != NC_FILL_USHORT) ERR;
|
||||
if (nc_get_var1_ushort(ncid, varid2, index, &ushort_data_in)) ERR;
|
||||
if (ushort_data_in != my_fill_value) ERR;
|
||||
if (nc_get_var1_ushort(ncid, varid3, index, &ushort_data_in)) ERR;
|
||||
if (ushort_data_in != my_fill_value2) ERR;
|
||||
if (nc_get_var1_ushort(ncid, varid4, index, &ushort_data_in)) ERR;
|
||||
if (ushort_data_in != my_fill_value) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
@ -1119,18 +1143,39 @@ main(int argc, char **argv)
|
||||
int varid;
|
||||
int no_fill;
|
||||
unsigned short ushort_data = 42, ushort_data_in, fill_value_in;
|
||||
unsigned short my_fill_value = 999;
|
||||
|
||||
/* Create a netcdf-4 file with one dim and 1 NC_USHORT var. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids,
|
||||
&varid)) ERR;
|
||||
if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;
|
||||
|
||||
/* Check stuff. */
|
||||
/* Turn off fill mode. */
|
||||
if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
|
||||
if (!no_fill) ERR;
|
||||
|
||||
/* Turn on fill mode. */
|
||||
if (nc_def_var_fill(ncid, varid, 0, NULL)) ERR;
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
|
||||
if (no_fill) ERR;
|
||||
|
||||
/* Turn off fill mode. */
|
||||
if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR;
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
|
||||
if (!no_fill) ERR;
|
||||
|
||||
/* Try and set a fill value and fill mode off. It will be
|
||||
* ignored because fill mode is off. */
|
||||
if (nc_def_var_fill(ncid, varid, 1, &my_fill_value)) ERR;
|
||||
|
||||
/* Turn on fill mode. */
|
||||
if (nc_def_var_fill(ncid, varid, 0, NULL)) ERR;
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
|
||||
if (fill_value_in != NC_FILL_USHORT) ERR;
|
||||
if (no_fill) ERR;
|
||||
|
||||
/* Write the second of two values. */
|
||||
index[0] = 1;
|
||||
if (nc_put_var1_ushort(ncid, varid, index, &ushort_data)) ERR;
|
||||
@ -1139,7 +1184,7 @@ main(int argc, char **argv)
|
||||
* value for USHORT. */
|
||||
index[0] = 0;
|
||||
if (nc_get_var1_ushort(ncid, varid, index, &ushort_data_in)) ERR;
|
||||
|
||||
if (ushort_data_in != NC_FILL_USHORT) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check the same stuff. */
|
||||
@ -1147,7 +1192,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Check stuff. */
|
||||
if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR;
|
||||
if (!no_fill) ERR;
|
||||
if (no_fill) ERR;
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
#define DIM1_NAME "Hoplites_Engaged"
|
||||
#define VAR_NAME "Battle_of_Marathon"
|
||||
#define LOSSES_NAME "Miltiades_Losses"
|
||||
|
||||
#define NDIMS1 1
|
||||
#define MAX_CNUM 4
|
||||
|
||||
int
|
||||
@ -66,15 +66,22 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define FILE_NAME2 "tst_vars2_latefill.nc"
|
||||
printf("**** testing simple fill value attribute creation...");
|
||||
{
|
||||
int status;
|
||||
int schar_data = 0;
|
||||
size_t index[1] = {0};
|
||||
int dimid;
|
||||
|
||||
/* Create a netcdf-4 file with one scalar var. Add fill
|
||||
* value. */
|
||||
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_BYTE, 0, NULL, &varid)) ERR;
|
||||
if (nc_create(FILE_NAME2, cmode, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, VAR_NAME, TEST_VAL_42, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME, NC_BYTE, 1, &dimid, &varid)) ERR;
|
||||
if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_put_var1(ncid, varid, index, &schar_data)) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
status = nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value);
|
||||
if (status != NC_ELATEFILL)
|
||||
@ -82,7 +89,7 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_open(FILE_NAME2, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
|
||||
if (nvars_in != 1 || varids_in[0] != 0) ERR;
|
||||
if (nc_inq_varname(ncid, 0, name_in)) ERR;
|
||||
@ -507,6 +514,7 @@ main(int argc, char **argv)
|
||||
/* THese won't work due to bad params. */
|
||||
if (nc_rename_dim(ncid + MILLION, lon_dim, "longitude") != NC_EBADID) ERR;
|
||||
if (nc_rename_dim(ncid + TEST_VAL_42, lon_dim, "longitude") != NC_EBADID) ERR;
|
||||
if (nc_rename_dim(ncid, lon_dim, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* rename dimension */
|
||||
if (nc_rename_dim(ncid, lon_dim, "longitude")) ERR;
|
||||
@ -533,13 +541,14 @@ main(int argc, char **argv)
|
||||
if (nc_rename_var(ncid, wind_id, too_long_name) != NC_EMAXNAME) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "temp2") != NC_ENAMEINUSE) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "windy") != NC_ENOTINDEFINE) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* rename variable */
|
||||
if (nc_rename_var(ncid, wind_id, "wind")) ERR;
|
||||
|
||||
/* Enter define mode and rename it to something longer. */
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "windy")) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "windy")) ERR;
|
||||
if (nc_inq_varid(ncid, "windy", &wind_id)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
@ -553,9 +562,9 @@ main(int argc, char **argv)
|
||||
wind_dims[0] = lon_dim;
|
||||
if (nc_def_var(ncid, "temp", NC_FLOAT, RANK_wind, wind_dims, &wind_id)) ERR;
|
||||
if (nc_enddef(ncid)) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "windy")) ERR;
|
||||
if (nc_rename_var(ncid, wind_id, "windy")) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
||||
@ -585,7 +594,7 @@ main(int argc, char **argv)
|
||||
ncclose(ncid);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
#endif
|
||||
#endif /* NO_NETCDF_2 */
|
||||
|
||||
#define NDIMS 3
|
||||
#define NNAMES 4
|
||||
@ -718,7 +727,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* This also works, uselessly. */
|
||||
if (nc_inq_var(ncid, 0, name_in, NULL, NULL, NULL, NULL)) ERR;
|
||||
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Open the file and check the same stuff. */
|
||||
@ -755,6 +764,8 @@ main(int argc, char **argv)
|
||||
#define VAR_NAME5 "V5"
|
||||
#define VAR_NAME5_1 "V5_1"
|
||||
#define VAR_NAME5_2 "V5_2"
|
||||
#define VAR_NAME5_3 "V5_3"
|
||||
#define VAR_NAME5_4 "V5_4"
|
||||
#define DIM5_LEN 1000
|
||||
#define CACHE_SIZE 32000000
|
||||
#define CACHE_NELEMS 1009
|
||||
@ -762,15 +773,17 @@ main(int argc, char **argv)
|
||||
#define CACHE_SIZE2 64000000
|
||||
#define CACHE_NELEMS2 2000
|
||||
#define CACHE_PREEMPTION2 .50
|
||||
#define NVAR4 5
|
||||
|
||||
int dimids[NDIMS5], dimids_in[NDIMS5];
|
||||
int varid, varid1, varid2;
|
||||
int varid, varid1, varid2, varid3, varid4;
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
nc_type xtype_in;
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
int data[DIM5_LEN], data_in[DIM5_LEN];
|
||||
size_t chunksize[NDIMS5] = {5};
|
||||
size_t bad_chunksize[NDIMS5] = {-5};
|
||||
size_t bad_chunksize[NDIMS5] = {-5}; /* Converted to large pos number since size_t is unsigned. */
|
||||
size_t large_chunksize[NDIMS5] = {(size_t)NC_MAX_INT + (size_t)1}; /* Too big for inq_var_chunking_ints(). */
|
||||
size_t chunksize_in[NDIMS5];
|
||||
int chunksize_int[NDIMS5];
|
||||
int chunksize_int_in[NDIMS5];
|
||||
@ -862,13 +875,16 @@ main(int argc, char **argv)
|
||||
chunksize_int_in) != NC_ENOTVAR) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid + TEST_VAL_42, &storage_in,
|
||||
chunksize_int_in) != NC_ENOTVAR) ERR;
|
||||
|
||||
|
||||
/* Now check with the fortran versions of the var_chunking. */
|
||||
if (nc_inq_var_chunking_ints(ncid, 0, &storage_in, chunksize_int_in)) ERR;
|
||||
if (storage_in != NC_CHUNKED) ERR;
|
||||
for (d = 0; d < NDIMS5; d++)
|
||||
if (chunksize_int_in[d] != chunksize[d]) ERR;
|
||||
for (d = 0; d < NDIMS5; d++)
|
||||
chunksize_int[d] = chunksize[d] * 2;
|
||||
if (nc_inq_var_chunking_ints(ncid, 0, &storage_in, NULL)) ERR;
|
||||
if (storage_in != NC_CHUNKED) ERR;
|
||||
|
||||
/* Check that some bad parameter values are rejected properly. */
|
||||
if (nc_def_var_chunking_ints(ncid + MILLION, varid, NC_CHUNKED,
|
||||
@ -881,19 +897,29 @@ main(int argc, char **argv)
|
||||
chunksize_int) != NC_ENOTVAR) ERR;
|
||||
if (nc_def_var_chunking_ints(ncid, varid + TEST_VAL_42, NC_CHUNKED,
|
||||
chunksize_int) != NC_ENOTVAR) ERR;
|
||||
|
||||
|
||||
if (nc_def_var_chunking_ints(ncid, varid, NC_CHUNKED, chunksize_int) != NC_ELATEDEF) ERR;
|
||||
if (nc_redef(ncid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME5_1, NC_INT, NDIMS5, dimids, &varid1)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME5_2, NC_INT, 0, NULL, &varid2)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME5_3, NC_INT, 0, NULL, &varid3)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME5_4, NC_INT, NDIMS5, dimids, &varid4)) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid2, NC_CHUNKED, chunksize)) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid3, NC_CONTIGUOUS, NULL)) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid4, NC_CHUNKED, large_chunksize) != NC_EBADCHUNK) ERR;
|
||||
if (nc_def_var_chunking_ints(ncid, varid2, NC_CHUNKED, chunksize_int)) ERR;
|
||||
if (nc_def_var_chunking_ints(ncid, varid1, NC_CHUNKED, chunksize_int)) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid2, NC_CHUNKED, chunksize_int_in)) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid2, NULL, chunksize_int_in)) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid1, NULL, chunksize_int_in)) ERR;
|
||||
for (d = 0; d < NDIMS5; d++)
|
||||
if (chunksize_int_in[d] != chunksize[d] * 2) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid1, NULL, NULL)) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid1, &storage_in, NULL)) ERR;
|
||||
if (storage_in != NC_CHUNKED) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid2, NULL, chunksize_int_in)) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid3, &storage_in, NULL)) ERR;
|
||||
if (storage_in != NC_CONTIGUOUS) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid3, &storage_in, chunksize_int_in)) ERR;
|
||||
if (storage_in != NC_CONTIGUOUS) ERR;
|
||||
|
||||
/* Check that some bad parameter values are rejected properly. */
|
||||
if (nc_get_var_chunk_cache(ncid + MILLION, varid, &cache_size_in, &cache_nelems_in,
|
||||
@ -902,7 +928,7 @@ main(int argc, char **argv)
|
||||
&cache_preemption_in) != NC_EBADID) ERR;
|
||||
if (nc_get_var_chunk_cache(ncid, varid + TEST_VAL_42, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in) != NC_ENOTVAR) ERR;
|
||||
if (nc_get_var_chunk_cache(ncid, varid2 + 1, &cache_size_in, &cache_nelems_in,
|
||||
if (nc_get_var_chunk_cache(ncid, varid4 + 1, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in) != NC_ENOTVAR) ERR;
|
||||
if (nc_get_var_chunk_cache(ncid, -TEST_VAL_42, &cache_size_in, &cache_nelems_in,
|
||||
&cache_preemption_in) != NC_ENOTVAR) ERR;
|
||||
@ -931,10 +957,10 @@ main(int argc, char **argv)
|
||||
|
||||
/* Check stuff. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS5 || nvars != NUM_VARS || natts != 0 ||
|
||||
if (ndims != NDIMS5 || nvars != NVAR4 || natts != 0 ||
|
||||
unlimdimid != -1) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
|
||||
if (nvars != NUM_VARS) ERR;
|
||||
if (nvars != NVAR4) ERR;
|
||||
if (varids_in[0] != 0 || varids_in[1] != 1) ERR;
|
||||
if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
|
||||
if (strcmp(name_in, VAR_NAME5) || xtype_in != NC_INT || ndims != 1 || natts != 0 ||
|
||||
@ -993,7 +1019,7 @@ main(int argc, char **argv)
|
||||
&cache_preemption_int_in)) ERR;
|
||||
if (cache_size_int_in != cache_size_int_default || cache_nelems_int_in != cache_nelems_int_default ||
|
||||
cache_preemption_int_in != (int)(CACHE_PREEMPTION2 * 100)) ERR;
|
||||
|
||||
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
@ -1075,7 +1101,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* This call passes but does nothing. */
|
||||
if (nc_inq_var_chunking(ncid, 0, &storage_in, chunksize_in)) ERR;
|
||||
|
||||
|
||||
if (nc_get_var_int(ncid, varid, data_in)) ERR;
|
||||
for (i = 0; i < DIM5_LEN; i++)
|
||||
if (data[i] != data_in[i])
|
||||
@ -1086,18 +1112,17 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
printf("**** testing contiguous storage...");
|
||||
{
|
||||
#define NDIMS6 1
|
||||
#define DIM6_NAME "D5"
|
||||
#define VAR_NAME6 "V5"
|
||||
#define DIM6_LEN 100
|
||||
|
||||
int dimids[NDIMS6], dimids_in[NDIMS6];
|
||||
int dimids[NDIMS1], dimids_in[NDIMS1];
|
||||
int varid;
|
||||
int ndims, nvars, natts, unlimdimid;
|
||||
nc_type xtype_in;
|
||||
char name_in[NC_MAX_NAME + 1];
|
||||
int data[DIM6_LEN], data_in[DIM6_LEN];
|
||||
size_t chunksize_in[NDIMS6];
|
||||
size_t chunksize_in[NDIMS1];
|
||||
int storage_in;
|
||||
int i;
|
||||
|
||||
@ -1108,13 +1133,13 @@ main(int argc, char **argv)
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR;
|
||||
if (dimids[0] != 0) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS6, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS1, dimids, &varid)) ERR;
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL)) ERR;
|
||||
if (nc_put_var_int(ncid, varid, data)) ERR;
|
||||
|
||||
/* Check stuff. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
|
||||
if (ndims != NDIMS1 || nvars != 1 || natts != 0 ||
|
||||
unlimdimid != -1) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
|
||||
if (nvars != 1) ERR;
|
||||
@ -1135,7 +1160,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Check stuff. */
|
||||
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
|
||||
if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
|
||||
if (ndims != NDIMS1 || nvars != 1 || natts != 0 ||
|
||||
unlimdimid != -1) ERR;
|
||||
if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
|
||||
if (nvars != 1) ERR;
|
||||
@ -1349,26 +1374,34 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
#define NDIMS6 1
|
||||
#define DIM8_NAME "num_monkeys"
|
||||
#define DIM9_NAME "num_coconuts"
|
||||
#define DIM9_LEN 10
|
||||
#define VAR_NAME8 "John_Clayton"
|
||||
#define VAR_NAME9 "Lord_Greystoke"
|
||||
#define VAR_NAME10 "Jane_Porter"
|
||||
printf("**** testing that contiguous storage can't be turned on for vars with unlimited dims or filters...");
|
||||
{
|
||||
int ncid;
|
||||
int dimids[NDIMS6];
|
||||
int dimids[NDIMS1];
|
||||
int varid, varid2;
|
||||
size_t chunksize_in[NDIMS6];
|
||||
size_t chunksize_in[NDIMS1];
|
||||
int storage_in;
|
||||
|
||||
/* Create a netcdf-4 file with one dim and some vars. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM8_NAME, NC_UNLIMITED, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS6, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS1, dimids, &varid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM9_NAME, DIM9_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME9, NC_INT, NDIMS6, dimids, &varid2)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME9, NC_INT, NDIMS1, dimids, &varid2)) ERR;
|
||||
|
||||
/* These will fail due to bad paramters. */
|
||||
if (nc_def_var_deflate(ncid, varid2, 0, 1,
|
||||
NC_MIN_DEFLATE_LEVEL - 1) != NC_EINVAL) ERR;
|
||||
if (nc_def_var_deflate(ncid, varid2, 0, 1,
|
||||
NC_MAX_DEFLATE_LEVEL + 1) != NC_EINVAL) ERR;
|
||||
|
||||
/* This will work. */
|
||||
if (nc_def_var_deflate(ncid, varid2, 0, 1, 4)) ERR;
|
||||
|
||||
/* This won't work because of the umlimited dimension. */
|
||||
@ -1390,8 +1423,10 @@ main(int argc, char **argv)
|
||||
printf("**** testing error conditions on nc_def_var functions...");
|
||||
{
|
||||
int ncid;
|
||||
int dimids[NDIMS6];
|
||||
int dimids[NDIMS1];
|
||||
int bad_dimids[NDIMS1] = {42};
|
||||
int varid;
|
||||
int varid_scalar;
|
||||
int num_models = 2;
|
||||
int m;
|
||||
int mode = NC_NETCDF4;
|
||||
@ -1399,26 +1434,71 @@ main(int argc, char **argv)
|
||||
/* Test without and with classic model. */
|
||||
for (m = 0; m < num_models; m++)
|
||||
{
|
||||
int contiguous_in;
|
||||
size_t chunksizes_in[NDIMS1];
|
||||
int shuffle_in, deflate_in, deflate_level_in;
|
||||
|
||||
if (m)
|
||||
mode |= NC_CLASSIC_MODEL;
|
||||
|
||||
/* Create a netcdf-4 file. */
|
||||
if (nc_create(FILE_NAME, mode, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM8_NAME, TEST_VAL_42, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS6, dimids, &varid)) ERR;
|
||||
|
||||
/* This won't work. */
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS1, bad_dimids,
|
||||
&varid) != NC_EBADDIM) ERR;
|
||||
|
||||
/* This will work. */
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS1, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME10, NC_INT, 0, NULL, &varid_scalar)) ERR;
|
||||
|
||||
/* Set the var to contiguous. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL)) ERR;
|
||||
|
||||
/* Now defalte can't be set. */
|
||||
/* Now defalte will change the var to chunked. */
|
||||
if (nc_def_var_deflate(ncid, varid, 0, 1, 4)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid, &contiguous_in, chunksizes_in)) ERR;
|
||||
if (contiguous_in) ERR;
|
||||
|
||||
/* Now I can't turn contiguous on, because deflate is on. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* Turn off deflation. */
|
||||
if (nc_def_var_deflate(ncid, varid, 0, 0, 0)) ERR;
|
||||
if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, &deflate_level_in)) ERR;
|
||||
if (shuffle_in || deflate_in) ERR;
|
||||
if (nc_inq_var_deflate(ncid, varid, NULL, NULL, NULL)) ERR;
|
||||
|
||||
/* Deflate is ignored for scalar. */
|
||||
if (nc_def_var_deflate(ncid, varid_scalar, 0, 1, 4)) ERR;
|
||||
if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, &deflate_level_in)) ERR;
|
||||
if (shuffle_in || deflate_in) ERR;
|
||||
|
||||
/* Turn on shuffle. */
|
||||
if (nc_def_var_deflate(ncid, varid, 1, 0, 0)) ERR;
|
||||
|
||||
/* Now I can't turn contiguous on, because shuffle is on. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* Turn off shuffle. */
|
||||
if (nc_def_var_deflate(ncid, varid, 0, 0, 0)) ERR;
|
||||
|
||||
/* Turn on fletcher32. */
|
||||
if (nc_def_var_fletcher32(ncid, varid, 1)) ERR;
|
||||
|
||||
/* Now I can't turn contiguous on, because fletcher32 is on. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL) != NC_EINVAL) ERR;
|
||||
|
||||
/* Turn off fletcher32. */
|
||||
if (nc_def_var_fletcher32(ncid, varid, 0)) ERR;
|
||||
|
||||
/* Now I can make it contiguous again. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
#define NDIMS6 1
|
||||
#define DIM8_NAME "num_monkeys"
|
||||
#define DIM9_NAME "num_coconuts"
|
||||
#define DIM9_LEN 10
|
||||
@ -1427,17 +1507,17 @@ main(int argc, char **argv)
|
||||
printf("**** testing that contiguous storage can't be turned on for vars with unlimited dims or filters...");
|
||||
{
|
||||
int ncid;
|
||||
int dimids[NDIMS6];
|
||||
int dimids[NDIMS1];
|
||||
int varid, varid2;
|
||||
size_t chunksize_in[NDIMS6];
|
||||
size_t chunksize_in[NDIMS1];
|
||||
int storage_in;
|
||||
|
||||
/* Create a netcdf-4 file with one dim and some vars. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM8_NAME, NC_UNLIMITED, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS6, dimids, &varid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME8, NC_INT, NDIMS1, dimids, &varid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM9_NAME, DIM9_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME9, NC_INT, NDIMS6, dimids, &varid2)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME9, NC_INT, NDIMS1, dimids, &varid2)) ERR;
|
||||
if (nc_def_var_deflate(ncid, varid2, 0, 1, 4)) ERR;
|
||||
|
||||
/* This won't work because of the umlimited dimension. */
|
||||
@ -1456,5 +1536,39 @@ main(int argc, char **argv)
|
||||
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
#define DIM10_NAME "num_monkeys"
|
||||
#define DIM11_NAME "num_hats"
|
||||
#define VAR_NAME11 "Silly_Sally"
|
||||
#define NDIM2 2
|
||||
printf("**** testing very large chunksizes...");
|
||||
{
|
||||
int ncid;
|
||||
int dimid[NDIM2];
|
||||
int varid;
|
||||
size_t chunksize[NDIM2] = {1, (size_t)NC_MAX_INT + (size_t)1};
|
||||
size_t chunksize_in[NDIM2];
|
||||
int chunksize_int_in[NDIM2];
|
||||
int storage_in;
|
||||
|
||||
/* Create a netcdf-4 file. */
|
||||
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM10_NAME, NC_UNLIMITED, &dimid[0])) ERR;
|
||||
if (nc_def_dim(ncid, DIM11_NAME, NC_UNLIMITED, &dimid[0])) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME11, NC_BYTE, NDIM2, dimid, &varid)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksize_in)) ERR;
|
||||
if (storage_in != NC_CHUNKED) ERR;
|
||||
|
||||
/* Set a large chunksize. */
|
||||
if (nc_def_var_chunking(ncid, varid, NC_CHUNKED, chunksize)) ERR;
|
||||
if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksize_in)) ERR;
|
||||
if (storage_in != NC_CHUNKED) ERR;
|
||||
if (chunksize_in[0] != chunksize[0] || chunksize_in[1] != chunksize[1]) ERR;
|
||||
if (nc_inq_var_chunking_ints(ncid, varid, &storage_in, chunksize_int_in) != NC_ERANGE) ERR;
|
||||
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
FINAL_RESULTS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user