mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
Refactored test.
This commit is contained in:
parent
99ef1624bc
commit
9d98aab40a
@ -915,31 +915,7 @@ get_type_info2(NC_HDF5_FILE_INFO_T *h5, hid_t datasetid,
|
||||
(*type_info)->nc_type_class = NC_INT;
|
||||
else
|
||||
(*type_info)->nc_type_class = NC_FLOAT;
|
||||
|
||||
|
||||
// if (class == H5T_INTEGER)
|
||||
// {
|
||||
// if ((order = H5Tget_order(hdf_typeid)) < 0)
|
||||
// return NC_EHDFERR;
|
||||
|
||||
/* Copy this into the type_info struct. */
|
||||
// if (order == H5T_ORDER_LE)
|
||||
// (*type_info)->endianness = NC_ENDIAN_LITTLE;
|
||||
// else if (order == H5T_ORDER_BE)
|
||||
// (*type_info)->endianness = NC_ENDIAN_BIG;
|
||||
// else /* don't support H5T_ORDER_VAX, H5T_ORDER_MIXED, H5T_ORDER_NONE */
|
||||
// return NC_EBADTYPE;
|
||||
|
||||
// /* Set a class for the type */
|
||||
// /* (Note use of 'NC_INT' for all integer types) */
|
||||
// (*type_info)->nc_type_class = NC_INT;
|
||||
// } else
|
||||
// {
|
||||
/* Set a class for the type */
|
||||
/* (Note use of 'NC_FLOAT' for all floating-point types) */
|
||||
// (*type_info)->nc_type_class = NC_FLOAT;
|
||||
// }
|
||||
}
|
||||
}
|
||||
(*type_info)->nc_typeid = nc_type_constant_g[t];
|
||||
(*type_info)->size = nc_type_size_g[t];
|
||||
if (!((*type_info)->name = strdup(nc_type_name_g[t])))
|
||||
|
@ -8,7 +8,7 @@ SET(NC4_TESTS tst_dims tst_dims2 tst_dims3 tst_files tst_files4 tst_vars
|
||||
tst_xplatform tst_xplatform2 tst_h_atts2 tst_endian_fill tst_atts
|
||||
t_type cdm_sea_soundings tst_vl tst_atts1 tst_atts2
|
||||
tst_vars2 tst_files5 tst_files6 tst_sync tst_h_strbug tst_h_refs
|
||||
tst_h_scalar tst_rename tst_endian_float)
|
||||
tst_h_scalar tst_rename tst_h_endians)
|
||||
|
||||
# Note, renamegroup needs to be compiled before run_grp_rename
|
||||
build_bin_test(renamegroup)
|
||||
|
@ -1,188 +0,0 @@
|
||||
/*! Test for NCF-331. Added May 11, 2015.
|
||||
* See the following links for more information:
|
||||
*
|
||||
* o Issue on GitHub: https://github.com/Unidata/netcdf-c/issues/112
|
||||
* o Issue in JIRA: https://bugtracking.unidata.ucar.edu/browse/NCF-331
|
||||
*
|
||||
* Test contributed by Jeff Whitaker
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <netcdf.h>
|
||||
#include <stdio.h>
|
||||
#include "nc_logging.h"
|
||||
#include <hdf5.h>
|
||||
#include <nc_tests.h>
|
||||
|
||||
#define FILE_NAME_NC "tst_endian_float.nc"
|
||||
#define FILE_NAME_H5 "tst_endian_float.h5"
|
||||
|
||||
|
||||
#define NDIM 10
|
||||
#define NLON 20
|
||||
#define DIM_NAME "x"
|
||||
#define DIM_LEN 3
|
||||
#define GRP_NAME "grp"
|
||||
#define VAR_NAME2 "fv"
|
||||
#define VAR_NAME3 "iv"
|
||||
#define VAR_NAME "jv"
|
||||
int main() {
|
||||
|
||||
int ncid, dimid, varid, varid2, varid3, retval;
|
||||
int ed, ed2, ed3;
|
||||
int failures = 0;
|
||||
int oldfill = 0;
|
||||
|
||||
#ifdef LOGGING1
|
||||
printf("Setting log level 10\n");
|
||||
nc_set_log_level(10);
|
||||
LOG((2,"setting Log_level, logging with level 2."));
|
||||
#endif
|
||||
printf("* Checking that endianness is properly read from file.\n");
|
||||
printf("** Generating test files.\n");
|
||||
/*
|
||||
* 1. Create a netcdf file with endianness as desired.
|
||||
*/
|
||||
{
|
||||
|
||||
printf("*** Creating a file via netcdf API: %s.\n",FILE_NAME_NC);
|
||||
retval = nc_create(FILE_NAME_NC, NC_NETCDF4 | NC_CLOBBER, &ncid);
|
||||
|
||||
retval = nc_def_dim(ncid, DIM_NAME, NDIM, &dimid);
|
||||
|
||||
/* First, Float */
|
||||
retval = nc_def_var(ncid, VAR_NAME, NC_FLOAT, 1, &dimid, &varid);
|
||||
retval = nc_def_var_endian(ncid, varid, NC_ENDIAN_BIG);
|
||||
|
||||
/* Second, Double */
|
||||
retval = nc_def_var(ncid, VAR_NAME2, NC_DOUBLE, 1, &dimid, &varid2);
|
||||
retval = nc_def_var_endian(ncid, varid2, NC_ENDIAN_BIG);
|
||||
|
||||
/* Third, Int */
|
||||
retval = nc_def_var(ncid, VAR_NAME3, NC_INT, 1, &dimid, &varid3);
|
||||
retval = nc_def_var_endian(ncid, varid3, NC_ENDIAN_BIG);
|
||||
|
||||
retval = nc_close(ncid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a file with the hdf5 api
|
||||
*/
|
||||
{
|
||||
hid_t fileid, grpid, spaceid;
|
||||
hid_t native_did, le_did, be_did;
|
||||
hsize_t dims[1];
|
||||
printf("*** Creating a file via hdf5 API: %s\n",FILE_NAME_H5);
|
||||
|
||||
if ((fileid = H5Fcreate(FILE_NAME_H5, H5F_ACC_TRUNC, H5P_DEFAULT,
|
||||
H5P_DEFAULT)) < 0) ERR;
|
||||
if ((grpid = H5Gcreate1(fileid, GRP_NAME, 0)) < 0) ERR;
|
||||
|
||||
/* Create a dataset of native endian. */
|
||||
dims[0] = DIM_LEN;
|
||||
if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
|
||||
if ((native_did = H5Dcreate1(grpid, VAR_NAME3, H5T_STD_I32BE,
|
||||
spaceid, H5P_DEFAULT)) < 0) ERR;
|
||||
if ((le_did = H5Dcreate1(grpid, VAR_NAME, H5T_IEEE_F32BE,
|
||||
spaceid, H5P_DEFAULT)) < 0) ERR;
|
||||
if ((be_did = H5Dcreate1(grpid, VAR_NAME2, H5T_IEEE_F32BE,
|
||||
spaceid, H5P_DEFAULT)) < 0) ERR;
|
||||
|
||||
if (H5Dclose(native_did) < 0 ||
|
||||
H5Dclose(le_did) < 0 ||
|
||||
H5Dclose(be_did) < 0 ||
|
||||
H5Sclose(spaceid) < 0 ||
|
||||
H5Gclose(grpid) < 0 ||
|
||||
H5Fclose(fileid) < 0)
|
||||
{
|
||||
printf("Error closing hdf5 file.\n");
|
||||
failures++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 3. Reopen netcdf-generated file, check to see if the endianness attribute
|
||||
* exists.
|
||||
*/
|
||||
printf("** Checking test files.\n");
|
||||
{
|
||||
ncid = 0;
|
||||
printf("*** %s\n",FILE_NAME_NC);
|
||||
retval = nc_open(FILE_NAME_NC, NC_NETCDF4 | NC_NOWRITE, &ncid);
|
||||
retval = nc_set_fill(ncid, NC_NOFILL, &oldfill);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME,&varid);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME2,&varid2);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME3,&varid3);
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid,&ed);
|
||||
if(ed != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 1: Error for float variable endianness: [%d] not NC_ENDIAN_BIG\n",ed);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 1: [%d] is NC_ENDIAN_BIG, Success.\n",ed);
|
||||
}
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid2,&ed2);
|
||||
if(ed2 != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 2: Error for double variable endianness: [%d] not NC_ENDIAN_BIG\n",ed);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 2: [%d] is NC_ENDIAN_BIG, Success.\n",ed2);
|
||||
}
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid3,&ed3);
|
||||
if(ed3 != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 3: Error for integer variable endianness: [%d] not NC_ENDIAN_BIG\n",ed2);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 3: [%d] is NC_ENDIAN_BIG, Success.\n",ed3);
|
||||
}
|
||||
|
||||
retval = nc_close(ncid);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 4. Reopen hdf5-generated file, check to see if the endianness attribute
|
||||
* exists.
|
||||
*/
|
||||
{
|
||||
ncid = 0;
|
||||
printf("*** %s\n",FILE_NAME_H5);
|
||||
retval = nc_open(FILE_NAME_H5, NC_NETCDF4 | NC_NOWRITE, &ncid);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME,&varid);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME2,&varid2);
|
||||
retval = nc_inq_varid(ncid,VAR_NAME3,&varid3);
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid,&ed);
|
||||
if(ed != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 1: Error for float variable endianness: [%d] not NC_ENDIAN_BIG\n",ed);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 1: [%d] is NC_ENDIAN_BIG, Success.\n",ed);
|
||||
}
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid2,&ed2);
|
||||
if(ed2 != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 2: Error for double variable endianness: [%d] not NC_ENDIAN_BIG\n",ed);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 2: [%d] is NC_ENDIAN_BIG, Success.\n",ed2);
|
||||
}
|
||||
|
||||
retval = nc_inq_var_endian(ncid,varid3,&ed3);
|
||||
if(ed3 != NC_ENDIAN_BIG) {
|
||||
printf("\tTest 3: Error for integer variable endianness: [%d] not NC_ENDIAN_BIG\n",ed2);
|
||||
failures++;
|
||||
} else {
|
||||
printf("\tTest 3: [%d] is NC_ENDIAN_BIG, Success.\n",ed3);
|
||||
}
|
||||
|
||||
retval = nc_close(ncid);
|
||||
}
|
||||
printf("** Failures Returned: [%d]\n",failures);
|
||||
return failures;
|
||||
}
|
108
nc_test4/tst_h_endians.c
Normal file
108
nc_test4/tst_h_endians.c
Normal file
@ -0,0 +1,108 @@
|
||||
/*! Test for NCF-331. Added May 11, 2015.
|
||||
* See the following links for more information:
|
||||
*
|
||||
* o Issue on GitHub: https://github.com/Unidata/netcdf-c/issues/112
|
||||
* o Issue in JIRA: https://bugtracking.unidata.ucar.edu/browse/NCF-331
|
||||
*
|
||||
* Test contributed by Jeff Whitaker
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <netcdf.h>
|
||||
#include <stdio.h>
|
||||
#include <nc_tests.h>
|
||||
#include "nc_logging.h"
|
||||
|
||||
#define FILE_NAME_NC "tst_h_endians.nc"
|
||||
#define FILE_NAME_H5 "tst_h_endians.h5"
|
||||
|
||||
|
||||
#define NDIM 10
|
||||
#define NLON 20
|
||||
#define DIM_NAME "x"
|
||||
#define DIM_LEN 4
|
||||
#define GRP_NAME "grp"
|
||||
#define LE_FLOAT_VARNAME "fl_le"
|
||||
#define BE_FLOAT_VARNAME "fl_be"
|
||||
#define LE_INT_VARNAME "int_le"
|
||||
#define BE_INT_VARNAME "int_be"
|
||||
int main() {
|
||||
|
||||
int ncid, dimid;
|
||||
int le_float_varid;
|
||||
int be_float_varid;
|
||||
int le_int_varid;
|
||||
int be_int_varid;
|
||||
int ed;
|
||||
int failures = 0;
|
||||
int retval = 0;
|
||||
|
||||
printf("* Checking that endianness is properly read from file.\n");
|
||||
printf("** Generating test files.\n");
|
||||
/*
|
||||
* 1. Create a netcdf file with endianness as desired.
|
||||
*/
|
||||
{
|
||||
|
||||
printf("*** Creating a file via netcdf API: %s.\n",FILE_NAME_NC);
|
||||
retval = nc_create(FILE_NAME_NC, NC_NETCDF4 | NC_CLOBBER, &ncid);
|
||||
|
||||
retval = nc_def_dim(ncid, DIM_NAME, NDIM, &dimid);
|
||||
|
||||
/* Little-Endian Float */
|
||||
retval = nc_def_var(ncid, LE_FLOAT_VARNAME, NC_FLOAT, 1, &dimid, &le_float_varid);
|
||||
retval = nc_def_var_endian(ncid, le_float_varid, NC_ENDIAN_LITTLE);
|
||||
|
||||
/* Big-Endian Float */
|
||||
retval = nc_def_var(ncid, BE_FLOAT_VARNAME, NC_FLOAT, 1, &dimid, &be_float_varid);
|
||||
retval = nc_def_var_endian(ncid, be_float_varid, NC_ENDIAN_BIG);
|
||||
|
||||
/* Little-Endian Int */
|
||||
retval = nc_def_var(ncid, LE_INT_VARNAME, NC_INT, 1, &dimid, &le_int_varid);
|
||||
retval = nc_def_var_endian(ncid, le_int_varid, NC_ENDIAN_LITTLE);
|
||||
|
||||
/* Big-Endian Int */
|
||||
retval = nc_def_var(ncid, BE_INT_VARNAME, NC_INT, 1, &dimid, &be_int_varid);
|
||||
retval = nc_def_var_endian(ncid, be_int_varid, NC_ENDIAN_BIG);
|
||||
|
||||
|
||||
retval = nc_close(ncid);
|
||||
}
|
||||
|
||||
/*
|
||||
* 2. Reopen netcdf-generated file, check to see if the endianness attribute
|
||||
* exists.
|
||||
*/
|
||||
printf("** Checking test files.\n");
|
||||
{
|
||||
ncid = 0;
|
||||
printf("*** %s\n",FILE_NAME_NC);
|
||||
retval = nc_open(FILE_NAME_NC, NC_NETCDF4 | NC_NOWRITE, &ncid);
|
||||
|
||||
retval = nc_inq_varid(ncid,LE_FLOAT_VARNAME,&le_float_varid);
|
||||
retval = nc_inq_varid(ncid,BE_FLOAT_VARNAME,&be_float_varid);
|
||||
retval = nc_inq_varid(ncid,LE_INT_VARNAME,&le_int_varid);
|
||||
retval = nc_inq_varid(ncid,BE_INT_VARNAME,&be_int_varid);
|
||||
|
||||
printf("\tLittle-Endian Float...\t");
|
||||
retval = nc_inq_var_endian(ncid,le_float_varid,&ed);
|
||||
if(ed == NC_ENDIAN_LITTLE) printf("passed\n"); else {printf("failed\n"); failures++;}
|
||||
|
||||
printf("\tBig-Endian Float...\t");
|
||||
retval = nc_inq_var_endian(ncid,be_float_varid,&ed);
|
||||
if(ed == NC_ENDIAN_BIG) printf("passed\n"); else {printf("failed\n"); failures++;}
|
||||
|
||||
printf("\tLittle-Endian Int...\t");
|
||||
retval = nc_inq_var_endian(ncid,le_int_varid,&ed);
|
||||
if(ed == NC_ENDIAN_LITTLE) printf("passed\n"); else {printf("failed\n"); failures++;}
|
||||
|
||||
printf("\tBig-Endian Int...\t");
|
||||
retval = nc_inq_var_endian(ncid,be_int_varid,&ed);
|
||||
if(ed == NC_ENDIAN_BIG) printf("passed\n"); else {printf("failed\n"); failures++;}
|
||||
|
||||
retval = nc_close(ncid);
|
||||
}
|
||||
|
||||
printf("** Failures Returned: [%d]\n",failures);
|
||||
return failures;
|
||||
}
|
Loading…
Reference in New Issue
Block a user