Exemple #1
0
static int write_numeric_attribute(int ncid, int varid, const char *name, harp_data_type data_type, harp_scalar data)
{
    int result;

    result = NC_NOERR;
    switch (data_type)
    {
        case harp_type_int8:
            result = nc_put_att_schar(ncid, varid, name, NC_BYTE, 1, &data.int8_data);
            break;
        case harp_type_int16:
            result = nc_put_att_short(ncid, varid, name, NC_SHORT, 1, &data.int16_data);
            break;
        case harp_type_int32:
            result = nc_put_att_int(ncid, varid, name, NC_INT, 1, &data.int32_data);
            break;
        case harp_type_float:
            result = nc_put_att_float(ncid, varid, name, NC_FLOAT, 1, &data.float_data);
            break;
        case harp_type_double:
            result = nc_put_att_double(ncid, varid, name, NC_DOUBLE, 1, &data.double_data);
            break;
        default:
            assert(0);
            exit(1);
    }

    if (result != NC_NOERR)
    {
        harp_set_error(HARP_ERROR_NETCDF, "%s", nc_strerror(result));
        return -1;
    }

    return 0;
}
Exemple #2
0
NcBool NcVar::add_att(NcToken aname, ncbyte val)
{
    if (! the_file->define_mode())
      return FALSE;
    if (nc_put_att_schar (the_file->id(), the_id, aname, (nc_type) NcTypeEnum(ncbyte),
		 1, &val) != NC_NOERR)
      return FALSE;
    return TRUE;
}
Exemple #3
0
NcBool NcVar::add_att(NcToken aname, int len, const ncbyte* vals)
{
    if (! the_file->define_mode())
      return FALSE;
    if (NcError::set_err(
			 nc_put_att_schar (the_file->id(), the_id, aname, (nc_type) NcTypeEnum(ncbyte),
		 len, vals)
			 ) != NC_NOERR)
      return FALSE;
    return TRUE;
}
Exemple #4
0
/*
 * Add or changes a numeric variable or global attribute of an open
 * netCDF file.
 */
