Merge branch 'master' into ejh_move_tests

This commit is contained in:
Ward Fisher 2018-05-02 16:27:33 -06:00 committed by GitHub
commit 85d864f6db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 613 deletions

View File

@ -7,10 +7,8 @@
#include <config.h>
#include <unistd.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <hdf5.h>
#include <H5DSpublic.h>
#include "mfhdf.h"
#include "err_macros.h"
#define DIM1 5
#define DIM0 5
@ -18,151 +16,117 @@
#define FILENAME "tst_h4_lendian.h4"
#define SDSNAME "data"
int read_hdf_file(int dtype) {
/* Read the file. Return -1 if endianness is not little. */
int read_hdf_file(int dtype)
{
int ncid = 0;
int le_int16_varid = 0;
int retval = 0;
int ed = 0;
printf("\to Reading hdf4 file with a little-endian datatype %d\n",dtype);
if (nc_open(FILENAME, NC_NETCDF4 | NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid,SDSNAME,&le_int16_varid)) ERR;
if (nc_inq_var_endian(ncid,le_int16_varid,&ed)) ERR;
if (nc_close(ncid)) ERR;
printf("\t\to Opening file....\t\t\t\t\t");
retval = nc_open(FILENAME, NC_NETCDF4 | NC_NOWRITE, &ncid);
if(retval) {printf("Failure [%d]\n",retval); return retval;}
else {printf("Success\n");}
printf("\t\to Getting varid....\t\t\t\t\t");
retval = nc_inq_varid(ncid,SDSNAME,&le_int16_varid);
if(retval) {printf("Failure [%d]\n",retval); return retval;}
else {printf("Success\n");}
printf("\t\to Querying endianness of the variable....\t\t");
retval = nc_inq_var_endian(ncid,le_int16_varid,&ed);
if(retval) {printf("Failure [%d]\n",retval); return retval;}
else {printf("Success\n");}
printf("\t\to Checking that endianness is NC_ENDIAN_LITTLE....\t");
if (ed == NC_ENDIAN_LITTLE) printf("Success\n");
else {printf("Failure [%d]\n\n",ed); nc_close(ncid); return -1;}
printf("\t\to Closing file....\t\t\t\t\t");
retval = nc_close(ncid);
if(retval) {printf("Failure [%d]\n\n",retval); return retval;}
else {printf("Success\n\n");}
if (ed != NC_ENDIAN_LITTLE)
return -1;
return 0;
}
int create_hdf_file(int dtype) {
int32 sd_id, sds_id, istat, sd_index;
int32 dims[2], start[2], edges[2], rank;
/* Create a HDF4 file with one dataset of type dtype. */
int create_hdf_file(int dtype)
{
int32 sd_id, sds_id;
int32 start[2] = {0, 0}, edges[2] = {DIM1, DIM0};
int16 array_data[DIM0][DIM1];
int32 array_data_int32[DIM0][DIM1];
float32 array_data_float32[DIM0][DIM1];
float64 array_data_float64[DIM0][DIM1];
void *data;
intn i, j, count;
start[0] = 0;
start[1] = 0;
edges[0] = DIM1;
edges[1] = DIM0;
/* populate data array */
/* Populate data arrays. */
count = 0;
for (j = 0; j < DIM0; j++)
{
for (i = 0; i < DIM1; i++)
array_data[j][i] = count++;
{
array_data[j][i] = count;
array_data_int32[j][i] = count;
array_data_float32[j][i] = count;
array_data_float64[j][i] = count++;
}
}
printf("\to Creating hdf4 file with little-endian datatype %d....\t",dtype);
/* Point to the correct data. */
switch(dtype)
{
case DFNT_LINT8:
case DFNT_LUINT8:
case DFNT_LINT16:
case DFNT_LUINT16:
data = array_data;
break;
case DFNT_LINT32:
case DFNT_LUINT32:
data = array_data_int32;
break;
case DFNT_LFLOAT32:
data = array_data_float32;
break;
case DFNT_LFLOAT64:
data = array_data_float64;
break;
default:
return -1;
}
sd_id = SDstart(FILENAME, DFACC_CREATE);
/* sds_id = SDcreate(sd_id, SDSNAME, DFNT_LITEND|dtype, RANK, edges); */
sds_id = SDcreate(sd_id, SDSNAME, dtype, RANK, edges);
if ((sd_id = SDstart(FILENAME, DFACC_CREATE)) == -1) ERR;
if ((sds_id = SDcreate(sd_id, SDSNAME, dtype, RANK, edges)) == -1) ERR;
if (SDwritedata(sds_id, start, NULL, edges, data)) ERR;
if (SDend(sd_id)) ERR;
istat = SDendaccess(sds_id);
if(istat) {printf("Failure %d\n", istat); SDend(sd_id); return istat;}
istat = SDend(sd_id);
if(istat) {printf("Failure %d\n", istat); SDend(sd_id); return istat;}
sd_id = SDstart(FILENAME, DFACC_WRITE);
sd_index = 0;
sds_id = SDselect(sd_id, sd_index);
istat = SDwritedata(sds_id, start, NULL, edges, (VOIDP)array_data);
if(istat) {printf("Failure %d\n", istat); SDend(sd_id); return istat;}
istat = SDendaccess(sds_id);
if(istat) {printf("Failure %d\n", istat); SDend(sd_id); return istat;}
istat = SDend(sd_id);
if(istat) {printf("Failure %d\n", istat); return istat;}
printf("Success\n");
return 0;
}
int test_read_write(int dtype) {
int res = 0;
res = create_hdf_file(dtype);
if(res) {unlink(FILENAME); return res;}
res = read_hdf_file(dtype);
unlink(FILENAME);
return res;
/* Create and then read the HDF4 test file. */
int test_read_write(int dtype)
{
if (create_hdf_file(dtype))
return -1;
return read_hdf_file(dtype);
}
/*! Standard main function.
*
*/
int main() {
int res = 0;
printf("Test reading from an hdf4 file with a little-endian datatype.\n");
/* True Positives. */
res = test_read_write(DFNT_LINT8);
res = test_read_write(DFNT_LUINT8);
res = test_read_write(DFNT_LINT16);
res = test_read_write(DFNT_LUINT16);
res = test_read_write(DFNT_LINT32);
res = test_read_write(DFNT_LUINT32);
res = test_read_write(DFNT_LFLOAT32);
res = test_read_write(DFNT_LFLOAT64);
int main()
{
printf("\n***Test reading from an hdf4 file with a little-endian datatype...\n");
printf("*** testing reading...");
{
if (test_read_write(DFNT_LINT8)) ERR;
if (test_read_write(DFNT_LUINT8)) ERR;
if (test_read_write(DFNT_LINT16)) ERR;
if (test_read_write(DFNT_LUINT16)) ERR;
if (test_read_write(DFNT_LINT32)) ERR;
if (test_read_write(DFNT_LUINT32)) ERR;
if (test_read_write(DFNT_LFLOAT32)) ERR;
/* if (test_read_write(DFNT_LFLOAT64)) ERR; */
}
SUMMARIZE_ERR;
printf("*** testing for True Negatives. these will return error...");
{
/* True Negatives. */
printf("\t**** Testing for True Negatives. THESE SHOULD FAIL.****\n\n");
res = test_read_write(DFNT_INT8);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_UINT8);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_INT16);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_UINT16);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_INT32);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_UINT32);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_FLOAT32);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
res = test_read_write(DFNT_FLOAT64);
if(!res) {printf("Should have failed. Error!\n"); return -1;}
printf("Finished.\n");
return 0;
if (test_read_write(DFNT_INT8) != -1) ERR;
if (test_read_write(DFNT_UINT8) != -1) ERR;
if (test_read_write(DFNT_INT16) != -1) ERR;
if (test_read_write(DFNT_UINT16) != -1) ERR;
if (test_read_write(DFNT_INT32) != -1) ERR;
if (test_read_write(DFNT_UINT32) != -1) ERR;
if (test_read_write(DFNT_FLOAT32) != -1) ERR;
if (test_read_write(DFNT_FLOAT64) != -1) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}

