mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-27 02:10:55 +08:00
[svn-r380] Finished tests for scalar dataspaces with both datasets and attributes.
This commit is contained in:
parent
07ca2821d2
commit
a9a1a52fec
142
test/tattr.c
142
test/tattr.c
@ -78,6 +78,10 @@ struct attr4_struct {
|
|||||||
} attr_data4[ATTR4_DIM1][ATTR4_DIM2]={{{3,-26.1,'d'},{-100000, 0.123,'3'}},
|
} attr_data4[ATTR4_DIM1][ATTR4_DIM2]={{{3,-26.1,'d'},{-100000, 0.123,'3'}},
|
||||||
{{-23,981724.2,'Q'},{0,2.0,'\n'}}}; /* Test data for 4th attribute */
|
{{-23,981724.2,'Q'},{0,2.0,'\n'}}}; /* Test data for 4th attribute */
|
||||||
|
|
||||||
|
#define ATTR5_NAME "Attr5"
|
||||||
|
#define ATTR5_RANK 0
|
||||||
|
float attr_data5=-5.123; /* Test data for 5th attribute */
|
||||||
|
|
||||||
int attr_op1(hid_t loc_id, const char *name, void *op_data);
|
int attr_op1(hid_t loc_id, const char *name, void *op_data);
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
@ -100,7 +104,7 @@ test_attr_basic_write(void)
|
|||||||
herr_t ret; /* Generic return value */
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
/* Output message about test being performed */
|
/* Output message about test being performed */
|
||||||
MESSAGE(5, ("Testing Basic Attribute Functions\n"));
|
MESSAGE(5, ("Testing Basic Scalar Attribute Writing Functions\n"));
|
||||||
|
|
||||||
/* Create file */
|
/* Create file */
|
||||||
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
@ -209,6 +213,7 @@ test_attr_basic_read(void)
|
|||||||
|
|
||||||
/* Open the dataset */
|
/* Open the dataset */
|
||||||
dataset=H5Dopen(fid1,"Dataset1");
|
dataset=H5Dopen(fid1,"Dataset1");
|
||||||
|
CHECK(dataset, FAIL, "H5Dopen");
|
||||||
|
|
||||||
/* Verify the correct number of attributes */
|
/* Verify the correct number of attributes */
|
||||||
ret=H5Anum_attrs(dataset);
|
ret=H5Anum_attrs(dataset);
|
||||||
@ -274,12 +279,12 @@ test_attr_basic_read(void)
|
|||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
**
|
**
|
||||||
** test_attr_complex_write(): Test H5A (attribute) code.
|
** test_attr_compound_write(): Test H5A (attribute) code.
|
||||||
** Tests complex datatype attributes
|
** Tests compound datatype attributes
|
||||||
**
|
**
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
static void
|
static void
|
||||||
test_attr_complex_write(void)
|
test_attr_compound_write(void)
|
||||||
{
|
{
|
||||||
hid_t fid1; /* HDF5 File IDs */
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
hid_t dataset; /* Dataset ID */
|
hid_t dataset; /* Dataset ID */
|
||||||
@ -356,15 +361,15 @@ test_attr_complex_write(void)
|
|||||||
/* Close file */
|
/* Close file */
|
||||||
ret = H5Fclose(fid1);
|
ret = H5Fclose(fid1);
|
||||||
CHECK(ret, FAIL, "H5Fclose");
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
} /* test_attr_complex_write() */
|
} /* test_attr_compound_write() */
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
**
|
**
|
||||||
** test_attr_complex_read(): Test basic H5A (attribute) code.
|
** test_attr_compound_read(): Test basic H5A (attribute) code.
|
||||||
**
|
**
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
static void
|
static void
|
||||||
test_attr_complex_read(void)
|
test_attr_compound_read(void)
|
||||||
{
|
{
|
||||||
hid_t fid1; /* HDF5 File IDs */
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
hid_t dataset; /* Dataset ID */
|
hid_t dataset; /* Dataset ID */
|
||||||
@ -511,7 +516,120 @@ test_attr_complex_read(void)
|
|||||||
/* Close file */
|
/* Close file */
|
||||||
ret = H5Fclose(fid1);
|
ret = H5Fclose(fid1);
|
||||||
CHECK(ret, FAIL, "H5Fclose");
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
} /* test_attr_complex_read() */
|
} /* test_attr_compound_read() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_attr_scalar_write(): Test scalar H5A (attribute) writing code.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_attr_scalar_write(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t sid1,sid2; /* Dataspace ID */
|
||||||
|
hid_t attr; /* Attribute ID */
|
||||||
|
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Basic Attribute Functions\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fcreate");
|
||||||
|
|
||||||
|
/* Create dataspace for dataset */
|
||||||
|
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
|
||||||
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
||||||
|
|
||||||
|
/* Create a dataset */
|
||||||
|
dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_UINT8,sid1,H5P_DEFAULT);
|
||||||
|
|
||||||
|
/* Create dataspace for attribute */
|
||||||
|
sid2 = H5Screate_simple(ATTR5_RANK, NULL, NULL);
|
||||||
|
CHECK(sid2, FAIL, "H5Screate_simple");
|
||||||
|
|
||||||
|
/* Create an attribute for the dataset */
|
||||||
|
attr=H5Acreate(dataset,ATTR5_NAME,H5T_NATIVE_FLOAT,sid2,H5P_DEFAULT);
|
||||||
|
CHECK(attr, FAIL, "H5Acreate");
|
||||||
|
|
||||||
|
/* Try to create the same attribute again (should fail) */
|
||||||
|
ret=H5Acreate(dataset,ATTR5_NAME,H5T_NATIVE_FLOAT,sid2,H5P_DEFAULT);
|
||||||
|
VERIFY(ret, FAIL, "H5Acreate");
|
||||||
|
|
||||||
|
/* Write attribute information */
|
||||||
|
ret=H5Awrite(attr,H5T_NATIVE_FLOAT,&attr_data5);
|
||||||
|
CHECK(ret, FAIL, "H5Awrite");
|
||||||
|
|
||||||
|
/* Close attribute */
|
||||||
|
ret=H5Aclose(attr);
|
||||||
|
CHECK(ret, FAIL, "H5Aclose");
|
||||||
|
|
||||||
|
ret = H5Sclose(sid1);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
ret = H5Sclose(sid2);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
|
||||||
|
/* Close Dataset */
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_attr_scalar_write() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_attr_scalar_read(): Test scalar H5A (attribute) reading code.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_attr_scalar_read(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t attr; /* Attribute ID */
|
||||||
|
float rdata=0.0; /* Buffer for reading 1st attribute */
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Basic Scalar Attribute Reading Functions\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fopen");
|
||||||
|
|
||||||
|
/* Open the dataset */
|
||||||
|
dataset=H5Dopen(fid1,"Dataset1");
|
||||||
|
CHECK(dataset, FAIL, "H5Dopen");
|
||||||
|
|
||||||
|
/* Verify the correct number of attributes */
|
||||||
|
ret=H5Anum_attrs(dataset);
|
||||||
|
VERIFY(ret, 1, "H5Anum_attrs");
|
||||||
|
|
||||||
|
/* Open an attribute for the dataset */
|
||||||
|
attr=H5Aopen_name(dataset,ATTR5_NAME);
|
||||||
|
CHECK(attr, FAIL, "H5Aopen_name");
|
||||||
|
|
||||||
|
/* Read attribute information */
|
||||||
|
ret=H5Aread(attr,H5T_NATIVE_FLOAT,&rdata);
|
||||||
|
CHECK(ret, FAIL, "H5Aread");
|
||||||
|
VERIFY(rdata, attr_data5, "H5Aread");
|
||||||
|
|
||||||
|
/* Close attribute */
|
||||||
|
ret=H5Aclose(attr);
|
||||||
|
CHECK(ret, FAIL, "H5Aclose");
|
||||||
|
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_attr_scalar_read() */
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
**
|
**
|
||||||
@ -1099,8 +1217,12 @@ test_attr(void)
|
|||||||
test_attr_basic_read(); /* Test basic H5A reading code */
|
test_attr_basic_read(); /* Test basic H5A reading code */
|
||||||
|
|
||||||
/* These next two tests use the same file information */
|
/* These next two tests use the same file information */
|
||||||
test_attr_complex_write(); /* Test complex datatype H5A writing code */
|
test_attr_compound_write(); /* Test complex datatype H5A writing code */
|
||||||
test_attr_complex_read(); /* Test complex datatype H5A reading code */
|
test_attr_compound_read(); /* Test complex datatype H5A reading code */
|
||||||
|
|
||||||
|
/* These next two tests use the same file information */
|
||||||
|
test_attr_scalar_write(); /* Test scalar dataspace H5A writing code */
|
||||||
|
test_attr_scalar_read(); /* Test scalar dataspace H5A reading code */
|
||||||
|
|
||||||
/* These next four tests use the same file information */
|
/* These next four tests use the same file information */
|
||||||
test_attr_mult_write(); /* Test H5A writing code for multiple attributes */
|
test_attr_mult_write(); /* Test H5A writing code for multiple attributes */
|
||||||
|
@ -165,7 +165,7 @@ main(int argc, char *argv[])
|
|||||||
InitTest("heap", test_heap, "Object and Name Heaps");
|
InitTest("heap", test_heap, "Object and Name Heaps");
|
||||||
InitTest("ohdr", test_ohdr, "Object Headers");
|
InitTest("ohdr", test_ohdr, "Object Headers");
|
||||||
InitTest("stab", test_stab, "Symbol Tables");
|
InitTest("stab", test_stab, "Symbol Tables");
|
||||||
InitTest("h5p", test_h5p, "Dataspaces");
|
InitTest("h5s", test_h5s, "Dataspaces");
|
||||||
InitTest("attr", test_attr, "Attributes");
|
InitTest("attr", test_attr, "Attributes");
|
||||||
|
|
||||||
Verbosity = 4; /* Default Verbosity is Low */
|
Verbosity = 4; /* Default Verbosity is Low */
|
||||||
|
@ -135,7 +135,7 @@ void test_heap(void);
|
|||||||
void test_ohdr(void);
|
void test_ohdr(void);
|
||||||
void test_stab(void);
|
void test_stab(void);
|
||||||
void test_h5t(void);
|
void test_h5t(void);
|
||||||
void test_h5p(void);
|
void test_h5s(void);
|
||||||
void test_h5d(void);
|
void test_h5d(void);
|
||||||
void test_attr(void);
|
void test_attr(void);
|
||||||
|
|
||||||
|
308
test/th5s.c
308
test/th5s.c
@ -31,7 +31,7 @@ static char RcsId[] = "$Revision$";
|
|||||||
#include <H5Sprivate.h>
|
#include <H5Sprivate.h>
|
||||||
#include <H5Pprivate.h>
|
#include <H5Pprivate.h>
|
||||||
|
|
||||||
#define FILE "th5p1.h5"
|
#define FILE "th5s1.h5"
|
||||||
|
|
||||||
/* 3-D dataset with fixed dimensions */
|
/* 3-D dataset with fixed dimensions */
|
||||||
#define SPACE1_NAME "Space1"
|
#define SPACE1_NAME "Space1"
|
||||||
@ -48,13 +48,36 @@ static char RcsId[] = "$Revision$";
|
|||||||
#define SPACE2_DIM3 13
|
#define SPACE2_DIM3 13
|
||||||
#define SPACE2_DIM4 23
|
#define SPACE2_DIM4 23
|
||||||
|
|
||||||
|
/* Scalar dataset with simple datatype */
|
||||||
|
#define SPACE3_NAME "Scalar1"
|
||||||
|
#define SPACE3_RANK 0
|
||||||
|
uint32 space3_data=65;
|
||||||
|
|
||||||
|
/* Scalar dataset with compound datatype */
|
||||||
|
#define SPACE4_NAME "Scalar2"
|
||||||
|
#define SPACE4_RANK 0
|
||||||
|
#define SPACE4_FIELDNAME1 "c1"
|
||||||
|
#define SPACE4_FIELDNAME2 "u"
|
||||||
|
#define SPACE4_FIELDNAME3 "f"
|
||||||
|
#define SPACE4_FIELDNAME4 "c2"
|
||||||
|
size_t space4_field1_off=0;
|
||||||
|
size_t space4_field2_off=0;
|
||||||
|
size_t space4_field3_off=0;
|
||||||
|
size_t space4_field4_off=0;
|
||||||
|
struct space4_struct {
|
||||||
|
char c1;
|
||||||
|
uint32 u;
|
||||||
|
float f;
|
||||||
|
char c2;
|
||||||
|
} space4_data={'v',987123,-3.14,'g'}; /* Test data for 4th dataspace */
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
**
|
**
|
||||||
** test_h5p_basic(): Test basic H5S (dataspace) code.
|
** test_h5s_basic(): Test basic H5S (dataspace) code.
|
||||||
**
|
**
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
static void
|
static void
|
||||||
test_h5p_basic(void)
|
test_h5s_basic(void)
|
||||||
{
|
{
|
||||||
hid_t fid1; /* HDF5 File IDs */
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
hid_t sid1, sid2; /* Dataspace ID */
|
hid_t sid1, sid2; /* Dataspace ID */
|
||||||
@ -67,7 +90,7 @@ test_h5p_basic(void)
|
|||||||
herr_t ret; /* Generic return value */
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
/* Output message about test being performed */
|
/* Output message about test being performed */
|
||||||
MESSAGE(5, ("Testing Datatype Manipulation\n"));
|
MESSAGE(5, ("Testing Dataspace Manipulation\n"));
|
||||||
|
|
||||||
/* Create file */
|
/* Create file */
|
||||||
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
@ -112,18 +135,285 @@ test_h5p_basic(void)
|
|||||||
/* Close first file */
|
/* Close first file */
|
||||||
ret = H5Fclose(fid1);
|
ret = H5Fclose(fid1);
|
||||||
CHECK(ret, FAIL, "H5Fclose");
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
} /* test_h5p_basic() */
|
} /* test_h5s_basic() */
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
**
|
**
|
||||||
** test_h5p(): Main H5S (dataspace) testing routine.
|
** test_h5s_scalar_write(): Test scalar H5S (dataspace) writing code.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_h5s_scalar_write(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t sid1; /* Dataspace ID */
|
||||||
|
uint32 rank; /* Logical rank of dataspace */
|
||||||
|
hsize_t tdims[4]; /* Dimension array to test with */
|
||||||
|
size_t n; /* Number of dataspace elements */
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Scalar Dataspace Manipulation\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fcreate");
|
||||||
|
|
||||||
|
/* Create scalar dataspace */
|
||||||
|
sid1 = H5Screate_simple(SPACE3_RANK, NULL, NULL);
|
||||||
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
||||||
|
|
||||||
|
n = H5Sget_npoints(sid1);
|
||||||
|
CHECK(n, UFAIL, "H5Sget_npoints");
|
||||||
|
VERIFY(n, 1, "H5Sget_npoints");
|
||||||
|
|
||||||
|
rank = H5Sget_ndims(sid1);
|
||||||
|
CHECK(rank, UFAIL, "H5Sget_lrank");
|
||||||
|
VERIFY(rank, SPACE3_RANK, "H5Sget_lrank");
|
||||||
|
|
||||||
|
ret = H5Sget_dims(sid1, tdims);
|
||||||
|
VERIFY(ret, 0, "H5Sget_dims");
|
||||||
|
|
||||||
|
/* Create a dataset */
|
||||||
|
dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_UINT32,sid1,H5P_DEFAULT);
|
||||||
|
CHECK(dataset, FAIL, "H5Dcreate");
|
||||||
|
|
||||||
|
ret = H5Dwrite(dataset, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, &space3_data);
|
||||||
|
CHECK(ret, FAIL, "H5Dwrite");
|
||||||
|
|
||||||
|
/* Close Dataset */
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close scalar dataspace */
|
||||||
|
ret = H5Sclose(sid1);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_h5s_scalar_write() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_h5s_scalar_read(): Test scalar H5S (dataspace) reading code.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_h5s_scalar_read(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t sid1; /* Dataspace ID */
|
||||||
|
uint32 rank; /* Logical rank of dataspace */
|
||||||
|
hsize_t tdims[4]; /* Dimension array to test with */
|
||||||
|
size_t n; /* Number of dataspace elements */
|
||||||
|
uint32 rdata; /* Scalar data read in */
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Scalar Dataspace Manipulation\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fopen");
|
||||||
|
|
||||||
|
/* Create a dataset */
|
||||||
|
dataset=H5Dopen(fid1,"Dataset1");
|
||||||
|
CHECK(dataset, FAIL, "H5Dopen");
|
||||||
|
|
||||||
|
sid1=H5Dget_space(dataset);
|
||||||
|
CHECK(sid1, FAIL, "H5Dget_space");
|
||||||
|
|
||||||
|
n = H5Sget_npoints(sid1);
|
||||||
|
CHECK(n, UFAIL, "H5Sget_npoints");
|
||||||
|
VERIFY(n, 1, "H5Sget_npoints");
|
||||||
|
|
||||||
|
rank = H5Sget_ndims(sid1);
|
||||||
|
CHECK(rank, UFAIL, "H5Sget_lrank");
|
||||||
|
VERIFY(rank, SPACE3_RANK, "H5Sget_lrank");
|
||||||
|
|
||||||
|
ret = H5Sget_dims(sid1, tdims);
|
||||||
|
VERIFY(ret, 0, "H5Sget_dims");
|
||||||
|
|
||||||
|
ret = H5Dread(dataset, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata);
|
||||||
|
CHECK(ret, FAIL, "H5Dread");
|
||||||
|
VERIFY(rdata, space3_data, "H5Dread");
|
||||||
|
|
||||||
|
/* Close Dataset */
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close scalar dataspace */
|
||||||
|
ret = H5Sclose(sid1);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_h5s_scalar_read() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_h5s_compound_scalar_write(): Test scalar H5S (dataspace) writing for
|
||||||
|
** compound datatypes.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_h5s_compound_scalar_write(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t tid1; /* Attribute datatype ID */
|
||||||
|
hid_t sid1; /* Dataspace ID */
|
||||||
|
uint32 rank; /* Logical rank of dataspace */
|
||||||
|
hsize_t tdims[4]; /* Dimension array to test with */
|
||||||
|
size_t n; /* Number of dataspace elements */
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Scalar Dataspace Manipulation\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fcreate");
|
||||||
|
|
||||||
|
/* Create the compound datatype. */
|
||||||
|
tid1 = H5Tcreate (H5T_COMPOUND, sizeof(struct space4_struct));
|
||||||
|
CHECK(tid1, FAIL, "H5Tcreate");
|
||||||
|
space4_field1_off=HOFFSET(struct space4_struct, c1);
|
||||||
|
ret = H5Tinsert(tid1, SPACE4_FIELDNAME1, space4_field1_off, H5T_NATIVE_CHAR);
|
||||||
|
CHECK(ret, FAIL, "H5Tinsert");
|
||||||
|
space4_field2_off=HOFFSET(struct space4_struct, u);
|
||||||
|
ret = H5Tinsert(tid1, SPACE4_FIELDNAME2, space4_field2_off, H5T_NATIVE_UINT32);
|
||||||
|
CHECK(ret, FAIL, "H5Tinsert");
|
||||||
|
space4_field3_off=HOFFSET(struct space4_struct, f);
|
||||||
|
ret = H5Tinsert(tid1, SPACE4_FIELDNAME3, space4_field3_off, H5T_NATIVE_FLOAT);
|
||||||
|
CHECK(ret, FAIL, "H5Tinsert");
|
||||||
|
space4_field4_off=HOFFSET(struct space4_struct, c2);
|
||||||
|
ret = H5Tinsert(tid1, SPACE4_FIELDNAME4, space4_field4_off, H5T_NATIVE_CHAR);
|
||||||
|
CHECK(ret, FAIL, "H5Tinsert");
|
||||||
|
|
||||||
|
/* Create scalar dataspace */
|
||||||
|
sid1 = H5Screate_simple(SPACE3_RANK, NULL, NULL);
|
||||||
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
||||||
|
|
||||||
|
n = H5Sget_npoints(sid1);
|
||||||
|
CHECK(n, UFAIL, "H5Sget_npoints");
|
||||||
|
VERIFY(n, 1, "H5Sget_npoints");
|
||||||
|
|
||||||
|
rank = H5Sget_ndims(sid1);
|
||||||
|
CHECK(rank, UFAIL, "H5Sget_lrank");
|
||||||
|
VERIFY(rank, SPACE3_RANK, "H5Sget_lrank");
|
||||||
|
|
||||||
|
ret = H5Sget_dims(sid1, tdims);
|
||||||
|
VERIFY(ret, 0, "H5Sget_dims");
|
||||||
|
|
||||||
|
/* Create a dataset */
|
||||||
|
dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
|
||||||
|
CHECK(dataset, FAIL, "H5Dcreate");
|
||||||
|
|
||||||
|
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, &space4_data);
|
||||||
|
CHECK(ret, FAIL, "H5Dwrite");
|
||||||
|
|
||||||
|
/* Close Dataset */
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close scalar dataspace */
|
||||||
|
ret = H5Sclose(sid1);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_h5s_compound_scalar_write() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_h5s_compound_scalar_read(): Test scalar H5S (dataspace) reading for
|
||||||
|
** compound datatypes.
|
||||||
|
**
|
||||||
|
****************************************************************/
|
||||||
|
static void
|
||||||
|
test_h5s_compound_scalar_read(void)
|
||||||
|
{
|
||||||
|
hid_t fid1; /* HDF5 File IDs */
|
||||||
|
hid_t dataset; /* Dataset ID */
|
||||||
|
hid_t sid1; /* Dataspace ID */
|
||||||
|
hid_t type; /* Datatype */
|
||||||
|
uint32 rank; /* Logical rank of dataspace */
|
||||||
|
hsize_t tdims[4]; /* Dimension array to test with */
|
||||||
|
size_t n; /* Number of dataspace elements */
|
||||||
|
struct space4_struct rdata; /* Scalar data read in */
|
||||||
|
herr_t ret; /* Generic return value */
|
||||||
|
|
||||||
|
/* Output message about test being performed */
|
||||||
|
MESSAGE(5, ("Testing Scalar Dataspace Manipulation\n"));
|
||||||
|
|
||||||
|
/* Create file */
|
||||||
|
fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||||
|
CHECK(fid1, FAIL, "H5Fopen");
|
||||||
|
|
||||||
|
/* Create a dataset */
|
||||||
|
dataset=H5Dopen(fid1,"Dataset1");
|
||||||
|
CHECK(dataset, FAIL, "H5Dopen");
|
||||||
|
|
||||||
|
sid1=H5Dget_space(dataset);
|
||||||
|
CHECK(sid1, FAIL, "H5Dget_space");
|
||||||
|
|
||||||
|
n = H5Sget_npoints(sid1);
|
||||||
|
CHECK(n, UFAIL, "H5Sget_npoints");
|
||||||
|
VERIFY(n, 1, "H5Sget_npoints");
|
||||||
|
|
||||||
|
rank = H5Sget_ndims(sid1);
|
||||||
|
CHECK(rank, UFAIL, "H5Sget_lrank");
|
||||||
|
VERIFY(rank, SPACE3_RANK, "H5Sget_lrank");
|
||||||
|
|
||||||
|
ret = H5Sget_dims(sid1, tdims);
|
||||||
|
VERIFY(ret, 0, "H5Sget_dims");
|
||||||
|
|
||||||
|
type=H5Dget_type(dataset);
|
||||||
|
CHECK(type, FAIL, "H5Dget_type");
|
||||||
|
|
||||||
|
ret = H5Dread(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata);
|
||||||
|
CHECK(ret, FAIL, "H5Dread");
|
||||||
|
if(HDmemcmp(&space4_data,&rdata,sizeof(struct space4_struct))) {
|
||||||
|
printf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n",space4_data.c1,rdata.c1);
|
||||||
|
printf("scalar data different: space4_data.u=%u, read_data4.u=%u\n",space4_data.u,rdata.u);
|
||||||
|
printf("scalar data different: space4_data.f=%f, read_data4.f=%f\n",space4_data.f,rdata.f);
|
||||||
|
printf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n",space4_data.c1,rdata.c2);
|
||||||
|
num_errs++;
|
||||||
|
} /* end if */
|
||||||
|
|
||||||
|
/* Close Dataset */
|
||||||
|
ret = H5Dclose(dataset);
|
||||||
|
CHECK(ret, FAIL, "H5Dclose");
|
||||||
|
|
||||||
|
/* Close scalar dataspace */
|
||||||
|
ret = H5Sclose(sid1);
|
||||||
|
CHECK(ret, FAIL, "H5Sclose");
|
||||||
|
|
||||||
|
/* Close file */
|
||||||
|
ret = H5Fclose(fid1);
|
||||||
|
CHECK(ret, FAIL, "H5Fclose");
|
||||||
|
} /* test_h5s_compound_scalar_read() */
|
||||||
|
|
||||||
|
/****************************************************************
|
||||||
|
**
|
||||||
|
** test_h5s(): Main H5S (dataspace) testing routine.
|
||||||
**
|
**
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
void
|
void
|
||||||
test_h5p(void)
|
test_h5s(void)
|
||||||
{
|
{
|
||||||
/* Output message about test being performed */
|
/* Output message about test being performed */
|
||||||
MESSAGE(5, ("Testing Dataspaces\n"));
|
MESSAGE(5, ("Testing Dataspaces\n"));
|
||||||
|
|
||||||
test_h5p_basic(); /* Test basic H5S code */
|
test_h5s_basic(); /* Test basic H5S code */
|
||||||
} /* test_h5p() */
|
test_h5s_scalar_write(); /* Test scalar H5S writing code */
|
||||||
|
test_h5s_scalar_read(); /* Test scalar H5S reading code */
|
||||||
|
test_h5s_compound_scalar_write(); /* Test compound datatype scalar H5S writing code */
|
||||||
|
test_h5s_compound_scalar_read(); /* Test compound datatype scalar H5S reading code */
|
||||||
|
} /* test_h5s() */
|
||||||
|
Loading…
Reference in New Issue
Block a user