static void
c_ncapt (
    int		ncid,		/* netCDF ID */
    int		varid,		/* variable ID */
    const char*	attname,	/* attribute name */
    nc_type	datatype,	/* attribute datatype */
    size_t	attlen,		/* attribute length */
    const void*	value,		/* pointer to data values */
    int*	rcode		/* returned error code */
)
{
    int		status;

    switch (datatype)
    {
    case NC_CHAR:
	status = NC_ECHAR;
	break;
    case NC_BYTE:
#	if NF_INT1_IS_C_SIGNED_CHAR
	    status = nc_put_att_schar(ncid, varid, attname, datatype,
				       attlen, (const signed char*)value);
#	elif NF_INT1_IS_C_SHORT
	    status = nc_put_att_short(ncid, varid, attname, datatype,
				       attlen, (const short*)value);
#	elif NF_INT1_IS_C_INT
	    status = nc_put_att_int(ncid, varid, attname, datatype,
				       attlen, (const int*)value);
#	elif NF_INT1_IS_C_LONG
	    status = nc_put_att_long(ncid, varid, attname, datatype,
				       attlen, (const long*)value);
#	endif
	break;
    case NC_SHORT:
#	if NF_INT2_IS_C_SHORT
	    status = nc_put_att_short(ncid, varid, attname, datatype,
				       attlen, (const short*)value);
#	elif NF_INT2_IS_C_INT
	    status = nc_put_att_int(ncid, varid, attname, datatype,
				       attlen, (const int*)value);
#	elif NF_INT2_IS_C_LONG
	    status = nc_put_att_long(ncid, varid, attname, datatype,
				       attlen, (const long*)value);
#	endif
	break;
    case NC_INT:
#	if NF_INT_IS_C_INT
	    status = nc_put_att_int(ncid, varid, attname, datatype,
				       attlen, (const int*)value);
#	elif NF_INT_IS_C_LONG
	    status = nc_put_att_long(ncid, varid, attname, datatype,
				       attlen, (const long*)value);
#	endif
	break;
    case NC_FLOAT:
#	if NF_REAL_IS_C_FLOAT
	    status = nc_put_att_float(ncid, varid, attname, datatype,
				       attlen, (const float*)value);
#	elif NF_REAL_IS_C_DOUBLE
	    status = nc_put_att_double(ncid, varid, attname, datatype,
				       attlen, (const double*)value);
#	endif
	break;
    case NC_DOUBLE:
#	if NF_DOUBLEPRECISION_IS_C_FLOAT
	    status = nc_put_att_float(ncid, varid, attname, datatype,
				       attlen, (const float*)value);
#	elif NF_DOUBLEPRECISION_IS_C_DOUBLE
	    status = nc_put_att_double(ncid, varid, attname, datatype,
				       attlen, (const double*)value);
#	endif
	break;
    }

    if (status == 0)
	*rcode = 0;
    else
    {
	nc_advise("NCAPT", status, "");
	*rcode = ncerr;
    }
}
Exemple #5
0
int
main(int argc, char **argv)
{
   int ncid, dimids[NUM_DIMS];
   int varid;
   int nvars_in, varids_in[NUM_DIMS];
   signed char fill_value = 42, fill_value_in;
   nc_type xtype_in;
   size_t len_in;
   char name_in[NC_MAX_NAME + 1];
   int attnum_in;
   int cnum;

#ifdef USE_PARALLEL
   MPI_Init(&argc, &argv);
#endif

   printf("\n*** Testing netcdf-4 variable functions, even more.\n");
   for (cnum = 0; cnum < MAX_CNUM; cnum++)
   {
      int cmode;
      
      switch(cnum)
      {
         case 0:
            printf("*** Testing with classic format:\n");
            cmode = 0;
            break;
         case 1:
            printf("*** Testing with 64-bit offset format:\n");
            cmode = NC_64BIT_OFFSET;
            break;
         case 2:
            printf("*** Testing with HDF5:\n");
            cmode = NC_NETCDF4|NC_CLOBBER;
            break;
         case 3:
            printf("*** Testing with HDF5, netCDF Classic Model:\n");
            cmode = NC_CLASSIC_MODEL | NC_NETCDF4;
      }

      printf("**** testing simple fill value attribute creation...");
      {
         /* Create a netcdf-4 file with one scalar var. Add fill
          * value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, 0, NULL, &varid)) ERR;
         if (nc_enddef(ncid)) ERR;
         if (nc_redef(ncid)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;              
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
         if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
         if (nvars_in != 1 || varids_in[0] != 0) ERR;
         if (nc_inq_varname(ncid, 0, name_in)) ERR;
         if (strcmp(name_in, VAR_NAME)) ERR;
         if (nc_inq_att(ncid, varid, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, varid, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing simple fill value with data read...");
      {
         size_t start[NUM_DIMS], count[NUM_DIMS];
         signed char data = 99, data_in;

         /* Create a netcdf-4 file with one unlimited dim and one
          * var. Add fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         if (nc_enddef(ncid)) ERR;
         if (nc_redef(ncid)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_enddef(ncid)) ERR;

         /* Write the second record. */
         start[0] = 1;
         count[0] = 1;
         if (nc_put_vara_schar(ncid, varid, start, count, &data)) ERR;

         /* Read the first record, it should be the fill value. */
         start[0] = 0;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != fill_value) ERR;

         /* Read the second record, it should be the value we just wrote
          * there. */
         start[0] = 1;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != data) ERR;
      
         /* Close up. */
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

         /* Check metadata. */
         if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
         if (nvars_in != 1 || varids_in[0] != 0) ERR;
         if (nc_inq_varname(ncid, 0, name_in)) ERR;
         if (strcmp(name_in, VAR_NAME)) ERR;

         /* Check fill value att. */
         if (nc_inq_att(ncid, varid, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, varid, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;

         /* Read the first record, it should be the fill value. */
         start[0] = 0;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != fill_value) ERR;

         /* Read the second record, it should be the value we just wrote
          * there. */
         start[0] = 1;
         if (nc_get_vara_schar(ncid, varid, start, count, &data_in)) ERR;
         if (data_in != data) ERR;
      
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with one other attribute...");

      {
         int losses_value = 192, losses_value_in;

         /* Create a netcdf-4 file with one dim and one var. Add another
          * attribute, then fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         if (nc_put_att_int(ncid, varid, LOSSES_NAME, NC_INT, 1, &losses_value)) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
         if (nc_inq_att(ncid, 0, LOSSES_NAME, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_INT || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, LOSSES_NAME, &losses_value_in)) ERR;
         if (losses_value_in != losses_value) ERR;
         if (nc_inq_att(ncid, 0, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;
         if (nc_inq_attid(ncid, 0, LOSSES_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with three other attributes...");
      {
#define NUM_LEADERS 3
         char leader[NUM_LEADERS][NC_MAX_NAME + 1] = {"hair_length_of_strategoi", 
                                                      "hair_length_of_Miltiades", 
                                                      "hair_length_of_Darius_I"};
         short hair_length[NUM_LEADERS] = {3, 11, 4};
         short short_in;
         int a;

         /* Create a netcdf file with one dim and one var. Add 3
          * attributes, then fill value. */
         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
         if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
         if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
         for (a = 0; a < NUM_LEADERS; a++)
            if (nc_put_att_short(ncid, varid, leader[a], NC_SHORT, 1, &hair_length[a])) ERR;
         if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;            
         if (nc_close(ncid)) ERR;

         /* Open the file. */
         if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

         /* Check our three hair-related attributes. */
         for (a = 0; a < NUM_LEADERS; a++)
         {
            if (nc_inq_att(ncid, 0, leader[a], &xtype_in, &len_in)) ERR;
            if (xtype_in != NC_SHORT || len_in != 1) ERR;
            if (nc_get_att(ncid, 0, leader[a], &short_in)) ERR;
            if (short_in != hair_length[a]) ERR;
            if (nc_inq_attid(ncid, 0, leader[a], &attnum_in)) ERR;
            if (attnum_in != a) ERR;
         }

         /* Check our fill value attribute. */
         if (nc_inq_att(ncid, 0, _FillValue, &xtype_in, &len_in)) ERR;
         if (xtype_in != NC_BYTE || len_in != 1) ERR;
         if (nc_get_att(ncid, 0, _FillValue, &fill_value_in)) ERR;
         if (fill_value_in != fill_value) ERR;

         if (nc_close(ncid)) ERR;
      }

      SUMMARIZE_ERR;
      printf("**** testing fill value with simple example...");
      {
/* Dims stuff. */
#define NDIMS 3
#define VAR_DIMS 3
#define DIM_A "dim1"
#define DIM_A_LEN 4
#define DIM_B "dim2"
#define DIM_B_LEN 3
#define DIM_C "dim3"
#define DIM_C_LEN NC_UNLIMITED

/* Var stuff. */
#define CXX_VAR_NAME "P"

/* Att stuff. */
#define NUM_ATTS 4
#define LONG_NAME "long_name"
#define PRES_MAX_WIND "pressure at maximum wind"
#define UNITS "units"
#define HECTOPASCALS "hectopascals"

         int dimid[NDIMS], var_dimids[VAR_DIMS] = {2, 1, 0};
         float fill_value = -9999.0f;
         char long_name[] = PRES_MAX_WIND;

         if (nc_create(FILE_NAME, cmode, &ncid)) ERR;

         /* Create dims. */
         if (nc_def_dim(ncid, DIM_A, DIM_A_LEN, &dimid[0])) ERR;
         if (nc_def_dim (ncid, DIM_B, DIM_B_LEN, &dimid[1])) ERR;
         if (nc_def_dim(ncid, DIM_C, DIM_C_LEN, &dimid[2])) ERR;

         /* Create var. */
         if (nc_def_var(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, 
                        var_dimids, &varid)) ERR;
         if (varid) ERR;

         if (nc_put_att(ncid, varid, LONG_NAME, NC_CHAR, strlen(long_name) + 1, 
                        long_name)) ERR;
         if (nc_put_att(ncid, varid, UNITS, NC_CHAR, strlen(UNITS) + 1, 
                        UNITS)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         /* Now add a fill value. This will acutually cause HDF5 to
          * destroy the dataset and recreate it, recreating also the
          * three attributes that are attached to it. */
         if (nc_put_att(ncid, varid, _FillValue, NC_FLOAT, 
                        1, &fill_value)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         if (nc_close(ncid)) ERR;

         /* Open the file and check. */
         if (nc_open(FILE_NAME, 0, &ncid)) ERR;
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 2) ERR;

         if (nc_close(ncid)) ERR;
      }
      SUMMARIZE_ERR;

#ifndef NO_NETCDF_2
      /* The following test is an attempt to recreate a problem occuring
         in the cxx tests. The file is created in c++ in nctsts.cpp. */
      printf("**** testing fill value with example from cxx tests in v2 api...");
      {
/* Dims stuff. */
#define NDIMS_1 4
#define VAR_DIMS 3
#define LAT "lat"
#define LAT_LEN 4
#define LON "lon"
#define LON_LEN 3
#define FRTIMED "frtimed"
#define FRTIMED_LEN NC_UNLIMITED
#define TIMELEN "timelen"
#define TIMELEN_LEN 20

/* Var stuff. */
#define CXX_VAR_NAME "P"

/* Att stuff. */
#define NUM_ATTS 4
#define LONG_NAME "long_name"
#define UNITS "units"

         int dimid[NDIMS_1], var_dimids[VAR_DIMS] = {2, 0, 1};
         float fill_value = -9999.0f;
         char long_name[] = PRES_MAX_WIND;
         int i, attid[NUM_ATTS];

         ncid = nccreate(FILE_NAME, NC_NETCDF4);

         /* Create dims. */
         dimid[0] = ncdimdef(ncid, LAT, LAT_LEN);
         dimid[1] = ncdimdef(ncid, LON, LON_LEN);
         dimid[2] = ncdimdef(ncid, FRTIMED, FRTIMED_LEN);
         dimid[3] = ncdimdef(ncid, TIMELEN, TIMELEN_LEN);

         /* Just check our dimids to see that they are correct. */
         for (i = 0; i < NDIMS_1; i++)
            if (dimid[i] != i) ERR;

         /* Create var. */
         varid = ncvardef(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, var_dimids);
         if (varid) ERR;

         /* Add three atts to the var, long_name, units, and
          * valid_range. */
         if (nc_put_att(ncid, varid, LONG_NAME, NC_CHAR, strlen(long_name) + 1,
                        long_name)) ERR;
         if (nc_put_att(ncid, varid, UNITS, NC_CHAR, strlen(UNITS) + 1,
                        UNITS)) ERR;

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         /* Now add a fill value. This will acutually cause HDF5 to
          * destroy the dataset and recreate it, recreating also the
          * three attributes that are attached to it. */
         attid[3] = ncattput(ncid, varid, _FillValue, NC_FLOAT,
                             1, &fill_value);

         /* Check to ensure the atts have their expected attnums. */
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;

         ncclose(ncid);

         /* Open the file and check. */
         ncid = ncopen(FILE_NAME, 0);
         if (nc_inq_attid(ncid, 0, LONG_NAME, &attnum_in)) ERR;
         if (attnum_in != 0) ERR;
         if (nc_inq_attid(ncid, 0, UNITS, &attnum_in)) ERR;
         if (attnum_in != 1) ERR;
         if (nc_inq_attid(ncid, 0, _FillValue, &attnum_in)) ERR;
         if (attnum_in != 2) ERR;
         ncclose(ncid);
      }
      SUMMARIZE_ERR;
#endif /* NO_NETCDF_2 */
   }

   printf("**** testing create order varids...");

#define UNITS "units"
#define DIMNAME "x"
#define VARNAME "data"
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int ncid, dimid, varid, xvarid;
      char units[] = "zlotys";

      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
      if (nc_def_dim(ncid, DIMNAME, 1, &dimid)) ERR;
      if (nc_enddef(ncid)) ERR;
      if (nc_redef(ncid)) ERR;
      if (nc_def_var(ncid, DIMNAME, NC_INT, 1, &dimid, &xvarid)) ERR;
      if (nc_put_att_text(ncid, xvarid, UNITS, strlen(units), units)) ERR;
      if (nc_def_var(ncid, VARNAME, NC_INT, 1, &dimid, &varid)) ERR;
      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
#define RANK_wind 1
   printf("**** testing simple variable renaming...");
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int  ncid, lat_dim, time_dim, lon_dim, wind_id;
      size_t lat_len = 73, time_len = 10, lon_len = 145;
      int cdf_goober[1];

/*      if (nc_set_default_format(NC_FORMAT_NETCDF4, NULL)) ERR;*/
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* define dimensions */
      if (nc_def_dim(ncid, "a", lon_len, &lon_dim)) ERR;
      if (nc_def_dim(ncid, "b", lat_len, &lat_dim)) ERR;
      if (nc_def_dim(ncid, "c", time_len, &time_dim)) ERR;

      if (nc_put_att_text(ncid, NC_GLOBAL, "a", 3, "bar")) ERR;
      cdf_goober[0] = 2;
      if (nc_put_att_int(ncid, NC_GLOBAL, "b", NC_INT, 1, cdf_goober)) ERR;

      /* define variables */
      if (nc_def_var(ncid, "aa", NC_FLOAT, RANK_wind, &lon_dim, &wind_id)) ERR;
      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_rename_var(ncid, 0, "az")) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR; 
   printf("**** testing dimension and variable renaming...");
   {
      /* This test contributed by Jeff Whitaker of NOAA - Thanks Jeff! */
      int  ncid, lat_dim, time_dim, lon_dim, wind_id;
      size_t lat_len = 73, time_len = 10, lon_len = 145;
      int wind_dims[RANK_wind], wind_slobber[1], cdf_goober[1];

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;

      /* define dimensions */
      if (nc_def_dim(ncid, "lon", lon_len, &lon_dim)) ERR;
      if (nc_def_dim(ncid, "lat", lat_len, &lat_dim)) ERR;
      if (nc_def_dim(ncid, "time", time_len, &time_dim)) ERR;

      if (nc_put_att_text(ncid, NC_GLOBAL, "foo", 3, "bar")) ERR;
      cdf_goober[0] = 2;
      if (nc_put_att_int(ncid, NC_GLOBAL, "goober", NC_INT, 1, cdf_goober)) ERR;

      /* define variables */
      wind_dims[0] = lon_dim;
      if (nc_def_var(ncid, "temp", NC_FLOAT, RANK_wind, wind_dims, &wind_id)) ERR;

      if (nc_put_att_text(ncid, wind_id, "bar", 3, "foo")) ERR;
      wind_slobber[0] = 3;
      if (nc_put_att_int(ncid, wind_id, "slobber", NC_INT, 1, wind_slobber)) ERR;
      if (nc_close(ncid)) ERR;

      /* re-open dataset*/
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_dimid(ncid, "lon", &lon_dim)) ERR;

      /* rename dimension */
      if (nc_rename_dim(ncid, lon_dim, "longitude")) ERR;
      if (nc_inq_varid(ncid, "temp", &wind_id)) ERR;

      /* rename variable */
      if (nc_rename_var(ncid, wind_id, "wind")) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR; 


/*    printf("*** testing 2D array of NC_CHAR..."); */
/*    { */
/*       int dimid[NDIMS_1], var_dimids[VAR_DIMS] = {2, 0, 1}; */
/*       float fill_value = -9999.0f; */
/*       char long_name[] = PRES_MAX_WIND; */
/*       int i, attid[NUM_ATTS]; */

/*       ncid = nccreate(FILE_NAME, NC_NETCDF4); */

/*       /\* Create dims. *\/ */
/*       dimid[0] = ncdimdef(ncid, LAT, LAT_LEN); */
/*       dimid[1] = ncdimdef(ncid, LON, LON_LEN); */

/*       /\* Create var. *\/ */
/*       varid = ncvardef(ncid, CXX_VAR_NAME, NC_FLOAT, VAR_DIMS, var_dimids); */
/*       if (varid) ERR; */

/*       ncclose(ncid); */

/*       /\* Open the file and check. *\/ */
/*       ncid = ncopen(FILE_NAME, 0); */
/*       ncclose(ncid); */
/*    } */

/*    SUMMARIZE_ERR; */

#define NDIMS 3
#define NNAMES 4
#define NLINES 13
/*    printf("**** testing funny names for netCDF-4..."); */
/*    { */
/*       int  ncid, wind_id; */
/*       size_t len[NDIMS] = {7, 3, 1}; */
/*       int dimids[NDIMS], dimids_in[NDIMS], ndims_in; */
/*       char funny_name[NNAMES][NC_MAX_NAME] = {"\a\t", "\f\n", "\r\v", "\b"}; */
/*       char name_in[NC_MAX_NAME + 1]; */
/*       char *speech[NLINES] = {"who would fardels bear, ", */
/* 			      "To grunt and sweat under a weary life, ", */
/* 			      "But that the dread of something after death, ", */
/* 			      "The undiscover'd country from whose bourn ", */
/* 			      "No traveller returns, puzzles the will ", */
/* 			      "And makes us rather bear those ills we have ", */
/* 			      "Than fly to others that we know not of? ", */
/* 			      "Thus conscience does make cowards of us all; ", */
/* 			      "And thus the native hue of resolution ", */
/* 			      "Is sicklied o'er with the pale cast of thought, ", */
/* 			      "And enterprises of great pith and moment ", */
/* 			      "With this regard their currents turn awry, ", */
/* 			      "And lose the name of action."}; */
/*       char *speech_in[NLINES]; */
/*       int i; */
/*       unsigned short nlines = NLINES; */
/*       unsigned int nlines_in; */

/*       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */

/*       /\* Define dimensions. *\/ */
/*       for (i = 0; i < NDIMS; i++) */
/* 	 if (nc_def_dim(ncid, funny_name[i], len[i], &dimids[i])) ERR; */

/*       /\* Write some global atts. *\/ */
/*       if (nc_put_att_string(ncid, NC_GLOBAL, funny_name[0], NLINES,  */
/* 			    (const char **)speech)) ERR; */
/*       if (nc_put_att_ushort(ncid, NC_GLOBAL, funny_name[1], NC_UINT, 1, &nlines)) ERR; */

/*       /\* Define variables. *\/ */
/*       if (nc_def_var(ncid, funny_name[3], NC_INT64, NDIMS, dimids, &wind_id)) ERR; */

/*       if (nc_close(ncid)) ERR; */

/*       /\* Open the file and check. *\/ */
/*       if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */
/*       if (nc_inq_dimids(ncid, &ndims_in, dimids_in, 0)) ERR; */
/*       if (ndims_in != NDIMS) ERR; */
/*       for (i = 0; i < NDIMS; i++) */
/*       { */
/* 	 if (dimids_in[i] != i) ERR; */
/* 	 if (nc_inq_dimname(ncid, i, name_in)) ERR; */
/* 	 if (strcmp(name_in, funny_name[i])) ERR; */
/*       } */

/*       if (nc_get_att_string(ncid, NC_GLOBAL, funny_name[0], (char **)speech_in)) ERR; */
/*       for (i = 0; i < NLINES; i++) */
/* 	 if (strcmp(speech_in[i], speech[i])) ERR; */
/*       if (nc_get_att_uint(ncid, NC_GLOBAL, funny_name[1], &nlines_in)) ERR; */
/*       if (nlines_in != NLINES) ERR; */
/*       if (nc_free_string(NLINES, (char **)speech_in)) ERR; */
/*       if (nc_inq_varname(ncid, 0, name_in)) ERR; */
/*       if (strcmp(name_in, funny_name[3])) ERR; */
/*       if (nc_close(ncid)) ERR; */
/*    } */
/*    SUMMARIZE_ERR; */
   printf("**** testing endianness...");

#define NDIMS4 1
#define DIM4_NAME "Joe"
#define VAR_NAME4 "Ed"
#define DIM4_LEN 10
   {
      int dimids[NDIMS4], dimids_in[NDIMS4];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM4_LEN], data_in[DIM4_LEN];
      int endian_in;
      int i;

      for (i = 0; i < DIM4_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM4_NAME, DIM4_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME4, NC_INT, NDIMS4, dimids, &varid)) ERR;
      if (nc_def_var_endian(ncid, varid, NC_ENDIAN_BIG)) ERR;
      if (varid != 0) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS4 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims,
                     dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT ||
          ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR;
      if (nc_inq_var_endian(ncid, 0, &endian_in)) ERR;
      if (endian_in != NC_ENDIAN_BIG) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS4 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims,
                     dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME4) || xtype_in != NC_INT ||
          ndims != 1 || natts != 0 || dimids_in[0] != 0) ERR;
      if (nc_inq_var_endian(ncid, 0, &endian_in)) ERR;
      if (endian_in != NC_ENDIAN_BIG) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM4_LEN; i++)
	 if (data[i] != data_in[i]) ERR;

      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing chunking...");
   {
#define NDIMS5 1
#define DIM5_NAME "D5"
#define VAR_NAME5 "V5"
#define DIM5_LEN 1000

      int dimids[NDIMS5], dimids_in[NDIMS5];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM5_LEN], data_in[DIM5_LEN];
      int chunksize[NDIMS5] = {5};
      int chunksize_in[NDIMS5];
      int contiguous_in;
      int i, d;

      for (i = 0; i < DIM5_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM5_NAME, DIM5_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME5, NC_INT, NDIMS5, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, chunksize)) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS5 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME5) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS5; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM5_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS5 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME5) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS5; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM5_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing contiguous storage...");
   {
#define NDIMS6 1
#define DIM6_NAME "D5"
#define VAR_NAME6 "V5"
#define DIM6_LEN 100

      int dimids[NDIMS6], dimids_in[NDIMS6];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int data[DIM6_LEN], data_in[DIM6_LEN];
      int chunksize_in[NDIMS6];
      int contiguous_in;
      int i, d;

      for (i = 0; i < DIM6_LEN; i++)
         data[i] = i;

      /* Create a netcdf-4 file with one dim and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR;
      if (dimids[0] != 0) ERR;
      if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS6, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 1, NULL)) ERR;
      if (nc_put_var_int(ncid, varid, data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS6; d++)
	 if (chunksize_in[d] != 0) ERR;
      if (!contiguous_in) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM6_LEN; i++)
         if (data_in[i] != data[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS6 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 || 
	  dimids_in[0] != 0) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS6; d++)
	 if (chunksize_in[d] != 0) ERR;
      if (!contiguous_in) ERR;
      if (nc_get_var_int(ncid, varid, data_in)) ERR;
      for (i = 0; i < DIM6_LEN; i++)
         if (data[i] != data_in[i])
	    ERR_RET;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing extreme numbers dude...");
   {
#define VAR_NAME7 "V5"
#define DIM6_LEN 100

      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
/*      unsigned long long data = 9223372036854775807ull, data_in;*/
      unsigned long long data = 9223372036854775817ull, data_in;

      /* Create a netcdf-4 file with scalar var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_var(ncid, VAR_NAME7, NC_UINT64, 0, NULL, &varid)) ERR;
      if (nc_put_var_ulonglong(ncid, varid, &data)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, NULL, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME7) || xtype_in != NC_UINT64 || ndims != 0 || natts != 0) ERR;
      if (nc_get_var_ulonglong(ncid, varid, &data_in)) ERR;
      if (data_in != data) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != 0 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, NULL, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME7) || xtype_in != NC_UINT64 || ndims != 0 || natts != 0) ERR;
      if (nc_get_var_ulonglong(ncid, varid, &data_in)) ERR;
      if (data_in != data) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes...");
   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_grp(ncid, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in != 1 || varids_in[0] != 0) ERR;
      if (nc_inq_varname(ncid, 0, name_in)) ERR;
      if (strcmp(name_in, GENERIC_NAME)) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes some more...");

   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_grp(ncid, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes != 1) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("**** testing error codes for name clashes even more...");

   {
#define GENERIC_NAME "bob"      
      int ncid, varid, numgrps, ntypes;

      /* Create a netcdf-4 file with one group. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_grp(ncid, GENERIC_NAME, NULL)) ERR;

      /* These don'e work, becuase the name is already in use. Make
       * sure the correct error is returned. */
      if (nc_def_opaque(ncid, 1, GENERIC_NAME, NULL) != NC_ENAMEINUSE) ERR;
      if (nc_def_var(ncid, GENERIC_NAME, NC_BYTE, 0, NULL, &varid) != NC_ENAMEINUSE) ERR;

      /* Close it. */
      if (nc_close(ncid)) ERR;
      
      /* Open the file and check. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR;
      if (nvars_in) ERR;
      if (nc_inq_grps(ncid, &numgrps, NULL)) ERR;
      if (numgrps != 1) ERR;
      if (nc_inq_typeids(ncid, &ntypes, NULL)) ERR;
      if (ntypes) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("**** testing error code for too-large chunks...");
   {
#define NDIMS17 2
#define DIM17_NAME "personality"
#define DIM17_NAME_2 "good_looks"
#define VAR_NAME17 "ed"
#define DIM17_LEN 2147483644 /* max dimension size - 2GB - 4. */
#define DIM17_2_LEN 1000

      int dimids[NDIMS17], dimids_in[NDIMS17];
      int varid;
      int ndims, nvars, natts, unlimdimid;
      nc_type xtype_in;
      char name_in[NC_MAX_NAME + 1];
      int chunksize[NDIMS17] = {5, 5};
      int bad_chunksize[NDIMS17] = {5, DIM17_LEN};
      int chunksize_in[NDIMS17];
      int contiguous_in;
      int d;

      /* Create a netcdf-4 file with two dims and one var. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM17_NAME, DIM17_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM17_NAME_2, DIM17_2_LEN, &dimids[1])) ERR;
      if (dimids[0] != 0 || dimids[1] != 1) ERR;
      if (nc_def_var(ncid, VAR_NAME17, NC_UINT64, NDIMS17, dimids, &varid)) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, bad_chunksize) != NC_EBADCHUNK) ERR;
      if (nc_def_var_chunking(ncid, varid, 0, chunksize)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS17 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME17) || xtype_in != NC_UINT64 || ndims != 2 || natts != 0 || 
	  dimids_in[0] != 0 || dimids_in[1] != 1) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS17; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_close(ncid)) ERR;

      /* Open the file and check the same stuff. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;

      /* Check stuff. */
      if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
      if (ndims != NDIMS17 || nvars != 1 || natts != 0 ||
          unlimdimid != -1) ERR;
      if (nc_inq_varids(ncid, &nvars, varids_in)) ERR;
      if (nvars != 1) ERR;
      if (varids_in[0] != 0) ERR;
      if (nc_inq_var(ncid, 0, name_in, &xtype_in, &ndims, dimids_in, &natts)) ERR;
      if (strcmp(name_in, VAR_NAME17) || xtype_in != NC_UINT64 || ndims != 2 || natts != 0 || 
	  dimids_in[0] != 0 || dimids_in[1] != 1) ERR;
      if (nc_inq_var_chunking(ncid, 0, &contiguous_in, chunksize_in)) ERR;
      for (d = 0; d < NDIMS17; d++)
	 if (chunksize[d] != chunksize_in[d]) ERR;
      if (contiguous_in != 0) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   FINAL_RESULTS;

#ifdef USE_PARALLEL
   MPI_Finalize();
#endif   
}
Exemple #6
0
int
main() {/* create ctest0_64.nc */

    int  stat;  /* return status */
    int  ncid;  /* netCDF id */

    /* dimension ids */
    int Dr_dim;
    int D1_dim;
    int D2_dim;
    int D3_dim;
    int dim_MINUS_name_MINUS_dashes_dim;
    int dim_PERIOD_name_PERIOD_dots_dim;
    int dim_PLUS_name_PLUS_plusses_dim;
    int dim_ATSIGN_name_ATSIGN_ats_dim;

    /* dimension lengths */
    size_t Dr_len = NC_UNLIMITED;
    size_t D1_len = 1;
    size_t D2_len = 2;
    size_t D3_len = 3;
    size_t dim_MINUS_name_MINUS_dashes_len = 4;
    size_t dim_PERIOD_name_PERIOD_dots_len = 5;
    size_t dim_PLUS_name_PLUS_plusses_len = 6;
    size_t dim_ATSIGN_name_ATSIGN_ats_len = 7;

    /* variable ids */
    int c_id;
    int b_id;
    int s_id;
    int i_id;
    int f_id;
    int d_id;
    int cr_id;
    int br_id;
    int sr_id;
    int ir_id;
    int fr_id;
    int dr_id;
    int c1_id;
    int b1_id;
    int s1_id;
    int i1_id;
    int f1_id;
    int d1_id;
    int c2_id;
    int b2_id;
    int s2_id;
    int i2_id;
    int f2_id;
    int d2_id;
    int c3_id;
    int b3_id;
    int s3_id;
    int i3_id;
    int f3_id;
    int d3_id;
    int cr1_id;
    int br2_id;
    int sr3_id;
    int f11_id;
    int d12_id;
    int c13_id;
    int s21_id;
    int i22_id;
    int f23_id;
    int c31_id;
    int b32_id;
    int s33_id;
    int sr11_id;
    int ir12_id;
    int fr13_id;
    int cr21_id;
    int br22_id;
    int sr23_id;
    int fr31_id;
    int dr32_id;
    int cr33_id;
    int c111_id;
    int b112_id;
    int s113_id;
    int f121_id;
    int d122_id;
    int c123_id;
    int s131_id;
    int i132_id;
    int f133_id;
    int f211_id;
    int d212_id;
    int c213_id;
    int s221_id;
    int i222_id;
    int f223_id;
    int c231_id;
    int b232_id;
    int s233_id;
    int s311_id;
    int i312_id;
    int f313_id;
    int var_MINUS_name_MINUS_dashes_id;
    int var_PERIOD_name_PERIOD_dots_id;
    int var_PLUS_name_PLUS_plusses_id;
    int var_ATSIGN_name_ATSIGN_ats_id;

    /* rank (number of dimensions) for each variable */
#   define RANK_c 0
#   define RANK_b 0
#   define RANK_s 0
#   define RANK_i 0
#   define RANK_f 0
#   define RANK_d 0
#   define RANK_cr 1
#   define RANK_br 1
#   define RANK_sr 1
#   define RANK_ir 1
#   define RANK_fr 1
#   define RANK_dr 1
#   define RANK_c1 1
#   define RANK_b1 1
#   define RANK_s1 1
#   define RANK_i1 1
#   define RANK_f1 1
#   define RANK_d1 1
#   define RANK_c2 1
#   define RANK_b2 1
#   define RANK_s2 1
#   define RANK_i2 1
#   define RANK_f2 1
#   define RANK_d2 1
#   define RANK_c3 1
#   define RANK_b3 1
#   define RANK_s3 1
#   define RANK_i3 1
#   define RANK_f3 1
#   define RANK_d3 1
#   define RANK_cr1 2
#   define RANK_br2 2
#   define RANK_sr3 2
#   define RANK_f11 2
#   define RANK_d12 2
#   define RANK_c13 2
#   define RANK_s21 2
#   define RANK_i22 2
#   define RANK_f23 2
#   define RANK_c31 2
#   define RANK_b32 2
#   define RANK_s33 2
#   define RANK_sr11 3
#   define RANK_ir12 3
#   define RANK_fr13 3
#   define RANK_cr21 3
#   define RANK_br22 3
#   define RANK_sr23 3
#   define RANK_fr31 3
#   define RANK_dr32 3
#   define RANK_cr33 3
#   define RANK_c111 3
#   define RANK_b112 3
#   define RANK_s113 3
#   define RANK_f121 3
#   define RANK_d122 3
#   define RANK_c123 3
#   define RANK_s131 3
#   define RANK_i132 3
#   define RANK_f133 3
#   define RANK_f211 3
#   define RANK_d212 3
#   define RANK_c213 3
#   define RANK_s221 3
#   define RANK_i222 3
#   define RANK_f223 3
#   define RANK_c231 3
#   define RANK_b232 3
#   define RANK_s233 3
#   define RANK_s311 3
#   define RANK_i312 3
#   define RANK_f313 3
#   define RANK_var_MINUS_name_MINUS_dashes 0
#   define RANK_var_PERIOD_name_PERIOD_dots 0
#   define RANK_var_PLUS_name_PLUS_plusses 0
#   define RANK_var_ATSIGN_name_ATSIGN_ats 0

    /* variable shapes */
    int cr_dims[RANK_cr];
    int br_dims[RANK_br];
    int sr_dims[RANK_sr];
    int ir_dims[RANK_ir];
    int fr_dims[RANK_fr];
    int dr_dims[RANK_dr];
    int c1_dims[RANK_c1];
    int b1_dims[RANK_b1];
    int s1_dims[RANK_s1];
    int i1_dims[RANK_i1];
    int f1_dims[RANK_f1];
    int d1_dims[RANK_d1];
    int c2_dims[RANK_c2];
    int b2_dims[RANK_b2];
    int s2_dims[RANK_s2];
    int i2_dims[RANK_i2];
    int f2_dims[RANK_f2];
    int d2_dims[RANK_d2];
    int c3_dims[RANK_c3];
    int b3_dims[RANK_b3];
    int s3_dims[RANK_s3];
    int i3_dims[RANK_i3];
    int f3_dims[RANK_f3];
    int d3_dims[RANK_d3];
    int cr1_dims[RANK_cr1];
    int br2_dims[RANK_br2];
    int sr3_dims[RANK_sr3];
    int f11_dims[RANK_f11];
    int d12_dims[RANK_d12];
    int c13_dims[RANK_c13];
    int s21_dims[RANK_s21];
    int i22_dims[RANK_i22];
    int f23_dims[RANK_f23];
    int c31_dims[RANK_c31];
    int b32_dims[RANK_b32];
    int s33_dims[RANK_s33];
    int sr11_dims[RANK_sr11];
    int ir12_dims[RANK_ir12];
    int fr13_dims[RANK_fr13];
    int cr21_dims[RANK_cr21];
    int br22_dims[RANK_br22];
    int sr23_dims[RANK_sr23];
    int fr31_dims[RANK_fr31];
    int dr32_dims[RANK_dr32];
    int cr33_dims[RANK_cr33];
    int c111_dims[RANK_c111];
    int b112_dims[RANK_b112];
    int s113_dims[RANK_s113];
    int f121_dims[RANK_f121];
    int d122_dims[RANK_d122];
    int c123_dims[RANK_c123];
    int s131_dims[RANK_s131];
    int i132_dims[RANK_i132];
    int f133_dims[RANK_f133];
    int f211_dims[RANK_f211];
    int d212_dims[RANK_d212];
    int c213_dims[RANK_c213];
    int s221_dims[RANK_s221];
    int i222_dims[RANK_i222];
    int f223_dims[RANK_f223];
    int c231_dims[RANK_c231];
    int b232_dims[RANK_b232];
    int s233_dims[RANK_s233];
    int s311_dims[RANK_s311];
    int i312_dims[RANK_i312];
    int f313_dims[RANK_f313];

    /* enter define mode */
    stat = nc_create("ctest0_64.nc", NC_CLOBBER|NC_64BIT_OFFSET, &ncid);
    check_err(stat,__LINE__,__FILE__);

    /* define dimensions */
    stat = nc_def_dim(ncid, "Dr", Dr_len, &Dr_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "D1", D1_len, &D1_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "D2", D2_len, &D2_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "D3", D3_len, &D3_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "dim-name-dashes", dim_MINUS_name_MINUS_dashes_len, &dim_MINUS_name_MINUS_dashes_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "dim.name.dots", dim_PERIOD_name_PERIOD_dots_len, &dim_PERIOD_name_PERIOD_dots_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "dim+name+plusses", dim_PLUS_name_PLUS_plusses_len, &dim_PLUS_name_PLUS_plusses_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "dim@name@ats", dim_ATSIGN_name_ATSIGN_ats_len, &dim_ATSIGN_name_ATSIGN_ats_dim);
    check_err(stat,__LINE__,__FILE__);

    /* define variables */

    stat = nc_def_var(ncid, "c", NC_CHAR, RANK_c, 0, &c_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "b", NC_BYTE, RANK_b, 0, &b_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "s", NC_SHORT, RANK_s, 0, &s_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "i", NC_INT, RANK_i, 0, &i_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "f", NC_FLOAT, RANK_f, 0, &f_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "d", NC_DOUBLE, RANK_d, 0, &d_id);
    check_err(stat,__LINE__,__FILE__);

    cr_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "cr", NC_CHAR, RANK_cr, cr_dims, &cr_id);
    check_err(stat,__LINE__,__FILE__);

    br_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "br", NC_BYTE, RANK_br, br_dims, &br_id);
    check_err(stat,__LINE__,__FILE__);

    sr_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "sr", NC_SHORT, RANK_sr, sr_dims, &sr_id);
    check_err(stat,__LINE__,__FILE__);

    ir_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "ir", NC_INT, RANK_ir, ir_dims, &ir_id);
    check_err(stat,__LINE__,__FILE__);

    fr_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "fr", NC_FLOAT, RANK_fr, fr_dims, &fr_id);
    check_err(stat,__LINE__,__FILE__);

    dr_dims[0] = Dr_dim;
    stat = nc_def_var(ncid, "dr", NC_DOUBLE, RANK_dr, dr_dims, &dr_id);
    check_err(stat,__LINE__,__FILE__);

    c1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "c1", NC_CHAR, RANK_c1, c1_dims, &c1_id);
    check_err(stat,__LINE__,__FILE__);

    b1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "b1", NC_BYTE, RANK_b1, b1_dims, &b1_id);
    check_err(stat,__LINE__,__FILE__);

    s1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "s1", NC_SHORT, RANK_s1, s1_dims, &s1_id);
    check_err(stat,__LINE__,__FILE__);

    i1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "i1", NC_INT, RANK_i1, i1_dims, &i1_id);
    check_err(stat,__LINE__,__FILE__);

    f1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "f1", NC_FLOAT, RANK_f1, f1_dims, &f1_id);
    check_err(stat,__LINE__,__FILE__);

    d1_dims[0] = D1_dim;
    stat = nc_def_var(ncid, "d1", NC_DOUBLE, RANK_d1, d1_dims, &d1_id);
    check_err(stat,__LINE__,__FILE__);

    c2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "c2", NC_CHAR, RANK_c2, c2_dims, &c2_id);
    check_err(stat,__LINE__,__FILE__);

    b2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "b2", NC_BYTE, RANK_b2, b2_dims, &b2_id);
    check_err(stat,__LINE__,__FILE__);

    s2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "s2", NC_SHORT, RANK_s2, s2_dims, &s2_id);
    check_err(stat,__LINE__,__FILE__);

    i2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "i2", NC_INT, RANK_i2, i2_dims, &i2_id);
    check_err(stat,__LINE__,__FILE__);

    f2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "f2", NC_FLOAT, RANK_f2, f2_dims, &f2_id);
    check_err(stat,__LINE__,__FILE__);

    d2_dims[0] = D2_dim;
    stat = nc_def_var(ncid, "d2", NC_DOUBLE, RANK_d2, d2_dims, &d2_id);
    check_err(stat,__LINE__,__FILE__);

    c3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "c3", NC_CHAR, RANK_c3, c3_dims, &c3_id);
    check_err(stat,__LINE__,__FILE__);

    b3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "b3", NC_BYTE, RANK_b3, b3_dims, &b3_id);
    check_err(stat,__LINE__,__FILE__);

    s3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "s3", NC_SHORT, RANK_s3, s3_dims, &s3_id);
    check_err(stat,__LINE__,__FILE__);

    i3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "i3", NC_INT, RANK_i3, i3_dims, &i3_id);
    check_err(stat,__LINE__,__FILE__);

    f3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "f3", NC_FLOAT, RANK_f3, f3_dims, &f3_id);
    check_err(stat,__LINE__,__FILE__);

    d3_dims[0] = D3_dim;
    stat = nc_def_var(ncid, "d3", NC_DOUBLE, RANK_d3, d3_dims, &d3_id);
    check_err(stat,__LINE__,__FILE__);

    cr1_dims[0] = Dr_dim;
    cr1_dims[1] = D1_dim;
    stat = nc_def_var(ncid, "cr1", NC_CHAR, RANK_cr1, cr1_dims, &cr1_id);
    check_err(stat,__LINE__,__FILE__);

    br2_dims[0] = Dr_dim;
    br2_dims[1] = D2_dim;
    stat = nc_def_var(ncid, "br2", NC_BYTE, RANK_br2, br2_dims, &br2_id);
    check_err(stat,__LINE__,__FILE__);

    sr3_dims[0] = Dr_dim;
    sr3_dims[1] = D3_dim;
    stat = nc_def_var(ncid, "sr3", NC_SHORT, RANK_sr3, sr3_dims, &sr3_id);
    check_err(stat,__LINE__,__FILE__);

    f11_dims[0] = D1_dim;
    f11_dims[1] = D1_dim;
    stat = nc_def_var(ncid, "f11", NC_FLOAT, RANK_f11, f11_dims, &f11_id);
    check_err(stat,__LINE__,__FILE__);

    d12_dims[0] = D1_dim;
    d12_dims[1] = D2_dim;
    stat = nc_def_var(ncid, "d12", NC_DOUBLE, RANK_d12, d12_dims, &d12_id);
    check_err(stat,__LINE__,__FILE__);

    c13_dims[0] = D1_dim;
    c13_dims[1] = D3_dim;
    stat = nc_def_var(ncid, "c13", NC_CHAR, RANK_c13, c13_dims, &c13_id);
    check_err(stat,__LINE__,__FILE__);

    s21_dims[0] = D2_dim;
    s21_dims[1] = D1_dim;
    stat = nc_def_var(ncid, "s21", NC_SHORT, RANK_s21, s21_dims, &s21_id);
    check_err(stat,__LINE__,__FILE__);

    i22_dims[0] = D2_dim;
    i22_dims[1] = D2_dim;
    stat = nc_def_var(ncid, "i22", NC_INT, RANK_i22, i22_dims, &i22_id);
    check_err(stat,__LINE__,__FILE__);

    f23_dims[0] = D2_dim;
    f23_dims[1] = D3_dim;
    stat = nc_def_var(ncid, "f23", NC_FLOAT, RANK_f23, f23_dims, &f23_id);
    check_err(stat,__LINE__,__FILE__);

    c31_dims[0] = D3_dim;
    c31_dims[1] = D1_dim;
    stat = nc_def_var(ncid, "c31", NC_CHAR, RANK_c31, c31_dims, &c31_id);
    check_err(stat,__LINE__,__FILE__);

    b32_dims[0] = D3_dim;
    b32_dims[1] = D2_dim;
    stat = nc_def_var(ncid, "b32", NC_BYTE, RANK_b32, b32_dims, &b32_id);
    check_err(stat,__LINE__,__FILE__);

    s33_dims[0] = D3_dim;
    s33_dims[1] = D3_dim;
    stat = nc_def_var(ncid, "s33", NC_SHORT, RANK_s33, s33_dims, &s33_id);
    check_err(stat,__LINE__,__FILE__);

    sr11_dims[0] = Dr_dim;
    sr11_dims[1] = D1_dim;
    sr11_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "sr11", NC_SHORT, RANK_sr11, sr11_dims, &sr11_id);
    check_err(stat,__LINE__,__FILE__);

    ir12_dims[0] = Dr_dim;
    ir12_dims[1] = D1_dim;
    ir12_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "ir12", NC_INT, RANK_ir12, ir12_dims, &ir12_id);
    check_err(stat,__LINE__,__FILE__);

    fr13_dims[0] = Dr_dim;
    fr13_dims[1] = D1_dim;
    fr13_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "fr13", NC_FLOAT, RANK_fr13, fr13_dims, &fr13_id);
    check_err(stat,__LINE__,__FILE__);

    cr21_dims[0] = Dr_dim;
    cr21_dims[1] = D2_dim;
    cr21_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "cr21", NC_CHAR, RANK_cr21, cr21_dims, &cr21_id);
    check_err(stat,__LINE__,__FILE__);

    br22_dims[0] = Dr_dim;
    br22_dims[1] = D2_dim;
    br22_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "br22", NC_BYTE, RANK_br22, br22_dims, &br22_id);
    check_err(stat,__LINE__,__FILE__);

    sr23_dims[0] = Dr_dim;
    sr23_dims[1] = D2_dim;
    sr23_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "sr23", NC_SHORT, RANK_sr23, sr23_dims, &sr23_id);
    check_err(stat,__LINE__,__FILE__);

    fr31_dims[0] = Dr_dim;
    fr31_dims[1] = D3_dim;
    fr31_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "fr31", NC_FLOAT, RANK_fr31, fr31_dims, &fr31_id);
    check_err(stat,__LINE__,__FILE__);

    dr32_dims[0] = Dr_dim;
    dr32_dims[1] = D3_dim;
    dr32_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "dr32", NC_DOUBLE, RANK_dr32, dr32_dims, &dr32_id);
    check_err(stat,__LINE__,__FILE__);

    cr33_dims[0] = Dr_dim;
    cr33_dims[1] = D3_dim;
    cr33_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "cr33", NC_CHAR, RANK_cr33, cr33_dims, &cr33_id);
    check_err(stat,__LINE__,__FILE__);

    c111_dims[0] = D1_dim;
    c111_dims[1] = D1_dim;
    c111_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "c111", NC_CHAR, RANK_c111, c111_dims, &c111_id);
    check_err(stat,__LINE__,__FILE__);

    b112_dims[0] = D1_dim;
    b112_dims[1] = D1_dim;
    b112_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "b112", NC_BYTE, RANK_b112, b112_dims, &b112_id);
    check_err(stat,__LINE__,__FILE__);

    s113_dims[0] = D1_dim;
    s113_dims[1] = D1_dim;
    s113_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "s113", NC_SHORT, RANK_s113, s113_dims, &s113_id);
    check_err(stat,__LINE__,__FILE__);

    f121_dims[0] = D1_dim;
    f121_dims[1] = D2_dim;
    f121_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "f121", NC_FLOAT, RANK_f121, f121_dims, &f121_id);
    check_err(stat,__LINE__,__FILE__);

    d122_dims[0] = D1_dim;
    d122_dims[1] = D2_dim;
    d122_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "d122", NC_DOUBLE, RANK_d122, d122_dims, &d122_id);
    check_err(stat,__LINE__,__FILE__);

    c123_dims[0] = D1_dim;
    c123_dims[1] = D2_dim;
    c123_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "c123", NC_CHAR, RANK_c123, c123_dims, &c123_id);
    check_err(stat,__LINE__,__FILE__);

    s131_dims[0] = D1_dim;
    s131_dims[1] = D3_dim;
    s131_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "s131", NC_SHORT, RANK_s131, s131_dims, &s131_id);
    check_err(stat,__LINE__,__FILE__);

    i132_dims[0] = D1_dim;
    i132_dims[1] = D3_dim;
    i132_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "i132", NC_INT, RANK_i132, i132_dims, &i132_id);
    check_err(stat,__LINE__,__FILE__);

    f133_dims[0] = D1_dim;
    f133_dims[1] = D3_dim;
    f133_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "f133", NC_FLOAT, RANK_f133, f133_dims, &f133_id);
    check_err(stat,__LINE__,__FILE__);

    f211_dims[0] = D2_dim;
    f211_dims[1] = D1_dim;
    f211_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "f211", NC_FLOAT, RANK_f211, f211_dims, &f211_id);
    check_err(stat,__LINE__,__FILE__);

    d212_dims[0] = D2_dim;
    d212_dims[1] = D1_dim;
    d212_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "d212", NC_DOUBLE, RANK_d212, d212_dims, &d212_id);
    check_err(stat,__LINE__,__FILE__);

    c213_dims[0] = D2_dim;
    c213_dims[1] = D1_dim;
    c213_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "c213", NC_CHAR, RANK_c213, c213_dims, &c213_id);
    check_err(stat,__LINE__,__FILE__);

    s221_dims[0] = D2_dim;
    s221_dims[1] = D2_dim;
    s221_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "s221", NC_SHORT, RANK_s221, s221_dims, &s221_id);
    check_err(stat,__LINE__,__FILE__);

    i222_dims[0] = D2_dim;
    i222_dims[1] = D2_dim;
    i222_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "i222", NC_INT, RANK_i222, i222_dims, &i222_id);
    check_err(stat,__LINE__,__FILE__);

    f223_dims[0] = D2_dim;
    f223_dims[1] = D2_dim;
    f223_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "f223", NC_FLOAT, RANK_f223, f223_dims, &f223_id);
    check_err(stat,__LINE__,__FILE__);

    c231_dims[0] = D2_dim;
    c231_dims[1] = D3_dim;
    c231_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "c231", NC_CHAR, RANK_c231, c231_dims, &c231_id);
    check_err(stat,__LINE__,__FILE__);

    b232_dims[0] = D2_dim;
    b232_dims[1] = D3_dim;
    b232_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "b232", NC_BYTE, RANK_b232, b232_dims, &b232_id);
    check_err(stat,__LINE__,__FILE__);

    s233_dims[0] = D2_dim;
    s233_dims[1] = D3_dim;
    s233_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "s233", NC_SHORT, RANK_s233, s233_dims, &s233_id);
    check_err(stat,__LINE__,__FILE__);

    s311_dims[0] = D3_dim;
    s311_dims[1] = D1_dim;
    s311_dims[2] = D1_dim;
    stat = nc_def_var(ncid, "s311", NC_SHORT, RANK_s311, s311_dims, &s311_id);
    check_err(stat,__LINE__,__FILE__);

    i312_dims[0] = D3_dim;
    i312_dims[1] = D1_dim;
    i312_dims[2] = D2_dim;
    stat = nc_def_var(ncid, "i312", NC_INT, RANK_i312, i312_dims, &i312_id);
    check_err(stat,__LINE__,__FILE__);

    f313_dims[0] = D3_dim;
    f313_dims[1] = D1_dim;
    f313_dims[2] = D3_dim;
    stat = nc_def_var(ncid, "f313", NC_FLOAT, RANK_f313, f313_dims, &f313_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "var-name-dashes", NC_DOUBLE, RANK_var_MINUS_name_MINUS_dashes, 0, &var_MINUS_name_MINUS_dashes_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "var.name.dots", NC_DOUBLE, RANK_var_PERIOD_name_PERIOD_dots, 0, &var_PERIOD_name_PERIOD_dots_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "var+name+plusses", NC_DOUBLE, RANK_var_PLUS_name_PLUS_plusses, 0, &var_PLUS_name_PLUS_plusses_id);
    check_err(stat,__LINE__,__FILE__);

    stat = nc_def_var(ncid, "var@name@ats", NC_DOUBLE, RANK_var_ATSIGN_name_ATSIGN_ats, 0, &var_ATSIGN_name_ATSIGN_ats_id);
    check_err(stat,__LINE__,__FILE__);

    /* assign global attributes */

    {
    stat = nc_put_att_text(ncid, NC_GLOBAL, "Gc", 1, "");
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const signed char c0_Gb_att[2] = {-128, 127} ;
    stat = nc_put_att_schar(ncid, NC_GLOBAL, "Gb", NC_BYTE, 2, c0_Gb_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const short c0_Gs_att[3] = {-32768, 0, 32767} ;
    stat = nc_put_att_short(ncid, NC_GLOBAL, "Gs", NC_SHORT, 3, c0_Gs_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_Gi_att[3] = {-2147483647, 0, 2147483647} ;
    stat = nc_put_att_int(ncid, NC_GLOBAL, "Gi", NC_INT, 3, c0_Gi_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const float c0_Gf_att[3] = {((float)-9.9999996e+35), ((float)0), ((float)9.9999996e+35)} ;
    stat = nc_put_att_float(ncid, NC_GLOBAL, "Gf", NC_FLOAT, 3, c0_Gf_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const double c0_Gd_att[3] = {((double)-1e+308), ((double)0), ((double)1e+308)} ;
    stat = nc_put_att_double(ncid, NC_GLOBAL, "Gd", NC_DOUBLE, 3, c0_Gd_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_Gatt_MINUS_name_MINUS_dashes_att[1] = {-1} ;
    stat = nc_put_att_int(ncid, NC_GLOBAL, "Gatt-name-dashes", NC_INT, 1, c0_Gatt_MINUS_name_MINUS_dashes_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_Gatt_DOT_name_DOT_dots_att[1] = {-2} ;
    stat = nc_put_att_int(ncid, NC_GLOBAL, "Gatt.name.dots", NC_INT, 1, c0_Gatt_DOT_name_DOT_dots_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_Gatt_PLUS_name_PLUS_plusses_att[1] = {-3} ;
    stat = nc_put_att_int(ncid, NC_GLOBAL, "Gatt+name+plusses", NC_INT, 1, c0_Gatt_PLUS_name_PLUS_plusses_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_Gatt_ATSIGN_name_ATSIGN_ats_att[1] = {-4} ;
    stat = nc_put_att_int(ncid, NC_GLOBAL, "Gatt@name@ats", NC_INT, 1, c0_Gatt_ATSIGN_name_ATSIGN_ats_att);
    check_err(stat,__LINE__,__FILE__);
    }


    /* assign per-variable attributes */

    {
    static const int c0_att_MINUS_name_MINUS_dashes_att[1] = {4} ;
    stat = nc_put_att_int(ncid, c_id, "att-name-dashes", NC_INT, 1, c0_att_MINUS_name_MINUS_dashes_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_att_DOT_name_DOT_dots_att[1] = {5} ;
    stat = nc_put_att_int(ncid, c_id, "att.name.dots", NC_INT, 1, c0_att_DOT_name_DOT_dots_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_att_PLUS_name_PLUS_plusses_att[1] = {6} ;
    stat = nc_put_att_int(ncid, c_id, "att+name+plusses", NC_INT, 1, c0_att_PLUS_name_PLUS_plusses_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_att_ATSIGN_name_ATSIGN_ats_att[1] = {7} ;
    stat = nc_put_att_int(ncid, c_id, "att@name@ats", NC_INT, 1, c0_att_ATSIGN_name_ATSIGN_ats_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    stat = nc_put_att_text(ncid, b_id, "c", 1, "");
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const signed char c0_b_att[4] = {0, 127, -128, -1} ;
    stat = nc_put_att_schar(ncid, s_id, "b", NC_BYTE, 4, c0_b_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const short c0_s_att[3] = {-32768, 0, 32767} ;
    stat = nc_put_att_short(ncid, s_id, "s", NC_SHORT, 3, c0_s_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const int c0_i_att[3] = {-2147483647, 0, 2147483647} ;
    stat = nc_put_att_int(ncid, i_id, "i", NC_INT, 3, c0_i_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const float c0_f_att[3] = {((float)-9.9999996e+35), ((float)0), ((float)9.9999996e+35)} ;
    stat = nc_put_att_float(ncid, i_id, "f", NC_FLOAT, 3, c0_f_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    static const double c0_d_att[3] = {((double)-1e+308), ((double)0), ((double)1e+308)} ;
    stat = nc_put_att_double(ncid, i_id, "d", NC_DOUBLE, 3, c0_d_att);
    check_err(stat,__LINE__,__FILE__);
    }

    {
    stat = nc_put_att_text(ncid, f_id, "c", 1, "x");
    check_err(stat,__LINE__,__FILE__);
    }

    {
    stat = nc_put_att_text(ncid, d_id, "c", 8, "abcd\tZ$&");
    check_err(stat,__LINE__,__FILE__);
    }


    /* leave define mode */
    stat = nc_enddef (ncid);
    check_err(stat,__LINE__,__FILE__);

    /* assign variable data */

    {
    size_t count = 0;
    static char c_data[1] = {'2'};
    stat = nc_put_var1(ncid, c_id, &count, c_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static signed char b_data[1] = {-2};
    stat = nc_put_var1(ncid, b_id, &count, b_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static short s_data[1] = {-5};
    stat = nc_put_var1(ncid, s_id, &count, s_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static int i_data[1] = {-20};
    stat = nc_put_var1(ncid, i_id, &count, i_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static float f_data[1] = {((float)-9)};
    stat = nc_put_var1(ncid, f_id, &count, f_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static double d_data[1] = {((double)-10)};
    stat = nc_put_var1(ncid, d_id, &count, d_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* cr_data = "ab\000\000" ;
    size_t cr_startset[1] = {0} ;
    size_t cr_countset[1] = {2};
    stat = nc_put_vara(ncid, cr_id, cr_startset, cr_countset, cr_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char br_data[2] = {-128, 127} ;
    size_t br_startset[1] = {0} ;
    size_t br_countset[1] = {2};
    stat = nc_put_vara(ncid, br_id, br_startset, br_countset, br_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short sr_data[2] = {-32768, 32767} ;
    size_t sr_startset[1] = {0} ;
    size_t sr_countset[1] = {2};
    stat = nc_put_vara(ncid, sr_id, sr_startset, sr_countset, sr_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int ir_data[2] = {-2147483646, 2147483647} ;
    size_t ir_startset[1] = {0} ;
    size_t ir_countset[1] = {2};
    stat = nc_put_vara(ncid, ir_id, ir_startset, ir_countset, ir_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float fr_data[2] = {((float)-9.9999996e+35), ((float)9.9999996e+35)} ;
    size_t fr_startset[1] = {0} ;
    size_t fr_countset[1] = {2};
    stat = nc_put_vara(ncid, fr_id, fr_startset, fr_countset, fr_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double dr_data[2] = {((double)-1e+308), ((double)1e+308)} ;
    size_t dr_startset[1] = {0} ;
    size_t dr_countset[1] = {2};
    stat = nc_put_vara(ncid, dr_id, dr_startset, dr_countset, dr_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c1_data = "\000" ;
    size_t c1_startset[1] = {0} ;
    size_t c1_countset[1] = {1};
    stat = nc_put_vara(ncid, c1_id, c1_startset, c1_countset, c1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b1_data[1] = {-128} ;
    size_t b1_startset[1] = {0} ;
    size_t b1_countset[1] = {1};
    stat = nc_put_vara(ncid, b1_id, b1_startset, b1_countset, b1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s1_data[1] = {-32768} ;
    size_t s1_startset[1] = {0} ;
    size_t s1_countset[1] = {1};
    stat = nc_put_vara(ncid, s1_id, s1_startset, s1_countset, s1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i1_data[1] = {-2147483646} ;
    size_t i1_startset[1] = {0} ;
    size_t i1_countset[1] = {1};
    stat = nc_put_vara(ncid, i1_id, i1_startset, i1_countset, i1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f1_data[1] = {((float)-9.9999996e+35)} ;
    size_t f1_startset[1] = {0} ;
    size_t f1_countset[1] = {1};
    stat = nc_put_vara(ncid, f1_id, f1_startset, f1_countset, f1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d1_data[1] = {((double)-1e+308)} ;
    size_t d1_startset[1] = {0} ;
    size_t d1_countset[1] = {1};
    stat = nc_put_vara(ncid, d1_id, d1_startset, d1_countset, d1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c2_data = "ab\000\000" ;
    size_t c2_startset[1] = {0} ;
    size_t c2_countset[1] = {2};
    stat = nc_put_vara(ncid, c2_id, c2_startset, c2_countset, c2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b2_data[2] = {-128, 127} ;
    size_t b2_startset[1] = {0} ;
    size_t b2_countset[1] = {2};
    stat = nc_put_vara(ncid, b2_id, b2_startset, b2_countset, b2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s2_data[2] = {-32768, 32767} ;
    size_t s2_startset[1] = {0} ;
    size_t s2_countset[1] = {2};
    stat = nc_put_vara(ncid, s2_id, s2_startset, s2_countset, s2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i2_data[2] = {-2147483646, 2147483647} ;
    size_t i2_startset[1] = {0} ;
    size_t i2_countset[1] = {2};
    stat = nc_put_vara(ncid, i2_id, i2_startset, i2_countset, i2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f2_data[2] = {((float)-9.9999996e+35), ((float)9.9999996e+35)} ;
    size_t f2_startset[1] = {0} ;
    size_t f2_countset[1] = {2};
    stat = nc_put_vara(ncid, f2_id, f2_startset, f2_countset, f2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d2_data[2] = {((double)-1e+308), ((double)1e+308)} ;
    size_t d2_startset[1] = {0} ;
    size_t d2_countset[1] = {2};
    stat = nc_put_vara(ncid, d2_id, d2_startset, d2_countset, d2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c3_data = "\001À.\000\000\000\000\000\000" ;
    size_t c3_startset[1] = {0} ;
    size_t c3_countset[1] = {3};
    stat = nc_put_vara(ncid, c3_id, c3_startset, c3_countset, c3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b3_data[3] = {-128, 127, -1} ;
    size_t b3_startset[1] = {0} ;
    size_t b3_countset[1] = {3};
    stat = nc_put_vara(ncid, b3_id, b3_startset, b3_countset, b3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s3_data[3] = {-32768, 0, 32767} ;
    size_t s3_startset[1] = {0} ;
    size_t s3_countset[1] = {3};
    stat = nc_put_vara(ncid, s3_id, s3_startset, s3_countset, s3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i3_data[3] = {-2147483646, 0, 2147483647} ;
    size_t i3_startset[1] = {0} ;
    size_t i3_countset[1] = {3};
    stat = nc_put_vara(ncid, i3_id, i3_startset, i3_countset, i3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f3_data[3] = {((float)-9.9999996e+35), ((float)0), ((float)9.9999996e+35)} ;
    size_t f3_startset[1] = {0} ;
    size_t f3_countset[1] = {3};
    stat = nc_put_vara(ncid, f3_id, f3_startset, f3_countset, f3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d3_data[3] = {((double)-1e+308), ((double)0), ((double)1e+308)} ;
    size_t d3_startset[1] = {0} ;
    size_t d3_countset[1] = {3};
    stat = nc_put_vara(ncid, d3_id, d3_startset, d3_countset, d3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* cr1_data = "xy" ;
    size_t cr1_startset[2] = {0, 0} ;
    size_t cr1_countset[2] = {2, 1};
    stat = nc_put_vara(ncid, cr1_id, cr1_startset, cr1_countset, cr1_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char br2_data[4] = {-24, -26, -20, -22} ;
    size_t br2_startset[2] = {0, 0} ;
    size_t br2_countset[2] = {2, 2};
    stat = nc_put_vara(ncid, br2_id, br2_startset, br2_countset, br2_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short sr3_data[6] = {-375, -380, -385, -350, -355, -360} ;
    size_t sr3_startset[2] = {0, 0} ;
    size_t sr3_countset[2] = {2, 3};
    stat = nc_put_vara(ncid, sr3_id, sr3_startset, sr3_countset, sr3_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f11_data[1] = {((float)-2187)} ;
    size_t f11_startset[2] = {0, 0} ;
    size_t f11_countset[2] = {1, 1};
    stat = nc_put_vara(ncid, f11_id, f11_startset, f11_countset, f11_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d12_data[2] = {((double)-3000), ((double)-3010)} ;
    size_t d12_startset[2] = {0, 0} ;
    size_t d12_countset[2] = {1, 2};
    stat = nc_put_vara(ncid, d12_id, d12_startset, d12_countset, d12_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c13_data = "\tb\177" ;
    size_t c13_startset[2] = {0, 0} ;
    size_t c13_countset[2] = {1, 3};
    stat = nc_put_vara(ncid, c13_id, c13_startset, c13_countset, c13_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s21_data[2] = {-375, -350} ;
    size_t s21_startset[2] = {0, 0} ;
    size_t s21_countset[2] = {2, 1};
    stat = nc_put_vara(ncid, s21_id, s21_startset, s21_countset, s21_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i22_data[4] = {-24000, -24020, -23600, -23620} ;
    size_t i22_startset[2] = {0, 0} ;
    size_t i22_countset[2] = {2, 2};
    stat = nc_put_vara(ncid, i22_id, i22_startset, i22_countset, i22_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f23_data[6] = {((float)-2187), ((float)-2196), ((float)-2205), ((float)-2106), ((float)-2115), ((float)-2124)} ;
    size_t f23_startset[2] = {0, 0} ;
    size_t f23_countset[2] = {2, 3};
    stat = nc_put_vara(ncid, f23_id, f23_startset, f23_countset, f23_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c31_data = "+- " ;
    size_t c31_startset[2] = {0, 0} ;
    size_t c31_countset[2] = {3, 1};
    stat = nc_put_vara(ncid, c31_id, c31_startset, c31_countset, c31_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b32_data[6] = {-24, -26, -20, -22, -16, -18} ;
    size_t b32_startset[2] = {0, 0} ;
    size_t b32_countset[2] = {3, 2};
    stat = nc_put_vara(ncid, b32_id, b32_startset, b32_countset, b32_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s33_data[9] = {-375, -380, -385, -350, -355, -360, -325, -330, -335} ;
    size_t s33_startset[2] = {0, 0} ;
    size_t s33_countset[2] = {3, 3};
    stat = nc_put_vara(ncid, s33_id, s33_startset, s33_countset, s33_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short sr11_data[2] = {2500, 2375} ;
    size_t sr11_startset[3] = {0, 0, 0} ;
    size_t sr11_countset[3] = {2, 1, 1};
    stat = nc_put_vara(ncid, sr11_id, sr11_startset, sr11_countset, sr11_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int ir12_data[4] = {640000, 639980, 632000, 631980} ;
    size_t ir12_startset[3] = {0, 0, 0} ;
    size_t ir12_countset[3] = {2, 1, 2};
    stat = nc_put_vara(ncid, ir12_id, ir12_startset, ir12_countset, ir12_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float fr13_data[6] = {((float)26244), ((float)26235), ((float)26226), ((float)25515), ((float)25506), ((float)25497)} ;
    size_t fr13_startset[3] = {0, 0, 0} ;
    size_t fr13_countset[3] = {2, 1, 3};
    stat = nc_put_vara(ncid, fr13_id, fr13_startset, fr13_countset, fr13_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* cr21_data = "@DHL" ;
    size_t cr21_startset[3] = {0, 0, 0} ;
    size_t cr21_countset[3] = {2, 2, 1};
    stat = nc_put_vara(ncid, cr21_id, cr21_startset, cr21_countset, cr21_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char br22_data[8] = {64, 62, 68, 66, 56, 54, 60, 58} ;
    size_t br22_startset[3] = {0, 0, 0} ;
    size_t br22_countset[3] = {2, 2, 2};
    stat = nc_put_vara(ncid, br22_id, br22_startset, br22_countset, br22_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short sr23_data[12] = {2500, 2495, 2490, 2525, 2520, 2515, 2375, 2370, 2365, 2400, 2395, 2390} ;
    size_t sr23_startset[3] = {0, 0, 0} ;
    size_t sr23_countset[3] = {2, 2, 3};
    stat = nc_put_vara(ncid, sr23_id, sr23_startset, sr23_countset, sr23_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float fr31_data[6] = {((float)26244), ((float)26325), ((float)26406), ((float)25515), ((float)25596), ((float)25677)} ;
    size_t fr31_startset[3] = {0, 0, 0} ;
    size_t fr31_countset[3] = {2, 3, 1};
    stat = nc_put_vara(ncid, fr31_id, fr31_startset, fr31_countset, fr31_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double dr32_data[12] = {((double)40000), ((double)39990), ((double)40100), ((double)40090), ((double)40200), ((double)40190), ((double)39000), ((double)38990), ((double)39100), ((double)39090), ((double)39200), ((double)39190)} ;
    size_t dr32_startset[3] = {0, 0, 0} ;
    size_t dr32_countset[3] = {2, 3, 2};
    stat = nc_put_vara(ncid, dr32_id, dr32_startset, dr32_countset, dr32_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* cr33_data = "1\000\000two3\000\0004\000\0005\000\000six" ;
    size_t cr33_startset[3] = {0, 0, 0} ;
    size_t cr33_countset[3] = {2, 3, 3};
    stat = nc_put_vara(ncid, cr33_id, cr33_startset, cr33_countset, cr33_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c111_data = "@" ;
    size_t c111_startset[3] = {0, 0, 0} ;
    size_t c111_countset[3] = {1, 1, 1};
    stat = nc_put_vara(ncid, c111_id, c111_startset, c111_countset, c111_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b112_data[2] = {64, 62} ;
    size_t b112_startset[3] = {0, 0, 0} ;
    size_t b112_countset[3] = {1, 1, 2};
    stat = nc_put_vara(ncid, b112_id, b112_startset, b112_countset, b112_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s113_data[3] = {2500, 2495, 2490} ;
    size_t s113_startset[3] = {0, 0, 0} ;
    size_t s113_countset[3] = {1, 1, 3};
    stat = nc_put_vara(ncid, s113_id, s113_startset, s113_countset, s113_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f121_data[2] = {((float)26244), ((float)26325)} ;
    size_t f121_startset[3] = {0, 0, 0} ;
    size_t f121_countset[3] = {1, 2, 1};
    stat = nc_put_vara(ncid, f121_id, f121_startset, f121_countset, f121_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d122_data[4] = {((double)40000), ((double)39990), ((double)40100), ((double)40090)} ;
    size_t d122_startset[3] = {0, 0, 0} ;
    size_t d122_countset[3] = {1, 2, 2};
    stat = nc_put_vara(ncid, d122_id, d122_startset, d122_countset, d122_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c123_data = "one2\000\000" ;
    size_t c123_startset[3] = {0, 0, 0} ;
    size_t c123_countset[3] = {1, 2, 3};
    stat = nc_put_vara(ncid, c123_id, c123_startset, c123_countset, c123_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s131_data[3] = {2500, 2525, 2550} ;
    size_t s131_startset[3] = {0, 0, 0} ;
    size_t s131_countset[3] = {1, 3, 1};
    stat = nc_put_vara(ncid, s131_id, s131_startset, s131_countset, s131_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i132_data[6] = {640000, 639980, 640400, 640380, 640800, 640780} ;
    size_t i132_startset[3] = {0, 0, 0} ;
    size_t i132_countset[3] = {1, 3, 2};
    stat = nc_put_vara(ncid, i132_id, i132_startset, i132_countset, i132_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f133_data[9] = {((float)26244), ((float)26235), ((float)26226), ((float)26325), ((float)26316), ((float)26307), ((float)26406), ((float)26397), ((float)26388)} ;
    size_t f133_startset[3] = {0, 0, 0} ;
    size_t f133_countset[3] = {1, 3, 3};
    stat = nc_put_vara(ncid, f133_id, f133_startset, f133_countset, f133_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f211_data[2] = {((float)26244), ((float)25515)} ;
    size_t f211_startset[3] = {0, 0, 0} ;
    size_t f211_countset[3] = {2, 1, 1};
    stat = nc_put_vara(ncid, f211_id, f211_startset, f211_countset, f211_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    double d212_data[4] = {((double)40000), ((double)39990), ((double)39000), ((double)38990)} ;
    size_t d212_startset[3] = {0, 0, 0} ;
    size_t d212_countset[3] = {2, 1, 2};
    stat = nc_put_vara(ncid, d212_id, d212_startset, d212_countset, d212_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c213_data = "\000\000\000\000\000\000" ;
    size_t c213_startset[3] = {0, 0, 0} ;
    size_t c213_countset[3] = {2, 1, 3};
    stat = nc_put_vara(ncid, c213_id, c213_startset, c213_countset, c213_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s221_data[4] = {2500, 2525, 2375, 2400} ;
    size_t s221_startset[3] = {0, 0, 0} ;
    size_t s221_countset[3] = {2, 2, 1};
    stat = nc_put_vara(ncid, s221_id, s221_startset, s221_countset, s221_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i222_data[8] = {640000, 639980, 640400, 640380, 632000, 631980, 632400, 632380} ;
    size_t i222_startset[3] = {0, 0, 0} ;
    size_t i222_countset[3] = {2, 2, 2};
    stat = nc_put_vara(ncid, i222_id, i222_startset, i222_countset, i222_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f223_data[12] = {((float)26244), ((float)26235), ((float)26226), ((float)26325), ((float)26316), ((float)26307), ((float)25515), ((float)25506), ((float)25497), ((float)25596), ((float)25587), ((float)25578)} ;
    size_t f223_startset[3] = {0, 0, 0} ;
    size_t f223_countset[3] = {2, 2, 3};
    stat = nc_put_vara(ncid, f223_id, f223_startset, f223_countset, f223_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    char* c231_data = "@DHHLP" ;
    size_t c231_startset[3] = {0, 0, 0} ;
    size_t c231_countset[3] = {2, 3, 1};
    stat = nc_put_vara(ncid, c231_id, c231_startset, c231_countset, c231_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    signed char b232_data[12] = {64, 62, 68, 66, 72, 70, 56, 54, 60, 58, 64, 62} ;
    size_t b232_startset[3] = {0, 0, 0} ;
    size_t b232_countset[3] = {2, 3, 2};
    stat = nc_put_vara(ncid, b232_id, b232_startset, b232_countset, b232_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s233_data[18] = {2500, 2495, 2490, 2525, 2520, 2515, 2550, 2545, 2540, 2375, 2370, 2365, 2400, 2395, 2390, 2425, 2420, 2415} ;
    size_t s233_startset[3] = {0, 0, 0} ;
    size_t s233_countset[3] = {2, 3, 3};
    stat = nc_put_vara(ncid, s233_id, s233_startset, s233_countset, s233_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    short s311_data[3] = {2500, 2375, 2250} ;
    size_t s311_startset[3] = {0, 0, 0} ;
    size_t s311_countset[3] = {3, 1, 1};
    stat = nc_put_vara(ncid, s311_id, s311_startset, s311_countset, s311_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    int i312_data[6] = {640000, 639980, 632000, 631980, 624000, 623980} ;
    size_t i312_startset[3] = {0, 0, 0} ;
    size_t i312_countset[3] = {3, 1, 2};
    stat = nc_put_vara(ncid, i312_id, i312_startset, i312_countset, i312_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    float f313_data[9] = {((float)26244), ((float)26235), ((float)26226), ((float)25515), ((float)25506), ((float)25497), ((float)24786), ((float)24777), ((float)24768)} ;
    size_t f313_startset[3] = {0, 0, 0} ;
    size_t f313_countset[3] = {3, 1, 3};
    stat = nc_put_vara(ncid, f313_id, f313_startset, f313_countset, f313_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static double var_MINUS_name_MINUS_dashes_data[1] = {((double)-1)};
    stat = nc_put_var1(ncid, var_MINUS_name_MINUS_dashes_id, &count, var_MINUS_name_MINUS_dashes_data);
    check_err(stat,__LINE__,__FILE__);
    }


    {
    size_t count = 0;
    static double var_PERIOD_name_PERIOD_dots_data[1] = {((double)-2)};
    stat = nc_put_var1(ncid, var_PERIOD_name_PERIOD_dots_id, &count, var_PERIOD_name_PERIOD_dots_data);
    check_err(stat,__LINE__,__FILE__);
    }


    stat = nc_close(ncid);
    check_err(stat,__LINE__,__FILE__);
    return 0;
}
Exemple #7
0
int
main(int argc, char **argv)
{
    (void) signal(SIGFPE, SIG_IGN);

   printf("\n*** Testing netcdf-4 attribute functions.\n");
   printf("*** testing really simple global atts...");
#define NUM_SIMPLE_ATTS 9
   {
      int ncid;
      char name[NUM_SIMPLE_ATTS][ATT_MAX_NAME + 1] = {"Gc", "Gb", "Gs", "Gi", "Gf", 
						      "Gd", "G7", "G8", "G9"};
      char name_in[NC_MAX_NAME];
      int j;

      /* Create a file with some global atts. */
      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
      for (j = 0; j < NUM_SIMPLE_ATTS; j++)
	 if (nc_put_att_int(ncid, NC_GLOBAL, name[j], NC_INT, 0, NULL)) ERR;      
      if (nc_close(ncid)) ERR;
      
      /* Reopen the file and check the order. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      for (j = 0; j < NUM_SIMPLE_ATTS; j++)
      {
	 if (nc_inq_attname(ncid, NC_GLOBAL, j, name_in)) ERR;
	 if (strcmp(name_in, name[j])) ERR;
      }

      /* Close up shop. */
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("*** testing simple global atts...");
   {      
      int ncid;
      nc_type att_type;
      size_t att_len;
      int i;

      char *speech_in;
      signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
      unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
      short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
      /*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
      int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
      float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
      double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
      unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
      unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
      unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
      long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};


      /* This won't work, because classic files can't create these types. */
      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
      if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, 
			    ushort_out) != NC_ESTRICTNC3) ERR;      
      if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, 
			  uint_out) != NC_ESTRICTNC3) ERR;      
      if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, 
			      int64_out) != NC_ESTRICTNC3) ERR;      
      if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, 
			       uint64_out) != NC_ESTRICTNC3) ERR;      
      if (nc_close(ncid)) ERR;

      /* Create a file with a global attribute of each type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;      
      if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;      
      if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
      if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;      
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;      
      if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;      
      if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;      
      if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;      
      if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;      
      if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;      
      if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;      
      if (nc_close(ncid)) ERR;

      /* Open the file and check attributes. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      /* Check text. */
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len))
	 ERR;
      if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
      if (!(speech_in = malloc(att_len + 1))) ERR;
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;      
      if (strcmp(speech, speech_in)) ERR;
      free(speech_in);
      /* Check numeric values. */
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != schar_out[i]) ERR;
      if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (uchar_in[i] != uchar_out[i]) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != short_out[i]) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != int_out[i]) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != float_out[i]) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != double_out[i]) ERR;
      if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (ushort_in[i] != ushort_out[i]) ERR;
      if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (uint_in[i] != uint_out[i]) ERR;
      if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int64_in[i] != int64_out[i]) ERR;
      if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (uint64_in[i] != uint64_out[i]) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("*** testing attribute data type conversions...");

   {
      int ncid;
      int i;

      signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
      short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
      /*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
      int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
      float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
      double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
      unsigned short ushort_in[ATT_LEN];
      unsigned int uint_in[ATT_LEN];
      unsigned long long uint64_in[ATT_LEN];
      long long int64_in[ATT_LEN];

      /* Reopen the file and try different type conversions. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;

      /* No text conversions are allowed, and people who try them shold
       * be locked up, away from decent folk! */
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_TEXT_NAME, short_in) != NC_ECHAR) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_TEXT_NAME, int_in) != NC_ECHAR) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_TEXT_NAME, float_in) != NC_ECHAR) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_TEXT_NAME, double_in) != NC_ECHAR) ERR;
/*   if (nc_get_att_ubyte(ncid, NC_GLOBAL, ATT_TEXT_NAME, uchar_in) != NC_ECHAR) ERR;*/
      if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_TEXT_NAME, ushort_in) != NC_ECHAR) ERR;
      if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint_in) != NC_ECHAR) ERR;
      if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_TEXT_NAME, int64_in) != NC_ECHAR) ERR;
      if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_TEXT_NAME, uint64_in) != NC_ECHAR) ERR;

      /* Read all atts (except text) as double. */
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SCHAR_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != schar_out[i]) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_SHORT_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != short_out[i]) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_INT_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != int_out[i]) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_FLOAT_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != float_out[i]) ERR;
      /* Read all atts (except text) as float. */
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SCHAR_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != schar_out[i]) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_SHORT_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != short_out[i]) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_INT_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != (float)int_out[i]) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != (float)double_out[i]) ERR;
      /* Read all atts (except text) as int. */
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SCHAR_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != schar_out[i]) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_SHORT_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != short_out[i]) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_FLOAT_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != (int)float_out[i]) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != (int)double_out[i]) ERR;
      /* Read all atts (except text) as short. */
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SCHAR_NAME, short_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != schar_out[i]) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_INT_NAME, short_in) != NC_ERANGE) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != (short)int_out[i]) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_FLOAT_NAME, short_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != (short)float_out[i]) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, short_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != (short)double_out[i]) ERR;
      /* Read all atts (except text) as schar. Some range errors will
       * result converting to schar. */
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in) != NC_ERANGE) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != (signed char)short_out[i]) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in) != NC_ERANGE) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != (signed char)int_out[i]) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != (signed char)float_out[i]) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != (signed char)double_out[i]) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("*** testing simple variable atts...");
   {
      int ncid, varid, dimids[2];
      nc_type att_type;
      size_t att_len;
      int i, v;

      char *speech_in;
      signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
      short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
      /*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
      int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
      float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
      double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};

      /* Create a file with two vars, attaching to each an attribute of
       * each type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
      if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
      if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;      
      if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;      
      if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;      
      if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;      
      if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;      
      if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;      
      if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR;
      if (nc_put_att_text(ncid, varid, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;      
      if (nc_put_att_schar(ncid, varid, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR; 
      if (nc_put_att_short(ncid, varid, ATT_SHORT_NAME, NC_SHORT, 3, short_out)) ERR;           
      if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;      
      if (nc_put_att_float(ncid, varid, ATT_FLOAT_NAME, NC_FLOAT, 3, float_out)) ERR;      
      if (nc_put_att_double(ncid, varid, ATT_DOUBLE_NAME, NC_DOUBLE, 3, double_out)) ERR;      
      if (nc_close(ncid)) ERR;

      /* Open the file and check attributes. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      for (v=0; v<2; v++)
      {
	 if (nc_inq_att(ncid, v, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
	 if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
	 if (!(speech_in = malloc(att_len + 1))) ERR;
	 if (nc_get_att_text(ncid, v, ATT_TEXT_NAME, speech_in)) ERR;      
	 if (strcmp(speech, speech_in)) ERR;
	 free(speech_in);
	 if (nc_get_att_schar(ncid, v, ATT_SCHAR_NAME, schar_in)) ERR;      
	 for (i = 0; i < ATT_LEN; i++)
	    if (schar_in[i] != schar_out[i]) ERR;
	 if (nc_get_att_short(ncid, v, ATT_SHORT_NAME, short_in)) ERR;      
	 for (i = 0; i < ATT_LEN; i++)
	    if (short_in[i] != short_out[i]) ERR;
	 if (nc_get_att_int(ncid, v, ATT_INT_NAME, int_in)) ERR;      
	 for (i = 0; i < ATT_LEN; i++)
	    if (int_in[i] != int_out[i]) ERR;
	 if (nc_get_att_float(ncid, v, ATT_FLOAT_NAME, float_in)) ERR;      
	 for (i = 0; i < ATT_LEN; i++)
	    if (float_in[i] != float_out[i]) ERR;
	 if (nc_get_att_double(ncid, v, ATT_DOUBLE_NAME, double_in)) ERR;      
	 for (i = 0; i < ATT_LEN; i++)
	    if (double_in[i] != double_out[i]) ERR;
      }
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("*** testing zero-length attributes...");
   {
      int ncid;

      /*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/

      /* Create a file with a global attribute of each type of zero length. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
      if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
/*   if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
      if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
      if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
      if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
      if (nc_close(ncid)) ERR;
   }

   /* Make sure we can read all these zero-length atts. */
   {
      int ncid;
      signed char schar_in[ATT_LEN];
      short short_in[ATT_LEN];
      /*int int_in[ATT_LEN], int_out[ATT_LEN] = {NC_MIN_INT, 128, NC_MAX_INT};*/
      int int_in[ATT_LEN];
      float float_in[ATT_LEN];
      double double_in[ATT_LEN];
      size_t len;
      nc_type xtype;

      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_CHAR) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_BYTE) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_SHORT) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_INT_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_INT) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_FLOAT) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, &xtype, &len)) ERR;
      if (len || xtype != NC_DOUBLE) ERR;
      /* Conversions no longer result in range errors, since there's no data. */
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing zero-length attributes and redef...(this test skipped for HDF5-1.8.0 beta1");
   {
      int ncid;
      signed char schar_in[ATT_LEN];
      short short_in[ATT_LEN];
      int int_in[ATT_LEN];
      float float_in[ATT_LEN];
      double double_in[ATT_LEN];


      /* Create a file with a global attribute of each type of zero length. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_enddef(ncid)) ERR;
      if (nc_redef(ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, 0, NULL)) ERR;
      if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, 0, NULL)) ERR;
/*   if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UCHAR, ATT_LEN, uchar_out)) ERR;*/
      if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, 0, NULL)) ERR;
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, 0, NULL)) ERR;
      if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, 0, NULL)) ERR;
      if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, 0, NULL)) ERR;
      if (nc_close(ncid)) ERR;

      /* Make sure we can read all these zero-length atts added during a
       * redef. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, NULL)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;
      /* Conversions no longer result in range errors, since there's no data. */
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_FLOAT_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_INT_NAME, schar_in)) ERR;
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SHORT_NAME, schar_in)) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;

   printf("*** testing attribute deletes and renames...");
   {
      int ncid, varid, dimids[2];
      nc_type att_type;
      size_t att_len;
      char *speech_in;
      char name_in[NC_MAX_NAME + 1];
      int attid_in, natts_in;
      int int_out[ATT_LEN] = {-100000, 128, 100000};

      /* Create a file with a global attribute. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, 
			  speech)) ERR;      
      if (nc_close(ncid)) ERR;
      
      /* Rename it. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_attid(ncid, NC_GLOBAL, ATT_TEXT_NAME, &attid_in)) ERR;
      if (attid_in != 0) ERR;
      if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
      if (strcmp(name_in, ATT_TEXT_NAME)) ERR;
      if (nc_rename_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ATT_TEXT_NAME2)) ERR;      
      if (nc_inq_attname(ncid, NC_GLOBAL, attid_in, name_in)) ERR;
      if (strcmp(name_in, ATT_TEXT_NAME2)) ERR;
      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2, &att_type, &att_len)) ERR;
      if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
      if (!(speech_in = malloc(att_len + 1))) ERR;
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME2, speech_in)) ERR;      
      if (strcmp(speech, speech_in)) ERR;
      free(speech_in);
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in) != NC_ENOTATT) ERR;      
      if (nc_close(ncid)) ERR;

      /* Now delete the att. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_del_att(ncid, NC_GLOBAL, ATT_TEXT_NAME2)) ERR;
      if (nc_close(ncid)) ERR;

      /* Now create a file with a variable, which has an att. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;      
      if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
      if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
      if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;      
      if (nc_close(ncid)) ERR;
      
      /* Reopen the file and delete it. Make sure it's gone. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
      if (nc_close(ncid)) ERR;

      /* Reopen the file and readd the attribute. Enddef and redef,
       * and delete it, then check to make sure it's gone. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_put_att_int(ncid, varid, ATT_INT_NAME, NC_INT, 3, int_out)) ERR;      
      if (nc_enddef(ncid)) ERR;
      if (nc_redef(ncid)) ERR;
      if (nc_del_att(ncid, 0, ATT_INT_NAME)) ERR;
      if (nc_inq_varnatts(ncid, 0, &natts_in)) ERR;
      if (natts_in != 0) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing attribute create order...");

#define ATT0 "Maturin"
#define ATT1 "Aubery"
   {
      int ncid, varid, dimids[2];
      int attid_in;
      const int number = 42;

      /* Create a file with several global attributes. */
      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT0, NC_INT, 1, &number)) ERR;
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT1, NC_INT, 1, &number)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Open it and check the order. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_attid(ncid, NC_GLOBAL, ATT0, &attid_in)) ERR;
      if (attid_in != 0) ERR;
      if (nc_inq_attid(ncid, NC_GLOBAL, ATT1, &attid_in)) ERR;
      if (attid_in != 1) ERR;
      if (nc_close(ncid)) ERR;

      /* Now create a file with a variable, which has two atts. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
      if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR;
      if (nc_put_att_int(ncid, varid, ATT0, NC_INT, 1, &number)) ERR;
      if (nc_put_att_int(ncid, varid, ATT1, NC_INT, 1, &number)) ERR;
      if (nc_close(ncid)) ERR;
      
      /* Reopen the file and check the order of the attributes on the var. */
      if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
      if (nc_inq_attid(ncid, 0, ATT0, &attid_in)) ERR;
      if (attid_in != 0) ERR;
      if (nc_inq_attid(ncid, 0, ATT1, &attid_in)) ERR;
      if (attid_in != 1) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing attribute ordering some more...");

#define VAR_NAME "i"
#define A1_NAME "i"      
#define A2_NAME "f"      
#define A3_NAME "d"      
#define A1_LEN 3
#define A2_LEN 4
#define A3_LEN 5
   {
      int ncid;
      int varid, natts, nvars;
      double dvalue[] = {999.99, 999.99, 999.99, 999.99, 999.99};
      int varids[1];
      char name_in[NC_MAX_NAME + 1];

      /* Create a file with one var, and attach three atts to it. */
      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
      if (nc_def_var(ncid, VAR_NAME, NC_INT, 0, NULL, &varid)) ERR;
      if (nc_put_att_double(ncid, varid, A1_NAME, NC_INT, A1_LEN, dvalue)) ERR;      
      if (nc_put_att_double(ncid, varid, A2_NAME, NC_INT, A2_LEN, dvalue)) ERR;      
      if (nc_put_att_double(ncid, varid, A3_NAME, NC_INT, A3_LEN, dvalue)) ERR;      
      if (nc_close(ncid)) ERR;
      
      /* Reopen the file and check. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_inq_varids(ncid, &nvars, varids)) ERR;
      if (nvars != 1 || varids[0] != 0) ERR;
      if (nc_inq_varnatts(ncid, 0, &natts)) ERR;
      if (natts != 3) ERR;
      if (nc_inq_attname(ncid, 0, 0, name_in)) ERR;
      if (strcmp(name_in, A1_NAME)) ERR;
      if (nc_inq_attname(ncid, 0, 1, name_in)) ERR;
      if (strcmp(name_in, A2_NAME)) ERR;
      if (nc_inq_attname(ncid, 0, 2, name_in)) ERR;
      if (strcmp(name_in, A3_NAME)) ERR;

      /* Close up shop. */
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing attribute ordering even more...");

   /* Test the ordering of atts for each cmode. */
   if (tst_att_ordering(NC_CLOBBER)) ERR;
   if (tst_att_ordering(NC_CLOBBER|NC_64BIT_OFFSET)) ERR;
   if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4)) ERR;
   if (tst_att_ordering(NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL)) ERR;

   SUMMARIZE_ERR;
   printf("*** testing attributes and enddef/redef...");

#define ATT_1 "a"
#define ATT_2 "b"
#define ATT_3 "c"
   {
      int ncid, att = 1;

      if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL|NC_CLOBBER, &ncid)) ERR;
      if (nc_enddef(ncid)) ERR;
      if (nc_redef(ncid)) ERR;
      if (nc_put_att(ncid, NC_GLOBAL, ATT_1, NC_INT, 1, &att)) ERR;
      if (nc_put_att(ncid, NC_GLOBAL, ATT_2, NC_INT, 1, &att)) ERR;
      if (nc_put_att(ncid, NC_GLOBAL, ATT_3, NC_INT, 1, &att)) ERR;

      if (nc_close(ncid)) ERR;

      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_close(ncid)) ERR;
   }

   SUMMARIZE_ERR;
   printf("*** testing copy of simple global atts...");
   {      
      int ncid, ncid2;
      nc_type att_type;
      size_t att_len;
      int i;

      char *speech_in;
      signed char schar_in[ATT_LEN], schar_out[ATT_LEN] = {NC_MIN_BYTE, 1, NC_MAX_BYTE};
      unsigned char uchar_in[ATT_LEN], uchar_out[ATT_LEN] = {0, 128, NC_MAX_CHAR};
      short short_in[ATT_LEN], short_out[ATT_LEN] = {NC_MIN_SHORT, -128, NC_MAX_SHORT};
      int int_in[ATT_LEN], int_out[ATT_LEN] = {-100000, 128, 100000};
      float float_in[ATT_LEN], float_out[ATT_LEN] = {.5, 0.25, 0.125};
      double double_in[ATT_LEN], double_out[ATT_LEN] = {0.25, .5, 0.125};
      unsigned short ushort_in[ATT_LEN], ushort_out[ATT_LEN] = {0, 128, NC_MAX_USHORT};
      unsigned int uint_in[ATT_LEN], uint_out[ATT_LEN] = {0, 128, NC_MAX_UINT};
      unsigned long long uint64_in[ATT_LEN], uint64_out[ATT_LEN] = {0, 128, 18446744073709551612ULL};
      long long int64_in[ATT_LEN], int64_out[ATT_LEN] = {NC_MIN_INT64, 128, NC_MAX_INT64};

      /* Create a file with a global attribute of each type. */
      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_put_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, strlen(speech)+1, speech)) ERR;      
      if (nc_put_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, NC_BYTE, ATT_LEN, schar_out)) ERR;      
      if (nc_put_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, NC_UBYTE, ATT_LEN, uchar_out)) ERR;
      if (nc_put_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, NC_SHORT, ATT_LEN, short_out)) ERR;      
      if (nc_put_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, NC_INT, ATT_LEN, int_out)) ERR;      
      if (nc_put_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, NC_FLOAT, ATT_LEN, float_out)) ERR;      
      if (nc_put_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, NC_DOUBLE, ATT_LEN, double_out)) ERR;      
      if (nc_put_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, NC_USHORT, ATT_LEN, ushort_out)) ERR;      
      if (nc_put_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, NC_UINT, ATT_LEN, uint_out)) ERR;      
      if (nc_put_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, NC_INT64, ATT_LEN, int64_out)) ERR;      
      if (nc_put_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, NC_UINT64, ATT_LEN, uint64_out)) ERR;      

      /* Create another file and copy all the attributes. */
      if (nc_create(FILE_NAME2, NC_NETCDF4, &ncid2)) ERR;      
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_SCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_UCHAR_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_SHORT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_FLOAT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_USHORT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_INT64_NAME, ncid2, NC_GLOBAL)) ERR;
      if (nc_copy_att(ncid, NC_GLOBAL, ATT_UINT64_NAME, ncid2, NC_GLOBAL)) ERR;

      /* Close both files. */
      if (nc_close(ncid)) ERR;
      if (nc_close(ncid2)) ERR;

      /* Open the file and check attributes. */
      if (nc_open(FILE_NAME2, 0, &ncid)) ERR;
      /* Check text. */
      if (nc_inq_att(ncid, NC_GLOBAL, ATT_TEXT_NAME, &att_type, &att_len)) ERR;
      if (att_type != NC_CHAR || att_len != strlen(speech) + 1) ERR;
      if (!(speech_in = malloc(att_len + 1))) ERR;
      if (nc_get_att_text(ncid, NC_GLOBAL, ATT_TEXT_NAME, speech_in)) ERR;      
      if (strcmp(speech, speech_in)) ERR;
      free(speech_in);
      /* Check numeric values. */
      if (nc_get_att_schar(ncid, NC_GLOBAL, ATT_SCHAR_NAME, schar_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (schar_in[i] != schar_out[i]) ERR;
      if (nc_get_att_uchar(ncid, NC_GLOBAL, ATT_UCHAR_NAME, uchar_in)) ERR;
      for (i = 0; i < ATT_LEN; i++)
	 if (uchar_in[i] != uchar_out[i]) ERR;
      if (nc_get_att_short(ncid, NC_GLOBAL, ATT_SHORT_NAME, short_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (short_in[i] != short_out[i]) ERR;
      if (nc_get_att_int(ncid, NC_GLOBAL, ATT_INT_NAME, int_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (int_in[i] != int_out[i]) ERR;
      if (nc_get_att_float(ncid, NC_GLOBAL, ATT_FLOAT_NAME, float_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (float_in[i] != float_out[i]) ERR;
      if (nc_get_att_double(ncid, NC_GLOBAL, ATT_DOUBLE_NAME, double_in)) ERR;      
      for (i = 0; i < ATT_LEN; i++)
	 if (double_in[i] != double_out[i]) ERR;
      if (nc_get_att_ushort(ncid, NC_GLOBAL, ATT_USHORT_NAME, ushort_in)) ERR;
      for (i = 0; i < ATT_LEN; i++)
	 if (ushort_in[i] != ushort_out[i]) ERR;
      if (nc_get_att_uint(ncid, NC_GLOBAL, ATT_UINT_NAME, uint_in)) ERR;
      for (i = 0; i < ATT_LEN; i++)
	 if (uint_in[i] != uint_out[i]) ERR;
      if (nc_get_att_longlong(ncid, NC_GLOBAL, ATT_INT64_NAME, int64_in)) ERR;
      for (i = 0; i < ATT_LEN; i++)
	 if (int64_in[i] != int64_out[i]) ERR;
      if (nc_get_att_ulonglong(ncid, NC_GLOBAL, ATT_UINT64_NAME, uint64_in)) ERR;
      for (i = 0; i < ATT_LEN; i++)
	 if (uint64_in[i] != uint64_out[i]) ERR;
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
Exemple #8
0
/* create netCDF from in-memory structure */
static void
gen_netcdf(
     char *filename)		/* name for output netcdf file */
{
    int idim, ivar, iatt;
    int dimid;
    int varid;
    int stat;

    stat = nc_create(filename, cmode_modifier, &ncid);
    check_err(stat);

    /* define dimensions from info in dims array */
    for (idim = 0; idim < ndims; idim++) {
	stat = nc_def_dim(ncid, dims[idim].name, dims[idim].size, &dimid);
	check_err(stat);
    }

    /* define variables from info in vars array */
    for (ivar = 0; ivar < nvars; ivar++) {
	stat = nc_def_var(ncid,
			  vars[ivar].name,
			  vars[ivar].type,
			  vars[ivar].ndims,
			  vars[ivar].dims,
			  &varid);
	check_err(stat);
    }

    /* define attributes from info in atts array */
    for (iatt = 0; iatt < natts; iatt++) {
	varid = (atts[iatt].var == -1) ? NC_GLOBAL : atts[iatt].var;
	switch(atts[iatt].type) {
	case NC_BYTE:
	    stat = nc_put_att_schar(ncid, varid, atts[iatt].name,
				    atts[iatt].type, atts[iatt].len,
				    (signed char *) atts[iatt].val);
	    break;
	case NC_CHAR:
	    stat = nc_put_att_text(ncid, varid, atts[iatt].name,
				   atts[iatt].len,
				   (char *) atts[iatt].val);
	    break;
	case NC_SHORT:
	    stat = nc_put_att_short(ncid, varid, atts[iatt].name,
				    atts[iatt].type, atts[iatt].len,
				    (short *) atts[iatt].val);
	    break;
	case NC_INT:
	    stat = nc_put_att_int(ncid, varid, atts[iatt].name,
				    atts[iatt].type, atts[iatt].len,
				    (int *) atts[iatt].val);
	    break;
	case NC_FLOAT:
	    stat = nc_put_att_float(ncid, varid, atts[iatt].name,
				    atts[iatt].type, atts[iatt].len,
				    (float *) atts[iatt].val);
	    break;
	case NC_DOUBLE:
	    stat = nc_put_att_double(ncid, varid, atts[iatt].name,
				    atts[iatt].type, atts[iatt].len,
				    (double *) atts[iatt].val);
	    break;
	default:
	    stat = NC_EBADTYPE;
	}
	check_err(stat);
    }

    if (nofill_flag) {
	stat = nc_set_fill(ncid, NC_NOFILL, 0);	/* don't initialize with fill values */
	check_err(stat);
    }

    stat = nc_enddef(ncid);
    check_err(stat);
}