summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2003-05-22 22:22:32 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2003-05-22 22:22:32 (GMT)
commit73508e8d655eed73a264e16b79387a6eb83c0b5a (patch)
treed08c2f053eaa30c8a7e823a438138fe15058491b
parent68caabdfd501d63db1f506d8a31e568c455f9111 (diff)
downloadhdf5-73508e8d655eed73a264e16b79387a6eb83c0b5a.zip
hdf5-73508e8d655eed73a264e16b79387a6eb83c0b5a.tar.gz
hdf5-73508e8d655eed73a264e16b79387a6eb83c0b5a.tar.bz2
[svn-r6912] Purpose:
added a new test for h5ls Description: Solution: Platforms tested: Misc. update:
-rw-r--r--tools/h5dump/h5dumpgentest.c652
1 files changed, 430 insertions, 222 deletions
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index 62e5d6d..cd1f727 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -26,38 +26,38 @@
#include "hdf5.h"
#include "H5private.h"
-#define FILE1 "tgroup.h5"
-#define FILE2 "tdset.h5"
-#define FILE3 "tattr.h5"
-#define FILE4 "tslink.h5"
-#define FILE5 "thlink.h5"
-#define FILE6 "tcompound.h5"
-#define FILE7 "tall.h5"
-#define FILE8 "tdset2.h5"
-#define FILE9 "tcompound2.h5"
-#define FILE10 "tloop.h5"
-#define FILE11 "tloop2.h5"
-#define FILE12 "tmany.h5"
-#define FILE13 "tstr.h5"
-#define FILE14 "tstr2.h5"
-#define FILE15 "tenum.h5"
-#define FILE16 "tobjref.h5"
-#define FILE17 "tdatareg.h5"
-#define FILE18 "tnestedcomp.h5"
-#define FILE19 "topaque.h5"
-#define FILE20 "tbitfields.h5"
-#define FILE21 "tvldtypes1.h5"
-#define FILE22 "tvldtypes2.h5"
-#define FILE23 "tvldtypes3.h5"
-#define FILE24 "tvldtypes4.h5"
-#define FILE25 "tarray1.h5"
-#define FILE26 "tarray2.h5"
-#define FILE27 "tarray3.h5"
-#define FILE28 "tarray4.h5"
-#define FILE29 "tarray5.h5"
-#define FILE30 "tarray6.h5"
-#define FILE31 "tarray7.h5"
-#define FILE32 "tempty.h5"
+#define FILE1 "tgroup.h5"
+#define FILE2 "tdset.h5"
+#define FILE3 "tattr.h5"
+#define FILE4 "tslink.h5"
+#define FILE5 "thlink.h5"
+#define FILE6 "tcompound.h5"
+#define FILE7 "tall.h5"
+#define FILE8 "tdset2.h5"
+#define FILE9 "tcompound2.h5"
+#define FILE10 "tloop.h5"
+#define FILE11 "tloop2.h5"
+#define FILE12 "tmany.h5"
+#define FILE13 "tstr.h5"
+#define FILE14 "tstr2.h5"
+#define FILE15 "tenum.h5"
+#define FILE16 "tobjref.h5"
+#define FILE17 "tdatareg.h5"
+#define FILE18 "tnestedcomp.h5"
+#define FILE19 "topaque.h5"
+#define FILE20 "tbitfields.h5"
+#define FILE21 "tvldtypes1.h5"
+#define FILE22 "tvldtypes2.h5"
+#define FILE23 "tvldtypes3.h5"
+#define FILE24 "tvldtypes4.h5"
+#define FILE25 "tarray1.h5"
+#define FILE26 "tarray2.h5"
+#define FILE27 "tarray3.h5"
+#define FILE28 "tarray4.h5"
+#define FILE29 "tarray5.h5"
+#define FILE30 "tarray6.h5"
+#define FILE31 "tarray7.h5"
+#define FILE32 "tempty.h5"
#define FILE33 "tgrp_comments.h5"
#define FILE34 "tsplit_file"
#define FILE35 "tfamily%05d.h5"
@@ -65,19 +65,25 @@
#define FILE37 "tlarge_objname.h5"
#define FILE38 "tvlstr.h5"
#define FILE39 "tchar.h5"
+#define FILE40 "tattr2.h5"
-#define LENSTR 50
-#define LENSTR2 11
+/* prototype */
+int write_attr(hid_t loc_id, int rank, hsize_t *dims, const char *attr_name,
+ hid_t type_id, void *buf);
-#define SPACE2_RANK 2
-#define SPACE2_DIM1 10
-#define SPACE2_DIM2 10
-#define SPACE1_RANK 1
-#define SPACE1_DIM1 4
+#define LENSTR 50
+#define LENSTR2 11
+
+#define SPACE2_RANK 2
+#define SPACE2_DIM1 10
+#define SPACE2_DIM2 10
+
+#define SPACE1_RANK 1
+#define SPACE1_DIM1 4
/* Element selection information */
-#define POINT1_NPOINTS 10
+#define POINT1_NPOINTS 10
typedef enum{
RED,
@@ -96,17 +102,17 @@ typedef struct s1_t {
/* 1-D array datatype */
-#define ARRAY1_RANK 1
+#define ARRAY1_RANK 1
#define ARRAY1_DIM1 4
/* 3-D array datatype */
-#define ARRAY2_RANK 3
+#define ARRAY2_RANK 3
#define ARRAY2_DIM1 3
#define ARRAY2_DIM2 4
#define ARRAY2_DIM3 5
/* 2-D array datatype */
-#define ARRAY3_RANK 2
+#define ARRAY3_RANK 2
#define ARRAY3_DIM1 6
#define ARRAY3_DIM2 3
@@ -739,12 +745,12 @@ static void gent_compound_dt2(void) { /* test compound data type */
/*
-/ : g1 g2 attr1 attr2
-g1 : g1.1 g1.2
-g1.1 : dset1.1.1(attr1, attr2) dset1.1.2
-g1.2 : g1.2.1
-g1.2.1 : slink
-g2 : dset2.1 dset2.2
+/ : g1 g2 attr1 attr2
+g1 : g1.1 g1.2
+g1.1 : dset1.1.1(attr1, attr2) dset1.1.2
+g1.2 : g1.2.1
+g1.2.1 : slink
+g2 : dset2.1 dset2.2
*/
@@ -945,8 +951,8 @@ static void gent_many(void) {
int i0, i1, i2, i3;
hsize_t sdim, maxdim;
- typedef struct { /* compound type has members with rank > 1 */
- int a[2][2][2][2]; /* arrays are 2x2x2x2 */
+ typedef struct { /* compound type has members with rank > 1 */
+ int a[2][2][2][2]; /* arrays are 2x2x2x2 */
double b[2][2][2][2];
double c[2][2][2][2];
} dset1_t;
@@ -1030,26 +1036,26 @@ static void gent_many(void) {
H5Aclose(attr);
for (j=0; j<(int)sdim; j++) {
- for (i3 = 0; i3 < 2; i3++) {
- idx[perm[3]] = i3;
- for (i2 = 0; i2 < 2; i2++) {
- idx[perm[2]] = i2;
- for (i1 = 0; i1 < 2; i1++) {
- idx[perm[1]] = i1;
- for (i0 = 0; i0 < 2; i0++) {
- idx[perm[0]] = i0;
-
- dset1[j].a[idx[3]][idx[2]][idx[1]][idx[0]] = i0+j;
- dset1[j].b[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j);
+ for (i3 = 0; i3 < 2; i3++) {
+ idx[perm[3]] = i3;
+ for (i2 = 0; i2 < 2; i2++) {
+ idx[perm[2]] = i2;
+ for (i1 = 0; i1 < 2; i1++) {
+ idx[perm[1]] = i1;
+ for (i0 = 0; i0 < 2; i0++) {
+ idx[perm[0]] = i0;
+
+ dset1[j].a[idx[3]][idx[2]][idx[1]][idx[0]] = i0+j;
+ dset1[j].b[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j);
#ifdef WIN32
- dset1[j].c[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j+(signed __int64)sdim);
+ dset1[j].c[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j+(signed __int64)sdim);
#else
- dset1[j].c[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j+sdim);
+ dset1[j].c[idx[3]][idx[2]][idx[1]][idx[0]] = (double)(i0+j+sdim);
#endif
- }
- }
- }
- }
+ }
+ }
+ }
+ }
}
H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
@@ -1330,11 +1336,11 @@ hsize_t sdim;
block[0]=1;
for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
H5Gclose(group);
@@ -1343,11 +1349,11 @@ hsize_t sdim;
dataset = H5Dcreate(group, "dset2", fxdlenstr, space, H5P_DEFAULT);
for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of string array",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
H5Gclose(group);
@@ -1363,11 +1369,11 @@ hsize_t sdim;
dataset = H5Dcreate(group, "dset3", fxdlenstr, space, H5P_DEFAULT);
for (i = 0;(hsize_t) i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
H5Gclose(group);
@@ -1377,11 +1383,11 @@ hsize_t sdim;
dataset = H5Dcreate(group, "dset4", fxdlenstr, space, H5P_DEFAULT);
for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of string array",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
H5Gclose(group);
@@ -1396,11 +1402,11 @@ hsize_t sdim;
dataset = H5Dcreate(group, "dset5", fxdlenstr, space, H5P_DEFAULT);
for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
H5Gclose(group);
@@ -1410,11 +1416,11 @@ hsize_t sdim;
dataset = H5Dcreate(group, "dset6", fxdlenstr, space, H5P_DEFAULT);
for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
+ start[0] = i;
+ sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of string array",i);
+ H5Tset_size(memtype, HDstrlen(buf)+1);
+ H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
+ H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
}
H5Dclose(dataset);
@@ -1433,9 +1439,9 @@ static void gent_enum(void)
hid_t file, type, space, dset;
int val;
enumtype data[] = {RED, GREEN, BLUE, GREEN, WHITE,
- WHITE, BLACK, GREEN, BLUE, RED,
- RED, BLUE, GREEN, BLACK, WHITE,
- RED, WHITE, GREEN, GREEN, BLUE};
+ WHITE, BLACK, GREEN, BLUE, RED,
+ RED, BLUE, GREEN, BLACK, WHITE,
+ RED, WHITE, GREEN, GREEN, BLUE};
hsize_t size[1] = {NELMTS(data)};
file = H5Fcreate(FILE15,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
@@ -1461,13 +1467,13 @@ static void gent_enum(void)
static void gent_objref(void)
{
/*some code is taken from enum.c in the test dir */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
- hid_t group; /* Group ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Datatype ID */
- hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t group; /* Group ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Datatype ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
hobj_ref_t *wbuf, /* buffer to write to disk */
*rbuf, /* buffer read from disk */
*tbuf; /* temp. buffer read from disk */
@@ -1567,18 +1573,18 @@ static void gent_datareg(void)
{
/*some code is taken from enum.c in the test dir */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dset1, /* Dataset ID */
+ 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 */
+ 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 */
hdset_reg_ref_t *wbuf, /* buffer to write to disk */
*rbuf; /* buffer read from disk */
uint8_t *dwbuf, /* Buffer for writing numeric data to disk */
@@ -1681,9 +1687,9 @@ static void gent_nestcomp(void)
/* First structure and dataset*/
typedef struct s1_t {
- int a;
- float b;
- double c;
+ int a;
+ float b;
+ double c;
cmp_t d;
} s2_t;
hid_t cmp_tid; /* Handle for the compound datatype */
@@ -1760,7 +1766,7 @@ static void gent_nestcomp(void)
*/
status = H5Dwrite(dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1);
if (status < 0)
- fprintf(stderr, "gent_nestcomp H5Dwrite failed\n");
+ fprintf(stderr, "gent_nestcomp H5Dwrite failed\n");
/*
* Release resources
@@ -1784,7 +1790,7 @@ static void gent_opaque(void)
test[x][0] = x;
test[x][1] = 99 - x;
}
-
+
/*
* Create the data space.
*/
@@ -1814,15 +1820,15 @@ static void gent_opaque(void)
H5Tclose(type);
H5Sclose(space);
H5Dclose(dataset);
- H5Fclose(file);
+ H5Fclose(file);
}
static void gent_bitfields(void)
{
- hid_t file, grp=-1, type=-1, space=-1, dset=-1;
- size_t i;
- hsize_t nelmts;
- unsigned char buf[32];
+ hid_t file, grp=-1, type=-1, space=-1, dset=-1;
+ size_t i;
+ hsize_t nelmts;
+ unsigned char buf[32];
file = H5Fcreate(FILE20, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
@@ -1831,13 +1837,13 @@ static void gent_bitfields(void)
/* bitfield_1 */
nelmts = sizeof(buf);
if ((type=H5Tcopy(H5T_STD_B8LE))<0 ||
- (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
- (dset=H5Dcreate(grp, "bitfield_1", type, space, H5P_DEFAULT))<0)
- goto error;
+ (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
+ (dset=H5Dcreate(grp, "bitfield_1", type, space, H5P_DEFAULT))<0)
+ goto error;
for (i=0; i<sizeof buf; i++) buf[i] = (unsigned char)0xff ^ (unsigned char)i;
if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0)
- goto error;
+ goto error;
if (H5Sclose(space)<0) goto error;
if (H5Tclose(type)<0) goto error;
if (H5Dclose(dset)<0) goto error;
@@ -1845,12 +1851,12 @@ static void gent_bitfields(void)
/* bitfield_2 */
nelmts = sizeof(buf)/2;
if ((type=H5Tcopy(H5T_STD_B16LE))<0 ||
- (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
- (dset=H5Dcreate(grp, "bitfield_2", type, space, H5P_DEFAULT))<0)
- goto error;
+ (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
+ (dset=H5Dcreate(grp, "bitfield_2", type, space, H5P_DEFAULT))<0)
+ goto error;
for (i=0; i<sizeof buf; i++) buf[i] = (unsigned char)0xff ^ (unsigned char)i;
if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0)
- goto error;
+ goto error;
if (H5Sclose(space)<0) goto error;
if (H5Tclose(type)<0) goto error;
if (H5Dclose(dset)<0) goto error;
@@ -1859,10 +1865,10 @@ static void gent_bitfields(void)
error:
H5E_BEGIN_TRY {
- H5Gclose(grp);
- H5Tclose(type);
- H5Sclose(space);
- H5Dclose(dset);
+ H5Gclose(grp);
+ H5Tclose(type);
+ H5Sclose(space);
+ H5Dclose(dset);
} H5E_END_TRY;
}
@@ -1878,7 +1884,7 @@ static void gent_vldatatypes(void)
/* Allocate and initialize VL dataset to write */
for(i = 0; i < SPACE1_DIM1; i++) {
- int j;
+ int j;
wdata[i].p = malloc((i + 1) * sizeof(int));
wdata[i].len = i + 1;
@@ -1905,7 +1911,7 @@ static void gent_vldatatypes(void)
/* Allocate and initialize VL dataset to write */
for(i = 0; i < SPACE1_DIM1; i++) {
- int j;
+ int j;
wdata[i].p = malloc((i + 1) * sizeof(float));
wdata[i].len = i + 1;
@@ -1960,13 +1966,13 @@ static void gent_vldatatypes2(void)
{
hvl_t wdata[SPACE1_DIM1]; /* Information to write */
hvl_t *t1; /* Temporary pointer to VL information */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1, tid2; /* Datatype IDs */
+ hsize_t dims1[] = {SPACE1_DIM1};
unsigned i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize VL data to write */
for(i=0; i<SPACE1_DIM1; i++) {
@@ -2033,13 +2039,13 @@ static void gent_vldatatypes3(void)
hvl_t v;
} s1;
s1 wdata[SPACE1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1, tid2; /* Datatype IDs */
+ hsize_t dims1[] = {SPACE1_DIM1};
unsigned i,j; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize VL data to write */
for(i=0; i<SPACE1_DIM1; i++) {
@@ -2102,13 +2108,13 @@ static void gent_vldatatypes4(void)
float f;
} s1;
hvl_t wdata[SPACE1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1, tid2; /* Datatype IDs */
+ hsize_t dims1[] = {SPACE1_DIM1};
unsigned i,j; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize VL data to write */
for(i=0; i<SPACE1_DIM1; i++) {
@@ -2165,14 +2171,14 @@ static void gent_vldatatypes4(void)
static void gent_array1(void)
{
int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
int i,j; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2209,14 +2215,14 @@ static void gent_array1(void)
static void gent_array2(void)
{
int wdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information to write */
- hid_t fid; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims2[] = {ARRAY2_DIM1,ARRAY2_DIM2,ARRAY2_DIM3};
+ hid_t fid; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid; /* Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims2[] = {ARRAY2_DIM1,ARRAY2_DIM2,ARRAY2_DIM3};
int i,j,k,l; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2255,16 +2261,16 @@ static void gent_array2(void)
static void gent_array3(void)
{
int wdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information to write */
- hid_t fid; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid1; /* 1-D array Datatype ID */
- hid_t tid2; /* 2-D array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- hsize_t tdims2[] = {ARRAY3_DIM1,ARRAY3_DIM2};
+ hid_t fid; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid1; /* 1-D array Datatype ID */
+ hid_t tid2; /* 2-D array Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
+ hsize_t tdims2[] = {ARRAY3_DIM1,ARRAY3_DIM2};
int i,j,k,l; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Allocate and initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2312,15 +2318,15 @@ static void gent_array4(void)
float f;
} s2_t;
s2_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* Compound Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Array Datatype ID */
+ hid_t tid2; /* Compound Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
int i,j; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2378,16 +2384,16 @@ static void gent_array5(void)
float f[ARRAY1_DIM1];
} s2_t;
s2_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* Compound Datatype ID */
- hid_t tid3; /* Nested Array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Array Datatype ID */
+ hid_t tid2; /* Compound Datatype ID */
+ hid_t tid3; /* Nested Array Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
int i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2449,15 +2455,15 @@ static void gent_array5(void)
static void gent_array6(void)
{
hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* VL Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Array Datatype ID */
+ hid_t tid2; /* VL Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
int i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2509,16 +2515,16 @@ static void gent_array6(void)
static void gent_array7(void)
{
hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* VL Datatype ID */
- hid_t tid3; /* Nested Array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hid_t tid1; /* Array Datatype ID */
+ hid_t tid2; /* VL Datatype ID */
+ hid_t tid3; /* Nested Array Datatype ID */
+ hsize_t sdims1[] = {SPACE1_DIM1};
+ hsize_t tdims1[] = {ARRAY1_DIM1};
int i,j,k,l; /* Index variables */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
@@ -2854,11 +2860,11 @@ static void gent_vlstr(void)
"testing whether that nation or any nation so conceived and so dedicated can long endure."
}; /* Information to write */
const char *string_att= "This is the string for the attribute";
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset, root; /* Dataset ID */
- hid_t sid1, dataspace;/* Dataspace ID */
- hid_t tid1, att; /* Datatype ID */
- hsize_t dims1[] = {SPACE1_DIM1};
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset, root; /* Dataset ID */
+ hid_t sid1, dataspace;/* Dataspace ID */
+ hid_t tid1, att; /* Datatype ID */
+ hsize_t dims1[] = {SPACE1_DIM1};
/* Create file */
fid1 = H5Fcreate(FILE38, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
@@ -2926,6 +2932,206 @@ static void gent_char(void)
H5Fclose(fid1);
}
+/*-------------------------------------------------------------------------
+ * Function: gent_attr_all
+ *
+ * Purpose: generate all datatype attributes
+ *
+ * Return: void
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 19, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static void gent_attr_all(void)
+{
+ /* Compound datatype */
+ typedef struct s_t
+ {
+ int a;
+ float b;
+ } s_t;
+
+ typedef enum
+ {
+ E_RED,
+ E_GREEN
+ } e_t;
+
+ hid_t file_id;
+ hid_t dset_id;
+ hid_t attr_id;
+ hid_t space_id;
+ hid_t type_id;
+ herr_t status;
+ int val, i, j;
+ hsize_t dims[1]={2};
+ hsize_t dims2[2]={2,3};
+ int buf0[2][3]= {{1,2,3},{4,5,6}};
+ char buf1[]= "string attribute";
+ char buf2[2]= {1,2};
+ s_t buf3[2]= {{1,1},{2,2}};
+ hobj_ref_t buf4[2];
+ hvl_t buf5[2];
+ hsize_t dimarray[1]={3};
+ int buf6[2][3]= {{1,1,1},{2,2,2}};
+
+ /* Create a file and a dataset */
+ file_id = H5Fcreate(FILE40, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ space_id = H5Screate_simple(2,dims2,NULL);
+ dset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT);
+ status = H5Dwrite(dset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf0);
+ status = H5Sclose(space_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_STRING
+ *-------------------------------------------------------------------------
+ */
+ space_id = H5Screate(H5S_SCALAR);
+ type_id = H5Tcopy(H5T_C_S1);
+ status = H5Tset_size(type_id, 17);
+ attr_id = H5Acreate(dset_id,"string",type_id,space_id,H5P_DEFAULT);
+ status = H5Awrite(attr_id,type_id,buf1);
+ status = H5Aclose(attr_id);
+ status = H5Sclose(space_id);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_BITFIELD
+ *-------------------------------------------------------------------------
+ */
+ type_id = H5Tcopy(H5T_STD_B8LE);
+ write_attr(dset_id,1,dims,"bitfield",type_id,buf2);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_OPAQUE
+ *-------------------------------------------------------------------------
+ */
+ type_id = H5Tcreate(H5T_OPAQUE, 1);
+ status = H5Tset_tag(type_id, "1-byte opaque type"); /* must set this */
+ write_attr(dset_id,1,dims,"opaque",type_id,buf2);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_COMPOUND
+ *-------------------------------------------------------------------------
+ */
+ type_id = H5Tcreate (H5T_COMPOUND, sizeof(s_t));
+ H5Tinsert(type_id, "a", HOFFSET(s_t, a), H5T_NATIVE_INT);
+ H5Tinsert(type_id, "b", HOFFSET(s_t, b), H5T_NATIVE_FLOAT);
+ write_attr(dset_id,1,dims,"compound",type_id,buf3);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_REFERENCE
+ *-------------------------------------------------------------------------
+ */
+ /* Create references to dataset */
+ status=H5Rcreate(&buf4[0],file_id,"/dset",H5R_OBJECT,-1);
+ status=H5Rcreate(&buf4[1],file_id,"/dset",H5R_OBJECT,-1);
+ write_attr(dset_id,1,dims,"reference",H5T_STD_REF_OBJ,buf4);
+
+/*-------------------------------------------------------------------------
+ * H5T_ENUM
+ *-------------------------------------------------------------------------
+ */
+ type_id = H5Tcreate(H5T_ENUM, sizeof(e_t));
+ H5Tenum_insert(type_id, "RED", (val = 0, &val));
+ H5Tenum_insert(type_id, "GREEN", (val = 1, &val));
+ write_attr(dset_id,1,dims,"enum",type_id,0);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_VLEN
+ *-------------------------------------------------------------------------
+ */
+
+ /* Allocate and initialize VL dataset to write */
+ for(i = 0; i<2; i++) {
+ buf5[i].p = malloc((i + 1) * sizeof(int));
+ buf5[i].len = i + 1;
+ for (j = 0; j < i + 1; j++)
+ ((int *)buf5[i].p)[j] = i * 10 + j;
+ }
+ space_id = H5Screate_simple(1,dims,NULL);
+ type_id = H5Tvlen_create(H5T_NATIVE_INT);
+ attr_id = H5Acreate(dset_id,"vlen",type_id,space_id,H5P_DEFAULT);
+ status = H5Awrite(attr_id,type_id,buf5);
+ assert(status>=0);
+ status = H5Dvlen_reclaim(type_id,space_id,H5P_DEFAULT,buf5);
+ assert(status>=0);
+ status = H5Aclose(attr_id);
+ status = H5Tclose(type_id);
+ status = H5Sclose(space_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_ARRAY
+ *-------------------------------------------------------------------------
+ */
+ type_id = H5Tarray_create(H5T_NATIVE_INT,1,dimarray,NULL);
+ write_attr(dset_id,1,dims,"array",type_id,buf6);
+ status = H5Tclose(type_id);
+
+/*-------------------------------------------------------------------------
+ * H5T_INTEGER and H5T_FLOAT
+ *-------------------------------------------------------------------------
+ */
+ write_attr(dset_id,1,dims,"integer",H5T_NATIVE_INT,0);
+ write_attr(dset_id,1,dims,"float",H5T_NATIVE_FLOAT,0);
+
+ /* Close */
+ status = H5Dclose(dset_id);
+ status = H5Fclose(file_id);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: write_attr
+ *
+ * Purpose: utility function to write an attribute
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 19, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int write_attr(hid_t loc_id, int rank, hsize_t *dims, const char *attr_name,
+ hid_t type_id, void *buf)
+{
+ hid_t attr_id;
+ hid_t space_id;
+ herr_t status;
+
+ /* Create a buf space */
+ space_id = H5Screate_simple(rank,dims,NULL);
+
+ /* Create the attribute */
+ attr_id = H5Acreate(loc_id,attr_name,type_id,space_id,H5P_DEFAULT);
+
+ /* Write the buf */
+ if ( buf )
+ status = H5Awrite(attr_id,type_id,buf);
+
+ /* Close */
+ status = H5Aclose(attr_id);
+ status = H5Sclose(space_id);
+ return status;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
int main(void)
{
gent_group();
@@ -2979,5 +3185,7 @@ int main(void)
gent_vlstr();
gent_char();
+ gent_attr_all();
+
return 0;
}