Merge branch 'master' into newhash0.dmh

This commit is contained in:
Ward Fisher 2018-02-22 14:55:31 -07:00 committed by GitHub
commit 8e169175e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 201 additions and 48 deletions

View File

@ -882,9 +882,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
if (var->type_info->nc_type_class == NC_STRING)
{
assert(*(char **)var->fill_value);
if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
return NC_ENOMEM;
/* This will allocate memeory and copy the string. */
if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
{
free(*(char **)fill_valuep);

View File

@ -8,7 +8,7 @@ SET(NC4_TESTS tst_dims tst_dims2 tst_dims3 tst_files tst_files4
tst_fillbug tst_xplatform2 tst_endian_fill tst_atts t_type
cdm_sea_soundings tst_vl tst_atts1 tst_atts2 tst_vars2 tst_files5
tst_files6 tst_sync tst_h_strbug tst_h_refs tst_h_scalar tst_rename
tst_h5_endians tst_atts_string_rewrite tst_put_vars_two_unlim_dim
tst_rename2 tst_h5_endians tst_atts_string_rewrite tst_put_vars_two_unlim_dim
tst_hdf5_file_compat tst_fill_attr_vanish tst_rehash tst_types)

View File

@ -28,8 +28,9 @@ tst_vars4 tst_chunks tst_chunks2 tst_utf8 tst_fills tst_fills2 \
tst_fillbug tst_xplatform tst_xplatform2 tst_endian_fill tst_atts \
t_type cdm_sea_soundings tst_camrun tst_vl tst_atts1 tst_atts2 \
tst_vars2 tst_files5 tst_files6 tst_sync tst_h_scalar tst_rename \
tst_h5_endians tst_atts_string_rewrite tst_hdf5_file_compat \
tst_fill_attr_vanish tst_rehash tst_filterparser tst_bug324 tst_types
tst_rename2 tst_h5_endians tst_atts_string_rewrite \
tst_hdf5_file_compat tst_fill_attr_vanish tst_rehash tst_filterparser \
tst_bug324 tst_types
# Temporary I hope
if !ISCYGWIN

View File

@ -285,6 +285,54 @@ main(int argc, char **argv)
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, too_long_name) != NC_EMAXNAME) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, OLD_NAME_2) != NC_ENAMEINUSE) ERR;
if (nc_put_att_text(ncid, NC_GLOBAL, OLD_NAME, strlen(CONTENTS),
NULL) != NC_EINVAL) ERR;
{
/* Check that the NC_GLOBAL reserved words are rejected. */
const char** reserved = NC_RESERVED_ATT_LIST;
for ( ; *reserved; reserved++)
{
if (nc_put_att_text(ncid, NC_GLOBAL, *reserved, strlen(CONTENTS),
CONTENTS) != NC_ENAMEINUSE) ERR;
}
}
{
/* Check that the variable reserved words are rejected. */
const char** reserved = NC_RESERVED_VARATT_LIST;
for ( ; *reserved; reserved++)
{
if (nc_put_att_text(ncid, 0, *reserved, strlen(CONTENTS),
CONTENTS) != NC_ENAMEINUSE) ERR;
}
}
{
/* Check that the read-only reserved words are rejected. */
const char** reserved = NC_RESERVED_SPECIAL_LIST;
for ( ; *reserved; reserved++)
{
if (nc_put_att_text(ncid, NC_GLOBAL, *reserved, strlen(CONTENTS),
CONTENTS) != NC_ENAMEINUSE) ERR;
}
}
/* Write the attribute at last. */
if (nc_put_att_text(ncid, NC_GLOBAL, OLD_NAME, strlen(CONTENTS),
CONTENTS)) ERR;
/* Write another with different name. */
if (nc_put_att_text(ncid, NC_GLOBAL, OLD_NAME_2, strlen(CONTENTS),
CONTENTS)) ERR;
/* These will not work. */
if (nc_rename_att(ncid + TEST_VAL_42, NC_GLOBAL, OLD_NAME, NEW_NAME) != NC_EBADID) ERR;
if (nc_rename_att(ncid, TEST_VAL_42, OLD_NAME, NEW_NAME) != NC_ENOTVAR) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, NULL) != NC_EINVAL) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, NULL, NEW_NAME) != NC_EINVAL) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, NULL, NULL) != NC_EINVAL) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, BAD_NAME) != NC_EBADNAME) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, too_long_name) != NC_EMAXNAME) ERR;
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, OLD_NAME_2) != NC_ENAMEINUSE) ERR;
/* Rename the att. */
if (nc_rename_att(ncid, NC_GLOBAL, OLD_NAME, NEW_NAME)) ERR;

