1998-10-14 06:42:24 +08:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
* NCSA HDF *
|
|
|
|
|
* Software Development Group *
|
|
|
|
|
* National Center for Supercomputing Applications *
|
|
|
|
|
* University of Illinois at Urbana-Champaign *
|
|
|
|
|
* 605 E. Springfield, Champaign IL 61820 *
|
|
|
|
|
* *
|
|
|
|
|
* For conditions of distribution and use, see the accompanying *
|
|
|
|
|
* hdf/COPYING file. *
|
|
|
|
|
* *
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef RCSID
|
|
|
|
|
static char RcsId[] = "$Revision$";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
|
*
|
|
|
|
|
* Test program: trefer
|
|
|
|
|
*
|
|
|
|
|
* Test the Reference functionality
|
|
|
|
|
*
|
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <testhdf5.h>
|
|
|
|
|
|
|
|
|
|
#include <hdf5.h>
|
|
|
|
|
|
1999-06-07 23:05:02 +08:00
|
|
|
|
#define FILE1 "trefer1.h5"
|
|
|
|
|
#define FILE2 "trefer2.h5"
|
2000-10-18 04:46:57 +08:00
|
|
|
|
#define FILE3 "trefer3.h5"
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
/* 1-D dataset with fixed dimensions */
|
|
|
|
|
#define SPACE1_NAME "Space1"
|
|
|
|
|
#define SPACE1_RANK 1
|
|
|
|
|
#define SPACE1_DIM1 4
|
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
/* 2-D dataset with fixed dimensions */
|
|
|
|
|
#define SPACE2_NAME "Space2"
|
|
|
|
|
#define SPACE2_RANK 2
|
|
|
|
|
#define SPACE2_DIM1 10
|
|
|
|
|
#define SPACE2_DIM2 10
|
|
|
|
|
|
|
|
|
|
/* Element selection information */
|
|
|
|
|
#define POINT1_NPOINTS 10
|
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Compound datatype */
|
|
|
|
|
typedef struct s1_t {
|
|
|
|
|
unsigned int a;
|
|
|
|
|
unsigned int b;
|
|
|
|
|
float c;
|
|
|
|
|
} s1_t;
|
|
|
|
|
|
|
|
|
|
|
1998-10-14 06:42:24 +08:00
|
|
|
|
/****************************************************************
|
|
|
|
|
**
|
|
|
|
|
** test_reference_obj(): Test basic H5R (reference) object reference code.
|
|
|
|
|
** Tests references to various kinds of objects
|
|
|
|
|
**
|
|
|
|
|
****************************************************************/
|
|
|
|
|
static void
|
|
|
|
|
test_reference_obj(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t fid1; /* HDF5 File IDs */
|
1998-10-20 06:25:03 +08:00
|
|
|
|
hid_t dataset, /* Dataset ID */
|
|
|
|
|
dset2; /* Dereferenced dataset ID */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
hid_t group; /* Group ID */
|
|
|
|
|
hid_t sid1; /* Dataspace ID */
|
1999-03-18 09:30:10 +08:00
|
|
|
|
hid_t tid1; /* Datatype ID */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
hsize_t dims1[] = {SPACE1_DIM1};
|
1998-10-23 06:49:16 +08:00
|
|
|
|
hobj_ref_t *wbuf, /* buffer to write to disk */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
*rbuf, /* buffer read from disk */
|
|
|
|
|
*tbuf; /* temp. buffer read from disk */
|
1999-09-25 06:35:30 +08:00
|
|
|
|
uintn *tu32; /* Temporary pointer to uint32 data */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
intn i; /* counting variables */
|
1999-03-18 08:07:55 +08:00
|
|
|
|
const char *write_comment="Foo!"; /* Comments for group */
|
|
|
|
|
char read_comment[10];
|
1998-10-14 06:42:24 +08:00
|
|
|
|
herr_t ret; /* Generic return value */
|
|
|
|
|
|
|
|
|
|
/* Output message about test being performed */
|
|
|
|
|
MESSAGE(5, ("Testing Object Reference Functions\n"));
|
|
|
|
|
|
|
|
|
|
/* Allocate write & read buffers */
|
1999-09-25 06:35:30 +08:00
|
|
|
|
wbuf=malloc(MAX(sizeof(uintn),sizeof(hobj_ref_t))*SPACE1_DIM1);
|
|
|
|
|
rbuf=malloc(MAX(sizeof(uintn),sizeof(hobj_ref_t))*SPACE1_DIM1);
|
|
|
|
|
tbuf=malloc(MAX(sizeof(uintn),sizeof(hobj_ref_t))*SPACE1_DIM1);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
/* Create file */
|
1999-06-07 23:05:02 +08:00
|
|
|
|
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(fid1, FAIL, "H5Fcreate");
|
|
|
|
|
|
|
|
|
|
/* Create dataspace for datasets */
|
|
|
|
|
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
|
|
|
|
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
|
|
|
|
|
|
|
|
|
/* Create a group */
|
|
|
|
|
group=H5Gcreate(fid1,"Group1",-1);
|
|
|
|
|
CHECK(group, FAIL, "H5Gcreate");
|
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Set group's comment */
|
|
|
|
|
ret=H5Gset_comment(group,".",write_comment);
|
|
|
|
|
CHECK(ret, FAIL, "H5Gset_comment");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Create a dataset (inside Group1) */
|
1999-09-25 06:35:30 +08:00
|
|
|
|
dataset=H5Dcreate(group,"Dataset1",H5T_NATIVE_UINT,sid1,H5P_DEFAULT);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(dataset, FAIL, "H5Dcreate");
|
|
|
|
|
|
1999-09-25 06:35:30 +08:00
|
|
|
|
for(tu32=(uintn *)wbuf,i=0; i<SPACE1_DIM1; i++)
|
1998-10-14 06:42:24 +08:00
|
|
|
|
*tu32++=i*3;
|
|
|
|
|
|
|
|
|
|
/* Write selection to disk */
|
1999-09-25 06:35:30 +08:00
|
|
|
|
ret=H5Dwrite(dataset,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dwrite");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Create another dataset (inside Group1) */
|
|
|
|
|
dataset=H5Dcreate(group,"Dataset2",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(dataset, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Create a datatype to refer to */
|
|
|
|
|
tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
|
|
|
|
|
CHECK(tid1, FAIL, "H5Tcreate");
|
|
|
|
|
|
|
|
|
|
/* Insert fields */
|
|
|
|
|
ret=H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tinsert");
|
|
|
|
|
|
|
|
|
|
ret=H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tinsert");
|
|
|
|
|
|
|
|
|
|
ret=H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tinsert");
|
|
|
|
|
|
|
|
|
|
/* Save datatype for later */
|
|
|
|
|
ret=H5Tcommit (group, "Datatype1", tid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tcommit");
|
|
|
|
|
|
|
|
|
|
/* Close datatype */
|
|
|
|
|
ret = H5Tclose(tid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tclose");
|
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Close group */
|
|
|
|
|
ret = H5Gclose(group);
|
|
|
|
|
CHECK(ret, FAIL, "H5Gclose");
|
|
|
|
|
|
1998-10-14 06:42:24 +08:00
|
|
|
|
/* Create a dataset */
|
1998-10-27 01:14:00 +08:00
|
|
|
|
dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dcreate");
|
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Create reference to dataset */
|
1999-03-18 08:07:55 +08:00
|
|
|
|
ret = H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
1999-03-13 04:05:49 +08:00
|
|
|
|
ret = H5Rget_object_type(dataset,&wbuf[0]);
|
1999-03-18 09:30:10 +08:00
|
|
|
|
VERIFY(ret, H5G_DATASET, "H5Rget_object_type");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Create reference to dataset */
|
1999-03-18 08:07:55 +08:00
|
|
|
|
ret = H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
1999-03-13 04:05:49 +08:00
|
|
|
|
ret = H5Rget_object_type(dataset,&wbuf[1]);
|
1999-03-18 09:30:10 +08:00
|
|
|
|
VERIFY(ret, H5G_DATASET, "H5Rget_object_type");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Create reference to group */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
ret = H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
1999-03-13 04:05:49 +08:00
|
|
|
|
ret = H5Rget_object_type(dataset,&wbuf[2]);
|
1999-03-18 09:30:10 +08:00
|
|
|
|
VERIFY(ret, H5G_GROUP, "H5Rget_object_type");
|
|
|
|
|
|
|
|
|
|
/* Create reference to named datatype */
|
|
|
|
|
ret = H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
|
|
|
|
ret = H5Rget_object_type(dataset,&wbuf[3]);
|
|
|
|
|
VERIFY(ret, H5G_TYPE, "H5Rget_object_type");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
/* Write selection to disk */
|
1998-10-27 01:14:00 +08:00
|
|
|
|
ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dwrite");
|
|
|
|
|
|
|
|
|
|
/* Close disk dataspace */
|
|
|
|
|
ret = H5Sclose(sid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
/* Re-open the file */
|
1999-06-07 23:05:02 +08:00
|
|
|
|
fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(fid1, FAIL, "H5Fopen");
|
|
|
|
|
|
|
|
|
|
/* Open the dataset */
|
|
|
|
|
dataset=H5Dopen(fid1,"/Dataset3");
|
|
|
|
|
CHECK(ret, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Read selection from disk */
|
1998-10-27 01:14:00 +08:00
|
|
|
|
ret=H5Dread(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dread");
|
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Open dataset object */
|
1998-10-23 06:49:16 +08:00
|
|
|
|
dset2 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[0]);
|
1998-10-29 02:51:56 +08:00
|
|
|
|
CHECK(dset2, FAIL, "H5Rdereference");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
/* Check information in referenced dataset */
|
1998-10-20 06:25:03 +08:00
|
|
|
|
sid1 = H5Dget_space(dset2);
|
|
|
|
|
CHECK(sid1, FAIL, "H5Dget_space");
|
|
|
|
|
|
|
|
|
|
ret=H5Sget_simple_extent_npoints(sid1);
|
|
|
|
|
VERIFY(ret, 4, "H5Sget_simple_extent_npoints");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
/* Read from disk */
|
1999-09-25 06:35:30 +08:00
|
|
|
|
ret=H5Dread(dset2,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tbuf);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dread");
|
|
|
|
|
|
1999-09-25 06:35:30 +08:00
|
|
|
|
for(tu32=(uintn *)tbuf,i=0; i<SPACE1_DIM1; i++,tu32++)
|
1998-11-19 02:40:09 +08:00
|
|
|
|
VERIFY(*tu32, (uint32_t)(i*3), "Data");
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
1998-10-20 06:25:03 +08:00
|
|
|
|
/* Close dereferenced Dataset */
|
|
|
|
|
ret = H5Dclose(dset2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
1999-03-18 08:07:55 +08:00
|
|
|
|
/* Open group object */
|
|
|
|
|
group = H5Rdereference(dataset,H5R_OBJECT,&rbuf[2]);
|
|
|
|
|
CHECK(group, FAIL, "H5Rdereference");
|
|
|
|
|
|
|
|
|
|
/* Get group's comment */
|
|
|
|
|
ret=H5Gget_comment(group,".",10,read_comment);
|
|
|
|
|
CHECK(ret, FAIL, "H5Gget_comment");
|
|
|
|
|
|
|
|
|
|
/* Check for correct comment value */
|
|
|
|
|
if(HDstrcmp(write_comment,read_comment)!=0) {
|
|
|
|
|
num_errs++;
|
|
|
|
|
MESSAGE(0, ("Error! Incorrect group comment, wanted: %s, got: %s",write_comment,read_comment));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Close group */
|
|
|
|
|
ret = H5Gclose(group);
|
|
|
|
|
CHECK(ret, FAIL, "H5Gclose");
|
|
|
|
|
|
1999-03-18 09:30:10 +08:00
|
|
|
|
/* Open datatype object */
|
|
|
|
|
tid1 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[3]);
|
|
|
|
|
CHECK(tid1, FAIL, "H5Rdereference");
|
|
|
|
|
|
|
|
|
|
/* Verify correct datatype */
|
|
|
|
|
{
|
|
|
|
|
H5T_class_t tclass;
|
|
|
|
|
|
|
|
|
|
tclass= H5Tget_class(tid1);
|
|
|
|
|
VERIFY(tclass, H5T_COMPOUND, "H5Tget_class");
|
|
|
|
|
|
|
|
|
|
ret= H5Tget_nmembers(tid1);
|
|
|
|
|
VERIFY(ret, 3, "H5Tget_nmembers");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Close datatype */
|
|
|
|
|
ret = H5Tclose(tid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Tclose");
|
|
|
|
|
|
1998-10-14 06:42:24 +08:00
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
/* Free memory buffers */
|
|
|
|
|
free(wbuf);
|
|
|
|
|
free(rbuf);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
free(tbuf);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
} /* test_reference_obj() */
|
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
/****************************************************************
|
|
|
|
|
**
|
|
|
|
|
** test_reference_region(): Test basic H5R (reference) object reference code.
|
|
|
|
|
** Tests references to various kinds of objects
|
|
|
|
|
**
|
|
|
|
|
****************************************************************/
|
|
|
|
|
static void
|
|
|
|
|
test_reference_region(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t fid1; /* HDF5 File IDs */
|
|
|
|
|
hid_t dset1, /* Dataset ID */
|
|
|
|
|
dset2; /* Dereferenced dataset ID */
|
|
|
|
|
hid_t sid1, /* Dataspace ID #1 */
|
|
|
|
|
sid2; /* Dataspace ID #2 */
|
|
|
|
|
hsize_t dims1[] = {SPACE1_DIM1},
|
|
|
|
|
dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
|
|
|
|
|
hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
|
|
|
|
|
hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
|
|
|
|
|
hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
|
|
|
|
|
hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
|
|
|
|
|
hssize_t coord1[POINT1_NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */
|
1999-03-11 07:50:25 +08:00
|
|
|
|
hsize_t * coords; /* Coordinate buffer */
|
|
|
|
|
hsize_t low[SPACE2_RANK]; /* Selection bounds */
|
|
|
|
|
hsize_t high[SPACE2_RANK]; /* Selection bounds */
|
1998-11-13 08:28:58 +08:00
|
|
|
|
hdset_reg_ref_t *wbuf, /* buffer to write to disk */
|
|
|
|
|
*rbuf; /* buffer read from disk */
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t *dwbuf, /* Buffer for writing numeric data to disk */
|
1998-11-13 08:28:58 +08:00
|
|
|
|
*drbuf; /* Buffer for reading numeric data from disk */
|
1998-11-19 02:40:09 +08:00
|
|
|
|
uint8_t *tu8; /* Temporary pointer to uint8 data */
|
1998-11-13 08:28:58 +08:00
|
|
|
|
intn i; /* counting variables */
|
|
|
|
|
herr_t ret; /* Generic return value */
|
|
|
|
|
|
|
|
|
|
/* Output message about test being performed */
|
|
|
|
|
MESSAGE(5, ("Testing Dataset Region Reference Functions\n"));
|
|
|
|
|
|
|
|
|
|
/* Allocate write & read buffers */
|
1999-06-08 04:20:32 +08:00
|
|
|
|
wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
|
1998-11-19 02:40:09 +08:00
|
|
|
|
dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2);
|
|
|
|
|
drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
|
|
|
|
|
/* Create file */
|
1999-06-07 23:05:02 +08:00
|
|
|
|
fid1 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(fid1, FAIL, "H5Fcreate");
|
|
|
|
|
|
|
|
|
|
/* Create dataspace for datasets */
|
|
|
|
|
sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
|
|
|
|
|
CHECK(sid2, FAIL, "H5Screate_simple");
|
|
|
|
|
|
|
|
|
|
/* Create a dataset */
|
|
|
|
|
dset2=H5Dcreate(fid1,"Dataset2",H5T_STD_U8LE,sid2,H5P_DEFAULT);
|
|
|
|
|
CHECK(dset2, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
for(tu8=dwbuf,i=0; i<SPACE2_DIM1*SPACE2_DIM2; i++)
|
|
|
|
|
*tu8++=i*3;
|
|
|
|
|
|
|
|
|
|
/* Write selection to disk */
|
|
|
|
|
ret=H5Dwrite(dset2,H5T_STD_U8LE,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dwrite");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dset2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Create dataspace for the reference dataset */
|
|
|
|
|
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
|
|
|
|
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
|
|
|
|
|
|
|
|
|
/* Create a dataset */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
dset1=H5Dcreate(fid1,"Dataset1",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Create references */
|
|
|
|
|
|
|
|
|
|
/* Select 6x6 hyperslab for first reference */
|
|
|
|
|
start[0]=2; start[1]=2;
|
|
|
|
|
stride[0]=1; stride[1]=1;
|
2000-09-14 07:50:39 +08:00
|
|
|
|
count[0]=1; count[1]=1;
|
|
|
|
|
block[0]=6; block[1]=6;
|
1998-11-13 08:28:58 +08:00
|
|
|
|
ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sselect_hyperslab");
|
|
|
|
|
|
1999-03-11 07:50:25 +08:00
|
|
|
|
ret = H5Sget_select_npoints(sid2);
|
|
|
|
|
VERIFY(ret, 36, "H5Sget_select_npoints");
|
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
/* Store first dataset region */
|
|
|
|
|
ret = H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
|
|
|
|
|
|
|
|
|
/* Select sequence of ten points for second reference */
|
|
|
|
|
coord1[0][0]=6; coord1[0][1]=9;
|
|
|
|
|
coord1[1][0]=2; coord1[1][1]=2;
|
|
|
|
|
coord1[2][0]=8; coord1[2][1]=4;
|
|
|
|
|
coord1[3][0]=1; coord1[3][1]=6;
|
|
|
|
|
coord1[4][0]=2; coord1[4][1]=8;
|
|
|
|
|
coord1[5][0]=3; coord1[5][1]=2;
|
|
|
|
|
coord1[6][0]=0; coord1[6][1]=4;
|
|
|
|
|
coord1[7][0]=9; coord1[7][1]=0;
|
|
|
|
|
coord1[8][0]=7; coord1[8][1]=1;
|
|
|
|
|
coord1[9][0]=3; coord1[9][1]=3;
|
|
|
|
|
ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sselect_elements");
|
|
|
|
|
|
1999-03-11 07:50:25 +08:00
|
|
|
|
ret = H5Sget_select_npoints(sid2);
|
|
|
|
|
VERIFY(ret, 10, "H5Sget_select_npoints");
|
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
/* Store second dataset region */
|
|
|
|
|
ret = H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
|
|
|
|
|
|
|
|
|
/* Write selection to disk */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dwrite");
|
|
|
|
|
|
|
|
|
|
/* Close disk dataspace */
|
|
|
|
|
ret = H5Sclose(sid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dset1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close uint8 dataset dataspace */
|
|
|
|
|
ret = H5Sclose(sid2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
/* Re-open the file */
|
1999-06-07 23:05:02 +08:00
|
|
|
|
fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(fid1, FAIL, "H5Fopen");
|
|
|
|
|
|
|
|
|
|
/* Open the dataset */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
dset1=H5Dopen(fid1,"/Dataset1");
|
|
|
|
|
CHECK(dset1, FAIL, "H5Dopen");
|
1998-11-13 08:28:58 +08:00
|
|
|
|
|
|
|
|
|
/* Read selection from disk */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dread");
|
|
|
|
|
|
|
|
|
|
/* Try to open objects */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(dset2, FAIL, "H5Rdereference");
|
|
|
|
|
|
|
|
|
|
/* Check information in referenced dataset */
|
|
|
|
|
sid1 = H5Dget_space(dset2);
|
|
|
|
|
CHECK(sid1, FAIL, "H5Dget_space");
|
|
|
|
|
|
|
|
|
|
ret=H5Sget_simple_extent_npoints(sid1);
|
1999-03-11 07:50:25 +08:00
|
|
|
|
VERIFY(ret, 100, "H5Sget_simple_extent_npoints");
|
1998-11-13 08:28:58 +08:00
|
|
|
|
|
|
|
|
|
/* Read from disk */
|
1999-03-11 07:50:25 +08:00
|
|
|
|
ret=H5Dread(dset2,H5T_STD_U8LE,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dread");
|
|
|
|
|
|
1999-03-11 07:50:25 +08:00
|
|
|
|
for(tu8=(uint8_t *)drbuf,i=0; i<SPACE2_DIM1*SPACE2_DIM2; i++,tu8++)
|
|
|
|
|
VERIFY(*tu8, (uint8_t)(i*3), "Data");
|
|
|
|
|
|
|
|
|
|
/* Get the hyperslab selection */
|
|
|
|
|
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
|
|
|
|
|
CHECK(sid2, FAIL, "H5Rget_region");
|
|
|
|
|
|
|
|
|
|
/* Verify correct hyperslab selected */
|
|
|
|
|
ret = H5Sget_select_npoints(sid2);
|
|
|
|
|
VERIFY(ret, 36, "H5Sget_select_npoints");
|
|
|
|
|
ret = H5Sget_select_hyper_nblocks(sid2);
|
|
|
|
|
VERIFY(ret, 1, "H5Sget_select_hyper_nblocks");
|
|
|
|
|
coords=HDmalloc(ret*SPACE2_RANK*sizeof(hsize_t)*2); /* allocate space for the hyperslab blocks */
|
1999-03-12 05:03:41 +08:00
|
|
|
|
ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
|
1999-03-11 07:50:25 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Sget_select_hyper_blocklist");
|
|
|
|
|
VERIFY(coords[0], 2, "Hyperslab Coordinates");
|
|
|
|
|
VERIFY(coords[1], 2, "Hyperslab Coordinates");
|
|
|
|
|
VERIFY(coords[2], 7, "Hyperslab Coordinates");
|
|
|
|
|
VERIFY(coords[3], 7, "Hyperslab Coordinates");
|
|
|
|
|
HDfree(coords);
|
|
|
|
|
ret = H5Sget_select_bounds(sid2,low,high);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sget_select_bounds");
|
|
|
|
|
VERIFY(low[0], 2, "Selection Bounds");
|
|
|
|
|
VERIFY(low[1], 2, "Selection Bounds");
|
|
|
|
|
VERIFY(high[0], 7, "Selection Bounds");
|
|
|
|
|
VERIFY(high[1], 7, "Selection Bounds");
|
|
|
|
|
|
|
|
|
|
/* Close region space */
|
|
|
|
|
ret = H5Sclose(sid2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
|
|
|
|
|
|
|
|
|
/* Get the element selection */
|
|
|
|
|
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);
|
|
|
|
|
CHECK(sid2, FAIL, "H5Rget_region");
|
|
|
|
|
|
|
|
|
|
/* Verify correct elements selected */
|
|
|
|
|
ret = H5Sget_select_npoints(sid2);
|
|
|
|
|
VERIFY(ret, 10, "H5Sget_select_npoints");
|
|
|
|
|
ret = H5Sget_select_elem_npoints(sid2);
|
|
|
|
|
VERIFY(ret, 10, "H5Sget_select_elem_npoints");
|
|
|
|
|
coords=HDmalloc(ret*SPACE2_RANK*sizeof(hsize_t)); /* allocate space for the element points */
|
1999-03-12 05:03:41 +08:00
|
|
|
|
ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
|
1999-03-11 07:50:25 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Sget_select_elem_pointlist");
|
|
|
|
|
VERIFY((hssize_t)coords[0], coord1[0][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[1], coord1[0][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[2], coord1[1][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[3], coord1[1][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[4], coord1[2][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[5], coord1[2][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[6], coord1[3][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[7], coord1[3][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[8], coord1[4][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[9], coord1[4][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[10], coord1[5][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[11], coord1[5][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[12], coord1[6][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[13], coord1[6][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[14], coord1[7][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[15], coord1[7][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[16], coord1[8][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[17], coord1[8][1], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[18], coord1[9][0], "Element Coordinates");
|
|
|
|
|
VERIFY((hssize_t)coords[19], coord1[9][1], "Element Coordinates");
|
|
|
|
|
HDfree(coords);
|
|
|
|
|
ret = H5Sget_select_bounds(sid2,low,high);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sget_select_bounds");
|
|
|
|
|
VERIFY(low[0], 0, "Selection Bounds");
|
|
|
|
|
VERIFY(low[1], 0, "Selection Bounds");
|
|
|
|
|
VERIFY(high[0], 9, "Selection Bounds");
|
|
|
|
|
VERIFY(high[1], 9, "Selection Bounds");
|
|
|
|
|
|
|
|
|
|
/* Close region space */
|
|
|
|
|
ret = H5Sclose(sid2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
1998-11-13 08:28:58 +08:00
|
|
|
|
|
1999-03-11 07:50:25 +08:00
|
|
|
|
/* Close first space */
|
|
|
|
|
ret = H5Sclose(sid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
1998-12-01 03:44:30 +08:00
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
/* Close dereferenced Dataset */
|
|
|
|
|
ret = H5Dclose(dset2);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
1998-12-01 03:44:30 +08:00
|
|
|
|
ret = H5Dclose(dset1);
|
1998-11-13 08:28:58 +08:00
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
/* Free memory buffers */
|
|
|
|
|
free(wbuf);
|
|
|
|
|
free(rbuf);
|
|
|
|
|
free(dwbuf);
|
|
|
|
|
free(drbuf);
|
|
|
|
|
} /* test_reference_region() */
|
|
|
|
|
|
2000-10-18 04:46:57 +08:00
|
|
|
|
/****************************************************************
|
|
|
|
|
**
|
|
|
|
|
** test_reference_obj_deleted(): Test H5R (reference) object reference code.
|
|
|
|
|
** Tests for correct failures for deleted and non-existent objects
|
|
|
|
|
**
|
|
|
|
|
****************************************************************/
|
|
|
|
|
static void
|
|
|
|
|
test_reference_obj_deleted(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t fid1; /* HDF5 File IDs */
|
|
|
|
|
hid_t dataset, /* Dataset ID */
|
|
|
|
|
dset2; /* Dereferenced dataset ID */
|
|
|
|
|
hid_t sid1; /* Dataspace ID */
|
|
|
|
|
hobj_ref_t oref; /* Object Reference to test */
|
|
|
|
|
herr_t ret; /* Generic return value */
|
|
|
|
|
|
|
|
|
|
/* Create file */
|
|
|
|
|
fid1 = H5Fcreate(FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
|
|
|
|
CHECK(fid1, FAIL, "H5Fcreate");
|
|
|
|
|
|
|
|
|
|
/* Create scalar dataspace for datasets */
|
|
|
|
|
sid1 = H5Screate_simple(0, NULL, NULL);
|
|
|
|
|
CHECK(sid1, FAIL, "H5Screate_simple");
|
|
|
|
|
|
|
|
|
|
/* Create a dataset to reference (deleted later) */
|
|
|
|
|
dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_INT,sid1,H5P_DEFAULT);
|
|
|
|
|
CHECK(dataset, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Create a dataset */
|
|
|
|
|
dataset=H5Dcreate(fid1,"Dataset2",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
|
|
|
|
|
CHECK(dataset, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Create reference to dataset */
|
|
|
|
|
ret = H5Rcreate(&oref,fid1,"/Dataset1",H5R_OBJECT,-1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Rcreate");
|
|
|
|
|
ret = H5Rget_object_type(dataset,&oref);
|
|
|
|
|
VERIFY(ret, H5G_DATASET, "H5Rget_object_type");
|
|
|
|
|
|
|
|
|
|
/* Write selection to disk */
|
|
|
|
|
ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,&oref);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dwrite");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Delete referenced dataset */
|
|
|
|
|
ret = H5Gunlink(fid1,"/Dataset1");
|
|
|
|
|
CHECK(ret, FAIL, "H5Gunlink");
|
|
|
|
|
|
|
|
|
|
/* Close disk dataspace */
|
|
|
|
|
ret = H5Sclose(sid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Sclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
/* Re-open the file */
|
|
|
|
|
fid1 = H5Fopen(FILE3, H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
CHECK(fid1, FAIL, "H5Fopen");
|
|
|
|
|
|
|
|
|
|
/* Open the dataset */
|
|
|
|
|
dataset=H5Dopen(fid1,"/Dataset2");
|
|
|
|
|
CHECK(ret, FAIL, "H5Dcreate");
|
|
|
|
|
|
|
|
|
|
/* Read selection from disk */
|
|
|
|
|
memset(&oref,0,sizeof(hobj_ref_t));
|
|
|
|
|
ret=H5Dread(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,&oref);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dread");
|
|
|
|
|
|
|
|
|
|
/* Open deleted dataset object */
|
|
|
|
|
dset2 = H5Rdereference(dataset,H5R_OBJECT,&oref);
|
|
|
|
|
VERIFY(dset2, FAIL, "H5Rdereference");
|
|
|
|
|
|
|
|
|
|
/* Open nonsense reference */
|
|
|
|
|
memset(&oref,0,sizeof(hobj_ref_t));
|
|
|
|
|
dset2 = H5Rdereference(dataset,H5R_OBJECT,&oref);
|
|
|
|
|
VERIFY(dset2, FAIL, "H5Rdereference");
|
|
|
|
|
|
|
|
|
|
/* Close Dataset */
|
|
|
|
|
ret = H5Dclose(dataset);
|
|
|
|
|
CHECK(ret, FAIL, "H5Dclose");
|
|
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
|
ret = H5Fclose(fid1);
|
|
|
|
|
CHECK(ret, FAIL, "H5Fclose");
|
|
|
|
|
|
|
|
|
|
} /* test_reference_obj_deleted() */
|
|
|
|
|
|
1998-10-14 06:42:24 +08:00
|
|
|
|
/****************************************************************
|
|
|
|
|
**
|
|
|
|
|
** test_reference(): Main H5R reference testing routine.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************/
|
|
|
|
|
void
|
|
|
|
|
test_reference(void)
|
|
|
|
|
{
|
|
|
|
|
/* Output message about test being performed */
|
|
|
|
|
MESSAGE(5, ("Testing References\n"));
|
|
|
|
|
|
1998-11-13 08:28:58 +08:00
|
|
|
|
test_reference_obj(); /* Test basic H5R object reference code */
|
|
|
|
|
test_reference_region(); /* Test basic H5R dataset region reference code */
|
2000-10-18 04:46:57 +08:00
|
|
|
|
test_reference_obj_deleted(); /* Test H5R object reference code for deleted objects */
|
1998-10-14 06:42:24 +08:00
|
|
|
|
|
|
|
|
|
} /* test_reference() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: cleanup_reference
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Cleanup temporary test files
|
|
|
|
|
*
|
|
|
|
|
* Return: none
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* September 8, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
cleanup_reference(void)
|
|
|
|
|
{
|
1999-06-07 23:05:02 +08:00
|
|
|
|
remove(FILE1);
|
|
|
|
|
remove(FILE2);
|
2000-10-18 04:46:57 +08:00
|
|
|
|
remove(FILE3);
|
1998-10-14 06:42:24 +08:00
|
|
|
|
}
|
|
|
|
|
|