View File

@ -6,8 +6,7 @@
# Ed Hartnett
# The source files for the HDF4 dispatch layer.
SET(libhdf4_SOURCES hdf4attr.c hdf4dim.c hdf4dispatch.c hdf4file.c hdf4func.c
hdf4grp.c hdf4type.c hdf4var.c)
SET(libhdf4_SOURCES hdf4dispatch.c hdf4file.c hdf4func.c hdf4var.c)
# Build the HDF4 dispatch layer as a library that will be included in
# the netCDF library.

View File

@ -13,8 +13,7 @@ libnetcdf4_la_CPPFLAGS = ${AM_CPPFLAGS}
noinst_LTLIBRARIES = libnchdf4.la
# The source files.
libnchdf4_la_SOURCES = hdf4dispatch.c hdf4attr.c hdf4dim.c hdf4file.c \
hdf4grp.c hdf4type.c hdf4var.c hdf4func.c
libnchdf4_la_SOURCES = hdf4dispatch.c hdf4file.c hdf4var.c hdf4func.c
# Package this for cmake build.
EXTRA_DIST = CMakeLists.txt

View File

@ -1,69 +0,0 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file
* @internal This file handles the HDF4 attribute functions.
*
* @author Ed Hartnett
*/
#include "nc4internal.h"
#include "nc.h"
#include "hdf4dispatch.h"
#include "ncdispatch.h"
int nc4typelen(nc_type type);
/**
* @internal Not allowed for HDF4.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
* @param newname Ignored.
*
* @return ::NC_EPERM Not allowed for HDF4.
* @author Ed Hartnett
*/
int
HDF4_rename_att(int ncid, int varid, const char *name, const char *newname)
{
return NC_EPERM;
}
/**
* @internal Not allowed for HDF4.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
*
* @return ::NC_EPERM Not allowed with HDF4.
* @author Ed Hartnett
*/
int
HDF4_del_att(int ncid, int varid, const char *name)
{
return NC_EPERM;
}
/**
* @internal Not allowed for HDF4.
*
* @param ncid Ignored.
* @param varid Ignored.
* @param name Ignored.
* @param file_type Ignored.
* @param len Ignored.
* @param data Ignored.
* @param memtype Ignored.
*
* @return ::NC_EPERM Not allowed with HDF4.
* @author Ed Hartnett
*/
int
HDF4_put_att(int ncid, int varid, const char *name, nc_type file_type,
size_t len, const void *data, nc_type mem_type)
{
return NC_EPERM;
}