View File

@ -4,7 +4,6 @@
* https://github.com/Unidata/netcdf-c/issues/113.
*/
#include <stdio.h>
#include <config.h>
#include <unistd.h>
#include <nc_tests.h>

View File

@ -7,10 +7,8 @@
* Test contributed by Jeff Whitaker
*/
#include <string.h>
#include <netcdf.h>
#include <stdio.h>
#include <nc_tests.h>
#include <string.h>
#include "nc_logging.h"
#define FILE_NAME_NC "tst_h5_endians.nc"

View File

@ -1,33 +0,0 @@
/* This is a quickie tester for netcdf-4.
$Id: tst_nc_test_file.c,v 1.7 2005/12/29 19:16:19 ed Exp $
*/
#include <tests.h>
#define FILE_NAME "../nc_test/nc_test_netcdf4.nc"
int
main()
{
int ncid;
int retval;
size_t start[1] = {0}, count[1] = {2};
ptrdiff_t stride[1] = {2};
short short_data[256];
float float_data[256];
printf("\n*** Testing with file %s\n", FILE_NAME);
/*nc_set_log_level(4);*/
printf("*** Testing whether we can open and read from it...");
if ((retval = nc_open(FILE_NAME, 0, &ncid))) ERR;
if ((retval = nc_get_vars_short(ncid, 35, start, count, stride,
short_data)) != NC_ERANGE) ERR;
if ((retval = nc_get_vars(ncid, 35, start, count, stride, short_data))) ERR;
if ((retval = nc_close(ncid))) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -3,6 +3,7 @@
* https://github.com/Unidata/netcdf-c/issues/160
*/
#include <config.h>
#include "netcdf.h"
#include <stdio.h>

View File

@ -8,10 +8,11 @@
Tests to see if the hashmap is being properly updated.
*/
#include <config.h>
#include <netcdf.h>
#define FILENAME "tst_rehash.nc"
#include <netcdf.h>
int main()
{
int status;

140
nc_test4/tst_rename2.c Normal file
View File

@ -0,0 +1,140 @@
/*
* Test more renames of vars and dims.
*
* Ed Hartnett
*/
#include "nc_tests.h"
#include "err_macros.h"
#define TEST_NAME "tst_rename"
#define LAT "lat"
#define LON "lon"
#define LEV "lev"
#define DIM_X "x"
#define DIM_Y "y"
#define DIM_Z "z"
#define DIM1_LEN 4
#define NDIM1 1
#define NDIM3 3
#define NUM_ENDDEF_SETTINGS 2
int
main(int argc, char **argv)
{
#define NUM_FORMATS 2
int formats[NUM_FORMATS] = {NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC};
int format;
fprintf(stderr,"*** Testing more renames\n");
for (format = 0; format < NUM_FORMATS; format++)
{
fprintf(stderr,"*** test renaming 3 dimensions with format %d...",
formats[format]);
{
char filename[NC_MAX_NAME + 1];
int ncid, dimid[NDIM3];
int dimid_in;
int enddef_setting;
if (nc_set_default_format(formats[format], NULL)) ERR;
for (enddef_setting = 0; enddef_setting < NUM_ENDDEF_SETTINGS;
enddef_setting++)
{
sprintf(filename, "%s_%d_%d.nc", TEST_NAME, formats[format],
enddef_setting);
/* Create file with three dims. */
if (nc_create(filename, 0, &ncid)) ERR;
if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR;
if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR;
if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR;
if (enddef_setting)
{
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
}
/* Rename the dimensions. */
if (nc_rename_dim(ncid, 0, DIM_X)) ERR;
if (nc_rename_dim(ncid, 1, DIM_Y)) ERR;
if (nc_rename_dim(ncid, 2, DIM_Z)) ERR;
/* Close the file. */
if (nc_close(ncid)) ERR;
/* Reopen the file and check. */
if (nc_open(filename, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR;
if (dimid_in != 0) ERR;
if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR;
if (dimid_in != 1) ERR;
if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR;
if (dimid_in != 2) ERR;
if (nc_close(ncid)) ERR;
} /* next enddef setting */
}
SUMMARIZE_ERR;
fprintf(stderr,"*** test renaming 3 dims with coord data format %d...",
formats[format]);
{
char filename[NC_MAX_NAME + 1];
int ncid, dimid[NDIM3], varid[NDIM3];
int dimid_in;
int lat_data[DIM1_LEN] = {0, 1, 2, 3};
int lon_data[DIM1_LEN] = {0, 10, 20, 30};
int lev_data[DIM1_LEN] = {0, 100, 200, 300};
if (nc_set_default_format(formats[format], NULL)) ERR;
sprintf(filename, "%s_data_%d.nc", TEST_NAME, formats[format]);
/* Create file with three dims. */
if (nc_create(filename, 0, &ncid)) ERR;
if (nc_def_dim(ncid, LAT, DIM1_LEN, &dimid[0])) ERR;
if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid[1])) ERR;
if (nc_def_dim(ncid, LEV, DIM1_LEN, &dimid[2])) ERR;
/* Define coordinate data vars. */
if (nc_def_var(ncid, LAT, NC_INT, NDIM1, &dimid[0], &varid[0])) ERR;
if (nc_def_var(ncid, LON, NC_INT, NDIM1, &dimid[1], &varid[1])) ERR;
if (nc_def_var(ncid, LEV, NC_INT, NDIM1, &dimid[2], &varid[2])) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_put_var(ncid, 0, lat_data)) ERR;
if (nc_put_var(ncid, 1, lon_data)) ERR;
if (nc_put_var(ncid, 2, lev_data)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(filename, NC_WRITE, &ncid)) ERR;
if (nc_redef(ncid)) ERR;
/* Rename the dimensions. */
if (nc_rename_dim(ncid, 0, DIM_X)) ERR;
if (nc_rename_dim(ncid, 1, DIM_Y)) ERR;
if (nc_rename_dim(ncid, 2, DIM_Z)) ERR;
/* Close the file. */
if (nc_close(ncid)) ERR;
/* Reopen the file and check. */
if (nc_open(filename, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_dimid(ncid, DIM_X, &dimid_in)) ERR;
if (dimid_in != 0) ERR;
if (nc_inq_dimid(ncid, DIM_Y, &dimid_in)) ERR;
if (dimid_in != 1) ERR;
if (nc_inq_dimid(ncid, DIM_Z, &dimid_in)) ERR;
if (dimid_in != 2) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
} /* next format */
FINAL_RESULTS;
}

View File

@ -514,7 +514,7 @@ main(int argc, char **argv)
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 (nc_free_string(1, (char **)fill_value_in)) ERR;
}
if (dim_combo < 2)

View File

@ -777,7 +777,7 @@ main(int argc, char **argv)
int dimids[NDIMS5], dimids_in[NDIMS5];
int varid, varid1, varid2, varid3, varid4;
int varids_in4[NVAR4] = {0};
int varids_in4[NVAR4];
int ndims, nvars, natts, unlimdimid;
nc_type xtype_in;
char name_in[NC_MAX_NAME + 1];
@ -850,9 +850,9 @@ main(int argc, char **argv)
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
if (ndims != NDIMS5 || nvars != 1 || natts != 0 ||
unlimdimid != -1) ERR;
if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
if (nc_inq_varids(ncid, &nvars, varids_in4)) ERR;
if (nvars != 1) ERR;
if (varids_in[0] != 0) ERR;
if (varids_in4[0] != 0) 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 ||
dimids_in[0] != 0) ERR;