/other/netcdf_write_matrix/src/nc_test/test_put.c
https://github.com/jbeezley/wrf-fire · C · 7354 lines · 6573 code · 423 blank · 358 comment · 1804 complexity · aac14ed06b320f51a19bc66dea284c63 MD5 · raw file
Large files are truncated click here to view the full file
- /* Do not edit this file. It is produced from the corresponding .m4 source */
- /*********************************************************************
- * Copyright 1996, UCAR/Unidata
- * See netcdf/COPYRIGHT file for copying and redistribution conditions.
- * $Id: test_put.m4,v 1.25 2005/03/08 03:04:19 ed Exp $
- *********************************************************************/
- #include "tests.h"
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_text(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = text_min;
- const double max = text_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_uchar(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = uchar_min;
- const double max = uchar_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_schar(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = schar_min;
- const double max = schar_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_short(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = short_min;
- const double max = short_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_int(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = int_min;
- const double max = int_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_long(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = long_min;
- const double max = long_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_float(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = float_min;
- const double max = float_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * ensure hash value within range for internal TYPE
- */
- static
- double
- hash_double(
- const nc_type type,
- const int rank,
- const size_t *index,
- const nct_itype itype)
- {
- const double min = double_min;
- const double max = double_max;
- return MAX(min, MIN(max, hash4( type, rank, index, itype)));
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_text(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- text value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_TEXT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_TEXT);
- err = nc_get_var1_text(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_TEXT)) {
- if (expect >= text_min && expect <= text_max) {
- IF (err) {
- error("nc_get_var1_text: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_TEXT)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_uchar(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- uchar value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_UCHAR);
- err = nc_get_var1_uchar(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_UCHAR)) {
- if (expect >= uchar_min && expect <= uchar_max) {
- IF (err) {
- error("nc_get_var1_uchar: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_UCHAR)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_schar(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- schar value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_SCHAR);
- err = nc_get_var1_schar(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_SCHAR)) {
- if (expect >= schar_min && expect <= schar_max) {
- IF (err) {
- error("nc_get_var1_schar: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_SCHAR)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_short(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- short value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_SHORT);
- err = nc_get_var1_short(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_SHORT)) {
- if (expect >= short_min && expect <= short_max) {
- IF (err) {
- error("nc_get_var1_short: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_SHORT)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_int(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- int value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_INT);
- err = nc_get_var1_int(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_INT)) {
- if (expect >= int_min && expect <= int_max) {
- IF (err) {
- error("nc_get_var1_int: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_INT)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_long(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- long value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_LONG);
- err = nc_get_var1_long(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_LONG)) {
- if (expect >= long_min && expect <= long_max) {
- IF (err) {
- error("nc_get_var1_long: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_LONG)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_float(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- float value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_FLOAT);
- err = nc_get_var1_float(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_FLOAT)) {
- if (expect >= float_min && expect <= float_max) {
- IF (err) {
- error("nc_get_var1_float: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_FLOAT)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all vars in file which are (text/numeric) compatible with TYPE
- */
- static
- void
- check_vars_double(const char *filename)
- {
- int ncid; /* netCDF id */
- size_t index[MAX_RANK];
- int err; /* status */
- int d;
- int i;
- size_t j;
- double value;
- nc_type datatype;
- int ndims;
- int dimids[MAX_RANK];
- double expect;
- char name[NC_MAX_NAME];
- size_t length;
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- err = nc_open(filename, NC_NOWRITE, &ncid);
- IF (err)
- error("nc_open: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL);
- IF (err)
- error("nc_inq_var: %s", nc_strerror(err));
- IF (strcmp(name, var_name[i]) != 0)
- error("Unexpected var_name");
- IF (datatype != var_type[i])
- error("Unexpected type");
- IF (ndims != var_rank[i])
- error("Unexpected rank");
- for (j = 0; j < ndims; j++) {
- err = nc_inq_dim(ncid, dimids[j], 0, &length);
- IF (err)
- error("nc_inq_dim: %s", nc_strerror(err));
- IF (length != var_shape[i][j])
- error("Unexpected shape");
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 2");
- expect = hash4( var_type[i], var_rank[i], index, NCT_DOUBLE);
- err = nc_get_var1_double(ncid, i, index, &value);
- if (inRange3(expect,datatype,NCT_DOUBLE)) {
- if (expect >= double_min && expect <= double_max) {
- IF (err) {
- error("nc_get_var1_double: %s", nc_strerror(err));
- } else {
- IF (!equal(value,expect,var_type[i],NCT_DOUBLE)) {
- error("Var value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("var_name: %s, ", var_name[i]);
- error("index:");
- for (d = 0; d < var_rank[i]; d++)
- error(" %d", index[d]);
- error(", expect: %g, ", expect);
- error("got: %g", (double) value);
- }
- } else {
- ++nok;
- }
- }
- }
- }
- }
- }
- }
- err = nc_close (ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_text(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- text value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_TEXT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_TEXT);
- if (inRange3(expect[k], datatype, NCT_TEXT)) {
- ++nInExtRange;
- if (expect[k] >= text_min && expect[k] <= text_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_text(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_TEXT)
- && expect[k] >= text_min && expect[k] <= text_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_TEXT)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_uchar(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- uchar value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_UCHAR == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_UCHAR);
- if (inRange3(expect[k], datatype, NCT_UCHAR)) {
- ++nInExtRange;
- if (expect[k] >= uchar_min && expect[k] <= uchar_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_uchar(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_UCHAR)
- && expect[k] >= uchar_min && expect[k] <= uchar_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_UCHAR)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_schar(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- schar value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SCHAR == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_SCHAR);
- if (inRange3(expect[k], datatype, NCT_SCHAR)) {
- ++nInExtRange;
- if (expect[k] >= schar_min && expect[k] <= schar_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_schar(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_SCHAR)
- && expect[k] >= schar_min && expect[k] <= schar_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_SCHAR)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_short(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- short value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SHORT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_SHORT);
- if (inRange3(expect[k], datatype, NCT_SHORT)) {
- ++nInExtRange;
- if (expect[k] >= short_min && expect[k] <= short_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_short(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_SHORT)
- && expect[k] >= short_min && expect[k] <= short_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_SHORT)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_int(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- int value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_INT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_INT);
- if (inRange3(expect[k], datatype, NCT_INT)) {
- ++nInExtRange;
- if (expect[k] >= int_min && expect[k] <= int_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_int(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_INT)
- && expect[k] >= int_min && expect[k] <= int_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_INT)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_long(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- long value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_LONG == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_LONG);
- if (inRange3(expect[k], datatype, NCT_LONG)) {
- ++nInExtRange;
- if (expect[k] >= long_min && expect[k] <= long_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_long(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_LONG)
- && expect[k] >= long_min && expect[k] <= long_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_LONG)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_float(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- float value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_FLOAT == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_FLOAT);
- if (inRange3(expect[k], datatype, NCT_FLOAT)) {
- ++nInExtRange;
- if (expect[k] >= float_min && expect[k] <= float_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_float(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_FLOAT)
- && expect[k] >= float_min && expect[k] <= float_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_FLOAT)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- /*
- * check all attributes in file which are (text/numeric) compatible with TYPE
- * ignore any attributes containing values outside range of TYPE
- */
- static
- void
- check_atts_double(int ncid)
- {
- int err; /* status */
- int i;
- int j;
- size_t k;
- double value[MAX_NELS];
- nc_type datatype;
- double expect[MAX_NELS];
- size_t length;
- size_t nInExtRange; /* number values within external range */
- size_t nInIntRange; /* number values within internal range */
- int canConvert; /* Both text or both numeric */
- int nok = 0; /* count of valid comparisons */
- for (i = -1; i < NVARS; i++) {
- for (j = 0; j < NATTS(i); j++) {
- canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT);
- if (canConvert) {
- err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length);
- IF (err)
- error("nc_inq_att: %s", nc_strerror(err));
- IF (datatype != ATT_TYPE(i,j))
- error("nc_inq_att: unexpected type");
- IF (length != ATT_LEN(i,j))
- error("nc_inq_att: unexpected length");
- assert(length <= MAX_NELS);
- nInIntRange = nInExtRange = 0;
- for (k = 0; k < length; k++) {
- expect[k] = hash4( datatype, -1, &k, NCT_DOUBLE);
- if (inRange3(expect[k], datatype, NCT_DOUBLE)) {
- ++nInExtRange;
- if (expect[k] >= double_min && expect[k] <= double_max)
- ++nInIntRange;
- }
- }
- err = nc_get_att_double(ncid, i, ATT_NAME(i,j), value);
- if (nInExtRange == length && nInIntRange == length) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != 0 && err != NC_ERANGE)
- error("OK or Range error: status = %d", err);
- }
- for (k = 0; k < length; k++) {
- if (inRange3(expect[k],datatype,NCT_DOUBLE)
- && expect[k] >= double_min && expect[k] <= double_max) {
- IF (!equal(value[k],expect[k],datatype,NCT_DOUBLE)) {
- error("att. value read not that expected");
- if (verbose) {
- error("\n");
- error("varid: %d, ", i);
- error("att_name: %s, ", ATT_NAME(i,j));
- error("element number: %d ", k);
- error("expect: %g, ", expect[k]);
- error("got: %g", (double) value[k]);
- }
- } else {
- nok++;
- }
- }
- }
- }
- }
- }
- print_nok(nok);
- }
- void
- test_nc_put_var1_text(void)
- {
- int ncid;
- int i;
- int j;
- int err;
- size_t index[MAX_RANK];
- int canConvert; /* Both text or both numeric */
- text value = 5; /* any value would do - only for error cases */
- err = nc_create(scratch, NC_CLOBBER, &ncid);
- IF (err) {
- error("nc_create: %s", nc_strerror(err));
- return;
- }
- def_dims(ncid);
- def_vars(ncid);
- err = nc_enddef(ncid);
- IF (err)
- error("nc_enddef: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_TEXT == NCT_TEXT);
- for (j = 0; j < var_rank[i]; j++)
- index[j] = 0;
- err = nc_put_var1_text(BAD_ID, i, index, &value);
- IF (err != NC_EBADID)
- error("bad ncid: status = %d", err);
- err = nc_put_var1_text(ncid, BAD_VARID, index, &value);
- IF (err != NC_ENOTVAR)
- error("bad var id: status = %d", err);
- for (j = 0; j < var_rank[i]; j++) {
- if (var_dimid[i][j] > 0) { /* skip record dim */
- index[j] = var_shape[i][j];
- err = nc_put_var1_text(ncid, i, index, &value);
- IF (canConvert && err != NC_EINVALCOORDS)
- error("bad index: status = %d", err);
- index[j] = 0;
- }
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 1");
- value = hash_text( var_type[i], var_rank[i], index, NCT_TEXT);
- if (var_rank[i] == 0 && i%2 == 0)
- err = nc_put_var1_text(ncid, i, NULL, &value);
- else
- err = nc_put_var1_text(ncid, i, index, &value);
- if (canConvert) {
- if (inRange3(value, var_type[i],NCT_TEXT)) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != NC_ERANGE) {
- error("Range error: status = %d", err);
- error("\n\t\tfor type %s value %.17e %ld",
- s_nc_type(var_type[i]),
- (double)value, (long)value);
- }
- }
- } else {
- IF (err != NC_ECHAR)
- error("wrong type: status = %d", err);
- }
- }
- }
- err = nc_close(ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- check_vars_text(scratch);
- err = remove(scratch);
- IF (err)
- error("remove of %s failed", scratch);
- }
- void
- test_nc_put_var1_uchar(void)
- {
- int ncid;
- int i;
- int j;
- int err;
- size_t index[MAX_RANK];
- int canConvert; /* Both text or both numeric */
- uchar value = 5; /* any value would do - only for error cases */
- err = nc_create(scratch, NC_CLOBBER, &ncid);
- IF (err) {
- error("nc_create: %s", nc_strerror(err));
- return;
- }
- def_dims(ncid);
- def_vars(ncid);
- err = nc_enddef(ncid);
- IF (err)
- error("nc_enddef: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT);
- for (j = 0; j < var_rank[i]; j++)
- index[j] = 0;
- err = nc_put_var1_uchar(BAD_ID, i, index, &value);
- IF (err != NC_EBADID)
- error("bad ncid: status = %d", err);
- err = nc_put_var1_uchar(ncid, BAD_VARID, index, &value);
- IF (err != NC_ENOTVAR)
- error("bad var id: status = %d", err);
- for (j = 0; j < var_rank[i]; j++) {
- if (var_dimid[i][j] > 0) { /* skip record dim */
- index[j] = var_shape[i][j];
- err = nc_put_var1_uchar(ncid, i, index, &value);
- IF (canConvert && err != NC_EINVALCOORDS)
- error("bad index: status = %d", err);
- index[j] = 0;
- }
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 1");
- value = hash_uchar( var_type[i], var_rank[i], index, NCT_UCHAR);
- if (var_rank[i] == 0 && i%2 == 0)
- err = nc_put_var1_uchar(ncid, i, NULL, &value);
- else
- err = nc_put_var1_uchar(ncid, i, index, &value);
- if (canConvert) {
- if (inRange3(value, var_type[i],NCT_UCHAR)) {
- IF (err)
- error("%s", nc_strerror(err));
- } else {
- IF (err != NC_ERANGE) {
- error("Range error: status = %d", err);
- error("\n\t\tfor type %s value %.17e %ld",
- s_nc_type(var_type[i]),
- (double)value, (long)value);
- }
- }
- } else {
- IF (err != NC_ECHAR)
- error("wrong type: status = %d", err);
- }
- }
- }
- err = nc_close(ncid);
- IF (err)
- error("nc_close: %s", nc_strerror(err));
- check_vars_uchar(scratch);
- err = remove(scratch);
- IF (err)
- error("remove of %s failed", scratch);
- }
- void
- test_nc_put_var1_schar(void)
- {
- int ncid;
- int i;
- int j;
- int err;
- size_t index[MAX_RANK];
- int canConvert; /* Both text or both numeric */
- schar value = 5; /* any value would do - only for error cases */
- err = nc_create(scratch, NC_CLOBBER, &ncid);
- IF (err) {
- error("nc_create: %s", nc_strerror(err));
- return;
- }
- def_dims(ncid);
- def_vars(ncid);
- err = nc_enddef(ncid);
- IF (err)
- error("nc_enddef: %s", nc_strerror(err));
- for (i = 0; i < NVARS; i++) {
- canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT);
- for (j = 0; j < var_rank[i]; j++)
- index[j] = 0;
- err = nc_put_var1_schar(BAD_ID, i, index, &value);
- IF (err != NC_EBADID)
- error("bad ncid: status = %d", err);
- err = nc_put_var1_schar(ncid, BAD_VARID, index, &value);
- IF (err != NC_ENOTVAR)
- error("bad var id: status = %d", err);
- for (j = 0; j < var_rank[i]; j++) {
- if (var_dimid[i][j] > 0) { /* skip record dim */
- index[j] = var_shape[i][j];
- err = nc_put_var1_schar(ncid, i, index, &value);
- IF (canConvert && err != NC_EINVALCOORDS)
- error("bad index: status = %d", err);
- index[j] = 0;
- }
- }
- for (j = 0; j < var_nels[i]; j++) {
- err = toMixedBase(j, var_rank[i], var_shape[i], index);
- IF (err)
- error("error in toMixedBase 1");
- value = hash_schar( var_type[i], var_rank[i], index, NCT_SCHAR);
- if (var_rank[i] == 0 && i%2 == 0)
- err = nc_put_var1_schar(ncid, i, NULL, &value);
- else
- err = nc_put_var1_schar(ncid, i, index, &value);…