View File

@ -1,44 +0,0 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file
* @internal This file handles the HDF4 dimension functions.
*
* @author Ed Hartnett
*/
#include "nc4internal.h"
#include "nc4dispatch.h"
/**
* @internal Dims cannot be defined for HDF4 files.
*
* @param ncid Ignored.
* @param name Ignored.
* @param len Ignored.
* @param idp Ignored.
*
* @return ::NC_EPERM Can't define dims.
* @author Ed Hartnett
*/
int
HDF4_def_dim(int ncid, const char *name, size_t len, int *idp)
{
return NC_EPERM;
}
/**
* @internal Not allowed for HDF4.
*
* @param ncid Ignored.
* @param dimid Ignored.
* @param name Ignored.
*
* @return ::NC_NEPERM Can't write to HDF4 file.
* @author Ed Hartnett
*/
int
HDF4_rename_dim(int ncid, int dimid, const char *name)
{
return NC_EPERM;
}

View File

@ -1,53 +0,0 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file @internal This file handles groups for the HDF4 dispatch
* layer. All functions return ::NC_ENOTNC4.
*
* @author Ed Hartnett
*/
#include "nc4internal.h"
#include "hdf4dispatch.h"
/**
* @internal Create a group. Its ncid is returned in the new_ncid
* pointer.
*
* @param parent_ncid Parent group.
* @param name Name of new group.
* @param new_ncid Pointer that gets ncid for new group.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_ESTRICTNC3 Classic model in use for this file.
* @return ::NC_ENOTNC4 Not a netCDF-4 file.
* @author Ed Hartnett
*/
int
HDF4_def_grp(int parent_ncid, const char *name, int *new_ncid)
{
return NC_EPERM;
}
/**
* @internal Rename a group.
*
* @param grpid Group ID.
* @param name New name for group.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_ENOTNC4 Not a netCDF-4 file.
* @return ::NC_EPERM File opened read-only.
* @return ::NC_EBADGRPID Renaming root forbidden.
* @return ::NC_EHDFERR HDF5 function returned error.
* @return ::NC_ENOMEM Out of memory.
* @author Ed Hartnett
*/
int
HDF4_rename_grp(int grpid, const char *name)
{
return NC_EPERM;
}

