Refactoring tests to separate out error macros from tests, in support of fixing http://github.com/Unidata/netcdf-c/issues/321

This commit is contained in:
Ward Fisher 2016-10-21 17:17:39 +00:00
parent a3327a3621
commit 157af11bc2
33 changed files with 405 additions and 385 deletions

View File

@ -9,6 +9,7 @@
*/
#include "nc_tests.h"
#include "err_macros.h"
#include <hdf5.h>
#include <H5DSpublic.h>

View File

@ -20,7 +20,7 @@ for conditions of use.
#include "netcdf_par.h"
#endif
#include "netcdf.h"
#include "err_macros.h"
//#include "err_macros.h"
#define NC_TESTS_MAX_DIMS 1024 /**< NC_MAX_DIMS for tests. Allows different NC_MAX_DIMS values without breaking this test with a heap or stack overflow. */

View File

@ -3,7 +3,7 @@
See COPYRIGHT file for copying and redistribution conditions.
This is part of netCDF.
This program runs some extra tests.
$Id: tst_misc.c,v 1.6 2010/05/05 22:15:36 dmh Exp $
@ -14,6 +14,7 @@
#include <stdlib.h>
#include "netcdf.h"
#include "nc_tests.h"
#include "err_macros.h"
#ifdef USE_PARALLEL
#include "netcdf_par.h"
#endif
@ -21,7 +22,7 @@
#define FILE_NAME "tst_misc.nc"
int
main(int argc, char **argv)
main(int argc, char **argv)
{
#ifdef TEST_PNETCDF
MPI_Init(&argc, &argv);
@ -29,7 +30,7 @@ main(int argc, char **argv)
printf("\n*** Testing some extra stuff.\n");
printf("*** Trying to open non-netCDF files of tiny length...");
{
#define DATA_LEN 32
#define DATA_LEN 32
int ncid,openstat;
char dummy_data[DATA_LEN];
FILE *file;
@ -45,7 +46,7 @@ main(int argc, char **argv)
if (!(file = fopen(FILE_NAME, "w+"))) ERR;
if (fwrite(dummy_data, 1, i, file) != i) ERR;
if (fclose(file)) ERR;
/* Make sure that netCDF rejects this file politely. */
#ifdef TEST_PNETCDF
openstat = nc_open_par(FILE_NAME, NC_PNETCDF, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
@ -55,7 +56,7 @@ main(int argc, char **argv)
/* Some platforms (OSX, buddy) return stat = 2 (file not found)
for index i == 2. Not sure why, but this is a work around. */
if(openstat != NC_ENOTNC && openstat != 2) ERR;
}
}

View File

@ -3,7 +3,7 @@
See COPYRIGHT file for conditions of use.
This is a very simple example which tests rejection of bad names for
netCDF data objects, including names with "/" character, trailing spaces,
netCDF data objects, including names with "/" character, trailing spaces,
leading special characters, and invalid UTF-8 strings.
$Id: tst_names.c 2792 2014-10-27 06:02:59Z wkliao $
@ -17,6 +17,7 @@
#include <netcdf_par.h>
#endif
#include <nc_tests.h>
#include "err_macros.h"
/* The data file we will create. */
#define FILE_NAME "tst_names.nc"
@ -249,7 +250,7 @@ main(int argc, char **argv)
if((res = nc_create(testfile, NC_CLOBBER, &ncid)))
#endif
ERROR
/* Define dimensions, variables, and attributes with various
* acceptable names */
for (i = 0; i < NUM_GOOD; i++) {
@ -258,34 +259,34 @@ main(int argc, char **argv)
dimids[i] = dimid;
/* Define variable with same name */
if ((res = nc_def_var(ncid, valid[i], NC_FLOAT, NDIMS, &dimids[i],
if ((res = nc_def_var(ncid, valid[i], NC_FLOAT, NDIMS, &dimids[i],
&varid)))
ERRORI
varids[i] = varid;
/* Define variable and global attributes with same name and value */
if ((res = nc_put_att_text(ncid, varid, valid[i],
if ((res = nc_put_att_text(ncid, varid, valid[i],
strlen(valid[i]), valid[i])))
ERRORI
if ((res = nc_put_att_double(ncid, NC_GLOBAL, valid[i], NC_DOUBLE,
if ((res = nc_put_att_double(ncid, NC_GLOBAL, valid[i], NC_DOUBLE,
NATTVALS, attvals)))
ERRORI
#if 0
attnums[i] = i;
#endif
}
/* Try defining dimensions, variables, and attributes with various
* bad names and make sure these are rejected */
for (i = 0; i < NUM_BAD; i++) {
if ((res = nc_def_dim(ncid, notvalid[i], DIMLEN, &dimid))
if ((res = nc_def_dim(ncid, notvalid[i], DIMLEN, &dimid))
!= NC_EBADNAME) ERRORI
if ((res = nc_def_var(ncid, notvalid[i], NC_FLOAT, NDIMS, dimids,
if ((res = nc_def_var(ncid, notvalid[i], NC_FLOAT, NDIMS, dimids,
&varid))
!= NC_EBADNAME) ERRORI
if ((res = nc_put_att_text(ncid, varid, notvalid[i],
if ((res = nc_put_att_text(ncid, varid, notvalid[i],
strlen(attstring), attstring))
!= NC_EBADNAME) ERRORI
if ((res = nc_put_att_double(ncid, NC_GLOBAL, notvalid[i], NC_DOUBLE,
if ((res = nc_put_att_double(ncid, NC_GLOBAL, notvalid[i], NC_DOUBLE,
NATTVALS, attvals))
!= NC_EBADNAME) ERRORI
}
@ -293,7 +294,7 @@ main(int argc, char **argv)
ERROR
if ((res = nc_close(ncid)))
ERROR
/* Check it out, make sure all objects with good names were defined OK */
#ifdef TEST_PNETCDF
if ((res = nc_open_par(testfile, NC_NOWRITE|NC_PNETCDF, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)))
@ -303,21 +304,21 @@ main(int argc, char **argv)
ERROR
for (i = 0; i < NUM_GOOD; i++) {
size_t attlen;
if ((res = nc_inq_dimid(ncid, valid[i], &dimid)) ||
if ((res = nc_inq_dimid(ncid, valid[i], &dimid)) ||
dimid != dimids[i])
ERRORI
if ((res = nc_inq_varid(ncid, valid[i], &varid)) ||
if ((res = nc_inq_varid(ncid, valid[i], &varid)) ||
varid != varids[i])
ERRORI
res = nc_inq_attlen(ncid, varid, valid[i], &attlen);
if ((res = nc_get_att_text(ncid, varid, valid[i], attstr_in)))
if ((res = nc_get_att_text(ncid, varid, valid[i], attstr_in)))
ERRORI
attstr_in[attlen] = '\0';
if (strcmp(valid[i], attstr_in) != 0)
if (strcmp(valid[i], attstr_in) != 0)
ERRORI
if ((res = nc_get_att_double(ncid, NC_GLOBAL, valid[i],
attvals_in))
|| attvals[0] != attvals_in[0])
if ((res = nc_get_att_double(ncid, NC_GLOBAL, valid[i],
attvals_in))
|| attvals[0] != attvals_in[0])
ERRORI
}
if ((res = nc_close(ncid)))

View File

@ -3,7 +3,7 @@
See COPYRIGHT file for copying and redistribution conditions.
This is part of netCDF.
This program tests for a bug discovered with nofill mode that failed
only on file systems with block size in a particular range. It fails
when invoked with the blksize argument between 2091953 and 2150032,
@ -14,6 +14,7 @@
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
@ -38,7 +39,7 @@ check_err(const int stat, const int line, const char *file) {
#define TIME_LEN 1
int
create_file(char *file_name, int fill_mode, size_t* sizehintp)
create_file(char *file_name, int fill_mode, size_t* sizehintp)
{
int i;
int stat; /* return status */
@ -177,7 +178,7 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
sfc_temp_dims[0] = time_dim;
sfc_temp_dims[1] = lat_dim;
sfc_temp_dims[2] = lon_dim;
stat = nc_def_var(ncid, "sfc_temp", NC_FLOAT, RANK_sfc_temp, sfc_temp_dims, &sfc_temp_id);
stat = nc_def_var(ncid, "sfc_temp", NC_FLOAT, RANK_sfc_temp, sfc_temp_dims, &sfc_temp_id);
check_err(stat,__LINE__,__FILE__);
zonal_wnd_dims[0] = time_dim;
@ -201,13 +202,13 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_double(ncid, time_id, time_start, time_count, time);
check_err(stat,__LINE__,__FILE__);
}
{ /* store lat */
float lat[] = {90, 88.5, 87, 85.5, 84, 82.5, 81, 79.5, 78, 76.5, 75, 73.5, 72, 70.5, 69, 67.5, 66, 64.5, 63, 61.5, 60, 58.5, 57, 55.5, 54, 52.5, 51, 49.5, 48, 46.5, 45, 43.5, 42, 40.5, 39, 37.5, 36, 34.5, 33, 31.5, 30, 28.5, 27, 25.5, 24, 22.5, 21, 19.5, 18, 16.5, 15, 13.5, 12, 10.5, 9, 7.5, 6, 4.5, 3, 1.5, 0, -1.5, -3, -4.5, -6, -7.5, -9, -10.5, -12, -13.5, -15, -16.5, -18, -19.5, -21, -22.5, -24, -25.5, -27, -28.5, -30, -31.5, -33, -34.5, -36, -37.5, -39, -40.5, -42, -43.5, -45, -46.5, -48, -49.5, -51, -52.5, -54, -55.5, -57, -58.5, -60, -61.5, -63, -64.5, -66, -67.5, -69, -70.5, -72, -73.5, -75, -76.5, -78, -79.5, -81, -82.5, -84, -85.5, -87, -88.5, -90};
stat = nc_put_var_float(ncid, lat_id, lat);
check_err(stat,__LINE__,__FILE__);
}
{ /* store lon */
float lon[] = {0, 1.5, 3, 4.5, 6, 7.5, 9, 10.5, 12, 13.5, 15, 16.5, 18, 19.5, 21, 22.5, 24, 25.5, 27, 28.5, 30, 31.5, 33, 34.5, 36, 37.5, 39, 40.5, 42, 43.5, 45, 46.5, 48, 49.5, 51, 52.5, 54, 55.5, 57, 58.5, 60, 61.5, 63, 64.5, 66, 67.5, 69, 70.5, 72, 73.5, 75, 76.5, 78, 79.5, 81, 82.5, 84, 85.5, 87, 88.5, 90, 91.5, 93, 94.5, 96, 97.5, 99, 100.5, 102, 103.5, 105, 106.5, 108, 109.5, 111, 112.5, 114, 115.5, 117, 118.5, 120, 121.5, 123, 124.5, 126, 127.5, 129, 130.5, 132, 133.5, 135, 136.5, 138, 139.5, 141, 142.5, 144, 145.5, 147, 148.5, 150, 151.5, 153, 154.5, 156, 157.5, 159, 160.5, 162, 163.5, 165, 166.5, 168, 169.5, 171, 172.5, 174, 175.5, 177, 178.5, 180, 181.5, 183, 184.5, 186, 187.5, 189, 190.5, 192, 193.5, 195, 196.5, 198, 199.5, 201, 202.5, 204, 205.5, 207, 208.5, 210, 211.5, 213, 214.5, 216, 217.5, 219, 220.5, 222, 223.5, 225, 226.5, 228, 229.5, 231, 232.5, 234, 235.5, 237, 238.5, 240, 241.5, 243, 244.5, 246, 247.5, 249, 250.5, 252, 253.5, 255, 256.5, 258, 259.5, 261, 262.5, 264, 265.5, 267, 268.5, 270, 271.5, 273, 274.5, 276, 277.5, 279, 280.5, 282, 283.5, 285, 286.5, 288, 289.5, 291, 292.5, 294, 295.5, 297, 298.5, 300, 301.5, 303, 304.5, 306, 307.5, 309, 310.5, 312, 313.5, 315, 316.5, 318, 319.5, 321, 322.5, 324, 325.5, 327, 328.5, 330, 331.5, 333, 334.5, 336, 337.5, 339, 340.5, 342, 343.5, 345, 346.5, 348, 349.5, 351, 352.5, 354, 355.5, 357, 358.5};
stat = nc_put_var_float(ncid, lon_id, lon);
@ -219,12 +220,12 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_var_float(ncid, lvl_id, lvl);
check_err(stat,__LINE__,__FILE__);
}
{ /* store sfc_pres */
size_t sfc_pres_start[RANK_sfc_pres];
size_t sfc_pres_count[RANK_sfc_pres];
float sfc_pres[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
sfc_pres[ii] = 6;
}
@ -242,7 +243,7 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
size_t temp_scrn_start[RANK_temp_scrn];
size_t temp_scrn_count[RANK_temp_scrn];
float temp_scrn[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
temp_scrn[ii] = 11;
}
@ -255,12 +256,12 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_float(ncid, temp_scrn_id, temp_scrn_start, temp_scrn_count, temp_scrn);
check_err(stat,__LINE__,__FILE__);
}
{ /* store qsair_scrn */
size_t qsair_scrn_start[RANK_qsair_scrn];
size_t qsair_scrn_count[RANK_qsair_scrn];
float qsair_scrn[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
qsair_scrn[ii] = 22;
}
@ -273,12 +274,12 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_float(ncid, qsair_scrn_id, qsair_scrn_start, qsair_scrn_count, qsair_scrn);
check_err(stat,__LINE__,__FILE__);
}
{ /* store topog */
size_t topog_start[RANK_topog];
size_t topog_count[RANK_topog];
float topog[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
topog[ii] = 33;
}
@ -291,12 +292,12 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_float(ncid, topog_id, topog_start, topog_count, topog);
check_err(stat,__LINE__,__FILE__);
}
{ /* store mslp */
size_t mslp_start[RANK_mslp];
size_t mslp_count[RANK_mslp];
float mslp[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
mslp[ii] = 44;
}
@ -309,12 +310,12 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_float(ncid, mslp_id, mslp_start, mslp_count, mslp);
check_err(stat,__LINE__,__FILE__);
}
{ /* store sfc_temp */
size_t sfc_temp_start[RANK_sfc_temp];
size_t sfc_temp_count[RANK_sfc_temp];
float sfc_temp[LON_LEN*LAT_LEN];
for(ii = 0; ii < LAT_LEN * LON_LEN; ii++) {
sfc_temp[ii] = 55;
}
@ -327,7 +328,7 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
stat = nc_put_vara_float(ncid, sfc_temp_id, sfc_temp_start, sfc_temp_count, sfc_temp);
check_err(stat,__LINE__,__FILE__);
}
{ /* store zonal_wnd */
/* Bug exposed when written in reverse order. */
for(i = LVL_LEN - 1; i>=0; i--)
@ -416,7 +417,7 @@ main(int argc, char **argv)
size_t nvals, nn;
int ndims, *dimids, dim;
nc_type vtype;
char varname1[NC_MAX_NAME];
char varname1[NC_MAX_NAME];
char varname2[NC_MAX_NAME];
/* How many values in this variable to compare? */
if (nc_inq_varndims(ncid1, varid, &ndims)) ERR;
@ -432,7 +433,7 @@ main(int argc, char **argv)
if (nc_inq_vartype(ncid1, varid, &vtype)) ERR;
if (nc_inq_varname(ncid1, varid, varname1)) ERR;
if (nc_inq_varname(ncid1, varid, varname2)) ERR;
if (vtype != NC_CHAR) { /* numeric data, just read in as doubles */
double *data1, *data2;
/* Allocate space to hold values in both files */
@ -447,8 +448,8 @@ main(int argc, char **argv)
for(nn = 0; nn < nvals; nn++) {
if (data1[nn] != data2[nn]) {
badvars++;
fprintf(stderr,
"\tFrom nofill file, %s[%lu] = %.15g\tFrom fill file, %s[%lu] = %.15g\n",
fprintf(stderr,
"\tFrom nofill file, %s[%lu] = %.15g\tFrom fill file, %s[%lu] = %.15g\n",
varname1, (unsigned long)nn, data1[nn], varname2, (unsigned long)nn, data2[nn]);
break;
};
@ -469,8 +470,8 @@ main(int argc, char **argv)
for(nn = 0; nn < nvals; nn++) {
if (data1[nn] != data2[nn]) {
badvars++;
fprintf(stderr,
"\tFrom nofill file, %s[%lu] = %d\tFrom fill file, %s[%lu] = %d\n",
fprintf(stderr,
"\tFrom nofill file, %s[%lu] = %d\tFrom fill file, %s[%lu] = %d\n",
varname1, (unsigned long)nn, data1[nn], varname2, (unsigned long)nn, data2[nn]);
break;
};

View File

@ -3,7 +3,7 @@
See COPYRIGHT file for copying and redistribution conditions.
This is part of netCDF.
This program tests for a bug discovered with nofill mode that failed
only on file systems with block size in a particular range. It fails
when invoked with the blksize argument between 2091953 and 2150032,
@ -12,6 +12,7 @@
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
@ -27,7 +28,7 @@
#define NDIMS4 4
int
create_file(char *file_name, int fill_mode, size_t* sizehintp)
create_file(char *file_name, int fill_mode, size_t* sizehintp)
{
int ncid, time_id, zonal_wnd_id;
int dimids[NDIMS4];
@ -39,7 +40,7 @@ create_file(char *file_name, int fill_mode, size_t* sizehintp)
int i;
/* Init data. */
for(i = 0; i < TIME_LEN * LAT_LEN * LON_LEN; i++)
for(i = 0; i < TIME_LEN * LAT_LEN * LON_LEN; i++)
zonal_wnd[i] = 100 + i;
/* To test bug on filesystem without large block size, we can get

View File

@ -3,7 +3,7 @@
See COPYRIGHT file for copying and redistribution conditions.
This is part of netCDF.
This program tests for a bug discovered with nofill mode that failed
only on file systems with block size in a particular range. This version
of the test showed failure using a normal nc_create() call rather tha
@ -12,6 +12,7 @@
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
@ -31,7 +32,7 @@
#define LVL_LEN 34
int
create_file(char *file_name, int fill_mode)
create_file(char *file_name, int fill_mode)
{
int ncid;
int lon_dim, lat_dim, lvl_dim, time_dim;

View File

@ -16,6 +16,7 @@
#include <netcdf_par.h>
#endif
#include <nc_tests.h>
#include "err_macros.h"
/* The data file we will create. */
#define FILE7_NAME "tst_norm.nc"

View File

@ -9,6 +9,7 @@
#include "config.h"
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#ifdef USE_PNETCDF
#include <netcdf_par.h>
@ -19,7 +20,7 @@
#define NUM_FORMATS (5)
#define ATT_NAME "Atom"
#define MAX_LEN 7
#define MAX_LEN 7
#define ERR2 { \
err++; \
@ -37,27 +38,27 @@
}\
}
#else
#define FMTCHECK
#define FMTCHECK
#endif
static int file_create(const char *filename, int cmode, int *ncid)
{
{
int err;
/* get the default file format */
int default_format;
nc_set_default_format(NC_FORMAT_CLASSIC, &default_format);
/* set it back to the default */
nc_set_default_format(default_format, NULL);
#ifdef USE_PNETCDF
if (default_format == NC_FORMAT_CLASSIC ||
default_format == NC_FORMAT_64BIT_OFFSET ||
default_format == NC_FORMAT_64BIT_DATA)
err = nc_create_par(filename, cmode|NC_PNETCDF, MPI_COMM_WORLD, MPI_INFO_NULL, ncid);
else
#endif
#endif
err = nc_create(filename, cmode, ncid);
return err;
@ -93,7 +94,7 @@ test_small_atts(const char *testfile)
int ndims, nvars, natts, unlimdimid;
size_t len_in;
int t, f;
/* Run this with and without fill mode. */
for (f = 0; f < 2; f++)
{
@ -103,13 +104,13 @@ test_small_atts(const char *testfile)
{
/* Create null-terminated text string of correct length. */
strncpy(att, source, t);
/* Create a file with one attribute. */
if (file_create(testfile, NC_CLOBBER, &ncid)) ERR;
if (nc_put_att_text(ncid, NC_GLOBAL, ATT_NAME, t + 1, att)) ERR;
if (f && nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
@ -118,7 +119,7 @@ test_small_atts(const char *testfile)
if (len_in != t + 1) ERR;
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, att_in)) ERR;
if (strncmp(att_in, att, t)) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
}
}
return 0;
@ -150,7 +151,7 @@ test_small_unlim(const char *testfile)
strcpy(data[i], source);*/
strcpy(data[0], "2005-04-11_12:00:00");
strcpy(data[1], "2005-04-11_13:00:00");
/* Create a file with two dimensions, one unlimited, and one
* var, and a global att. */
if (file_create(testfile, NC_CLOBBER, &ncid)) ERR;
@ -172,7 +173,7 @@ test_small_unlim(const char *testfile)
/* We're done! */
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
@ -180,7 +181,7 @@ test_small_unlim(const char *testfile)
if (nc_get_var_text(ncid, varid, (char *)data_in)) ERR;
for (i = 0; i < NUM_VALS; i++)
if (strncmp(data[i], data_in[i], STR_LEN)) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
return 0;
}
@ -198,7 +199,7 @@ test_small_fixed(const char *testfile)
strcpy(data[i], source);*/
strcpy(data[0], "2005-04-11_12:00:00");
strcpy(data[1], "2005-04-11_13:00:00");
/* Create a file with two dimensions, one unlimited, and one
* var, and a global att. */
if (file_create(testfile, NC_CLOBBER, &ncid)) ERR;
@ -217,7 +218,7 @@ test_small_fixed(const char *testfile)
/* We're done! */
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
@ -225,7 +226,7 @@ test_small_fixed(const char *testfile)
if (nc_get_var_text(ncid, varid, (char *)data_in)) ERR;
for (i = 0; i < NUM_VALS; i++)
if (strncmp(data[i], data_in[i], STR_LEN)) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
return 0;
}
@ -254,14 +255,14 @@ test_small_one(const char *testfile)
/* We're done! */
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
if (ndims != 1 && nvars != 1 && natts != 0 && unlimdimid != 0) ERR;
if (nc_get_var_text(ncid, varid, &data_in)) ERR;
if (data_in != data) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
return 0;
}
@ -314,7 +315,7 @@ test_one_growing(const char *testfile)
FMTCHECK;
if (nc_put_vara_text(ncid, varid, start, count, &data[r])) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_dimlen(ncid, 0, &len_in)) ERR;
@ -322,7 +323,7 @@ test_one_growing(const char *testfile)
index[0] = r;
if (nc_get_var1_text(ncid, 0, index, &data_in)) ERR;
if (data_in != data[r]) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
} /* Next record. */
}
return 0;
@ -369,7 +370,7 @@ test_one_growing_with_att(const char *testfile)
if (nc_redef(ncid)) ERR;
if (nc_put_att_text(ncid, varid, att_name, 1, &data[r])) ERR;
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_dimlen(ncid, 0, &len_in)) ERR;
@ -379,7 +380,7 @@ test_one_growing_with_att(const char *testfile)
if (data_in != data[r]) ERR;
if (nc_get_att_text(ncid, varid, att_name, &data_in)) ERR;
if (data_in != data[r]) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
} /* Next record. */
return 0;
}
@ -436,7 +437,7 @@ test_two_growing_with_att(const char *testfile)
if (nc_enddef(ncid)) ERR;
}
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_dimlen(ncid, 0, &len_in)) ERR;
@ -447,7 +448,7 @@ test_two_growing_with_att(const char *testfile)
if (nc_get_var1_text(ncid, varid[v], index, &data_in)) ERR;
if (data_in != data[r]) ERR;
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
} /* Next record. */
return 0;
}
@ -478,7 +479,7 @@ test_one_with_att(const char *testfile)
/* We're done! */
if (nc_close(ncid)) ERR;
/* Reopen the file and check it. */
if (file_open(testfile, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
@ -487,7 +488,7 @@ test_one_with_att(const char *testfile)
if (data_in != data) ERR;
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in)) ERR;
if (data_in != data) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
return 0;
}
@ -508,7 +509,7 @@ main(int argc, char **argv)
* only builds), or 4 (for netCDF-4 builds) different formats. */
for (i = NUM_FORMATS; i >= 1; i--)
{
switch (i)
switch (i)
{
case NC_FORMAT_CLASSIC:
nc_set_default_format(NC_FORMAT_CLASSIC, NULL);
@ -549,7 +550,7 @@ main(int argc, char **argv)
printf("*** testing simple small file with a global attribute...");
test_small_atts(testfile);
SUMMARIZE_ERR;
printf("*** testing simple small file with fixed dimensions...");
test_small_fixed(testfile);
SUMMARIZE_ERR;
@ -557,15 +558,15 @@ main(int argc, char **argv)
printf("*** testing simple small file with an unlimited dimension...");
test_small_unlim(testfile);
SUMMARIZE_ERR;
printf("*** testing small file with one variable...");
test_small_one(testfile);
SUMMARIZE_ERR;
printf("*** testing small file with one variable and one att...");
test_one_with_att(testfile);
SUMMARIZE_ERR;
printf("*** testing small file with one record variable, which grows...");
test_one_growing(testfile);
SUMMARIZE_ERR;
@ -586,4 +587,3 @@ main(int argc, char **argv)
#endif
FINAL_RESULTS;
}

View File

@ -16,7 +16,9 @@
$Id: bm_file.c,v 1.64 2010/01/11 19:27:11 ed Exp $
*/
#include <config.h>
#include <nc_tests.h> /* The ERR macro is here... */
#include <err_macros.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
@ -28,8 +30,7 @@
#ifdef USE_PARALLEL
#include <mpi.h>
#endif
#include <nc_tests.h> /* The ERR macro is here... */
#include <netcdf.h>
#include <netcdf.h>
#define MILLION 1000000
#define BAD -99
@ -65,15 +66,15 @@ MPI_Error_string(e, err_buffer, &resultlen); \
printf("MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
MPI_Finalize(); \
return 2; \
} while (0)
} while (0)
#endif
/* This function will fill the start and count arrays for the reads
* and writes. */
static int
get_starts_counts(int ndims, size_t *dimlen, int p, int my_rank,
int slow_count, int use_scs, VAR_OPTS_T *vo,
int *num_steps, int *start_inc, int *slice_len,
static int
get_starts_counts(int ndims, size_t *dimlen, int p, int my_rank,
int slow_count, int use_scs, VAR_OPTS_T *vo,
int *num_steps, int *start_inc, int *slice_len,
size_t *last_count, size_t *start, size_t *count)
{
int extra_step = 0;
@ -140,7 +141,7 @@ get_starts_counts(int ndims, size_t *dimlen, int p, int my_rank,
if (start[0] > dimlen[0])
{
fprintf(stderr, "slow_count too large for this many processors, "
"start_inc=%d, slow_count=%d, p=%d, my_rank=%d start[0]=%ld\n",
"start_inc=%d, slow_count=%d, p=%d, my_rank=%d start[0]=%ld\n",
*start_inc, slow_count, p, my_rank, start[0]);
return 2;
}
@ -211,7 +212,7 @@ check_att(int ncid1, int ncid2, int varid, int a)
return ret;
if ((ret = nc_inq_att(ncid2, varid, name, &typeid2, &len2)))
return ret;
if (len != len2 || typeid != typeid2)
if (len != len2 || typeid != typeid2)
return BAD;
if ((ret = nc_inq_type(ncid1, typeid, NULL, &typelen)))
return ret;
@ -230,7 +231,7 @@ check_att(int ncid1, int ncid2, int varid, int a)
goto exit;
if ((ret = nc_get_att(ncid2, varid, name, d2)))
goto exit;
/* Are they the same? */
if (memcmp(d, d2, typelen * len))
ret = BAD;
@ -247,9 +248,9 @@ check_att(int ncid1, int ncid2, int varid, int a)
}
/* Do two files contain the same data and metadata? */
static int
static int
cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
int use_par, int par_access, int do_cmp, int p, int my_rank,
int use_par, int par_access, int do_cmp, int p, int my_rank,
int slow_count, int verbose, int num_vo, VAR_OPTS_T *vo, int use_scs)
{
int ncid1, ncid2;
@ -317,11 +318,11 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
/* Check dims. */
for (d = 0; d < ndims; d++)
{
if ((ret = nc_inq_dim(ncid1, d, name, &len)))
if ((ret = nc_inq_dim(ncid1, d, name, &len)))
ERR1(ret);
if ((ret = nc_inq_dim(ncid2, d, name2, &len2)))
ERR1(ret);
if (len != len2 || strcmp(name, name2))
if (len != len2 || strcmp(name, name2))
ERR1(BAD);
}
@ -378,12 +379,12 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
if (ndims == 0)
dimlen[0] = 1;
if ((ret = get_starts_counts(ndims, dimlen, p, my_rank, slow_count, use_scs,
&vo[v], &num_steps, &start_inc, &slice_len,
if ((ret = get_starts_counts(ndims, dimlen, p, my_rank, slow_count, use_scs,
&vo[v], &num_steps, &start_inc, &slice_len,
&last_count, start, count)))
return ret;
if (verbose)
printf("%d: num_steps=%d, start_inc=%d, slice_len=%d, last_count=%ld\n",
printf("%d: num_steps=%d, start_inc=%d, slice_len=%d, last_count=%ld\n",
my_rank, num_steps, start_inc, slice_len, last_count);
/* If there are no records, we're done. */
@ -400,7 +401,7 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
ERR1(NC_ENOMEM);
if (!(data2 = malloc(slice_len * type_size)))
ERR1(NC_ENOMEM);
/* Check the var data for each slice. */
/* for (step = 0; !ret && step < num_steps; step++)*/
for (step = 0; !ret && step < num_steps; step++)
@ -413,7 +414,7 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
/* Read data from file2. */
#ifdef USE_PARALLEL
ftime = MPI_Wtime();
ftime = MPI_Wtime();
#else
if (gettimeofday(&start_time, NULL)) ERR;
#endif
@ -438,7 +439,7 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
* dimension. */
start[0] += start_inc;
}
exit:
if (data) free(data);
if (data2) free(data2);
@ -459,9 +460,9 @@ cmp_file(char *file1, char *file2, int *meta_read_us, int *data_read_us,
* deflate, shuffle, and endianness parameters if desired. */
static
int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
int num_vo, VAR_OPTS_T *vo, int *meta_read_us, int *meta_write_us,
int *data_read_us, int *data_write_us, int *in_format, int use_par,
int par_access, long long *num_bytes, int p, int my_rank,
int num_vo, VAR_OPTS_T *vo, int *meta_read_us, int *meta_write_us,
int *data_read_us, int *data_write_us, int *in_format, int use_par,
int par_access, long long *num_bytes, int p, int my_rank,
int slow_count, int verbose, int use_scs, int endianness,
int convert_unlim)
{
@ -480,7 +481,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
if (use_par)
{
#ifdef USE_PARALLEL
ftime = MPI_Wtime();
ftime = MPI_Wtime();
if ((ret = nc_open_par(file_name_in, 0, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid_in)))
ERR1(ret);
*meta_read_us += (MPI_Wtime() - ftime) * MILLION;
@ -511,7 +512,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
if (use_par)
{
#ifdef USE_PARALLEL
if ((ret = nc_create_par(file_name_out, cmode_out, MPI_COMM_WORLD,
if ((ret = nc_create_par(file_name_out, cmode_out, MPI_COMM_WORLD,
MPI_INFO_NULL, &ncid_out)))
ERR1(ret);
#else
@ -529,7 +530,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
ERR1(ret);
}
}
if ((ret = nc_inq(ncid_in, &ndims, &nvars, &natts, &unlimdimid)))
ERR1(ret);
@ -538,7 +539,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
/* Copy dims. */
for (d = 0; d < ndims; d++)
{
if ((ret = nc_inq_dim(ncid_in, d, name, &len)))
if ((ret = nc_inq_dim(ncid_in, d, name, &len)))
ERR1(ret);
if (convert_unlim)
{
@ -547,20 +548,20 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
}
else
{
if ((ret = nc_def_dim(ncid_out, name,
(d == unlimdimid) ? NC_UNLIMITED : len,
if ((ret = nc_def_dim(ncid_out, name,
(d == unlimdimid) ? NC_UNLIMITED : len,
NULL)))
ERR1(ret);
}
}
/* Copy global atts. */
for (a = 0; a < natts; a++)
{
if (nc_inq_attname(ncid_in, NC_GLOBAL, a, name)) ERR;
if (nc_copy_att(ncid_in, NC_GLOBAL, name, ncid_out, NC_GLOBAL)) ERR;
}
/* Copy the variable metadata. */
for (v = 0; v < nvars; v++)
{
@ -571,21 +572,21 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
int varid_out;
int a, o1;
int ret = NC_NOERR;
/* Learn about this var. */
if ((ret = nc_inq_var(ncid_in, v, name, &xtype, &ndims, dimids, &natts)))
return ret;
/* Create the output var. */
if (nc_def_var(ncid_out, name, xtype, ndims, dimids, &varid_out)) ERR;
/* Set the output endianness. For simplicity in this program,
* all vars get the same endianness. But there's no reason why
* this couldn't be varied from var to var, though it is hard to
* see why one would do so. */
if (endianness)
if (nc_def_var_endian(ncid_out, varid_out, endianness)) ERR;
/* Sent chunking and compression if specified in the var options. */
for (o1 = 0; o1 < num_vo; o1++)
if (vo[o1].varid == v)
@ -602,7 +603,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
if (nc_def_var_deflate(ncid_out, v, vo[o1].shuffle, 1, vo[o1].deflate_num)) ERR;
break;
}
/* Copy the attributes. */
for (a=0; a<natts; a++)
{
@ -610,9 +611,9 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
if (nc_copy_att(ncid_in, v, att_name, ncid_out, varid_out)) ERR;
}
}
#ifdef USE_PARALLEL
ftime = MPI_Wtime();
ftime = MPI_Wtime();
#else
if (gettimeofday(&start_time, NULL)) ERR;
#endif
@ -625,7 +626,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
if (nc4_timeval_subtract(&diff_time, &end_time, &start_time)) ERR;
*meta_write_us += (int)diff_time.tv_sec * MILLION + (int)diff_time.tv_usec;
#endif
if (verbose)
printf("%d: copying %d vars, %d global atts, and %d dims took %d micro-seconds\n",
my_rank, nvars, natts, ndims, *meta_write_us);
@ -687,12 +688,12 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
* varying (i.e. the zeroth) dimension to read at one time. For
* vars with an unlimited dimension, this is the number of
* records to read at once. */
if ((ret = get_starts_counts(ndims, dimlen, p, my_rank, slow_count, use_scs,
if ((ret = get_starts_counts(ndims, dimlen, p, my_rank, slow_count, use_scs,
&vo[v], &num_steps, &start_inc, &slice_len,
&last_count, start, count)))
return ret;
if (verbose)
printf("%d: num_steps=%d, start_inc=%d, slice_len=%d, last_count=%ld\n",
printf("%d: num_steps=%d, start_inc=%d, slice_len=%d, last_count=%ld\n",
my_rank, num_steps, start_inc, slice_len, last_count);
/* If there are no records, we're done. */
@ -702,7 +703,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
/* Allocate memory for one slice. */
if (!(data = malloc(slice_len * type_size)))
return NC_ENOMEM;
/* Copy the var data one slice at a time. */
for (step = 0; !ret && step < num_steps; step++)
{
@ -716,7 +717,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
/* Read input data. */
#ifdef USE_PARALLEL
ftime = MPI_Wtime();
ftime = MPI_Wtime();
#else
if (gettimeofday(&start_time, NULL)) ERR;
#endif
@ -755,16 +756,16 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
printf("%d: writing step %d, var %d took %d micro-seconds\n",
my_rank, step, v, *data_write_us);
}
/* Increment start index. */
start[0] += start_inc;
} /* next step */
/* Calculate the data read and write rates in MB/sec. */
for (d = 0, var_num_bytes = type_size; d < ndims; d++)
var_num_bytes *= dimlen[d];
(*num_bytes) += var_num_bytes;
exit:
if (data) free(data);
if (dimlen) free(dimlen);
@ -780,7 +781,7 @@ int copy_file(char *file_name_in, char *file_name_out, int cmode_out,
}
#define NDIMS 3
#define MAX_DEFLATE 9
#define MAX_DEFLATE 9
#define INPUT_FILE "/upc/share/testdata/nssl/mosaic3d_nc/tile1/20070803-2300.netcdf"
#define COLON ":"
#define COMMA ","
@ -854,7 +855,7 @@ main(int argc, char **argv)
vo[o1].chunksize[i] = 0;
while ((c = getopt(argc, argv, "vo:f:hc:dpms:it:u:r:e:l")) != EOF)
switch(c)
switch(c)
{
case 'v':
verbose++;
@ -889,14 +890,14 @@ main(int argc, char **argv)
header++;
break;
case 'c':
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
{
int got_z = 0, got_s = 0;
if (num_vo > MAX_VO)
return 1;
if (!(token = strtok_r(str1, COMMA, &saveptr1)))
break;
for (ndims = 0, str2 = token; ; str2 = NULL)
for (ndims = 0, str2 = token; ; str2 = NULL)
{
int tmp_int;
if (!(subtoken = strtok_r(str2, COLON, &saveptr2)))
@ -917,13 +918,13 @@ main(int argc, char **argv)
}
break;
case 't':
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
{
if (num_vo > MAX_VO)
return 1;
if (!(token = strtok_r(str1, COMMA, &saveptr1)))
break;
for (ndims = 0, str2 = token; ; str2 = NULL)
for (ndims = 0, str2 = token; ; str2 = NULL)
{
if (!(subtoken = strtok_r(str2, COLON, &saveptr2)))
break;
@ -937,13 +938,13 @@ main(int argc, char **argv)
use_scs++;
break;
case 'u':
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
{
if (num_vo > MAX_VO)
return 1;
if (!(token = strtok_r(str1, COMMA, &saveptr1)))
break;
for (ndims = 0, str2 = token; ; str2 = NULL)
for (ndims = 0, str2 = token; ; str2 = NULL)
{
if (!(subtoken = strtok_r(str2, COLON, &saveptr2)))
break;
@ -956,13 +957,13 @@ main(int argc, char **argv)
}
break;
case 'r':
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
for (num_vo = 0, str1 = optarg; ; num_vo++, str1 = NULL)
{
if (num_vo > MAX_VO)
return 1;
if (!(token = strtok_r(str1, COMMA, &saveptr1)))
break;
for (ndims = 0, str2 = token; ; str2 = NULL)
for (ndims = 0, str2 = token; ; str2 = NULL)
{
if (!(subtoken = strtok_r(str2, COLON, &saveptr2)))
break;
@ -1041,10 +1042,10 @@ main(int argc, char **argv)
* anything else to figure out what the heck is going on. */
if (verbose && !my_rank)
{
printf("copying %s to %s on %d processors with endianness %d and...\n",
printf("copying %s to %s on %d processors with endianness %d and...\n",
file_in, file_out, p, endianness);
if (use_scs)
for (v = 0; v < num_vo; v++)
for (v = 0; v < num_vo; v++)
{
printf("options for var %d:\n", vo[v].varid);
for (d = 0; d < vo[v].ndims; d++)
@ -1056,8 +1057,8 @@ main(int argc, char **argv)
}
/* Copy the file, keeping track of the read and write times for metadata and data. */
if ((ret = copy_file(file_in, file_out, cmode, num_vo, vo, &meta_read_us, &meta_write_us,
&data_read_us, &data_write_us, &in_format, use_par, par_access,
if ((ret = copy_file(file_in, file_out, cmode, num_vo, vo, &meta_read_us, &meta_write_us,
&data_read_us, &data_write_us, &in_format, use_par, par_access,
&num_bytes, p, my_rank, slow_count, verbose, use_scs, endianness,
convert_unlim)))
return ret;
@ -1068,9 +1069,9 @@ main(int argc, char **argv)
{
#ifdef USE_PARALLEL
MPI_Barrier(MPI_COMM_WORLD);
#endif
if ((ret = cmp_file(file_in, file_out, &meta_read2_us, &data_read2_us,
use_par, par_access, do_cmp, p, my_rank, slow_count,
#endif
if ((ret = cmp_file(file_in, file_out, &meta_read2_us, &data_read2_us,
use_par, par_access, do_cmp, p, my_rank, slow_count,
verbose, num_vo, vo, use_scs)))
return ret;
}
@ -1104,7 +1105,7 @@ main(int argc, char **argv)
write_rate = (float)num_bytes/((float)tdata_write_us/p);
reread_rate = (float)num_bytes/((float)tdata_read2_us/p);
if (verbose)
printf("%d: read rate %g, write rate %g, reread_rate %g\n", my_rank, read_rate,
printf("%d: read rate %g, write rate %g, reread_rate %g\n", my_rank, read_rate,
write_rate, reread_rate);
/* Print some output. */
@ -1126,11 +1127,11 @@ main(int argc, char **argv)
"chunksize[3]\n");
}
printf("%d, %d, %ld, %ld, %d, %d, %d, %d, %d, ", in_format, out_format, file_size(file_in),
printf("%d, %d, %ld, %ld, %d, %d, %d, %d, %d, ", in_format, out_format, file_size(file_in),
file_size(file_out), tmeta_read_us, tmeta_write_us, tdata_read_us, tdata_write_us,
endianness);
if (doublecheck)
printf("%d, %d, %g, %g, %g, ", tmeta_read2_us, tdata_read2_us, read_rate, write_rate,
printf("%d, %d, %g, %g, %g, ", tmeta_read2_us, tdata_read2_us, read_rate, write_rate,
reread_rate);
else
printf("%g, %g, ", read_rate, write_rate);
@ -1138,7 +1139,7 @@ main(int argc, char **argv)
printf("%d, ", p);
for (o1 = 0; o1 < num_vo; o1++)
{
printf("%d, %d, %d, %d, %d, %d ", vo[o1].deflate_num, vo[o1].shuffle,
printf("%d, %d, %d, %d, %d, %d ", vo[o1].deflate_num, vo[o1].shuffle,
(int)vo[o1].chunksize[0], (int)vo[o1].chunksize[1], (int)vo[o1].chunksize[2], (int)vo[o1].chunksize[3]);
if (o1 != num_vo - 1)
printf(", ");
@ -1148,7 +1149,7 @@ main(int argc, char **argv)
#ifdef USE_PARALLEL
MPI_Finalize();
#endif
#endif
return 0;
}

View File

@ -12,6 +12,7 @@
#include <stdio.h>
#include <string.h>
#include "ncdispatch.h"
#include <math.h>
/* We will create this file. */
#define FILE_NAME "tst_floats_1D.nc"
@ -19,8 +20,8 @@
int
main(int argc, char **argv)
{
nc_argc = argc;
nc_argv = argv;
int nc_argc = argc;
int nc_argv = argv;
nc_initialize();
printf("\n*** Create some files for testing benchmarks.\n");
@ -41,7 +42,7 @@ main(int argc, char **argv)
size_t chunk_sizes[NDIMS3] = {1, D1, D2};
float *data;
char file_name[NC_MAX_NAME * 2 + 1];
int d, i;
int d, i;
/* Initialize the data to random floats. */
if (!(data = (float *)malloc(D1 * D2 * sizeof(float)))) ERR;
@ -78,7 +79,7 @@ main(int argc, char **argv)
count[d] = dim_len[d];
}
for ( ; start[0] < D0; (start[0])++)
if (nc_put_vara_float(ncid, varid, start, count, (const float *) data))
if (nc_put_vara_float(ncid, varid, start, count, (const float *) data))
ERR_RET;
/* Close up shop. */
@ -101,7 +102,7 @@ main(int argc, char **argv)
char name_in[NC_MAX_NAME + 1];
size_t len;
float data[DIMLEN], data_in[DIMLEN];
int i;
int i;
for (i = 0; i < DIMLEN; i++)
data[i] = ((float)rand() / (float)(RAND_MAX));
@ -114,7 +115,7 @@ main(int argc, char **argv)
if (nc_enddef(ncid)) ERR;
if (nc_put_var_float(ncid, varid, data)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen and check the file. */
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
@ -124,12 +125,12 @@ main(int argc, char **argv)
if (nc_inq_dim(ncid, 0, name_in, &len)) ERR;
if (strcmp(name_in, DIM_NAME) || len != DIMLEN) ERR;
if (nc_inq_var(ncid, 0, name_in, &xtype, &ndims, dimids, &natts)) ERR;
if (strcmp(name_in, var_name) || xtype != NC_FLOAT || ndims != 1 ||
if (strcmp(name_in, var_name) || xtype != NC_FLOAT || ndims != 1 ||
dimids[0] != 0 || natts != 0) ERR;
if (nc_get_var_float(ncid, 0, data_in)) ERR;
for (i = 0; i < DIMLEN; i++)
if (data_in[i] != data[i]) ERR;
if (nc_close(ncid)) ERR;
}
@ -151,7 +152,7 @@ main(int argc, char **argv)
short sdata[TOTAL_SIZE];
void *data[MAX_TYPES];
int ndims;
int i, d, t;
int i, d, t;
/* Initialize the data to random floats. */
for (i = 0; i < TOTAL_SIZE; i++)
@ -195,11 +196,11 @@ main(int argc, char **argv)
#define NDIMS 3
#define E_VAR_NAME "Like_Elenas_Benchmark"
#define ELENA_FILE_NAME "tst_elena_int_3D.nc"
#define E_TYPE_SIZE 4
#define E_TYPE_SIZE 4
int ncid, dimids[NDIMS], varid;
int *idata;
int i;
int i;
/* Initialize data to random int between 0 and 255. */
if (!(idata = malloc(XLEN * YLEN * ZLEN * E_TYPE_SIZE)))
@ -230,7 +231,7 @@ main(int argc, char **argv)
int ncid, dimids[NDIMS1], varid;
int data[DIM_LEN];
int i;
int i;
/* Initialize data to my favorite numbers. */
for (i = 0; i < DIM_LEN; i++)
@ -263,7 +264,7 @@ main(int argc, char **argv)
short sdata[TOTAL_SIZE];
void *data[MAX_TYPES];
int ndims;
int i, d, t;
int i, d, t;
/* Initialize the data to random floats. */
for (i = 0; i < TOTAL_SIZE; i++)
@ -302,4 +303,3 @@ main(int argc, char **argv)
nc_finalize();
FINAL_RESULTS;
}

View File

@ -2,13 +2,14 @@
Copyright 2005 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
Test internal netcdf-4 file code.
Test internal netcdf-4 file code.
$Id$
*/
#include <config.h>
#include <stdio.h>
#include <nc_tests.h>
#include <err_macros.h>
#include "netcdf.h"
#include <hdf5.h>
#include <unistd.h>
@ -27,7 +28,7 @@ get_mem_used2(int *mem_used)
{
char buf[30];
FILE *pf;
snprintf(buf, 30, "/proc/%u/statm", (unsigned)getpid());
pf = fopen(buf, "r");
if (pf) {
@ -38,7 +39,7 @@ get_mem_used2(int *mem_used)
unsigned lib;/* library */
unsigned data;/* data/stack */
/*unsigned dt; dirty pages (unused in Linux 2.6)*/
fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share,
fscanf(pf, "%u %u %u %u %u %u", &size, &resident, &share,
&text, &lib, &data);
*mem_used = data;
}
@ -58,14 +59,14 @@ int main(void)
printf("\n*** Testing netcdf-4 memory use with unlimited dimensions.\n");
printf("*** testing with user-contributed code...");
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, TIME_NAME, NC_UNLIMITED, &dimid)) ERR;
if (nc_def_var(ncid, SFC_TEMP_NAME, NC_FLOAT, NDIMS, &dimid, &sfc_tempid)) ERR;
/* Write data each 100ms*/
get_mem_used2(&mem_used);
for (i = 0; i < NUM_TRIES; i++)
for (i = 0; i < NUM_TRIES; i++)
{
data = 25.5 + l_index[0];
if (nc_put_var1_float(ncid, sfc_tempid, l_index, (const float*) &data)) ERR;

View File

@ -1,4 +1,5 @@
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
@ -12,7 +13,7 @@
#define NAME_H "h"
int
main(int argc, char **argv)
main(int argc, char **argv)
{/* Test bug fix for NCF-324, file that caused nc_close() failure for
* non-coordinate variable and dimension with the same name */
@ -60,7 +61,7 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check file can be opened and read correctly */
{
{
int format;
int ndims, nvars, ngatts, xdimid, nunlim;
nc_type lat_type, h_type;
@ -91,7 +92,7 @@ main(int argc, char **argv)
}
}
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -9,6 +9,7 @@
#include <netcdf.h>
#include <nc_tests.h>
#include "err_macros.h"
#define FILE_NAME "tst_chunking.nc"
#define VAR_RANK 7

View File

@ -9,6 +9,7 @@
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#include <string.h>
@ -46,12 +47,12 @@ main(int argc, char **argv)
obs_t obsdata[DIM6_LEN] = {
{15, 2, 1, 0.5, 3600.01, 0, 0, 0, 0LL},
{-99, -99, -99, -99.0f, -99.0, 255, 65535, 4294967295U,
{-99, -99, -99, -99.0f, -99.0, 255, 65535, 4294967295U,
-9223372036854775806LL},
{20, 6, 3, 0.75, 5000.01, 200, 64000, 4220002000U, 9000000000000000000LL }
};
obs_t missing_val = {-99, -99, -99, -99, -99, 255, 65535, 4294967295U,
obs_t missing_val = {-99, -99, -99, -99, -99, 255, 65535, 4294967295U,
-9223372036854775806LL};
obs_t val_in;
size_t size_in;
@ -64,29 +65,29 @@ main(int argc, char **argv)
/* Create a compound type. */
if (nc_def_compound(ncid, sizeof(obs_t), TYPE6_NAME, &typeid)) ERR;
if (nc_insert_compound(ncid, typeid, "day",
if (nc_insert_compound(ncid, typeid, "day",
NC_COMPOUND_OFFSET(struct obs_t, day), NC_BYTE)) ERR;
if (nc_insert_compound(ncid, typeid, "elev",
if (nc_insert_compound(ncid, typeid, "elev",
NC_COMPOUND_OFFSET(struct obs_t, elev), NC_SHORT)) ERR;
if (nc_insert_compound(ncid, typeid, "count",
if (nc_insert_compound(ncid, typeid, "count",
NC_COMPOUND_OFFSET(struct obs_t, count), NC_INT)) ERR;
if (nc_insert_compound(ncid, typeid, "relhum",
NC_COMPOUND_OFFSET(struct obs_t, relhum),
if (nc_insert_compound(ncid, typeid, "relhum",
NC_COMPOUND_OFFSET(struct obs_t, relhum),
NC_FLOAT)) ERR;
if (nc_insert_compound(ncid, typeid, "time",
NC_COMPOUND_OFFSET(struct obs_t, time),
if (nc_insert_compound(ncid, typeid, "time",
NC_COMPOUND_OFFSET(struct obs_t, time),
NC_DOUBLE)) ERR;
if (nc_insert_compound(ncid, typeid, "category",
NC_COMPOUND_OFFSET(struct obs_t, category),
if (nc_insert_compound(ncid, typeid, "category",
NC_COMPOUND_OFFSET(struct obs_t, category),
NC_UBYTE)) ERR;
if (nc_insert_compound(ncid, typeid, "id",
NC_COMPOUND_OFFSET(struct obs_t, id),
if (nc_insert_compound(ncid, typeid, "id",
NC_COMPOUND_OFFSET(struct obs_t, id),
NC_USHORT)) ERR;
if (nc_insert_compound(ncid, typeid, "particularity",
NC_COMPOUND_OFFSET(struct obs_t, particularity),
if (nc_insert_compound(ncid, typeid, "particularity",
NC_COMPOUND_OFFSET(struct obs_t, particularity),
NC_UINT)) ERR;
if (nc_insert_compound(ncid, typeid, "attention_span",
NC_COMPOUND_OFFSET(struct obs_t, attention_span),
if (nc_insert_compound(ncid, typeid, "attention_span",
NC_COMPOUND_OFFSET(struct obs_t, attention_span),
NC_INT64)) ERR;
/* Declare a dimension for number of obs */
@ -107,19 +108,19 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE6_NAME, NC_NOWRITE, &ncid)) ERR;
/* Get info with the generic inquire for user-defined types */
if (nc_inq_user_type(ncid, typeid, name_in, NULL, NULL,
if (nc_inq_user_type(ncid, typeid, name_in, NULL, NULL,
NULL, &class_in)) ERR;
if (strcmp(name_in, TYPE6_NAME) ||
if (strcmp(name_in, TYPE6_NAME) ||
class_in != NC_COMPOUND) ERR;
/* Get the same info with the compound-specific inquire function */
if (nc_inq_compound(ncid, typeid, name_in, &size_in, &nfields_in)) ERR;
if (strcmp(name_in, TYPE6_NAME) ||
if (strcmp(name_in, TYPE6_NAME) ||
size_in != sizeof(obs_t) ||
nfields_in != 9) ERR;
@ -130,7 +131,7 @@ main(int argc, char **argv)
if (val_in.day != missing_val.day ||
val_in.elev != missing_val.elev ||
val_in.count != missing_val.count ||
val_in.relhum != missing_val.relhum ||
val_in.relhum != missing_val.relhum ||
val_in.time != missing_val.time ||
val_in.category != missing_val.category ||
val_in.id != missing_val.id ||
@ -152,10 +153,9 @@ main(int argc, char **argv)
if (val_in.particularity != obsdata[i].particularity) ERR;
if (val_in.attention_span != obsdata[i].attention_span) ERR;
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -10,6 +10,7 @@
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#include <string.h>
@ -47,21 +48,21 @@ main(int argc, char **argv)
struct vecmat_t data[DIM_LEN] = {
{
'S',
'S',
"jan",
{1, 2, 3},
{1, 2, 3},
{{4, 5, 6}, {7, 8, 9}}
},
{
'M',
'M',
"feb",
{11, 12, 13},
{11, 12, 13},
{{4.25, 5.25, 6.25}, {7.25, 8.25, 9.25}}
},
{
'T',
'T',
"mar",
{21, 22, 23},
{21, 22, 23},
{{4.5, 5.5, 6.5}, {7.5, 8.5, 9.5}}
}
};
@ -69,7 +70,7 @@ main(int argc, char **argv)
struct vecmat_t missing_val = {
'?',
"---",
{-1, -2, -3},
{-1, -2, -3},
{{-4.0f, -5.0f, -6.0f}, {-7.0f, -8.0f, -9.0f}}
};
struct vecmat_t val_in;
@ -93,10 +94,10 @@ main(int argc, char **argv)
NC_COMPOUND_OFFSET(struct vecmat_t, mon),
NC_CHAR, 1, mon_sizes)) ERR;
if (nc_insert_array_compound(ncid, typeid, "vect",
NC_COMPOUND_OFFSET(struct vecmat_t, vec),
NC_COMPOUND_OFFSET(struct vecmat_t, vec),
NC_SHORT, 1, vec_sizes)) ERR;
if (nc_insert_array_compound(ncid, typeid, "matr",
NC_COMPOUND_OFFSET(struct vecmat_t, mat),
NC_COMPOUND_OFFSET(struct vecmat_t, mat),
NC_FLOAT, 2, mat_sizes)) ERR;
/* Declare a dimension for number of obs */
@ -117,19 +118,19 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE9_NAME, NC_NOWRITE, &ncid)) ERR;
/* Get info with the generic inquire for user-defined types */
if (nc_inq_user_type(ncid, typeid, name_in, NULL, NULL,
if (nc_inq_user_type(ncid, typeid, name_in, NULL, NULL,
NULL, &class_in)) ERR;
if (strcmp(name_in, TYPE_NAME) ||
if (strcmp(name_in, TYPE_NAME) ||
class_in != NC_COMPOUND) ERR;
/* Get the same info with the compound-specific inquire function */
if (nc_inq_compound(ncid, typeid, name_in, &size_in, &nfields_in)) ERR;
if (strcmp(name_in, TYPE_NAME) ||
if (strcmp(name_in, TYPE_NAME) ||
size_in != sizeof(struct vecmat_t) ||
nfields_in != NFIELDS) ERR;
@ -166,10 +167,9 @@ main(int argc, char **argv)
}
}
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -9,6 +9,7 @@
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <stdlib.h>
#include <netcdf.h>

View File

@ -9,6 +9,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#include <stdlib.h>
@ -71,36 +72,36 @@ main(int argc, char **argv)
if (nc_def_grp(ncid, SOLAR_SYSTEM, &solar_system_id)) ERR;
if (nc_def_grp(solar_system_id, EARTH, &earth_id)) ERR;
if (nc_def_grp(earth_id, LUNA, &luna_id)) ERR;
/* Put some attributes in the root group. */
if (nc_put_att_uchar(ncid, NC_GLOBAL, UCHAR_ATT_NAME, NC_UBYTE,
ATT_LEN, num_vogons)) ERR;
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ULONGLONG_ATT_NAME,
if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ULONGLONG_ATT_NAME,
NC_UINT64, ATT_LEN, num_poems)) ERR;
/* Put a dimension in the root group. */
if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid)) ERR;
/* Put an attribute in the Earth group. */
if (nc_put_att_longlong(earth_id, NC_GLOBAL, LONGLONG_ATT_NAME, NC_INT64,
ATT_LEN, alien)) ERR;
/* Put an attribute in the bottom group. */
if (nc_put_att_text(luna_id, NC_GLOBAL, ATT_NAME,
if (nc_put_att_text(luna_id, NC_GLOBAL, ATT_NAME,
strlen(poem) + 1, poem)) ERR;
/* Put a variable in the bottom group. */
if (nc_def_var(luna_id, VAR_NAME, NC_INT64, 1, &dimid, &varid)) ERR;
if (nc_put_var_longlong(luna_id, varid, data)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** checking nested group file %s...", FILE_NAME_1);
#define CHAR_ATT_MAX 3000
{
int ncid, solar_system_id;
int earth_id, luna_id;
@ -116,8 +117,8 @@ main(int argc, char **argv)
/* Oh well, might as well check this file. It will also be
* checked by ncdump tests. */
if (nc_open(FILE_NAME_1, NC_NOWRITE, &ncid)) ERR;
if (nc_open(FILE_NAME_1, NC_NOWRITE, &ncid)) ERR;
/* Check nested groups. */
if (nc_inq_grps(ncid, &numgrps_in, &solar_system_id)) ERR;
if (numgrps_in != 1) ERR;
@ -148,12 +149,12 @@ main(int argc, char **argv)
if (ndims_in != 1) ERR;
if (nc_inq_dim(ncid, dimid_in, name_in, &len_in)) ERR;
if (strcmp(name_in, DIM_NAME) || len_in != DIM_LEN) ERR;
/* Check an attribute in the Earth group. */
if (nc_inq_att(earth_id, NC_GLOBAL, LONGLONG_ATT_NAME, &xtype_in,
&len_in)) ERR;
if (xtype_in != NC_INT64 || len_in != ATT_LEN) ERR;
if (nc_get_att_longlong(earth_id, NC_GLOBAL, LONGLONG_ATT_NAME,
if (nc_get_att_longlong(earth_id, NC_GLOBAL, LONGLONG_ATT_NAME,
longlong_in)) ERR;
for (i = 0; i < ATT_LEN; i++)
if (longlong_in[i] != alien[i]) ERR;
@ -161,17 +162,17 @@ main(int argc, char **argv)
/* Check an attribute in the bottom group. */
if (nc_inq_att(luna_id, NC_GLOBAL, ATT_NAME, &xtype_in,
&len_in)) ERR;
if (xtype_in != NC_CHAR || len_in != strlen(poem) + 1 ||
if (xtype_in != NC_CHAR || len_in != strlen(poem) + 1 ||
len_in > CHAR_ATT_MAX) ERR;
if (nc_get_att_text(luna_id, NC_GLOBAL, ATT_NAME, char_in)) ERR;
char_in[len_in] = '\0'; /* null terminate, because nc_get_att_text doesn't */
if (strcmp(char_in, poem)) ERR;
/* Check a variable in the bottom group. */
if (nc_inq_varids(luna_id, &nvars_in, &varid_in)) ERR;
if (nc_inq_var(luna_id, varid_in, name_in, &xtype_in, &ndims_in,
if (nc_inq_var(luna_id, varid_in, name_in, &xtype_in, &ndims_in,
&dimid_in_2, &natts_in)) ERR;
if (strcmp(name_in, VAR_NAME) || xtype_in != NC_INT64 ||
if (strcmp(name_in, VAR_NAME) || xtype_in != NC_INT64 ||
ndims_in != 1 || dimid_in_2 != dimid_in || natts_in != 0) ERR;
if (nc_get_var_longlong(luna_id, varid_in, data_in)) ERR;
for (i = 0; i < DIM_LEN; i++)
@ -180,7 +181,7 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("*** creating file with VLEN %s...", FILE_NAME_2);
#define ATT_NAME2 "equally_unimaginatively_named_attribute_YAWN"
@ -206,7 +207,7 @@ main(int argc, char **argv)
/* Create a file with a VLEN attribute. */
if (nc_create(FILE_NAME_2, NC_NETCDF4, &ncid)) ERR;
if (nc_def_vlen(ncid, VLEN_TYPE_NAME, NC_INT, &typeid)) ERR;
if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME2, typeid, DIM_LEN, data)) ERR;
@ -219,7 +220,7 @@ main(int argc, char **argv)
for (i=0; i<DIM_LEN; i++)
free(data[i].p);
}
SUMMARIZE_ERR;
printf("*** creating file with compound type %s...", FILE_NAME_CMP);
#define ATT_NAME_CMP "my_favorite_wind_speeds"
@ -232,7 +233,7 @@ main(int argc, char **argv)
int ncid;
/* Store winds as two floats: the u and v components of the wind. */
struct wind_vector
struct wind_vector
{
float u, v;
} favs[NUM_FAVS];
@ -244,24 +245,23 @@ main(int argc, char **argv)
{
favs[fav].u = U_VALUE;
favs[fav].v = V_VALUE;
}
}
/* Create a file with a compound attribute. */
if (nc_create(FILE_NAME_CMP, NC_NETCDF4, &ncid)) ERR;
if (nc_def_compound(ncid, sizeof(struct wind_vector), COMPOUND_NAME,
if (nc_def_compound(ncid, sizeof(struct wind_vector), COMPOUND_NAME,
&typeid)) ERR;
if (nc_insert_compound(ncid, typeid, "u", NC_COMPOUND_OFFSET(struct wind_vector, u),
if (nc_insert_compound(ncid, typeid, "u", NC_COMPOUND_OFFSET(struct wind_vector, u),
NC_FLOAT)) ERR;
if (nc_insert_compound(ncid, typeid, "v", NC_COMPOUND_OFFSET(struct wind_vector, v),
if (nc_insert_compound(ncid, typeid, "v", NC_COMPOUND_OFFSET(struct wind_vector, v),
NC_FLOAT)) ERR;
if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME_CMP, typeid, NUM_FAVS, favs)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -1,4 +1,5 @@
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
@ -23,7 +24,7 @@ Also, leave the files around so we can test with ncdump.
*/
int
main(int argc, char **argv)
main(int argc, char **argv)
{
int ncid;
size_t dimsize;
@ -73,7 +74,7 @@ main(int argc, char **argv)
if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
if(dimsize != DIMMAX64DATA) ERR;
if ((stat=nc_close(ncid))) ERRSTAT(stat);
}
}
SUMMARIZE_ERR;
FINAL_RESULTS;

View File

@ -8,6 +8,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#define FILE2_NAME "tst_enum_data.nc"
@ -52,17 +53,17 @@ main(int argc, char **argv)
char *name;
unsigned char value;
} cloud_types[] = {
{"Clear", CLEAR},
{"Cumulonimbus", CUMULONIMBUS},
{"Stratus", STRATUS},
{"Stratocumulus", STRATOCUMULUS},
{"Cumulus", CUMULUS},
{"Altostratus", ALTOSTRATUS},
{"Nimbostratus", NIMBOSTRATUS},
{"Altocumulus", ALTOCUMULUS},
{"Cirrostratus", CIRROSTRATUS},
{"Cirrocumulus", CIRROCUMULUS},
{"Cirrus", CIRRUS},
{"Clear", CLEAR},
{"Cumulonimbus", CUMULONIMBUS},
{"Stratus", STRATUS},
{"Stratocumulus", STRATOCUMULUS},
{"Cumulus", CUMULUS},
{"Altostratus", ALTOSTRATUS},
{"Nimbostratus", NIMBOSTRATUS},
{"Altocumulus", ALTOCUMULUS},
{"Cirrostratus", CIRROSTRATUS},
{"Cirrocumulus", CIRROCUMULUS},
{"Cirrus", CIRRUS},
{"Missing", MISSING}
};
int var_dims[VAR2_RANK];
@ -81,7 +82,7 @@ main(int argc, char **argv)
num_members = (sizeof cloud_types) / (sizeof cloud_types[0]);
for (i = 0; i < num_members; i++) {
if (nc_insert_enum(ncid, typeid, cloud_types[i].name,
&cloud_types[i].value))
&cloud_types[i].value))
ERR;
}
/* Declare a station dimension */
@ -99,28 +100,28 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE2_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_nc_type_in,
&nfields_in, &class_in)) ERR;
if (strcmp(name_in, TYPE2_NAME) ||
if (strcmp(name_in, TYPE2_NAME) ||
base_size_in != sizeof(unsigned char) ||
base_nc_type_in != NC_UBYTE ||
nfields_in != num_members ||
base_nc_type_in != NC_UBYTE ||
nfields_in != num_members ||
class_in != NC_ENUM) ERR;
if (nc_inq_enum(ncid, typeid, name_in,
if (nc_inq_enum(ncid, typeid, name_in,
&base_nc_type_in, &base_size_in, &num_members_in)) ERR;
if (strcmp(name_in, TYPE2_NAME) ||
base_nc_type_in != NC_UBYTE ||
if (strcmp(name_in, TYPE2_NAME) ||
base_nc_type_in != NC_UBYTE ||
num_members_in != num_members) ERR;
for (i = 0; i < num_members; i++)
{
if (nc_inq_enum_member(ncid, typeid, i, name_in, &value_in)) ERR;
if (strcmp(name_in, cloud_types[i].name) ||
if (strcmp(name_in, cloud_types[i].name) ||
value_in != cloud_types[i].value) ERR;
if (nc_inq_enum_ident(ncid, typeid, cloud_types[i].value,
if (nc_inq_enum_ident(ncid, typeid, cloud_types[i].value,
name_in)) ERR;
if (strcmp(name_in, cloud_types[i].name)) ERR;
}
@ -133,11 +134,10 @@ main(int argc, char **argv)
for (i = 0; i < DIM2_LEN; i++) {
if (cloud_data_in[i] != cloud_data[i]) ERR;
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -2,7 +2,7 @@
Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
conditions of use. See www.unidata.ucar.edu for more info.
*/
/*
Test _NCProperties and other special attributes
*/
@ -14,6 +14,7 @@ Test _NCProperties and other special attributes
#include <hdf5.h>
#include "nc_tests.h"
#include "err_macros.h"
#include "netcdf.h"
#include "nc4internal.h"
@ -33,7 +34,7 @@ main(int argc, char **argv)
hid_t fileid;
hid_t fcplid;
hid_t scalar_spaceid;
printf("*** creating test file using HDF5 directly %s...", HDFFILE);
/* Create scalar dataspace */
@ -56,7 +57,7 @@ main(int argc, char **argv)
/* Create scalar dataspace */
if((scalar_spaceid = H5Screate(H5S_SCALAR)) < 0) ERR;
/* Create attribute with native integer datatype on object */
if((attid = H5Acreate2(fileid, INT_ATT_NAME, H5T_NATIVE_INT, scalar_spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) ERR;
if(H5Aclose(attid) < 0) ERR;
@ -81,7 +82,7 @@ main(int argc, char **argv)
char name[NC_MAX_NAME];
printf("\n*** creating netcdf-4 test file using netCDF %s...", NC4FILE);
if(nc_create(NC4FILE,NC_WRITE|NC_CLOBBER|NC_NETCDF4,&root)!=0) ERR;
/* Create global attribute */
if(nc_put_att_int(root,NC_GLOBAL,INT_ATT_NAME,NC_INT,1,&data)!=0) ERR;
@ -120,9 +121,9 @@ main(int argc, char **argv)
/* Attempt to get attribute metadata piecemeal; some will fail */
id = -1;
stat = nc_inq_attid(root,NC_GLOBAL,NCPROPS,&id);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
stat = nc_inq_attname(root,NC_GLOBAL,id,name);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
if(nc_inq_atttype(root,NC_GLOBAL,NCPROPS,&xtype)!=0) ERR;
if(xtype != NC_CHAR) ERR;
if(nc_inq_attlen(root,NC_GLOBAL,NCPROPS,&len)!=0) ERR;
@ -147,9 +148,9 @@ main(int argc, char **argv)
/* Attempt to get attribute metadata piecemeal */
stat = nc_inq_attid(root,NC_GLOBAL,SUPERBLOCKATT,&id);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
stat = nc_inq_attname(root,NC_GLOBAL,id,name);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
if(nc_inq_atttype(root,NC_GLOBAL,SUPERBLOCKATT,&xtype)!=0) ERR;
if(xtype != NC_INT) ERR;
if(nc_inq_attlen(root,NC_GLOBAL,SUPERBLOCKATT,&len)!=0) ERR;
@ -174,9 +175,9 @@ main(int argc, char **argv)
/* Attempt to get attribute metadata piecemeal */
stat = nc_inq_attid(root,NC_GLOBAL,ISNETCDF4ATT,&id);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
stat = nc_inq_attname(root,NC_GLOBAL,id,name);
if(stat == NC_NOERR) ERR;
if(stat == NC_NOERR) ERR;
if(nc_inq_atttype(root,NC_GLOBAL,ISNETCDF4ATT,&xtype)!=0) ERR;
if(xtype != NC_INT) ERR;
if(nc_inq_attlen(root,NC_GLOBAL,ISNETCDF4ATT,&len)!=0) ERR;
@ -191,7 +192,7 @@ main(int argc, char **argv)
if(stat == NC_NOERR) ERR;
if(nc_close(root)!=0) ERR;
}
}
SUMMARIZE_ERR;
FINAL_RESULTS;

View File

@ -1,4 +1,5 @@
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
@ -8,7 +9,7 @@
static int count_udtypes(int ncid);
int
main(int argc, char **argv)
main(int argc, char **argv)
{/* create file that caused seg fault in ncdump */
int ncid; /* netCDF id */
@ -74,8 +75,8 @@ main(int argc, char **argv)
* made by ncdump, or an earlier ncdump bug masks the real problem
* until a call is made into the netCDF-4 library ... */
if (nc_open(FILENAME, NC_NOWRITE, &ncid)) ERR;
{
{
/* We declare local arrays with small constant sizes to avoid
* all the mallocs and frees used in ncdump. For the example
* above, the fixed-size arrays are ample. */
@ -105,7 +106,7 @@ main(int argc, char **argv)
for (v_grp = 0; v_grp < nvars_grp; v_grp++) {
varid = varids_grp[v_grp];
if ( nc_inq_varndims(ncid, varid, &varndims) ) ERR;
if ( nc_inq_var(ncid, varid, varname, &vartype, 0, vardims,
if ( nc_inq_var(ncid, varid, varname, &vartype, 0, vardims,
&varnatts) ) ERR;
for (id = 0; id < varndims; id++) {
if ( nc_inq_dimname(ncid, vardims[id], dimname) ) ERR;
@ -114,7 +115,7 @@ main(int argc, char **argv)
for (v_grp = 0; v_grp < nvars_grp; v_grp++) {
varid = varids_grp[v_grp];
if( nc_inq_varndims(ncid, varid, &varndims) ) ERR;
if( nc_inq_var(ncid, varid, varname, &vartype, 0, vardims,
if( nc_inq_var(ncid, varid, varname, &vartype, 0, vardims,
&varnatts) ) ERR;
{
is_recvar = 0;
@ -131,7 +132,7 @@ main(int argc, char **argv)
if(dimids[dim] == recdimids[recdim]) {
is_recvar = 1;
break;
}
}
}
}
}
@ -154,7 +155,7 @@ main(int argc, char **argv)
/* first slice retrieved OK */
if (nc_get_vara(ncid, varid, cor, edg, P_data)) ERR;
/* In ncdump, reading second slice gets seg fault in
* nc4_open_var_grp(), but this attempt to do all the
* same netCDF calls as ncdump can't duplicate the
@ -166,7 +167,7 @@ main(int argc, char **argv)
}
}
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -1,4 +1,4 @@
/* This is part of the netCDF package.
/* This is part of the netCDF package.
Copyright 2005-2007, University Corporation for Atmospheric
Research/Unidata See COPYRIGHT file for conditions of use.
@ -10,6 +10,7 @@
#include <netcdf.h>
#include <nc_tests.h>
#include "err_macros.h"
#define FILE_NAME "tst_group_data.nc"
#define DIM_NAME "dim"
@ -41,9 +42,9 @@ main(int argc, char **argv) {
int var_dims[VAR_RANK], var2_dims[VAR2_RANK];
int g1id, g2id, g3id;
float vals[] = {1.0, 2.0, 3.0, 4.0};
float vals2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
float vals2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
printf("\n*** Testing groups.\n");
printf("*** creating nested group file %s...", FILE_NAME);
@ -54,18 +55,18 @@ main(int argc, char **argv) {
var_dims[0] = dimid;
if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, VAR_RANK, var_dims, &varid)) ERR;
if (nc_put_att_text(ncid, varid, ATT_NAME, strlen(ATT_VAL), ATT_VAL)) ERR;
if (nc_put_att_text(ncid, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL),
if (nc_put_att_text(ncid, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL),
GATT_VAL)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_put_var_float(ncid, varid, vals)) ERR;
/* put dim, var, atts with same names in a group */
if (nc_def_grp(ncid, G1_NAME, &g1id)) ERR;
if (nc_def_dim(g1id, DIM_NAME, DIM_LEN1, &dimid1)) ERR;
var_dims[0] = dimid1;
if (nc_def_var(g1id, VAR_NAME, NC_FLOAT, VAR_RANK, var_dims, &varid)) ERR;
if (nc_put_att_text(g1id, varid, ATT_NAME, strlen(ATT_VAL1), ATT_VAL1)) ERR;
if (nc_put_att_text(g1id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL1),
if (nc_put_att_text(g1id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL1),
GATT_VAL1)) ERR;
if (nc_enddef(g1id)) ERR;
if (nc_put_var_float(g1id, varid, vals)) ERR;
@ -76,18 +77,18 @@ main(int argc, char **argv) {
var_dims[0] = dimid2;
if (nc_def_var(g2id, VAR_NAME, NC_FLOAT, VAR_RANK, var_dims, &varid)) ERR;
if (nc_put_att_text(g2id, varid, ATT_NAME, strlen(ATT_VAL2), ATT_VAL2)) ERR;
if (nc_put_att_text(g2id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL2),
if (nc_put_att_text(g2id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL2),
GATT_VAL2)) ERR;
if (nc_enddef(g2id)) ERR;
if (nc_put_var_float(g2id, varid, vals)) ERR;
/* put dim, var, atts with same names in a subgroup of second group */
if (nc_def_grp(g2id, G3_NAME, &g3id)) ERR;
if (nc_def_dim(g3id, DIM_NAME, DIM_LEN3, &dimid3)) ERR;
var_dims[0] = dimid3;
if (nc_def_var(g3id, VAR_NAME, NC_FLOAT, VAR_RANK, var_dims, &varid)) ERR;
if (nc_put_att_text(g3id, varid, ATT_NAME, strlen(ATT_VAL3), ATT_VAL3)) ERR;
if (nc_put_att_text(g3id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL3),
if (nc_put_att_text(g3id, NC_GLOBAL, GATT_NAME, strlen(GATT_VAL3),
GATT_VAL3)) ERR;
var2_dims[0] = dimid;
var2_dims[1] = dimid2;

View File

@ -8,6 +8,7 @@
$Id: tst_h_rdc0.c,v 1.5 2010/06/01 15:34:53 ed Exp $
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <hdf5.h>
#define FILE_NAME "c0.nc"
@ -24,7 +25,7 @@ main()
hsize_t num_obj, i;
char obj_name[MAX_NAME];
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;
/* Find the variables. Read their metadata and attributes. */

View File

@ -8,6 +8,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <hdf5.h>
#define FILE_NAME "tst_h_scalar.nc"
@ -34,7 +35,7 @@ add_attrs(hid_t objid)
/* Create scalar dataspace */
if ((scalar_spaceid = H5Screate(H5S_SCALAR)) < 0) ERR_GOTO;
/* Create string datatypes */
if ((vlstr_typeid = H5Tcreate(H5T_STRING, (size_t)H5T_VARIABLE)) < 0) ERR_GOTO;
if ((fixstr_typeid = H5Tcreate(H5T_STRING, (size_t)10)) < 0) ERR_GOTO;
@ -111,10 +112,10 @@ main()
if ((fcplid = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
if (H5Pset_link_creation_order(fcplid, H5P_CRT_ORDER_TRACKED) < 0) ERR;
if (H5Pset_attr_creation_order(fcplid, H5P_CRT_ORDER_TRACKED) < 0) ERR;
/* Create new file, using default properties */
if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcplid, H5P_DEFAULT)) < 0) ERR;
/* Close file creation property list */
if (H5Pclose(fcplid) < 0) ERR;
@ -130,7 +131,7 @@ main()
if ((dcplid = H5Pcreate(H5P_DATASET_CREATE)) < 0) ERR;
if (H5Pset_attr_creation_order(dcplid, H5P_CRT_ORDER_TRACKED) < 0) ERR;
/* Create scalar dataset with VL string datatype */
if ((dsetid = H5Dcreate2(fileid, VSTR_VAR1_NAME, vlstr_typeid, scalar_spaceid, H5P_DEFAULT, dcplid, H5P_DEFAULT)) < 0) ERR;
@ -186,7 +187,7 @@ main()
char *vlstr;
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
/* Define new VL string variable */
if (nc_def_var(ncid, VSTR_VAR2_NAME , NC_STRING, 0, NULL, &varid)) ERR;
@ -220,4 +221,3 @@ main()
FINAL_RESULTS;
}

View File

@ -8,6 +8,7 @@
$Id: tst_nans.c,v 1.9 2009/09/14 20:50:45 russ Exp $
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
@ -45,7 +46,7 @@ main(int argc, char **argv)
float fvals[NVALS], fvals_in[NVALS];
double dvals[NVALS], dvals_in[NVALS];
float fnan = NC_FNAN;/*(NC_INFINITE-NC_INFINITE);//0.f/0.f; */
double dnan = NC_DNAN;/*(NC_INFINITE-NC_INFINITE);//0.0/0.0; */
float fpinf = NC_FPINF;/*NC_INFINITE;//1.0f/0.0f; */
@ -60,9 +61,9 @@ main(int argc, char **argv)
printf("\n*** Testing NaN\n");
printf("*** creating NaN test file %s...", FILE8_NAME);
if (nc_create(FILE8_NAME, NC_CLOBBER, &ncid)) ERR;
if (nc_def_dim(ncid, DIM_NAME, NVALS, &dimid)) ERR;
if (nc_def_var(ncid, F_NAME, NC_FLOAT, NDIMS, &dimid, &fvarid)) ERR;
if (nc_def_var(ncid, D_NAME, NC_DOUBLE, NDIMS, &dimid, &dvarid)) ERR;
@ -72,23 +73,23 @@ main(int argc, char **argv)
dvals[0] = dninf;
dvals[1] = dnan;
dvals[2] = dpinf;
/* Create float and double attributes */
if (nc_put_att_float(ncid, fvarid, FV_NAME, NC_FLOAT, FV_NVALS, &fnan)) ERR;
if (nc_put_att_float(ncid, fvarid, ATT_NAME, NC_FLOAT, NVALS, fvals)) ERR;
if (nc_put_att_double(ncid, dvarid, FV_NAME, NC_DOUBLE, FV_NVALS, &dnan)) ERR;
if (nc_put_att_double(ncid, dvarid, ATT_NAME, NC_DOUBLE, NVALS, dvals)) ERR;
if (nc_enddef(ncid)) ERR;
/* Write float and double data */
if (nc_put_var_float(ncid, fvarid, fvals)) ERR;
if (nc_put_var_double(ncid, dvarid, dvals)) ERR;
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE8_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, F_NAME, &fvarid)) ERR;
@ -123,7 +124,7 @@ main(int argc, char **argv)
if (!(isinf(dvals_in[2]) && dvals_in[2] > 0)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -9,6 +9,7 @@
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#define FILE3_NAME "tst_opaque_data.nc"
@ -69,19 +70,19 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE3_NAME, NC_NOWRITE, &ncid)) ERR;
/* Get info with the generic inquire for user-defined types */
if (nc_inq_user_type(ncid, typeid, name_in, &size_in, NULL,
NULL, &class_in)) ERR;
if (strcmp(name_in, TYPE3_NAME) ||
if (strcmp(name_in, TYPE3_NAME) ||
size_in != TYPE3_SIZE ||
class_in != NC_OPAQUE) ERR;
/* Get the same info with the opaque-specific inquire function */
if (nc_inq_opaque(ncid, typeid, name_in, &size_in)) ERR;
if (strcmp(name_in, TYPE3_NAME) ||
if (strcmp(name_in, TYPE3_NAME) ||
size_in != TYPE3_SIZE) ERR;
if (nc_inq_varid(ncid, VAR3_NAME, &varid)) ERR;
@ -95,11 +96,10 @@ main(int argc, char **argv)
if(nc_get_var1(ncid, varid, index, val_in)) ERR;
if (memcmp(val_in, sensor_data[i], TYPE3_SIZE) != 0) ERR;
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -10,6 +10,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#define FILE_NAME "tst_special_atts.nc"
@ -49,11 +50,11 @@ main(int argc, char **argv)
int data2_in[DIM1_LEN][DIM2_LEN];
int data3[DIM1_LEN][DIM2_LEN][DIM3_LEN];
int data3_in[DIM1_LEN][DIM2_LEN][DIM3_LEN];
printf("\n*** Testing '-s' option for special attributes.\n");
printf("*** creating special attributes test file %s...", FILE_NAME);
if (nc_create(FILE_NAME, NC_CLOBBER | NC_NETCDF4, &ncid)) ERR;
/* Declare dimensions and variables */
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
@ -79,33 +80,33 @@ main(int argc, char **argv)
/* Create a compound type. */
if (nc_def_compound(ncid, sizeof(obs_t), TYPE6_NAME, &typeid)) ERR;
if (nc_insert_compound(ncid, typeid, "day",
if (nc_insert_compound(ncid, typeid, "day",
NC_COMPOUND_OFFSET(struct obs_t, day), NC_BYTE)) ERR;
if (nc_insert_compound(ncid, typeid, "elev",
if (nc_insert_compound(ncid, typeid, "elev",
NC_COMPOUND_OFFSET(struct obs_t, elev), NC_SHORT)) ERR;
if (nc_insert_compound(ncid, typeid, "count",
if (nc_insert_compound(ncid, typeid, "count",
NC_COMPOUND_OFFSET(struct obs_t, count), NC_INT)) ERR;
if (nc_insert_compound(ncid, typeid, "relhum",
NC_COMPOUND_OFFSET(struct obs_t, relhum),
if (nc_insert_compound(ncid, typeid, "relhum",
NC_COMPOUND_OFFSET(struct obs_t, relhum),
NC_FLOAT)) ERR;
if (nc_insert_compound(ncid, typeid, "time",
NC_COMPOUND_OFFSET(struct obs_t, time),
if (nc_insert_compound(ncid, typeid, "time",
NC_COMPOUND_OFFSET(struct obs_t, time),
NC_DOUBLE)) ERR;
if (nc_insert_compound(ncid, typeid, "category",
NC_COMPOUND_OFFSET(struct obs_t, category),
if (nc_insert_compound(ncid, typeid, "category",
NC_COMPOUND_OFFSET(struct obs_t, category),
NC_UBYTE)) ERR;
if (nc_insert_compound(ncid, typeid, "id",
NC_COMPOUND_OFFSET(struct obs_t, id),
if (nc_insert_compound(ncid, typeid, "id",
NC_COMPOUND_OFFSET(struct obs_t, id),
NC_USHORT)) ERR;
if (nc_insert_compound(ncid, typeid, "particularity",
NC_COMPOUND_OFFSET(struct obs_t, particularity),
if (nc_insert_compound(ncid, typeid, "particularity",
NC_COMPOUND_OFFSET(struct obs_t, particularity),
NC_UINT)) ERR;
if (nc_insert_compound(ncid, typeid, "attention_span",
NC_COMPOUND_OFFSET(struct obs_t, attention_span),
if (nc_insert_compound(ncid, typeid, "attention_span",
NC_COMPOUND_OFFSET(struct obs_t, attention_span),
NC_INT64)) ERR;
/* create a variable of that compound type */
if (nc_def_var(ncid, "var5", typeid, VAR1_RANK, dimids, &var5id))
ERR;
if (nc_def_var(ncid, "var5", typeid, VAR1_RANK, dimids, &var5id))
ERR;
}
/* Specify contiguous storage and endianness explicitly for var1. */
@ -153,16 +154,16 @@ main(int argc, char **argv)
if(nc_put_var(ncid, var2id, &data2[0][0])) ERR;
if(nc_put_var(ncid, var3id, &data3[0][0][0])) ERR;
if(nc_put_var(ncid, var4id, &data3[0][0][0])) ERR;
if (nc_close(ncid)) ERR;
/* Check it out. */
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, VAR1_NAME, &var1id)) ERR;
if (nc_inq_varid(ncid, VAR2_NAME, &var2id)) ERR;
if (nc_inq_varid(ncid, VAR3_NAME, &var3id)) ERR;
if (nc_inq_varid(ncid, VAR4_NAME, &var4id)) ERR;
/* Check chunk sizes */
{
size_t chunks_in[VAR3_RANK];
@ -179,18 +180,18 @@ main(int argc, char **argv)
if(nc_get_var(ncid, var1id, &data1_in[0])) ERR;
for(i = 0; i < DIM1_LEN; i++)
if(data1_in[i] != data1[i]) ERR;
if(nc_get_var(ncid, var2id, &data2_in[0][0])) ERR;
for(i = 0; i < DIM1_LEN; i++)
for(j = 0; j < DIM2_LEN; j++)
if(data2_in[i][j] != data2[i][j]) ERR;
if(nc_get_var(ncid, var3id, &data3_in[0][0][0])) ERR;
for(i = 0; i < DIM1_LEN; i++)
for(j = 0; j < DIM2_LEN; j++)
for(k = 0; k < DIM3_LEN; k++)
if(data3_in[i][j][k] != data3[i][j][k]) ERR;
if(nc_get_var(ncid, var4id, &data3_in[0][0][0])) ERR;
for(i = 0; i < DIM1_LEN; i++)
for(j = 0; j < DIM2_LEN; j++)
@ -200,4 +201,3 @@ main(int argc, char **argv)
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -8,6 +8,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#define FILE4_NAME "tst_string_data.nc"
@ -34,39 +35,39 @@ main(int argc, char **argv)
};
const char *missing_val[ATT4_LEN] = {""};
char *strings_in[DIM4_LEN];
printf("\n*** Testing strings.\n");
printf("*** creating strings test file %s...", FILE4_NAME);
if (nc_create(FILE4_NAME, NC_CLOBBER | NC_NETCDF4, &ncid)) ERR;
/* Declare a line dimension */
if (nc_def_dim(ncid, DIM4_NAME, DIM4_LEN, &dimid)) ERR;
/* Declare a string variable */
var_dims[0] = dimid;
if (nc_def_var(ncid, VAR4_NAME, NC_STRING, VAR4_RANK, var_dims, &varid)) ERR;
/* Create and write a variable attribute of string type */
if (nc_put_att_string(ncid, varid, ATT4_NAME, ATT4_LEN, missing_val)) ERR;
if (nc_enddef(ncid)) ERR;
/* Store some data of string type */
if(nc_put_var(ncid, varid, desc_data)) ERR;
/* Write the file. */
if (nc_close(ncid)) ERR;
/* Check it out. */
if (nc_open(FILE4_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, VAR4_NAME, &varid)) ERR;
if (nc_inq_att(ncid, varid, ATT4_NAME, &att_type, &att_len)) ERR;
if (att_type != NC_STRING || att_len != ATT4_LEN) ERR;
if (nc_get_att_string(ncid, varid, ATT4_NAME, strings_in)) ERR;
if (strcmp(strings_in[0], *missing_val) != 0) ERR;
/* string atts should be explicitly freed when done with them */
nc_free_string(ATT4_LEN, strings_in);
if(nc_get_var_string(ncid, varid, strings_in)) ERR;
for (i = 0; i < DIM4_LEN; i++) {
if (strcmp(strings_in[i], desc_data[i]) != 0) ERR;
@ -95,9 +96,8 @@ main(int argc, char **argv)
nc_free_string(DIM4_LEN, strings_in);
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -8,6 +8,7 @@
$Id: tst_unicode.c,v 1.12 2008/10/20 01:48:08 ed Exp $
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <stdlib.h>
#include <stdio.h>
#include <netcdf.h>
@ -66,7 +67,7 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE7_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, UNAME, &varid)) ERR;
@ -75,7 +76,7 @@ main(int argc, char **argv)
/* Note, name was normalized before storing, so retrieved name
won't match original unnormalized name. Check that we get
normalized version, instead. */
/* NFC normalized UTF-8 for Unicode 8-character "Hello" in Greek */
unsigned char norm_utf8[] = {
0xCE, 0x9A, /* GREEK CAPITAL LETTER KAPPA : 2-bytes utf8 */
@ -83,7 +84,7 @@ main(int argc, char **argv)
0xCE, 0xBB, /* GREEK SMALL LETTER ALPHA : 2-bytes utf8 */
0xCE, 0xB7, /* GREEK SMALL LETTER ETA : 2-bytes utf8 */
0xCE, 0xBC, /* GREEK SMALL LETTER MU : 2-bytes utf8 */
0xCE, 0xAD, /* GREEK SMALL LETTER EPSILON WITH TONOS
0xCE, 0xAD, /* GREEK SMALL LETTER EPSILON WITH TONOS
: 2-bytes utf8 */
0xCF, 0x81, /* GREEK SMALL LETTER RHO : 2-bytes utf8 */
0xCE, 0xB1, /* GREEK SMALL LETTER ALPHA : 2-bytes utf8 */
@ -98,8 +99,8 @@ main(int argc, char **argv)
if (nc_get_att_text(ncid, varid, UNITS, strings_in)) ERR;
strings_in[att_len] = '\0'; /* null terminate, because nc_get_att_text doesn't */
if (strncmp(UNAME, strings_in, UNAMELEN) != 0) ERR;
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -12,6 +12,7 @@
#include <config.h>
#include <stdlib.h>
#include <nc_tests.h>
#include <err_macros.h>
#include <netcdf.h>
#include <string.h>
@ -48,7 +49,7 @@ main(int argc, char **argv)
char name_in[UNAMELEN + 1], strings_in[UNAMELEN + 1];
nc_type att_type;
size_t att_len;
printf("\n*** Testing UTF-8.\n");
printf("*** creating UTF-8 test file %s...", FILE7_NAME);
if (nc_create(FILE7_NAME, NC_CLOBBER, &ncid))
@ -78,7 +79,7 @@ main(int argc, char **argv)
ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE7_NAME, NC_NOWRITE, &ncid))
ERR;
@ -90,7 +91,7 @@ main(int argc, char **argv)
/* Note, name was normalized before storing, so retrieved name
won't match original unnormalized name. Check that we get
normalized version, instead. */
/* NFC normalized UTF-8 for Unicode 8-character "Hello" in Greek */
unsigned char norm_utf8[] = {
0xCE, 0x9A, /* GREEK CAPITAL LETTER KAPPA : 2-bytes utf8 */
@ -98,7 +99,7 @@ main(int argc, char **argv)
0xCE, 0xBB, /* GREEK SMALL LETTER ALPHA : 2-bytes utf8 */
0xCE, 0xB7, /* GREEK SMALL LETTER ETA : 2-bytes utf8 */
0xCE, 0xBC, /* GREEK SMALL LETTER MU : 2-bytes utf8 */
0xCE, 0xAD, /* GREEK SMALL LETTER EPSILON WITH TONOS
0xCE, 0xAD, /* GREEK SMALL LETTER EPSILON WITH TONOS
: 2-bytes utf8 */
0xCF, 0x81, /* GREEK SMALL LETTER RHO : 2-bytes utf8 */
0xCE, 0xB1, /* GREEK SMALL LETTER ALPHA : 2-bytes utf8 */

View File

@ -8,6 +8,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#include <stdlib.h>
@ -75,7 +76,7 @@ main(int argc, char **argv)
}
}
array[4][0] = missing_value; /* overwrite last row with missing for equality test */
for (i = 0; i < DIM5_LEN; i++) {
ragged_data[i].p = array[i];
ragged_data[i].len = NROWS - i;
@ -88,21 +89,21 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
/* Check it out. */
/* Reopen the file. */
if (nc_open(FILE5_NAME, NC_NOWRITE, &ncid)) ERR;
/* Get info with the generic inquire for user-defined types */
if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_typeid,
if (nc_inq_user_type(ncid, typeid, name_in, &base_size_in, &base_typeid,
NULL, &class_in)) ERR;
if (strcmp(name_in, TYPE5_NAME) ||
if (strcmp(name_in, TYPE5_NAME) ||
base_size_in != sizeof(nc_vlen_t) ||
base_typeid != NC_FLOAT ||
class_in != NC_VLEN) ERR;
/* Get the same info with the vlen-specific inquire function */
if (nc_inq_vlen(ncid, typeid, name_in, &base_size_in, &base_typeid)) ERR;
if (strcmp(name_in, TYPE5_NAME) ||
if (strcmp(name_in, TYPE5_NAME) ||
base_size_in != sizeof(nc_vlen_t) ||
base_typeid != NC_FLOAT) ERR;
@ -148,14 +149,13 @@ main(int argc, char **argv)
}
if (nc_close(ncid)) ERR;
if (nc_close(ncid)) ERR;
/* Free space used for sample data. */
for (i = 0; i < NROWS; i++)
for (i = 0; i < NROWS; i++)
free(array[i]);
free(array);
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -6,7 +6,7 @@
*/
#include <nc_tests.h>
#include "err_macros.h"
#define FILE_NAME "tst_rename.nc"