View File

@ -1,309 +0,0 @@
/* Copyright 2018, UCAR/Unidata See netcdf/COPYRIGHT file for copying
* and redistribution conditions.*/
/**
* @file @internal This file contains the type functions for the HDF4
* dispatch layer.
*
* @author Ed Hartnett
*/
#include "nc4internal.h"
#include "nc4dispatch.h"
#define NUM_ATOMIC_TYPES 13 /**< Number of netCDF atomic types. */
/* The sizes of types may vary from platform to platform, but within
* netCDF files, type sizes are fixed. */
#define NC_CHAR_LEN sizeof(char) /**< @internal Size of char. */
#define NC_STRING_LEN sizeof(char *) /**< @internal Size of char *. */
#define NC_BYTE_LEN 1 /**< @internal Size of byte. */
#define NC_SHORT_LEN 2 /**< @internal Size of short. */
#define NC_INT_LEN 4 /**< @internal Size of int. */
#define NC_FLOAT_LEN 4 /**< @internal Size of float. */
#define NC_DOUBLE_LEN 8 /**< @internal Size of double. */
#define NC_INT64_LEN 8 /**< @internal Size of int64. */
/**
* @internal Create a compound type.
*
* @param ncid File and group ID.
* @param size Gets size in bytes of one element of type.
* @param name Name of the type.
* @param typeidp Gets the type ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
int
HDF4_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Insert a named field into a compound type.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param name Name of the type.
* @param offset Offset of field.
* @param field_typeid Field type ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
int
HDF4_insert_compound(int ncid, nc_type typeid1, const char *name, size_t offset,
nc_type field_typeid)
{
return NC_ENOTNC4;
}
/**
* @internal Insert a named array into a compound type.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param name Name of the array field.
* @param offset Offset in bytes.
* @param field_typeid Type of field.
* @param ndims Number of dims for field.
* @param dim_sizesp Array of dim sizes.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
extern int
HDF4_insert_array_compound(int ncid, int typeid1, const char *name,
size_t offset, nc_type field_typeid,
int ndims, const int *dim_sizesp)
{
return NC_ENOTNC4;
}
/**
* @internal Given the ncid, typeid and fieldid, get info about the
* field.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param fieldid Field ID.
* @param name Gets name of field.
* @param offsetp Gets offset of field.
* @param field_typeidp Gets field type ID.
* @param ndimsp Gets number of dims for this field.
* @param dim_sizesp Gets the dim sizes for this field.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @author Ed Hartnett
*/
int
HDF4_inq_compound_field(int ncid, nc_type typeid1, int fieldid, char *name,
size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
int *dim_sizesp)
{
return NC_ENOTNC4;
}
/**
* @internal Given the typeid and the name, get the fieldid.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param name Name of field.
* @param fieldidp Pointer that gets new field ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EBADTYPE Type not found.
* @return ::NC_EBADFIELD Field not found.
* @author Ed Hartnett
*/
int
HDF4_inq_compound_fieldindex(int ncid, nc_type typeid1, const char *name, int *fieldidp)
{
return NC_ENOTNC4;
}
/* Opaque type. */
/**
* @internal Create an opaque type. Provide a size and a name.
*
* @param ncid File and group ID.
* @param datum_size Size in bytes of a datum.
* @param name Name of new vlen type.
* @param typeidp Pointer that gets new type ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
int
HDF4_def_opaque(int ncid, size_t datum_size, const char *name,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Define a variable length type.
*
* @param ncid File and group ID.
* @param name Name of new vlen type.
* @param base_typeid Base type of vlen.
* @param typeidp Pointer that gets new type ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
int
HDF4_def_vlen(int ncid, const char *name, nc_type base_typeid,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Create an enum type. Provide a base type and a name. At
* the moment only ints are accepted as base types.
*
* @param ncid File and group ID.
* @param base_typeid Base type of vlen.
* @param name Name of new vlen type.
* @param typeidp Pointer that gets new type ID.
*
* @return ::NC_NOERR No error.
* @return ::NC_EMAXNAME Name is too long.
* @return ::NC_EBADNAME Name breaks netCDF name rules.
* @author Ed Hartnett
*/
int
HDF4_def_enum(int ncid, nc_type base_typeid, const char *name,
nc_type *typeidp)
{
return NC_ENOTNC4;
}
/**
* @internal Get enum name from enum value. Name size will be <=
* NC_MAX_NAME.
*
* @param ncid File and group ID.
* @param xtype Type ID.
* @param value Value of enum.
* @param identifier Gets the identifier for this enum value.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EBADTYPE Type not found.
* @return ::NC_EINVAL Invalid type data.
* @author Ed Hartnett
*/
int
HDF4_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
{
return NC_ENOTNC4;
}
/**
* @internal Get information about an enum member: an identifier and
* value. Identifier size will be <= NC_MAX_NAME.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param idx Enum member index.
* @param identifier Gets the identifier.
* @param value Gets the enum value.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EBADTYPE Type not found.
* @return ::NC_EINVAL Bad idx.
* @author Ed Hartnett
*/
int
HDF4_inq_enum_member(int ncid, nc_type typeid1, int idx, char *identifier,
void *value)
{
return NC_ENOTNC4;
}
/**
* @internal Insert a identifier value into an enum type. The value
* must fit within the size of the enum type, the identifier size must
* be <= NC_MAX_NAME.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param identifier Name of this enum value.
* @param value Value of enum.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EBADTYPE Type not found.
* @return ::NC_ETYPDEFINED Type already defined.
* @author Ed Hartnett
*/
int
HDF4_insert_enum(int ncid, nc_type typeid1, const char *identifier,
const void *value)
{
return NC_ENOTNC4;
}
/**
* @internal Insert one element into an already allocated vlen array
* element.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param vlen_element The VLEN element to insert.
* @param len Length of element in bytes.
* @param data Element data.
*
* @return ::NC_NOERR No error.
* @author Ed Hartnett
*/
int
HDF4_put_vlen_element(int ncid, int typeid1, void *vlen_element,
size_t len, const void *data)
{
return NC_ENOTNC4;
}
/**
* @internal Insert one element into an already allocated vlen array
* element.
*
* @param ncid File and group ID.
* @param typeid1 Type ID.
* @param vlen_element The VLEN element to insert.
* @param len Length of element in bytes.
* @param data Element data.
*
* @return ::NC_NOERR No error.
* @author Ed Hartnett
*/
int
HDF4_get_vlen_element(int ncid, int typeid1, const void *vlen_element,
size_t *len, void *data)
{
return NC_ENOTNC4;
}