Clang-format of source files

This commit is contained in:
Allen Byrne
2020-09-30 09:27:10 -05:00
parent 29ab58b58d
commit b2d661b508
1118 changed files with 320526 additions and 318330 deletions

View File

@@ -29,193 +29,192 @@
#define H5FILE_NAME "Attributes.h5"
#define RANK 1 /* Rank and size of the dataset */
#define SIZE 7
#define RANK 1 /* Rank and size of the dataset */
#define SIZE 7
#define ARANK 2 /* Rank and dimension sizes of the first dataset attribute */
#define ARANK 2 /* Rank and dimension sizes of the first dataset attribute */
#define ADIM1 2
#define ADIM2 3
#define ANAME "Float attribute" /* Name of the array attribute */
#define ANAME "Float attribute" /* Name of the array attribute */
#define ANAMES "Character attribute" /* Name of the string attribute */
static herr_t attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata);
/* Operator function */
/* Operator function */
int
main (void)
main(void)
{
hid_t file, dataset; /* File and dataset identifiers */
hid_t file, dataset; /* File and dataset identifiers */
hid_t fid; /* Dataspace identifier */
hid_t attr1, attr2, attr3; /* Attribute identifiers */
hid_t attr;
hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */
hid_t atype, atype_mem; /* Attribute type */
H5T_class_t type_class;
hid_t fid; /* Dataspace identifier */
hid_t attr1, attr2, attr3; /* Attribute identifiers */
hid_t attr;
hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */
hid_t atype, atype_mem; /* Attribute type */
H5T_class_t type_class;
hsize_t fdim[] = {SIZE};
hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */
hsize_t fdim[] = {SIZE};
hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */
float matrix[ADIM1][ADIM2]; /* Attribute data */
float matrix[ADIM1][ADIM2]; /* Attribute data */
herr_t ret; /* Return value */
H5O_info2_t oinfo; /* Object info */
unsigned i, j; /* Counters */
char string_out[80]; /* Buffer to read string attribute back */
int point_out; /* Buffer to read scalar attribute back */
herr_t ret; /* Return value */
H5O_info2_t oinfo; /* Object info */
unsigned i, j; /* Counters */
char string_out[80]; /* Buffer to read string attribute back */
int point_out; /* Buffer to read scalar attribute back */
/*
* Data initialization.
*/
int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */
int point = 1; /* Value of the scalar attribute */
char string[] = "ABCD"; /* Value of the string attribute */
/*
* Data initialization.
*/
int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */
int point = 1; /* Value of the scalar attribute */
char string[] = "ABCD"; /* Value of the string attribute */
for (i=0; i < ADIM1; i++) { /* Values of the array attribute */
for (j=0; j < ADIM2; j++)
matrix[i][j] = -1.;
}
/*
* Create a file.
*/
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create the dataspace for the dataset in the file.
*/
fid = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(fid, RANK, fdim, NULL);
/*
* Create the dataset in the file.
*/
dataset = H5Dcreate2(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT, vector);
/*
* Create dataspace for the first attribute.
*/
aid1 = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL);
/*
* Create array attribute.
*/
attr1 = H5Acreate2(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write array attribute.
*/
ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix);
/*
* Create scalar attribute.
*/
aid2 = H5Screate(H5S_SCALAR);
attr2 = H5Acreate2(dataset, "Integer attribute", H5T_NATIVE_INT, aid2,
H5P_DEFAULT, H5P_DEFAULT);
/*
* Write scalar attribute.
*/
ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
/*
* Create string attribute.
*/
aid3 = H5Screate(H5S_SCALAR);
atype = H5Tcopy(H5T_C_S1);
H5Tset_size(atype, 5);
H5Tset_strpad(atype,H5T_STR_NULLTERM);
attr3 = H5Acreate2(dataset, ANAMES, atype, aid3, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write string attribute.
*/
ret = H5Awrite(attr3, atype, string);
/*
* Close attribute and file dataspaces, and datatype.
*/
ret = H5Sclose(aid1);
ret = H5Sclose(aid2);
ret = H5Sclose(aid3);
ret = H5Sclose(fid);
ret = H5Tclose(atype);
/*
* Close the attributes.
*/
ret = H5Aclose(attr1);
ret = H5Aclose(attr2);
ret = H5Aclose(attr3);
/*
* Close the dataset.
*/
ret = H5Dclose(dataset);
/*
* Close the file.
*/
ret = H5Fclose(file);
/*
* Reopen the file.
*/
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Open the dataset.
*/
dataset = H5Dopen2(file, "Dataset", H5P_DEFAULT);
/*
* Attach to the scalar attribute using attribute name, then read and
* display its value.
*/
attr = H5Aopen(dataset, "Integer attribute", H5P_DEFAULT);
ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
ret = H5Aclose(attr);
/*
* Find string attribute by iterating through all attributes
*/
ret = H5Oget_info3(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
for(i = 0; i < (unsigned)oinfo.num_attrs; i++) {
attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)i, H5P_DEFAULT, H5P_DEFAULT);
atype = H5Aget_type(attr);
type_class = H5Tget_class(atype);
if (type_class == H5T_STRING) {
atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
ret = H5Aread(attr, atype_mem, string_out);
printf("Found string attribute; its index is %d , value = %s \n", i, string_out);
ret = H5Tclose(atype_mem);
}
ret = H5Aclose(attr);
ret = H5Tclose(atype);
for (i = 0; i < ADIM1; i++) { /* Values of the array attribute */
for (j = 0; j < ADIM2; j++)
matrix[i][j] = -1.;
}
/*
* Get attribute info using iteration function.
*/
/*
* Create a file.
*/
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create the dataspace for the dataset in the file.
*/
fid = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(fid, RANK, fdim, NULL);
/*
* Create the dataset in the file.
*/
dataset = H5Dcreate2(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, vector);
/*
* Create dataspace for the first attribute.
*/
aid1 = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL);
/*
* Create array attribute.
*/
attr1 = H5Acreate2(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write array attribute.
*/
ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix);
/*
* Create scalar attribute.
*/
aid2 = H5Screate(H5S_SCALAR);
attr2 = H5Acreate2(dataset, "Integer attribute", H5T_NATIVE_INT, aid2, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write scalar attribute.
*/
ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
/*
* Create string attribute.
*/
aid3 = H5Screate(H5S_SCALAR);
atype = H5Tcopy(H5T_C_S1);
H5Tset_size(atype, 5);
H5Tset_strpad(atype, H5T_STR_NULLTERM);
attr3 = H5Acreate2(dataset, ANAMES, atype, aid3, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write string attribute.
*/
ret = H5Awrite(attr3, atype, string);
/*
* Close attribute and file dataspaces, and datatype.
*/
ret = H5Sclose(aid1);
ret = H5Sclose(aid2);
ret = H5Sclose(aid3);
ret = H5Sclose(fid);
ret = H5Tclose(atype);
/*
* Close the attributes.
*/
ret = H5Aclose(attr1);
ret = H5Aclose(attr2);
ret = H5Aclose(attr3);
/*
* Close the dataset.
*/
ret = H5Dclose(dataset);
/*
* Close the file.
*/
ret = H5Fclose(file);
/*
* Reopen the file.
*/
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Open the dataset.
*/
dataset = H5Dopen2(file, "Dataset", H5P_DEFAULT);
/*
* Attach to the scalar attribute using attribute name, then read and
* display its value.
*/
attr = H5Aopen(dataset, "Integer attribute", H5P_DEFAULT);
ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
ret = H5Aclose(attr);
/*
* Find string attribute by iterating through all attributes
*/
ret = H5Oget_info3(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
for (i = 0; i < (unsigned)oinfo.num_attrs; i++) {
attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)i, H5P_DEFAULT,
H5P_DEFAULT);
atype = H5Aget_type(attr);
type_class = H5Tget_class(atype);
if (type_class == H5T_STRING) {
atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
ret = H5Aread(attr, atype_mem, string_out);
printf("Found string attribute; its index is %d , value = %s \n", i, string_out);
ret = H5Tclose(atype_mem);
}
ret = H5Aclose(attr);
ret = H5Tclose(atype);
}
/*
* Get attribute info using iteration function.
*/
ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_info, NULL);
/*
* Close the dataset and the file.
*/
H5Dclose(dataset);
H5Fclose(file);
/*
* Close the dataset and the file.
*/
H5Dclose(dataset);
H5Fclose(file);
return 0;
return 0;
}
/*
@@ -224,13 +223,13 @@ main (void)
static herr_t
attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
{
hid_t attr, atype, aspace; /* Attribute, datatype and dataspace identifiers */
int rank;
hid_t attr, atype, aspace; /* Attribute, datatype and dataspace identifiers */
int rank;
hsize_t sdim[64];
herr_t ret;
int i;
size_t npoints; /* Number of elements in the array attribute. */
float *float_array; /* Pointer to the array attribute. */
herr_t ret;
int i;
size_t npoints; /* Number of elements in the array attribute. */
float * float_array; /* Pointer to the array attribute. */
/* avoid warnings */
opdata = opdata;
@@ -250,17 +249,17 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
*/
atype = H5Aget_type(attr);
aspace = H5Aget_space(attr);
rank = H5Sget_simple_extent_ndims(aspace);
ret = H5Sget_simple_extent_dims(aspace, sdim, NULL);
rank = H5Sget_simple_extent_ndims(aspace);
ret = H5Sget_simple_extent_dims(aspace, sdim, NULL);
/*
* Display rank and dimension sizes for the array attribute.
*/
if(rank > 0) {
if (rank > 0) {
printf("Rank : %d \n", rank);
printf("Dimension sizes : ");
for (i=0; i< rank; i++)
for (i = 0; i < rank; i++)
printf("%d ", (int)sdim[i]);
printf("\n");
}
@@ -271,11 +270,11 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
if (H5T_FLOAT == H5Tget_class(atype)) {
printf("Type : FLOAT \n");
npoints = H5Sget_simple_extent_npoints(aspace);
float_array = (float *)malloc(sizeof(float)*(int)npoints);
ret = H5Aread(attr, atype, float_array);
npoints = H5Sget_simple_extent_npoints(aspace);
float_array = (float *)malloc(sizeof(float) * (int)npoints);
ret = H5Aread(attr, atype, float_array);
printf("Values : ");
for( i = 0; i < (int)npoints; i++)
for (i = 0; i < (int)npoints; i++)
printf("%f ", float_array[i]);
printf("\n");
free(float_array);
@@ -290,4 +289,3 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
return 0;
}

View File

@@ -18,68 +18,66 @@
#include "hdf5.h"
#define H5FILE_NAME "SDSextendible.h5"
#define H5FILE_NAME "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
#define RANK 2
#define RANKC 1
#define NX 10
#define NY 5
#define RANK 2
#define RANKC 1
#define NX 10
#define NY 5
int
main (void)
main(void)
{
hid_t file; /* handles */
hid_t dataset;
hid_t filespace;
hid_t memspace;
hid_t cparms;
hsize_t dims[2]; /* dataset and chunk dimensions*/
hsize_t chunk_dims[2];
hsize_t col_dims[1];
hsize_t count[2];
hsize_t offset[2];
herr_t status, status_n;
int data_out[NX][NY]; /* buffer for dataset to be read */
int chunk_out[2][5]; /* buffer for chunk to be read */
int column[10]; /* buffer for column to be read */
int rank, rank_chunk;
int i, j;
hid_t file; /* handles */
hid_t dataset;
hid_t filespace;
hid_t memspace;
hid_t cparms;
hsize_t dims[2]; /* dataset and chunk dimensions*/
hsize_t chunk_dims[2];
hsize_t col_dims[1];
hsize_t count[2];
hsize_t offset[2];
herr_t status, status_n;
int data_out[NX][NY]; /* buffer for dataset to be read */
int chunk_out[2][5]; /* buffer for chunk to be read */
int column[10]; /* buffer for column to be read */
int rank, rank_chunk;
int i, j;
/*
* Open the file and the dataset.
*/
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
/*
* Get dataset rank and dimension.
*/
filespace = H5Dget_space(dataset); /* Get filespace handle first. */
filespace = H5Dget_space(dataset); /* Get filespace handle first. */
rank = H5Sget_simple_extent_ndims(filespace);
status_n = H5Sget_simple_extent_dims(filespace, dims, NULL);
printf("dataset rank %d, dimensions %lu x %lu\n",
rank, (unsigned long)(dims[0]), (unsigned long)(dims[1]));
printf("dataset rank %d, dimensions %lu x %lu\n", rank, (unsigned long)(dims[0]),
(unsigned long)(dims[1]));
/*
* Define the memory space to read dataset.
*/
memspace = H5Screate_simple(RANK,dims,NULL);
memspace = H5Screate_simple(RANK, dims, NULL);
/*
* Read dataset back and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, data_out);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, data_out);
printf("\n");
printf("Dataset: \n");
for (j = 0; j < dims[0]; j++) {
for (i = 0; i < dims[1]; i++) printf("%d ", data_out[j][i]);
printf("\n");
for (i = 0; i < dims[1]; i++)
printf("%d ", data_out[j][i]);
printf("\n");
}
/*
@@ -110,7 +108,7 @@ main (void)
* and read it into column array.
*/
col_dims[0] = 10;
memspace = H5Screate_simple(RANKC, col_dims, NULL);
memspace = H5Screate_simple(RANKC, col_dims, NULL);
/*
* Define the column (hyperslab) to read.
@@ -119,14 +117,12 @@ main (void)
offset[1] = 2;
count[0] = 10;
count[1] = 1;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, column);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, column);
printf("\n");
printf("Third column: \n");
for (i = 0; i < 10; i++) {
printf("%d \n", column[i]);
printf("%d \n", column[i]);
}
/*
@@ -153,19 +149,19 @@ main (void)
*/
cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */
if (H5D_CHUNKED == H5Pget_layout(cparms)) {
if (H5D_CHUNKED == H5Pget_layout(cparms)) {
/*
* Get chunking information: rank and dimensions
*/
rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk,
(unsigned long)(chunk_dims[0]), (unsigned long)(chunk_dims[1]));
/*
* Get chunking information: rank and dimensions
*/
rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk, (unsigned long)(chunk_dims[0]),
(unsigned long)(chunk_dims[1]));
/*
* Define the memory space to read a chunk.
*/
memspace = H5Screate_simple(rank_chunk,chunk_dims,NULL);
memspace = H5Screate_simple(rank_chunk, chunk_dims, NULL);
/*
* Define chunk in the file (hyperslab) to read.
@@ -174,18 +170,17 @@ main (void)
offset[1] = 0;
count[0] = chunk_dims[0];
count[1] = chunk_dims[1];
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);
/*
* Read chunk back and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, chunk_out);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, chunk_out);
printf("\n");
printf("Chunk: \n");
for (j = 0; j < chunk_dims[0]; j++) {
for (i = 0; i < chunk_dims[1]; i++) printf("%d ", chunk_out[j][i]);
for (i = 0; i < chunk_dims[1]; i++)
printf("%d ", chunk_out[j][i]);
printf("\n");
}
/*

View File

@@ -18,27 +18,29 @@
#include "hdf5.h"
#define FILE "cmprss.h5"
#define RANK 2
#define DIM0 100
#define DIM1 20
#define FILE "cmprss.h5"
#define RANK 2
#define DIM0 100
#define DIM1 20
int main () {
int
main()
{
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hid_t plist_id;
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hid_t plist_id;
size_t nelmts;
unsigned flags, filter_info;
size_t nelmts;
unsigned flags, filter_info;
H5Z_filter_t filter_type;
herr_t status;
hsize_t dims[2];
hsize_t cdims[2];
herr_t status;
hsize_t dims[2];
hsize_t cdims[2];
int i,j, numfilt;
int buf[DIM0][DIM1];
int rbuf [DIM0][DIM1];
int i, j, numfilt;
int buf[DIM0][DIM1];
int rbuf[DIM0][DIM1];
/* Uncomment these variables to use SZIP compression
unsigned szip_options_mask;
@@ -46,25 +48,24 @@ int main () {
*/
/* Create a file. */
file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataset "Compressed Data" in the group using absolute name. */
dims[0] = DIM0;
dims[1] = DIM1;
dataspace_id = H5Screate_simple (RANK, dims, NULL);
dims[0] = DIM0;
dims[1] = DIM1;
dataspace_id = H5Screate_simple(RANK, dims, NULL);
plist_id = H5Pcreate (H5P_DATASET_CREATE);
plist_id = H5Pcreate(H5P_DATASET_CREATE);
/* Dataset must be chunked for compression */
cdims[0] = 20;
cdims[1] = 20;
status = H5Pset_chunk (plist_id, 2, cdims);
status = H5Pset_chunk(plist_id, 2, cdims);
/* Set ZLIB / DEFLATE Compression using compression level 6.
* To use SZIP Compression comment out these lines.
*/
status = H5Pset_deflate (plist_id, 6);
*/
status = H5Pset_deflate(plist_id, 6);
/* Uncomment these lines to set SZIP Compression
szip_options_mask = H5_SZIP_NN_OPTION_MASK;
@@ -72,51 +73,49 @@ int main () {
status = H5Pset_szip (plist_id, szip_options_mask, szip_pixels_per_block);
*/
dataset_id = H5Dcreate2 (file_id, "Compressed_Data", H5T_STD_I32BE,
dataspace_id, H5P_DEFAULT, plist_id, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "Compressed_Data", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, plist_id,
H5P_DEFAULT);
for (i = 0; i< DIM0; i++)
for (j=0; j<DIM1; j++)
buf[i][j] = i+j;
for (i = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++)
buf[i][j] = i + j;
status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
status = H5Sclose (dataspace_id);
status = H5Dclose (dataset_id);
status = H5Pclose (plist_id);
status = H5Fclose (file_id);
status = H5Sclose(dataspace_id);
status = H5Dclose(dataset_id);
status = H5Pclose(plist_id);
status = H5Fclose(file_id);
/* Now reopen the file and dataset in the file. */
file_id = H5Fopen (FILE, H5F_ACC_RDWR, H5P_DEFAULT);
dataset_id = H5Dopen2 (file_id, "Compressed_Data", H5P_DEFAULT);
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
dataset_id = H5Dopen2(file_id, "Compressed_Data", H5P_DEFAULT);
/* Retrieve filter information. */
plist_id = H5Dget_create_plist (dataset_id);
plist_id = H5Dget_create_plist(dataset_id);
numfilt = H5Pget_nfilters (plist_id);
printf ("Number of filters associated with dataset: %i\n", numfilt);
numfilt = H5Pget_nfilters(plist_id);
printf("Number of filters associated with dataset: %i\n", numfilt);
for (i=0; i<numfilt; i++) {
nelmts = 0;
filter_type = H5Pget_filter2 (plist_id, i, &flags, &nelmts, NULL, 0, NULL,
&filter_info);
printf ("Filter Type: ");
switch (filter_type) {
case H5Z_FILTER_DEFLATE:
printf ("H5Z_FILTER_DEFLATE\n");
break;
case H5Z_FILTER_SZIP:
printf ("H5Z_FILTER_SZIP\n");
break;
default:
printf ("Other filter type included.\n");
}
for (i = 0; i < numfilt; i++) {
nelmts = 0;
filter_type = H5Pget_filter2(plist_id, i, &flags, &nelmts, NULL, 0, NULL, &filter_info);
printf("Filter Type: ");
switch (filter_type) {
case H5Z_FILTER_DEFLATE:
printf("H5Z_FILTER_DEFLATE\n");
break;
case H5Z_FILTER_SZIP:
printf("H5Z_FILTER_SZIP\n");
break;
default:
printf("Other filter type included.\n");
}
}
status = H5Dread (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, rbuf);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
status = H5Dclose (dataset_id);
status = H5Pclose (plist_id);
status = H5Fclose (file_id);
status = H5Dclose(dataset_id);
status = H5Pclose(plist_id);
status = H5Fclose(file_id);
}

View File

@@ -19,10 +19,10 @@
#include "hdf5.h"
#define H5FILE_NAME "SDScompound.h5"
#define DATASETNAME "ArrayOfStructures"
#define LENGTH 10
#define RANK 1
#define H5FILE_NAME "SDScompound.h5"
#define DATASETNAME "ArrayOfStructures"
#define LENGTH 10
#define RANK 1
int
main(void)
@@ -30,38 +30,37 @@ main(void)
/* First structure and dataset*/
typedef struct s1_t {
int a;
float b;
double c;
int a;
float b;
double c;
} s1_t;
s1_t s1[LENGTH];
hid_t s1_tid; /* File datatype identifier */
s1_t s1[LENGTH];
hid_t s1_tid; /* File datatype identifier */
/* Second structure (subset of s1_t) and dataset*/
typedef struct s2_t {
double c;
int a;
double c;
int a;
} s2_t;
s2_t s2[LENGTH];
hid_t s2_tid; /* Memory datatype handle */
s2_t s2[LENGTH];
hid_t s2_tid; /* Memory datatype handle */
/* Third "structure" ( will be used to read float field of s1) */
hid_t s3_tid; /* Memory datatype handle */
float s3[LENGTH];
int i;
hid_t file, dataset, space; /* Handles */
herr_t status;
hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
hid_t s3_tid; /* Memory datatype handle */
float s3[LENGTH];
int i;
hid_t file, dataset, space; /* Handles */
herr_t status;
hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
/*
* Initialize the data
*/
for (i = 0; i< LENGTH; i++) {
for (i = 0; i < LENGTH; i++) {
s1[i].a = i;
s1[i].b = i*i;
s1[i].c = 1./(i+1);
s1[i].b = i * i;
s1[i].c = 1. / (i + 1);
}
/*
@@ -77,7 +76,7 @@ main(void)
/*
* Create the memory data type.
*/
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
@@ -126,12 +125,14 @@ main(void)
*/
printf("\n");
printf("Field c : \n");
for( i = 0; i < LENGTH; i++) printf("%.4f ", s2[i].c);
for (i = 0; i < LENGTH; i++)
printf("%.4f ", s2[i].c);
printf("\n");
printf("\n");
printf("Field a : \n");
for( i = 0; i < LENGTH; i++) printf("%d ", s2[i].a);
for (i = 0; i < LENGTH; i++)
printf("%d ", s2[i].a);
printf("\n");
/*
@@ -151,7 +152,8 @@ main(void)
*/
printf("\n");
printf("Field b : \n");
for( i = 0; i < LENGTH; i++) printf("%.4f ", s3[i]);
for (i = 0; i < LENGTH; i++)
printf("%.4f ", s3[i]);
printf("\n");
/*

View File

@@ -19,43 +19,44 @@
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
int
main()
{
hid_t file_id, dataset_id, attribute_id, dataspace_id; /* identifiers */
hsize_t dims;
int attr_data[2];
herr_t status;
hid_t file_id, dataset_id, attribute_id, dataspace_id; /* identifiers */
hsize_t dims;
int attr_data[2];
herr_t status;
/* Initialize the attribute data. */
attr_data[0] = 100;
attr_data[1] = 200;
/* Initialize the attribute data. */
attr_data[0] = 100;
attr_data[1] = 200;
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
/* Create the data space for the attribute. */
dims = 2;
dataspace_id = H5Screate_simple(1, &dims, NULL);
/* Create the data space for the attribute. */
dims = 2;
dataspace_id = H5Screate_simple(1, &dims, NULL);
/* Create a dataset attribute. */
attribute_id = H5Acreate2 (dataset_id, "Units", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT);
/* Create a dataset attribute. */
attribute_id = H5Acreate2(dataset_id, "Units", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
/* Write the attribute data. */
status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
/* Write the attribute data. */
status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
/* Close the attribute. */
status = H5Aclose(attribute_id);
/* Close the attribute. */
status = H5Aclose(attribute_id);
/* Close the dataspace. */
status = H5Sclose(dataspace_id);
/* Close the dataspace. */
status = H5Sclose(dataspace_id);
/* Close to the dataset. */
status = H5Dclose(dataset_id);
/* Close to the dataset. */
status = H5Dclose(dataset_id);
/* Close the file. */
status = H5Fclose(file_id);
/* Close the file. */
status = H5Fclose(file_id);
}

View File

@@ -19,31 +19,32 @@
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
int
main()
{
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create the dataset. */
dataset_id =
H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
/* Close the file. */
status = H5Fclose(file_id);
}

View File

@@ -19,20 +19,22 @@
#include "hdf5.h"
#define FILE "group.h5"
int main() {
int
main()
{
hid_t file_id, group_id; /* identifiers */
herr_t status;
hid_t file_id, group_id; /* identifiers */
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group named "/MyGroup" in the file. */
group_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group named "/MyGroup" in the file. */
group_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Close the group. */
status = H5Gclose(group_id);
/* Close the group. */
status = H5Gclose(group_id);
/* Terminate access to the file. */
status = H5Fclose(file_id);
/* Terminate access to the file. */
status = H5Fclose(file_id);
}

View File

@@ -19,28 +19,30 @@
#include "hdf5.h"
#define FILE "groups.h5"
int main() {
int
main()
{
hid_t file_id, group1_id, group2_id, group3_id; /* identifiers */
herr_t status;
hid_t file_id, group1_id, group2_id, group3_id; /* identifiers */
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "MyGroup" in the root group using absolute name. */
group1_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "MyGroup" in the root group using absolute name. */
group1_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "Group_A" in group "MyGroup" using absolute name. */
group2_id = H5Gcreate2(file_id, "/MyGroup/Group_A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "Group_A" in group "MyGroup" using absolute name. */
group2_id = H5Gcreate2(file_id, "/MyGroup/Group_A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "Group_B" in group "MyGroup" using relative name. */
group3_id = H5Gcreate2(group1_id, "Group_B", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create group "Group_B" in group "MyGroup" using relative name. */
group3_id = H5Gcreate2(group1_id, "Group_B", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Close groups. */
status = H5Gclose(group1_id);
status = H5Gclose(group2_id);
status = H5Gclose(group3_id);
/* Close groups. */
status = H5Gclose(group1_id);
status = H5Gclose(group2_id);
status = H5Gclose(group3_id);
/* Close the file. */
status = H5Fclose(file_id);
/* Close the file. */
status = H5Fclose(file_id);
}

View File

@@ -19,71 +19,70 @@
#include "hdf5.h"
#define FILE "groups.h5"
int main() {
int
main()
{
hid_t file_id, group_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
int i, j, dset1_data[3][3], dset2_data[2][10];
hid_t file_id, group_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
int i, j, dset1_data[3][3], dset2_data[2][10];
/* Initialize the first dataset. */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
dset1_data[i][j] = j + 1;
/* Initialize the first dataset. */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
dset1_data[i][j] = j + 1;
/* Initialize the second dataset. */
for (i = 0; i < 2; i++)
for (j = 0; j < 10; j++)
dset2_data[i][j] = j + 1;
/* Initialize the second dataset. */
for (i = 0; i < 2; i++)
for (j = 0; j < 10; j++)
dset2_data[i][j] = j + 1;
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Create the data space for the first dataset. */
dims[0] = 3;
dims[1] = 3;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the data space for the first dataset. */
dims[0] = 3;
dims[1] = 3;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create a dataset in group "MyGroup". */
dataset_id = H5Dcreate2(file_id, "/MyGroup/dset1", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create a dataset in group "MyGroup". */
dataset_id = H5Dcreate2(file_id, "/MyGroup/dset1", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
/* Write the first dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset1_data);
/* Write the first dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1_data);
/* Close the data space for the first dataset. */
status = H5Sclose(dataspace_id);
/* Close the data space for the first dataset. */
status = H5Sclose(dataspace_id);
/* Close the first dataset. */
status = H5Dclose(dataset_id);
/* Close the first dataset. */
status = H5Dclose(dataset_id);
/* Open an existing group of the specified file. */
group_id = H5Gopen2(file_id, "/MyGroup/Group_A", H5P_DEFAULT);
/* Open an existing group of the specified file. */
group_id = H5Gopen2(file_id, "/MyGroup/Group_A", H5P_DEFAULT);
/* Create the data space for the second dataset. */
dims[0] = 2;
dims[1] = 10;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the data space for the second dataset. */
dims[0] = 2;
dims[1] = 10;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the second dataset in group "Group_A". */
dataset_id = H5Dcreate2(group_id, "dset2", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create the second dataset in group "Group_A". */
dataset_id =
H5Dcreate2(group_id, "dset2", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Write the second dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset2_data);
/* Write the second dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_data);
/* Close the data space for the second dataset. */
status = H5Sclose(dataspace_id);
/* Close the data space for the second dataset. */
status = H5Sclose(dataspace_id);
/* Close the second dataset */
status = H5Dclose(dataset_id);
/* Close the second dataset */
status = H5Dclose(dataset_id);
/* Close the group. */
status = H5Gclose(group_id);
/* Close the group. */
status = H5Gclose(group_id);
/* Close the file. */
status = H5Fclose(file_id);
/* Close the file. */
status = H5Fclose(file_id);
}

View File

@@ -12,7 +12,7 @@
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* This example demonstrates debug trace output.
*
* Debug/trace/performance output is not tested as a regular part of our
@@ -42,33 +42,33 @@
* fast machines, these numbers may be 0.0. Adjust the loop variables in
* the program as needed to generate reasonable output.
*/
#include <stdio.h>
#include <stdlib.h>
#include "hdf5.h"
#define BUF_SIZE 1048576
#define N_LOOPS 64
#define BUF_SIZE 1048576
#define N_LOOPS 64
#define TESTFILE "h5_debug_trace_out.h5"
int
main(int argc, char **argv)
{
int i, j;
int i, j;
int *data;
hid_t fid;
hid_t pid;
hid_t did;
hid_t sid;
hsize_t dims[1] = { BUF_SIZE };
hsize_t chunk_sizes[1] = { 1024 };
hid_t fid;
hid_t pid;
hid_t did;
hid_t sid;
hsize_t dims[1] = {BUF_SIZE};
hsize_t chunk_sizes[1] = {1024};
herr_t err;
/*************************************************************************/
/* Warn the user about trace deluge to come */
@@ -82,55 +82,52 @@ main(int argc, char **argv)
fflush(stdout);
/* This will emit H5Tconvert() performance information */
for(i = 0; i < N_LOOPS; i++) {
for (i = 0; i < N_LOOPS; i++) {
/* The buffer has to be large enough to hold the conversion output */
data = (int *)malloc(BUF_SIZE * sizeof(double));
for(j = 0; j < BUF_SIZE; j++) {
for (j = 0; j < BUF_SIZE; j++) {
data[j] = j;
}
err = H5Tconvert(H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, BUF_SIZE, data,
NULL, H5P_DEFAULT);
if(err < 0) {
err = H5Tconvert(H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, BUF_SIZE, data, NULL, H5P_DEFAULT);
if (err < 0) {
fprintf(stderr, "ERROR: Conversion failed\n");
free(data);
return err;
}
free(data);
}
/* This will emit H5Z performance information */
data = (int *)malloc(BUF_SIZE * sizeof(int));
for(i = 0; i < BUF_SIZE; i++) {
for (i = 0; i < BUF_SIZE; i++) {
data[i] = i;
}
fid = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
pid = H5Pcreate(H5P_DATASET_CREATE);
err = H5Pset_chunk(pid, 1, chunk_sizes);
err = H5Pset_shuffle(pid);
sid = H5Screate_simple(1, dims, dims);
did = H5Dcreate2(fid, "somedata", H5T_NATIVE_INT, sid, H5P_DEFAULT, pid, H5P_DEFAULT);
err = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, data);
H5Sclose(sid);
H5Dclose(did);
H5Pclose(pid);
H5Fclose(fid);
free(data);
/* Finished */
fflush(stdout);
printf("\n");
@@ -138,7 +135,6 @@ main(int argc, char **argv)
printf("\n");
remove(TESTFILE);
return 0;
}

View File

@@ -22,13 +22,12 @@
#include "stdlib.h"
/* global variables */
int cleanup_g = -1; /* whether to clean. Init to not set. */
int cleanup_g = -1; /* whether to clean. Init to not set. */
/* prototypes */
void cleanup(const char *);
void split_file(void);
/*
* Cleanup a file unless $HDF5_NOCLEANUP is set.
*/
@@ -36,12 +35,11 @@ void
cleanup(const char *filename)
{
if (cleanup_g == -1)
cleanup_g = getenv("HDF5_NOCLEANUP") ? 0 : 1;
cleanup_g = getenv("HDF5_NOCLEANUP") ? 0 : 1;
if (cleanup_g)
remove(filename);
remove(filename);
}
/*
* This shows how to use the split file driver.
*/
@@ -55,7 +53,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);
fid=H5Fcreate("Station1",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
fid = H5Fcreate("Station1", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -68,7 +66,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "/tmp/%s-r.h5", H5P_DEFAULT);
fid=H5Fcreate("PointA",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
fid = H5Fcreate("PointA", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -81,7 +79,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, NULL, H5P_DEFAULT, NULL, H5P_DEFAULT);
fid=H5Fcreate("Measure",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
fid = H5Fcreate("Measure", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -90,13 +88,12 @@ split_file(void)
cleanup("Measure.raw");
}
/* Main Body */
int
main (void)
main(void)
{
split_file();
return(0);
return (0);
}

View File

@@ -33,8 +33,8 @@
#include "hdf5.h"
#define ROWS 12
#define COLS 18
#define ROWS 12
#define COLS 18
/* clang-format off */
const float windchillF[ROWS][COLS] =
@@ -53,32 +53,28 @@ const float windchillF[ROWS][COLS] =
};
/* clang-format on */
#define PRINT(array) \
{ \
for(i=0; i<ROWS; i++) \
{ \
for(j=0; j<COLS; j++) \
printf("%6.2f ", array[i][j]); \
printf("\n"); \
} \
}
#define PRINT(array) \
{ \
for (i = 0; i < ROWS; i++) { \
for (j = 0; j < COLS; j++) \
printf("%6.2f ", array[i][j]); \
printf("\n"); \
} \
}
int
main (void)
main(void)
{
hid_t file, dataset; /* file and dataset handles */
hid_t dataspace; /* handles */
hsize_t dimsf[2]; /* dataset dimensions */
hid_t file, dataset; /* file and dataset handles */
hid_t dataspace; /* handles */
hsize_t dimsf[2]; /* dataset dimensions */
herr_t status;
hid_t dxpl_id_f_to_c, dxpl_id_c_to_f; /* data transform handles */
const char* f_to_c = "(5/9.0)*(x-32)";
const char* c_to_f = "(9/5.0)*x + 32";
char* transform;
float windchillC[ROWS][COLS];
int i,j, transform_size;
hid_t dxpl_id_f_to_c, dxpl_id_c_to_f; /* data transform handles */
const char *f_to_c = "(5/9.0)*(x-32)";
const char *c_to_f = "(9/5.0)*x + 32";
char * transform;
float windchillC[ROWS][COLS];
int i, j, transform_size;
/*
* Create a new file using H5F_ACC_TRUNC access,
@@ -91,28 +87,25 @@ main (void)
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
dimsf[0] = ROWS;
dimsf[1] = COLS;
dimsf[0] = ROWS;
dimsf[1] = COLS;
dataspace = H5Screate_simple(2, dimsf, NULL);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
dataset = H5Dcreate2(file, "data_no_trans", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset =
H5Dcreate2(file, "data_no_trans", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
printf("\nOriginal Data: \n");
PRINT(windchillF);
/**************** PART 1 **************/
/**************** PART 1 **************/
/*
* Write the data to the dataset using default transfer properties (ie, no transform set)
*/
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, windchillF);
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, windchillF);
/* Create the dataset transfer property list */
dxpl_id_f_to_c = H5Pcreate(H5P_DATASET_XFER);
@@ -127,13 +120,11 @@ main (void)
printf("\nData with no write transform, but a read transform: \n");
PRINT(windchillC);
/**************** PART 2 **************/
/**************** PART 2 **************/
/*
* Write the data to the dataset with the f_to_c transform set
*/
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
dxpl_id_f_to_c, windchillF);
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_f_to_c, windchillF);
/* Read out the data with the default transfer list (ie, no transform set) */
H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, windchillC);
@@ -142,8 +133,7 @@ main (void)
printf("\nData with write transform, but no read transform: \n");
PRINT(windchillC);
/************** PART 3 ***************/
/************** PART 3 ***************/
/* Create the dataset transfer property list */
dxpl_id_c_to_f = H5Pcreate(H5P_DATASET_XFER);
@@ -151,12 +141,10 @@ main (void)
/* Set the data transform to be used on the read*/
H5Pset_data_transform(dxpl_id_c_to_f, c_to_f);
/*
* Write the data to the dataset using the f_to_c transform
*/
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
dxpl_id_f_to_c, windchillF);
status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_f_to_c, windchillF);
/* Read the data with the c_to_f data transform */
H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillC);
@@ -165,10 +153,10 @@ main (void)
printf("\nData with both read and write data transform: \n");
PRINT(windchillC);
/************** PART 4 **************/
/************** PART 4 **************/
transform_size = H5Pget_data_transform(dxpl_id_f_to_c, NULL, 0);
transform = (char*) malloc(transform_size+1);
H5Pget_data_transform(dxpl_id_f_to_c, transform, transform_size+1);
transform = (char *)malloc(transform_size + 1);
H5Pget_data_transform(dxpl_id_f_to_c, transform, transform_size + 1);
printf("\nTransform string (from dxpl_id_f_to_c) is: %s\n", transform);

View File

@@ -27,7 +27,6 @@
#include <stdlib.h>
#include <string.h>
/* "Windows to Unix" traversal function for external links
*
* Translates a filename stored in Unix format to Windows format by replacing
@@ -37,45 +36,44 @@
* Note that this may not be necessary on your system; many Windows systems can
* understand Unix paths.
*/
static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
static hid_t
elink_unix2win_trav(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
hid_t lapl_id, hid_t dxpl_id)
{
hid_t fid;
const char *file_name;
const char *obj_name;
char *new_fname = NULL; /* Buffer allocated to hold Unix file path */
ssize_t prefix_len; /* External link prefix length */
size_t fname_len;
size_t start_pos; /* Initial position in new_fname buffer */
size_t x; /* Counter variable */
hid_t ret_value = -1;
hid_t fid;
const char *file_name;
const char *obj_name;
char * new_fname = NULL; /* Buffer allocated to hold Unix file path */
ssize_t prefix_len; /* External link prefix length */
size_t fname_len;
size_t start_pos; /* Initial position in new_fname buffer */
size_t x; /* Counter variable */
hid_t ret_value = -1;
printf("Converting Unix path to Windows path.\n");
if(H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0)
if (H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0)
goto error;
fname_len = strlen(file_name);
/* See if the external link prefix property is set */
if((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0)
if ((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0)
goto error;
/* If so, prepend it to the filename. We assume that the prefix
* is in the correct format for the current file system.
*/
if(prefix_len > 0)
{
if (prefix_len > 0) {
/* Allocate a buffer to hold the filename plus prefix */
new_fname = malloc(prefix_len + fname_len + 1);
/* Copy the prefix into the buffer */
if(H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0)
if (H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0)
goto error;
start_pos = prefix_len;
}
else
{
else {
/* Allocate a buffer to hold just the filename */
new_fname = malloc(fname_len + 1);
start_pos = 0;
@@ -84,9 +82,8 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
/* We should now copy file_name into new_fname starting at position pos.
* We'll convert '/' characters into '\' characters as we go.
*/
for(x=0; file_name[x] != '\0'; x++)
{
if(file_name[x] == '/')
for (x = 0; file_name[x] != '\0'; x++) {
if (file_name[x] == '/')
new_fname[x + start_pos] = '\\';
else
new_fname[x + start_pos] = file_name[x];
@@ -94,38 +91,37 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
new_fname[x + start_pos] = '\0';
/* Now open the file and object within it */
if((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
if ((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
goto error;
ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */
if(H5Fclose(fid) < 0)
if (H5Fclose(fid) < 0)
goto error;
/* Free file name if it's been allocated */
if(new_fname)
if (new_fname)
free(new_fname);
return ret_value;
error:
/* Free file name if it's been allocated */
if(new_fname)
if (new_fname)
free(new_fname);
return -1;
}
const H5L_class_t elink_unix2win_class[1] = {{
H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
H5L_TYPE_EXTERNAL, /* Link type id number */
"unix2win external link", /* Link class name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
elink_unix2win_trav, /* The actual traversal function */
NULL, /* Deletion callback */
NULL /* Query callback */
H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
H5L_TYPE_EXTERNAL, /* Link type id number */
"unix2win external link", /* Link class name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
elink_unix2win_trav, /* The actual traversal function */
NULL, /* Deletion callback */
NULL /* Query callback */
}};
/* The example function.
* Creates a file named "unix2win.h5" with an external link pointing to
* the file "u2w/u2w_target.h5".
@@ -136,55 +132,65 @@ const H5L_class_t elink_unix2win_class[1] = {{
static int
unix2win_example(void)
{
hid_t fid = (-1); /* File ID */
hid_t gid = (-1); /* Group ID */
hid_t fid = (-1); /* File ID */
hid_t gid = (-1); /* Group ID */
/* Create the target file. */
#ifdef H5_HAVE_WIN32_API
if((fid=H5Fcreate("u2w\\u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
if ((fid = H5Fcreate("u2w\\u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
#else
if((fid=H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
if ((fid = H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
#endif
if(H5Fclose(fid) < 0) goto error;
if (H5Fclose(fid) < 0)
goto error;
/* Create the source file with an external link in Windows format */
if((fid=H5Fcreate("unix2win.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
if ((fid = H5Fcreate("unix2win.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
/* Create the external link */
if(H5Lcreate_external("u2w/../u2w/u2w_target.h5", "/", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) goto error;
if (H5Lcreate_external("u2w/../u2w/u2w_target.h5", "/", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0)
goto error;
/* If we are not on Windows, assume we are on a Unix-y filesystem and
* follow the external link normally.
* If we are on Windows, register the unix2win traversal function so
* that external links can be traversed.
*/
/* If we are not on Windows, assume we are on a Unix-y filesystem and
* follow the external link normally.
* If we are on Windows, register the unix2win traversal function so
* that external links can be traversed.
*/
#ifdef H5_HAVE_WIN32_API
/* Register the elink_unix2win class defined above to replace default
* external links
*/
if(H5Lregister(elink_unix2win_class) < 0) goto error;
if (H5Lregister(elink_unix2win_class) < 0)
goto error;
#endif
/* Now follow the link */
if((gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT)) < 0) goto error;
if ((gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT)) < 0)
goto error;
printf("Successfully followed external link.\n");
/* Close the group and the file */
if(H5Gclose(gid) <0) goto error;
if(H5Fclose(fid) <0) goto error;
if (H5Gclose(gid) < 0)
goto error;
if (H5Fclose(fid) < 0)
goto error;
return 0;
error:
error:
printf("Error!\n");
H5E_BEGIN_TRY {
H5Gclose (gid);
H5Fclose (fid);
} H5E_END_TRY;
H5E_BEGIN_TRY
{
H5Gclose(gid);
H5Fclose(fid);
}
H5E_END_TRY;
return -1;
}
/* Main function
*
@@ -193,12 +199,10 @@ unix2win_example(void)
int
main(void)
{
int ret;
int ret;
printf("Testing unix2win external links.\n");
ret = unix2win_example();
return ret;
}

View File

@@ -18,127 +18,114 @@
* It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILENAME "extend.h5"
#define DATASETNAME "ExtendibleArray"
#define RANK 2
#define RANK 2
int
main (void)
main(void)
{
hid_t file; /* handles */
hid_t dataspace, dataset;
hid_t filespace, memspace;
hid_t prop;
hid_t file; /* handles */
hid_t dataspace, dataset;
hid_t filespace, memspace;
hid_t prop;
hsize_t dims[2] = {3, 3}; /* dataset dimensions at creation time */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
herr_t status;
hsize_t chunk_dims[2] = {2, 5};
int data[3][3] = { {1, 1, 1}, /* data to write */
{1, 1, 1},
{1, 1, 1} };
hsize_t dims[2] = {3, 3}; /* dataset dimensions at creation time */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
herr_t status;
hsize_t chunk_dims[2] = {2, 5};
int data[3][3] = {{1, 1, 1}, /* data to write */
{1, 1, 1},
{1, 1, 1}};
/* Variables used in extending and writing to the extended portion of dataset */
hsize_t size[2];
hsize_t offset[2];
hsize_t dimsext[2] = {7, 3}; /* extend dimensions */
int dataext[7][3] = { {2, 3, 4},
{2, 3, 4},
{2, 3, 4},
{2, 3, 4},
{2, 3, 4},
{2, 3, 4},
{2, 3, 4} };
hsize_t size[2];
hsize_t offset[2];
hsize_t dimsext[2] = {7, 3}; /* extend dimensions */
int dataext[7][3] = {{2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}};
/* Variables used in reading data back */
hsize_t chunk_dimsr[2];
hsize_t dimsr[2];
hsize_t i, j;
int rdata[10][3];
herr_t status_n;
int rank, rank_chunk;
hsize_t chunk_dimsr[2];
hsize_t dimsr[2];
hsize_t i, j;
int rdata[10][3];
herr_t status_n;
int rank, rank_chunk;
/* Create the data space with unlimited dimensions. */
dataspace = H5Screate_simple (RANK, dims, maxdims);
dataspace = H5Screate_simple(RANK, dims, maxdims);
/* Create a new file. If file exists its contents will be overwritten. */
file = H5Fcreate (FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Modify dataset creation properties, i.e. enable chunking */
prop = H5Pcreate (H5P_DATASET_CREATE);
status = H5Pset_chunk (prop, RANK, chunk_dims);
prop = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk(prop, RANK, chunk_dims);
/* Create a new dataset within the file using chunk
creation properties. */
dataset = H5Dcreate2 (file, DATASETNAME, H5T_NATIVE_INT, dataspace,
H5P_DEFAULT, prop, H5P_DEFAULT);
dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, prop, H5P_DEFAULT);
/* Write data to dataset */
status = H5Dwrite (dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
/* Extend the dataset. Dataset becomes 10 x 3 */
size[0] = dims[0]+ dimsext[0];
size[0] = dims[0] + dimsext[0];
size[1] = dims[1];
status = H5Dset_extent (dataset, size);
status = H5Dset_extent(dataset, size);
/* Select a hyperslab in extended portion of dataset */
filespace = H5Dget_space (dataset);
filespace = H5Dget_space(dataset);
offset[0] = 3;
offset[1] = 0;
status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL,
dimsext, NULL);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dimsext, NULL);
/* Define memory space */
memspace = H5Screate_simple (RANK, dimsext, NULL);
memspace = H5Screate_simple(RANK, dimsext, NULL);
/* Write the data to the extended portion of dataset */
status = H5Dwrite (dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, dataext);
status = H5Dwrite(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, dataext);
/* Close resources */
status = H5Dclose (dataset);
status = H5Pclose (prop);
status = H5Sclose (dataspace);
status = H5Sclose (memspace);
status = H5Sclose (filespace);
status = H5Fclose (file);
status = H5Dclose(dataset);
status = H5Pclose(prop);
status = H5Sclose(dataspace);
status = H5Sclose(memspace);
status = H5Sclose(filespace);
status = H5Fclose(file);
/********************************************
* Re-open the file and read the data back. *
********************************************/
file = H5Fopen (FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2 (file, DATASETNAME, H5P_DEFAULT);
file = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
filespace = H5Dget_space (dataset);
rank = H5Sget_simple_extent_ndims (filespace);
status_n = H5Sget_simple_extent_dims (filespace, dimsr, NULL);
filespace = H5Dget_space(dataset);
rank = H5Sget_simple_extent_ndims(filespace);
status_n = H5Sget_simple_extent_dims(filespace, dimsr, NULL);
prop = H5Dget_create_plist (dataset);
prop = H5Dget_create_plist(dataset);
if (H5D_CHUNKED == H5Pget_layout (prop))
rank_chunk = H5Pget_chunk (prop, rank, chunk_dimsr);
if (H5D_CHUNKED == H5Pget_layout(prop))
rank_chunk = H5Pget_chunk(prop, rank, chunk_dimsr);
memspace = H5Screate_simple (rank, dimsr, NULL);
status = H5Dread (dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, rdata);
memspace = H5Screate_simple(rank, dimsr, NULL);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, rdata);
printf("\n");
printf("Dataset: \n");
for (j = 0; j < dimsr[0]; j++)
{
for (i = 0; i < dimsr[1]; i++)
printf("%d ", rdata[j][i]);
printf("\n");
for (j = 0; j < dimsr[0]; j++) {
for (i = 0; i < dimsr[1]; i++)
printf("%d ", rdata[j][i]);
printf("\n");
}
status = H5Pclose (prop);
status = H5Dclose (dataset);
status = H5Sclose (filespace);
status = H5Sclose (memspace);
status = H5Fclose (file);
status = H5Pclose(prop);
status = H5Dclose(dataset);
status = H5Sclose(filespace);
status = H5Sclose(memspace);
status = H5Fclose(file);
}

View File

@@ -20,43 +20,42 @@
#include "hdf5.h"
#define H5FILE_NAME "SDSextendible.h5"
#define H5FILE_NAME "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
#define RANK 2
#define NX 10
#define NY 5
#define RANK 2
#define NX 10
#define NY 5
int
main (void)
main(void)
{
hid_t file; /* handles */
hid_t dataspace, dataset;
hid_t filespace;
hid_t cparms;
hsize_t dims[2] = { 3, 3}; /*
* dataset dimensions
* at the creation time
*/
hsize_t dims1[2] = { 3, 3}; /* data1 dimensions */
hsize_t dims2[2] = { 7, 1}; /* data2 dimensions */
hsize_t dims3[2] = { 2, 2}; /* data3 dimensions */
hid_t file; /* handles */
hid_t dataspace, dataset;
hid_t filespace;
hid_t cparms;
hsize_t dims[2] = {3, 3}; /*
* dataset dimensions
* at the creation time
*/
hsize_t dims1[2] = {3, 3}; /* data1 dimensions */
hsize_t dims2[2] = {7, 1}; /* data2 dimensions */
hsize_t dims3[2] = {2, 2}; /* data3 dimensions */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
hsize_t chunk_dims[2] ={2, 5};
hsize_t size[2];
hsize_t offset[2];
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
hsize_t chunk_dims[2] = {2, 5};
hsize_t size[2];
hsize_t offset[2];
herr_t status;
herr_t status;
int data1[3][3] = { {1, 1, 1}, /* data to write */
{1, 1, 1},
{1, 1, 1} };
int data1[3][3] = {{1, 1, 1}, /* data to write */
{1, 1, 1},
{1, 1, 1}};
int data2[7] = { 2, 2, 2, 2, 2, 2, 2};
int data2[7] = {2, 2, 2, 2, 2, 2, 2};
int data3[2][2] = { {3, 3},
{3, 3} };
int fillvalue = 0;
int data3[2][2] = {{3, 3}, {3, 3}};
int fillvalue = 0;
/*
* Create the data space with unlimited dimensions.
@@ -72,22 +71,21 @@ main (void)
* Modify dataset creation properties, i.e. enable chunking.
*/
cparms = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk( cparms, RANK, chunk_dims);
status = H5Pset_fill_value (cparms, H5T_NATIVE_INT, &fillvalue );
status = H5Pset_chunk(cparms, RANK, chunk_dims);
status = H5Pset_fill_value(cparms, H5T_NATIVE_INT, &fillvalue);
/*
* Create a new dataset within the file using cparms
* creation properties.
*/
dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT,
cparms, H5P_DEFAULT);
dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
/*
* Extend the dataset. This call assures that dataset is at least 3 x 3.
*/
size[0] = 3;
size[1] = 3;
status = H5Dset_extent(dataset, size);
size[0] = 3;
size[1] = 3;
status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab.
@@ -95,22 +93,20 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 0;
offset[1] = 0;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims1, NULL);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims1, NULL);
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data1);
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data1);
/*
* Extend the dataset. Dataset becomes 10 x 3.
*/
dims[0] = dims1[0] + dims2[0];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dset_extent(dataset, size);
dims[0] = dims1[0] + dims2[0];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab.
@@ -118,8 +114,7 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 3;
offset[1] = 0;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims2, NULL);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims2, NULL);
/*
* Define memory space
@@ -129,16 +124,15 @@ main (void)
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data2);
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data2);
/*
* Extend the dataset. Dataset becomes 10 x 5.
*/
dims[1] = dims1[1] + dims3[1];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dset_extent(dataset, size);
dims[1] = dims1[1] + dims3[1];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab
@@ -146,8 +140,7 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 0;
offset[1] = 3;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims3, NULL);
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims3, NULL);
/*
* Define memory space.
@@ -157,8 +150,7 @@ main (void)
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data3);
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data3);
/*
* Resulting dataset

View File

@@ -26,37 +26,36 @@
#define PREFIX_SOURCE_FILE "extlink_prefix_source.h5"
#define SOFT_LINK_FILE "soft_link.h5"
#define SOFT_LINK_NAME "soft_link_to_group"
#define SOFT_LINK_FILE "soft_link.h5"
#define SOFT_LINK_NAME "soft_link_to_group"
#define UD_SOFT_LINK_NAME "ud_soft_link"
#define TARGET_GROUP "target_group"
#define TARGET_GROUP "target_group"
#define UD_SOFT_CLASS 65
#define HARD_LINK_FILE "hard_link.h5"
#define HARD_LINK_NAME "hard_link_to_group"
#define HARD_LINK_FILE "hard_link.h5"
#define HARD_LINK_NAME "hard_link_to_group"
#define UD_HARD_LINK_NAME "ud_hard_link"
#define UD_HARD_CLASS 66
#define PLIST_LINK_PROP "plist_link_prop"
#define UD_PLIST_CLASS 66
#define UD_PLIST_CLASS 66
/* Basic external link example
*
* Creates two files and uses an external link to access an object in the
* second file from the first file.
*/
static void extlink_example(void)
static void
extlink_example(void)
{
hid_t source_file_id, targ_file_id;
hid_t group_id, group2_id;
/* Create two files, a source and a target */
source_file_id = H5Fcreate(SOURCE_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
targ_file_id = H5Fcreate(TARGET_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
targ_file_id = H5Fcreate(TARGET_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group in the target file for the external link to point to. */
group_id = H5Gcreate2(targ_file_id, "target_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -96,7 +95,6 @@ static void extlink_example(void)
*/
}
/* External link prefix example
*
* Uses a group access property list to set a "prefix" for the filenames
@@ -109,7 +107,8 @@ static void extlink_example(void)
* where it is run (so to run this example on Unix, first mkdir red and mkdir
* blue).
*/
static void extlink_prefix_example(void)
static void
extlink_prefix_example(void)
{
hid_t source_file_id, red_file_id, blue_file_id;
hid_t group_id, group2_id;
@@ -119,14 +118,15 @@ static void extlink_prefix_example(void)
* the same name, but one will be located in the red directory and one will
* be located in the blue directory */
source_file_id = H5Fcreate(PREFIX_SOURCE_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
red_file_id = H5Fcreate("red/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
blue_file_id = H5Fcreate("blue/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
red_file_id = H5Fcreate("red/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
blue_file_id = H5Fcreate("blue/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* This test needs a red and a blue directory in the filesystem. If they're not present,
* trying to create the files above will fail.
*/
if(red_file_id < 0 || blue_file_id < 0)
printf("This test requires directories named 'red' and 'blue' to exist. Did you forget to create them?\n");
if (red_file_id < 0 || blue_file_id < 0)
printf("This test requires directories named 'red' and 'blue' to exist. Did you forget to create "
"them?\n");
/* Create an external link in the source file pointing to the root group of
* a file named prefix_target.h5. This file doesn't exist in the current
@@ -163,7 +163,7 @@ static void extlink_prefix_example(void)
* directory.
*/
H5Pset_elink_prefix(gapl_id, "blue/");
group_id = H5Gopen2(source_file_id, "ext_link", gapl_id);
group_id = H5Gopen2(source_file_id, "ext_link", gapl_id);
group2_id = H5Gcreate2(group_id, "sky blue", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Close both groups. */
@@ -171,7 +171,7 @@ static void extlink_prefix_example(void)
H5Gclose(group_id);
/* Each file has had a group created inside it using the same external link. */
group_id = H5Gopen2(red_file_id, "pink", H5P_DEFAULT);
group_id = H5Gopen2(red_file_id, "pink", H5P_DEFAULT);
group2_id = H5Gopen2(blue_file_id, "sky blue", H5P_DEFAULT);
/* Clean up our open IDs */
@@ -189,7 +189,6 @@ static void extlink_prefix_example(void)
*/
}
/* Soft Link example
*
* Create a new class of user-defined links that behave like HDF5's built-in
@@ -207,10 +206,11 @@ static void extlink_prefix_example(void)
* We might also have wanted to supply a creation callback that checks
* that a path was supplied in the udata.
*/
static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
hid_t lapl_id, hid_t dxpl_id);
static void soft_link_example(void)
static void
soft_link_example(void)
{
hid_t file_id;
hid_t group_id;
@@ -220,27 +220,26 @@ static void soft_link_example(void)
* callback.
*/
const H5L_class_t UD_soft_class[1] = {{
H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
* This field is always H5L_LINK_CLASS_T_VERS */
(H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any
* value between H5L_TYPE_UD_MIN (64) and
* H5L_TYPE_MAX (255). It should be a
* value that isn't already being used by
* another kind of link. We'll use 65. */
"UD_soft_link", /* Link class name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
UD_soft_traverse, /* The actual traversal function */
NULL, /* Deletion callback */
NULL /* Query callback */
H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
* This field is always H5L_LINK_CLASS_T_VERS */
(H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any
* value between H5L_TYPE_UD_MIN (64) and
* H5L_TYPE_MAX (255). It should be a
* value that isn't already being used by
* another kind of link. We'll use 65. */
"UD_soft_link", /* Link class name for debugging */
NULL, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
UD_soft_traverse, /* The actual traversal function */
NULL, /* Deletion callback */
NULL /* Query callback */
}};
/* First, create a file and an object within the file for the link to
* point to.
*/
file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
@@ -275,12 +274,13 @@ static void soft_link_example(void)
* The actual traversal function simply needs to open the correct object by
* name and return its ID.
*/
static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
static hid_t
UD_soft_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
hid_t dxpl_id)
{
const char *target = (const char *) udata;
hid_t ret_value;
const char *target = (const char *)udata;
hid_t ret_value;
/* Pass the udata straight through to HDF5. If it's invalid, let HDF5
* return an error.
@@ -289,7 +289,6 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
return ret_value;
}
/* Hard Link example
*
* Create a new class of user-defined links that behave like HDF5's built-in
@@ -305,17 +304,17 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
* To keep the example simple, these links don't have a query callback.
* Generally, real link classes should always be query-able.
*/
static herr_t UD_hard_create(const char *link_name, hid_t loc_group,
const void *udata, size_t udata_size, hid_t lcpl_id);
static herr_t UD_hard_delete(const char *link_name, hid_t loc_group,
const void *udata, size_t udata_size);
static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
static herr_t UD_hard_create(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size,
hid_t lcpl_id);
static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size);
static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
hid_t lapl_id, hid_t dxpl_id);
static void hard_link_example(void)
static void
hard_link_example(void)
{
hid_t file_id;
hid_t group_id;
hid_t file_id;
hid_t group_id;
H5L_info2_t li;
/* Define the link class that we'll use to register "user-defined hard
* links" using the callbacks we defined above.
@@ -323,27 +322,26 @@ static void hard_link_example(void)
* callback.
*/
const H5L_class_t UD_hard_class[1] = {{
H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
* This field is always H5L_LINK_CLASS_T_VERS */
(H5L_type_t)UD_HARD_CLASS, /* Link class id number. This can be any
* value between H5L_TYPE_UD_MIN (64) and
* H5L_TYPE_MAX (255). It should be a
* value that isn't already being used by
* another kind of link. We'll use 66. */
"UD_hard_link", /* Link class name for debugging */
UD_hard_create, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
UD_hard_traverse, /* The actual traversal function */
UD_hard_delete, /* Deletion callback */
NULL /* Query callback */
H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
* This field is always H5L_LINK_CLASS_T_VERS */
(H5L_type_t)UD_HARD_CLASS, /* Link class id number. This can be any
* value between H5L_TYPE_UD_MIN (64) and
* H5L_TYPE_MAX (255). It should be a
* value that isn't already being used by
* another kind of link. We'll use 66. */
"UD_hard_link", /* Link class name for debugging */
UD_hard_create, /* Creation callback */
NULL, /* Move callback */
NULL, /* Copy callback */
UD_hard_traverse, /* The actual traversal function */
UD_hard_delete, /* Deletion callback */
NULL /* Query callback */
}};
/* First, create a file and an object within the file for the link to
* point to.
*/
file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
@@ -366,8 +364,8 @@ static void hard_link_example(void)
/* Now create a user-defined link. We give it the group's address
* as its udata.
*/
H5Lcreate_ud(file_id, UD_HARD_LINK_NAME, (H5L_type_t)UD_HARD_CLASS, &(li.u.token),
sizeof(H5O_token_t), H5P_DEFAULT, H5P_DEFAULT);
H5Lcreate_ud(file_id, UD_HARD_LINK_NAME, (H5L_type_t)UD_HARD_CLASS, &(li.u.token), sizeof(H5O_token_t),
H5P_DEFAULT, H5P_DEFAULT);
/* The UD hard link has now incremented the group's reference count
* like a normal hard link would. This means that we can unlink the
@@ -401,42 +399,39 @@ static void hard_link_example(void)
* If this function returns a negative value, the call to H5Lcreate_ud()
* will also return failure and the link will not be created.
*/
static herr_t UD_hard_create(const char *link_name, hid_t loc_group,
const void *udata, size_t udata_size, hid_t lcpl_id)
static herr_t
UD_hard_create(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size, hid_t lcpl_id)
{
H5O_token_t token;
hid_t target_obj = H5I_INVALID_HID;
herr_t ret_value = 0;
hid_t target_obj = H5I_INVALID_HID;
herr_t ret_value = 0;
/* Make sure that the address passed in looks valid */
if(udata_size != sizeof(H5O_token_t))
{
ret_value = -1;
goto done;
if (udata_size != sizeof(H5O_token_t)) {
ret_value = -1;
goto done;
}
token = *((H5O_token_t *) udata);
token = *((H5O_token_t *)udata);
/* Open the object this link points to so that we can increment
* its reference count. This also ensures that the token passed
* in points to a real object (although this check is not perfect!) */
target_obj = H5Oopen_by_token(loc_group, token);
if(target_obj < 0)
{
ret_value = -1;
goto done;
if (target_obj < 0) {
ret_value = -1;
goto done;
}
/* Increment the reference count of the target object */
if(H5Oincr_refcount(target_obj) < 0)
{
ret_value = -1;
goto done;
if (H5Oincr_refcount(target_obj) < 0) {
ret_value = -1;
goto done;
}
done:
/* Close the target object if we opened it */
if(target_obj >= 0)
if (target_obj >= 0)
H5Oclose(target_obj);
return ret_value;
}
@@ -445,42 +440,39 @@ done:
* Since the creation function increments the object's reference count, it's
* important to decrement it again when the link is deleted.
*/
static herr_t UD_hard_delete(const char *link_name, hid_t loc_group,
const void *udata, size_t udata_size)
static herr_t
UD_hard_delete(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size)
{
H5O_token_t token;
hid_t target_obj = H5I_INVALID_HID;
herr_t ret_value = 0;
hid_t target_obj = H5I_INVALID_HID;
herr_t ret_value = 0;
/* Sanity check; we have already verified the udata's size in the creation
* callback.
*/
if(udata_size != sizeof(H5O_token_t))
{
ret_value = -1;
goto done;
if (udata_size != sizeof(H5O_token_t)) {
ret_value = -1;
goto done;
}
token = *((H5O_token_t *) udata);
token = *((H5O_token_t *)udata);
/* Open the object this link points to */
target_obj = H5Oopen_by_token(loc_group, token);
if(target_obj < 0)
{
ret_value = -1;
goto done;
if (target_obj < 0) {
ret_value = -1;
goto done;
}
/* Decrement the reference count of the target object */
if(H5Odecr_refcount(target_obj) < 0)
{
ret_value = -1;
goto done;
if (H5Odecr_refcount(target_obj) < 0) {
ret_value = -1;
goto done;
}
done:
/* Close the target object if we opened it */
if(target_obj >= 0)
if (target_obj >= 0)
H5Oclose(target_obj);
return ret_value;
}
@@ -489,19 +481,20 @@ done:
* The actual traversal function simply needs to open the correct object and
* return its ID.
*/
static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
static hid_t
UD_hard_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
hid_t dxpl_id)
{
H5O_token_t token;
hid_t ret_value = H5I_INVALID_HID;
hid_t ret_value = H5I_INVALID_HID;
/* Sanity check; we have already verified the udata's size in the creation
* callback.
*/
if(udata_size != sizeof(H5O_token_t))
return H5I_INVALID_HID;
if (udata_size != sizeof(H5O_token_t))
return H5I_INVALID_HID;
token = *((H5O_token_t *) udata);
token = *((H5O_token_t *)udata);
/* Open the object by token. If H5Oopen_by_token fails, ret_value will
* be negative to indicate that the traversal function failed.
@@ -511,8 +504,6 @@ static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
return ret_value;
}
/* Plist example
*
* Create a new class of user-defined links that open objects within a file
@@ -526,10 +517,11 @@ static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
* These are defined after the example below.
* These links have no udata, so they don't need a query function.
*/
static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
hid_t lapl_id, hid_t dxpl_id);
static void plist_link_example(void)
static void
plist_link_example(void)
{
hid_t file_id;
hid_t group_id, group2_id;
@@ -558,11 +550,10 @@ static void plist_link_example(void)
NULL /* Query callback */
}};
/* First, create a file and two objects within the file for the link to
* point to.
*/
file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, "group_1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
group_id = H5Gcreate2(file_id, "group_1/group_2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -570,8 +561,7 @@ static void plist_link_example(void)
/* Register "plist links" and create one. It has no udata at all. */
H5Lregister(UD_plist_class);
H5Lcreate_ud(file_id, "plist_link", (H5L_type_t)UD_PLIST_CLASS, NULL, 0,
H5P_DEFAULT, H5P_DEFAULT);
H5Lcreate_ud(file_id, "plist_link", (H5L_type_t)UD_PLIST_CLASS, NULL, 0, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group access property list to pass in the target for the
* plist link.
@@ -617,17 +607,18 @@ static void plist_link_example(void)
/* UD_plist_traverse
* Open a path passed in through the property list.
*/
static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group,
const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
static hid_t
UD_plist_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
hid_t dxpl_id)
{
char * path;
hid_t ret_value = H5I_INVALID_HID;
char *path;
hid_t ret_value = H5I_INVALID_HID;
/* If the link property isn't set or can't be found, traversal fails. */
if(H5Pexist(lapl_id, PLIST_LINK_PROP) < 0)
if (H5Pexist(lapl_id, PLIST_LINK_PROP) < 0)
goto error;
if(H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0)
if (H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0)
goto error;
/* Open the object by address. If H5Oopen_by_addr fails, ret_value will
@@ -641,13 +632,11 @@ error:
return H5I_INVALID_HID;
}
/* Main function
*
* Invokes the example functions.
*/
int
int
main(void)
{
printf("Testing basic external links.\n");
@@ -667,5 +656,3 @@ main(void)
return 0;
}

View File

@@ -19,31 +19,29 @@
* in the root group and in the created group.
*/
#include "hdf5.h"
#define H5FILE_NAME "group.h5"
#define RANK 2
#define H5FILE_NAME "group.h5"
#define RANK 2
static herr_t file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo,
void *opdata); /* Link iteration operator function */
void *opdata); /* Link iteration operator function */
static herr_t group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo,
void *opdata); /* Link iteration operator function */
void *opdata); /* Link iteration operator function */
int
main(void)
{
hid_t file;
hid_t grp;
hid_t dataset, dataspace;
hid_t plist;
hid_t file;
hid_t grp;
hid_t dataset, dataspace;
hid_t plist;
herr_t status;
hsize_t dims[2];
hsize_t cdims[2];
herr_t status;
hsize_t dims[2];
hsize_t cdims[2];
int idx_f, idx_g;
int idx_f, idx_g;
/*
* Create a file.
@@ -61,16 +59,16 @@ main(void)
* GZIP compression with the compression effort set to 6.
* Note that compression can be used only when dataset is chunked.
*/
dims[0] = 1000;
dims[1] = 20;
cdims[0] = 20;
cdims[1] = 20;
dims[0] = 1000;
dims[1] = 20;
cdims[0] = 20;
cdims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
plist = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(plist, 2, cdims);
H5Pset_deflate( plist, 6);
dataset = H5Dcreate2(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
H5Pset_chunk(plist, 2, cdims);
H5Pset_deflate(plist, 6);
dataset =
H5Dcreate2(file, "/Data/Compressed_Data", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
/*
* Close the first dataset .
*/
@@ -80,11 +78,11 @@ main(void)
/*
* Create the second dataset.
*/
dims[0] = 500;
dims[1] = 20;
dims[0] = 500;
dims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
dataset = H5Dcreate2(file, "/Data/Float_Data", H5T_NATIVE_FLOAT,
dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset = H5Dcreate2(file, "/Data/Float_Data", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
/*
*Close the second dataset and file.
@@ -105,7 +103,8 @@ main(void)
* Access "Compressed_Data" dataset in the group.
*/
dataset = H5Dopen2(grp, "Compressed_Data", H5P_DEFAULT);
if( dataset < 0) printf(" Dataset 'Compressed-Data' is not found. \n");
if (dataset < 0)
printf(" Dataset 'Compressed-Data' is not found. \n");
printf("\"/Data/Compressed_Data\" dataset is open \n");
/*
@@ -123,7 +122,8 @@ main(void)
* hard link "Data_new".
*/
dataset = H5Dopen2(file, "/Data_new/Compressed_Data", H5P_DEFAULT);
if( dataset < 0) printf(" Dataset is not found. \n");
if (dataset < 0)
printf(" Dataset is not found. \n");
printf("\"/Data_new/Compressed_Data\" dataset is open \n");
/*
@@ -131,7 +131,6 @@ main(void)
*/
status = H5Dclose(dataset);
/*
* Use iterator to see the names of the objects in the root group.
*/
@@ -141,10 +140,10 @@ main(void)
* Unlink name "Data" and use iterator to see the names
* of the objects in the file root direvtory.
*/
if(H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
printf(" H5Ldelete failed \n");
if (H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
printf(" H5Ldelete failed \n");
else
printf("\"Data\" is unlinked \n");
printf("\"Data\" is unlinked \n");
idx_f = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
@@ -152,7 +151,8 @@ main(void)
* Use iterator to see the names of the objects in the group
* /Data_new.
*/
idx_g = H5Literate_by_name2(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL, H5P_DEFAULT);
idx_g = H5Literate_by_name2(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL,
H5P_DEFAULT);
/*
* Close the file.
@@ -173,7 +173,7 @@ file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata
/* avoid compiler warnings */
loc_id = loc_id;
opdata = opdata;
linfo = linfo;
linfo = linfo;
/*
* Display group name. The name is passed to the function by
@@ -184,23 +184,22 @@ file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata
return 0;
}
/*
* Operator function.
*/
static herr_t
group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
{
hid_t did; /* dataset identifier */
hid_t tid; /* datatype identifier */
hid_t did; /* dataset identifier */
hid_t tid; /* datatype identifier */
H5T_class_t t_class;
hid_t pid; /* data_property identifier */
hsize_t chunk_dims_out[2];
int rank_chunk;
hid_t pid; /* data_property identifier */
hsize_t chunk_dims_out[2];
int rank_chunk;
/* avoid warnings */
opdata = opdata;
linfo = linfo;
linfo = linfo;
/*
* Open the datasets using their names.
@@ -215,38 +214,37 @@ group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdat
/*
* Display dataset information.
*/
tid = H5Dget_type(did); /* get datatype*/
tid = H5Dget_type(did); /* get datatype*/
pid = H5Dget_create_plist(did); /* get creation property list */
/*
* Check if dataset is chunked.
*/
if(H5D_CHUNKED == H5Pget_layout(pid)) {
if (H5D_CHUNKED == H5Pget_layout(pid)) {
/*
* get chunking information: rank and dimensions.
*/
rank_chunk = H5Pget_chunk(pid, 2, chunk_dims_out);
printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk,
(unsigned long)(chunk_dims_out[0]),
(unsigned long)(chunk_dims_out[1]));
printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk, (unsigned long)(chunk_dims_out[0]),
(unsigned long)(chunk_dims_out[1]));
}
else {
t_class = H5Tget_class(tid);
if(t_class < 0) {
if (t_class < 0) {
puts(" Invalid datatype.\n");
}
else {
if(t_class == H5T_INTEGER)
if (t_class == H5T_INTEGER)
puts(" Datatype is 'H5T_NATIVE_INTEGER'.\n");
if(t_class == H5T_FLOAT)
if (t_class == H5T_FLOAT)
puts(" Datatype is 'H5T_NATIVE_FLOAT'.\n");
if(t_class == H5T_STRING)
if (t_class == H5T_STRING)
puts(" Datatype is 'H5T_NATIVE_STRING'.\n");
if(t_class == H5T_BITFIELD)
if (t_class == H5T_BITFIELD)
puts(" Datatype is 'H5T_NATIVE_BITFIELD'.\n");
if(t_class == H5T_OPAQUE)
if (t_class == H5T_OPAQUE)
puts(" Datatype is 'H5T_NATIVE_OPAQUE'.\n");
if(t_class == H5T_COMPOUND)
if (t_class == H5T_COMPOUND)
puts(" Datatype is 'H5T_NATIVE_COMPOUND'.\n");
}
}
@@ -256,4 +254,3 @@ group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdat
H5Tclose(tid);
return 0;
}

View File

@@ -16,27 +16,24 @@
* all intermediate groups.
*/
#include "hdf5.h"
#define H5FILE_NAME "interm_group.h5"
#define TRUE 1
#define FALSE 0
#define H5FILE_NAME "interm_group.h5"
#define TRUE 1
#define FALSE 0
int
main(void)
{
hid_t file;
hid_t g1_id, g2_id, g3_id;
hid_t grp_crt_plist;
hid_t file;
hid_t g1_id, g2_id, g3_id;
hid_t grp_crt_plist;
H5G_info_t g2_info;
char name[3];
herr_t status;
int i;
char name[3];
herr_t status;
int i;
/*
* Create a file using the default properties.
@@ -59,53 +56,44 @@ main(void)
/*
* Check if group /G1 exists in the file.
*/
if(H5Lexists(file, "/G1", H5P_DEFAULT) !=FALSE)
printf("Group /G1 exists in the file\n");
if (H5Lexists(file, "/G1", H5P_DEFAULT) != FALSE)
printf("Group /G1 exists in the file\n");
/*
* Check that group G2/G3 exists in /G1 and if not create it using
* intermediate group creation property.
*/
g1_id = H5Gopen2(file, "/G1", H5P_DEFAULT);
/* Next commented call causes error stack to be printed out; the next one
* works fine; is it a bug or a feature? EIP 04-25-07
*/
/* if (H5Lexists(g1_id, "G2/G3", H5P_DEFAULT) !=TRUE) { */
if (H5Lexists(g1_id, "G2", H5P_DEFAULT) !=TRUE) {
/* Next commented call causes error stack to be printed out; the next one
* works fine; is it a bug or a feature? EIP 04-25-07
*/
/* if (H5Lexists(g1_id, "G2/G3", H5P_DEFAULT) !=TRUE) { */
if (H5Lexists(g1_id, "G2", H5P_DEFAULT) != TRUE) {
grp_crt_plist = H5Pcreate(H5P_LINK_CREATE);
grp_crt_plist = H5Pcreate(H5P_LINK_CREATE);
/* Set flag for intermediate group creation */
status = H5Pset_create_intermediate_group(grp_crt_plist, TRUE);
g3_id = H5Gcreate2(g1_id, "G2/G3", grp_crt_plist, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(g3_id);
/* Set flag for intermediate group creation */
status = H5Pset_create_intermediate_group(grp_crt_plist, TRUE);
g3_id = H5Gcreate2(g1_id, "G2/G3", grp_crt_plist, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(g3_id);
}
H5Gclose(g1_id);
/* Now check if group /G1/G2 exists in the file, then open it and print
* its members names
*/
if (H5Lexists(file, "/G1/G2", H5P_DEFAULT)) {
g2_id = H5Gopen2(file, "/G1/G2", H5P_DEFAULT);
status = H5Gget_info(g2_id, &g2_info);
printf("Group /G1/G2 has %d member(s)\n", (int)g2_info.nlinks);
g2_id = H5Gopen2(file, "/G1/G2", H5P_DEFAULT);
status = H5Gget_info(g2_id, &g2_info);
printf("Group /G1/G2 has %d member(s)\n", (int)g2_info.nlinks);
for (i=0; i < (int)g2_info.nlinks; i++) {
H5Lget_name_by_idx(g2_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, (hsize_t)i,
name, 3, H5P_DEFAULT);
printf("Object's name is %s\n", name);
}
H5Gclose(g2_id);
for (i = 0; i < (int)g2_info.nlinks; i++) {
H5Lget_name_by_idx(g2_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, (hsize_t)i, name, 3, H5P_DEFAULT);
printf("Object's name is %s\n", name);
}
H5Gclose(g2_id);
}
H5Fclose(file);
return 0;
}

View File

@@ -25,107 +25,105 @@
#define FILE2 "mount2.h5"
#define RANK 2
#define NX 4
#define NY 5
#define NX 4
#define NY 5
int main(void)
int
main(void)
{
hid_t fid1, fid2, gid; /* Files and group identifiers */
hid_t did, tid, sid; /* Dataset and datatype identifiers */
hid_t fid1, fid2, gid; /* Files and group identifiers */
hid_t did, tid, sid; /* Dataset and datatype identifiers */
herr_t status;
hsize_t dims[] = {NX,NY}; /* Dataset dimensions */
herr_t status;
hsize_t dims[] = {NX, NY}; /* Dataset dimensions */
int i, j;
int bm[NX][NY], bm_out[NX][NY]; /* Data buffers */
int i, j;
int bm[NX][NY], bm_out[NX][NY]; /* Data buffers */
/*
* Initialization of buffer matrix "bm"
*/
for(i =0; i < NX; i++)
for(j = 0; j < NY; j++)
bm[i][j] = i + j;
/*
* Initialization of buffer matrix "bm"
*/
for (i = 0; i < NX; i++)
for (j = 0; j < NY; j++)
bm[i][j] = i + j;
/*
* Create first file and a group in it.
*/
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
gid = H5Gcreate2(fid1, "/G", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create first file and a group in it.
*/
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
gid = H5Gcreate2(fid1, "/G", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Close group and file
*/
H5Gclose(gid);
H5Fclose(fid1);
/*
* Close group and file
*/
H5Gclose(gid);
H5Fclose(fid1);
/*
* Create second file and dataset "D" in it.
*/
fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dims[0] = NX;
dims[1] = NY;
sid = H5Screate_simple(RANK, dims, NULL);
did = H5Dcreate2(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create second file and dataset "D" in it.
*/
fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dims[0] = NX;
dims[1] = NY;
sid = H5Screate_simple(RANK, dims, NULL);
did = H5Dcreate2(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);
/*
* Write data to the dataset.
*/
status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);
/*
* Close all identifiers.
*/
H5Sclose(sid);
H5Dclose(did);
H5Fclose(fid2);
/*
* Close all identifiers.
*/
H5Sclose(sid);
H5Dclose(did);
H5Fclose(fid2);
/*
* Reopen both files
*/
fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Reopen both files
*/
fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Mount second file under G in the first file.
*/
H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);
/*
* Mount second file under G in the first file.
*/
H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);
/*
* Access dataset D in the first file under /G/D name.
*/
did = H5Dopen2(fid1, "/G/D", H5P_DEFAULT);
tid = H5Dget_type(did);
status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);
/*
* Access dataset D in the first file under /G/D name.
*/
did = H5Dopen2(fid1, "/G/D", H5P_DEFAULT);
tid = H5Dget_type(did);
status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);
/*
* Print out the data.
*/
for(i=0; i<NX; i++){
for(j=0; j<NY; j++)
printf(" %d", bm_out[i][j]);
printf("\n");
}
/*
* Print out the data.
*/
for (i = 0; i < NX; i++) {
for (j = 0; j < NY; j++)
printf(" %d", bm_out[i][j]);
printf("\n");
}
/*
* Close all identifers
*/
H5Tclose(tid);
H5Dclose(did);
/*
* Close all identifers
*/
H5Tclose(tid);
H5Dclose(did);
/*
* Unmounting second file
*/
H5Funmount(fid1, "/G");
/*
* Unmounting second file
*/
H5Funmount(fid1, "/G");
/*
* Close both files
*/
H5Fclose(fid1);
H5Fclose(fid2);
/*
* Close both files
*/
H5Fclose(fid1);
H5Fclose(fid2);
return 0;
return 0;
}

View File

@@ -19,33 +19,33 @@
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
int
main()
{
hid_t file_id, dataset_id; /* identifiers */
herr_t status;
int i, j, dset_data[4][6];
hid_t file_id, dataset_id; /* identifiers */
herr_t status;
int i, j, dset_data[4][6];
/* Initialize the dataset. */
for (i = 0; i < 4; i++)
for (j = 0; j < 6; j++)
dset_data[i][j] = i * 6 + j + 1;
/* Initialize the dataset. */
for (i = 0; i < 4; i++)
for (j = 0; j < 6; j++)
dset_data[i][j] = i * 6 + j + 1;
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
/* Write the dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
/* Write the dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
/* Close the dataset. */
status = H5Dclose(dataset_id);
/* Close the dataset. */
status = H5Dclose(dataset_id);
/* Close the file. */
status = H5Fclose(file_id);
/* Close the file. */
status = H5Fclose(file_id);
}

View File

@@ -20,71 +20,73 @@
#include "hdf5.h"
#define H5FILE_NAME "SDS.h5"
#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "IntArray"
#define NX_SUB 3 /* hyperslab dimensions */
#define NY_SUB 4
#define NX 7 /* output buffer dimensions */
#define NY 7
#define NZ 3
#define RANK 2
#define RANK_OUT 3
#define NX_SUB 3 /* hyperslab dimensions */
#define NY_SUB 4
#define NX 7 /* output buffer dimensions */
#define NY 7
#define NZ 3
#define RANK 2
#define RANK_OUT 3
int
main (void)
main(void)
{
hid_t file, dataset; /* handles */
hid_t file, dataset; /* handles */
hid_t datatype, dataspace;
hid_t memspace;
H5T_class_t t_class; /* data type class */
H5T_order_t order; /* data order */
size_t size; /*
* size of the data element
* stored in file
*/
hsize_t dimsm[3]; /* memory space dimensions */
hsize_t dims_out[2]; /* dataset dimensions */
herr_t status;
H5T_class_t t_class; /* data type class */
H5T_order_t order; /* data order */
size_t size; /*
* size of the data element
* stored in file
*/
hsize_t dimsm[3]; /* memory space dimensions */
hsize_t dims_out[2]; /* dataset dimensions */
herr_t status;
int data_out[NX][NY][NZ ]; /* output buffer */
int data_out[NX][NY][NZ]; /* output buffer */
hsize_t count[2]; /* size of the hyperslab in the file */
hsize_t offset[2]; /* hyperslab offset in the file */
hsize_t count_out[3]; /* size of the hyperslab in memory */
hsize_t offset_out[3]; /* hyperslab offset in memory */
int i, j, k, status_n, rank;
hsize_t count[2]; /* size of the hyperslab in the file */
hsize_t offset[2]; /* hyperslab offset in the file */
hsize_t count_out[3]; /* size of the hyperslab in memory */
hsize_t offset_out[3]; /* hyperslab offset in memory */
int i, j, k, status_n, rank;
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++) {
for (k = 0; k < NZ ; k++)
data_out[j][i][k] = 0;
}
for (i = 0; i < NY; i++) {
for (k = 0; k < NZ; k++)
data_out[j][i][k] = 0;
}
}
/*
* Open the file and the dataset.
*/
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
/*
* Get datatype and dataspace handles and then query
* dataset class, order, size, rank and dimensions.
*/
datatype = H5Dget_type(dataset); /* datatype handle */
t_class = H5Tget_class(datatype);
if (t_class == H5T_INTEGER) printf("Data set has INTEGER type \n");
order = H5Tget_order(datatype);
if (order == H5T_ORDER_LE) printf("Little endian order \n");
datatype = H5Dget_type(dataset); /* datatype handle */
t_class = H5Tget_class(datatype);
if (t_class == H5T_INTEGER)
printf("Data set has INTEGER type \n");
order = H5Tget_order(datatype);
if (order == H5T_ORDER_LE)
printf("Little endian order \n");
size = H5Tget_size(datatype);
size = H5Tget_size(datatype);
printf(" Data size is %d \n", (int)size);
dataspace = H5Dget_space(dataset); /* dataspace handle */
dataspace = H5Dget_space(dataset); /* dataspace handle */
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
printf("rank %d, dimensions %lu x %lu \n", rank,
(unsigned long)(dims_out[0]), (unsigned long)(dims_out[1]));
printf("rank %d, dimensions %lu x %lu \n", rank, (unsigned long)(dims_out[0]),
(unsigned long)(dims_out[1]));
/*
* Define hyperslab in the dataset.
@@ -93,16 +95,15 @@ main (void)
offset[1] = 2;
count[0] = NX_SUB;
count[1] = NY_SUB;
status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);
/*
* Define the memory dataspace.
*/
dimsm[0] = NX;
dimsm[1] = NY;
dimsm[2] = NZ ;
memspace = H5Screate_simple(RANK_OUT,dimsm,NULL);
dimsm[2] = NZ;
memspace = H5Screate_simple(RANK_OUT, dimsm, NULL);
/*
* Define memory hyperslab.
@@ -113,18 +114,17 @@ main (void)
count_out[0] = NX_SUB;
count_out[1] = NY_SUB;
count_out[2] = 1;
status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
count_out, NULL);
status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, count_out, NULL);
/*
* Read data from hyperslab in the file into the hyperslab in
* memory and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace,
H5P_DEFAULT, data_out);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace, H5P_DEFAULT, data_out);
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++) printf("%d ", data_out[j][i][0]);
printf("\n");
for (i = 0; i < NY; i++)
printf("%d ", data_out[j][i][0]);
printf("\n");
}
/*
* 0 0 0 0 0 0 0

View File

@@ -26,33 +26,34 @@
#include "hdf5.h"
#define filename "REF_REG.h5"
#define filename "REF_REG.h5"
#define dsetnamev "MATRIX"
#define dsetnamer "REGION_REFERENCES"
int main(void)
int
main(void)
{
hid_t file_id; /* file identifier */
hid_t space_id; /* dataspace identifiers */
hid_t spacer_id;
hid_t dsetv_id; /*dataset identifiers*/
hid_t dsetr_id;
hsize_t dims[2] = {2,9};
hsize_t dimsr[1] = {2};
int rank = 2;
int rankr =1;
herr_t status;
hid_t file_id; /* file identifier */
hid_t space_id; /* dataspace identifiers */
hid_t spacer_id;
hid_t dsetv_id; /*dataset identifiers*/
hid_t dsetr_id;
hsize_t dims[2] = {2, 9};
hsize_t dimsr[1] = {2};
int rank = 2;
int rankr = 1;
herr_t status;
hdset_reg_ref_t ref[2];
hdset_reg_ref_t ref_out[2];
int data[2][9] = {{1,1,2,3,3,4,5,5,6},{1,2,2,3,4,4,5,6,6}};
int data_out[2][9] = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0}};
hsize_t start[2];
hsize_t count[2];
hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}};
unsigned num_points = 3;
int i, j;
size_t name_size1, name_size2;
char buf1[10], buf2[10];
int data[2][9] = {{1, 1, 2, 3, 3, 4, 5, 5, 6}, {1, 2, 2, 3, 4, 4, 5, 6, 6}};
int data_out[2][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}};
hsize_t start[2];
hsize_t count[2];
hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}};
unsigned num_points = 3;
int i, j;
size_t name_size1, name_size2;
char buf1[10], buf2[10];
/*
* Create file with default file access and file creation properties.
@@ -62,24 +63,26 @@ int main(void)
/*
* Create dataspace for datasets.
*/
space_id = H5Screate_simple(rank, dims, NULL);
space_id = H5Screate_simple(rank, dims, NULL);
spacer_id = H5Screate_simple(rankr, dimsr, NULL);
/*
* Create integer dataset.
*/
dsetv_id = H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dsetv_id =
H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT,data);
status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
status = H5Dclose(dsetv_id);
/*
* Dataset with references.
*/
dsetr_id = H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dsetr_id =
H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a reference to the hyperslab.
@@ -88,8 +91,8 @@ int main(void)
start[1] = 3;
count[0] = 2;
count[1] = 3;
status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL);
status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id);
status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL);
status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id);
/*
* Create a reference to elements selection.
@@ -101,7 +104,7 @@ int main(void)
/*
* Write dataset with the references.
*/
status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref);
status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref);
/*
* Close all objects.
@@ -114,7 +117,7 @@ int main(void)
/*
* Reopen the file to read selections back.
*/
file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
/*
* Reopen the dataset with object references and read references
@@ -122,8 +125,7 @@ int main(void)
*/
dsetr_id = H5Dopen2(file_id, dsetnamer, H5P_DEFAULT);
status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
H5P_DEFAULT, ref_out);
status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_out);
/*
* Dereference the first reference.
@@ -133,26 +135,26 @@ int main(void)
* Get name of the dataset the first region reference points to
* using H5Rget_name
*/
name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, 10);
printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n", buf1, (int)name_size1);
name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char *)buf1, 10);
printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n",
buf1, (int)name_size1);
/*
* Get name of the dataset the first region reference points to
* using H5Iget_name
*/
name_size2 = H5Iget_name(dsetv_id, (char*)buf2, 10);
printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n", buf2, (int)name_size2);
name_size2 = H5Iget_name(dsetv_id, (char *)buf2, 10);
printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n",
buf2, (int)name_size2);
space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION,&ref_out[0]);
space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION, &ref_out[0]);
/*
* Read and display hyperslab selection from the dataset.
*/
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
H5P_DEFAULT, data_out);
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out);
printf("Selected hyperslab: ");
for (i = 0; i <= 1; i++)
{
for (i = 0; i <= 1; i++) {
printf("\n");
for (j = 0; j <= 8; j++)
printf("%d ", data_out[i][j]);
@@ -176,17 +178,15 @@ int main(void)
* Dereference the second reference.
*/
dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[1]);
space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION,&ref_out[1]);
space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION, &ref_out[1]);
/*
* Read selected data from the dataset.
*/
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
H5P_DEFAULT, data_out);
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out);
printf("Selected points: ");
for (i = 0; i <= 1; i++)
{
for (i = 0; i <= 1; i++) {
printf("\n");
for (j = 0; j <= 8; j++)
printf("%d ", data_out[i][j]);
@@ -203,6 +203,3 @@ int main(void)
return 0;
}

View File

@@ -10,12 +10,12 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* The example below illustrates the use of the new API with a file that was
* written using the old-style reference API, showing how one can take
* advantage of the automatic type conversion from old reference type to new
* reference type.
*/
/*
* The example below illustrates the use of the new API with a file that was
* written using the old-style reference API, showing how one can take
* advantage of the automatic type conversion from old reference type to new
* reference type.
*/
#include <stdlib.h>
@@ -24,22 +24,23 @@
#define H5FILE_NAME "refer_deprec.h5"
#define NDIMS 1 /* Number of dimensions */
#define BUF_SIZE 4 /* Size of example buffer */
#define NREFS 1 /* Number of references */
#define NDIMS 1 /* Number of dimensions */
#define BUF_SIZE 4 /* Size of example buffer */
#define NREFS 1 /* Number of references */
int
main(void) {
hid_t file1, dset1, space1;
hsize_t dset1_dims[NDIMS] = { BUF_SIZE };
int dset_buf[BUF_SIZE];
main(void)
{
hid_t file1, dset1, space1;
hsize_t dset1_dims[NDIMS] = {BUF_SIZE};
int dset_buf[BUF_SIZE];
hid_t dset2, space2;
hsize_t dset2_dims[NDIMS] = { NREFS };
hobj_ref_t ref_buf[NREFS] = { 0 };
H5R_ref_t new_ref_buf[NREFS] = { 0 };
hid_t dset2, space2;
hsize_t dset2_dims[NDIMS] = {NREFS};
hobj_ref_t ref_buf[NREFS] = {0};
H5R_ref_t new_ref_buf[NREFS] = {0};
H5O_type_t obj_type;
int i;
int i;
for (i = 0; i < BUF_SIZE; i++)
dset_buf[i] = i;
@@ -48,8 +49,7 @@ main(void) {
file1 = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space1 = H5Screate_simple(NDIMS, dset1_dims, NULL);
dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
H5Dclose(dset1);
H5Sclose(space1);
@@ -62,7 +62,7 @@ main(void) {
/* Store reference in separate dataset using deprecated reference type */
space2 = H5Screate_simple(NDIMS, dset2_dims, NULL);
dset2 = H5Dcreate2(file1, "references", H5T_STD_REF_OBJ, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dset2 = H5Dcreate2(file1, "references", H5T_STD_REF_OBJ, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dset2, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf);
H5Dclose(dset2);
H5Sclose(space2);
@@ -87,4 +87,3 @@ main(void) {
assert(dset_buf[i] == i);
return 0;
}

View File

@@ -10,12 +10,12 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* The example below illustrates the use of the new API with files that are
* opened read-only. Created references to the objects in that file are
* stored into a separate file, and accessed from that file, without the user
* explicitly opening the original file that was referenced.
*/
/*
* The example below illustrates the use of the new API with files that are
* opened read-only. Created references to the objects in that file are
* stored into a separate file, and accessed from that file, without the user
* explicitly opening the original file that was referenced.
*/
#include <stdlib.h>
@@ -25,30 +25,30 @@
#define H5FILE_NAME1 "refer_extern1.h5"
#define H5FILE_NAME2 "refer_extern2.h5"
#define NDIMS 1 /* Number of dimensions */
#define BUF_SIZE 4 /* Size of example buffer */
#define NREFS 1 /* Number of references */
#define NDIMS 1 /* Number of dimensions */
#define BUF_SIZE 4 /* Size of example buffer */
#define NREFS 1 /* Number of references */
int
main(void) {
hid_t file1, dset1, space1;
hsize_t dset1_dims[NDIMS] = { BUF_SIZE };
int dset_buf[BUF_SIZE];
main(void)
{
hid_t file1, dset1, space1;
hsize_t dset1_dims[NDIMS] = {BUF_SIZE};
int dset_buf[BUF_SIZE];
hid_t file2, dset2, space2;
hsize_t dset2_dims[NDIMS] = { NREFS };
H5R_ref_t ref_buf[NREFS] = { 0 };
hid_t file2, dset2, space2;
hsize_t dset2_dims[NDIMS] = {NREFS};
H5R_ref_t ref_buf[NREFS] = {0};
H5O_type_t obj_type;
int i;
int i;
for (i = 0; i < BUF_SIZE; i++)
dset_buf[i] = i;
/* Create file with one dataset and close it */
file1 = H5Fcreate(H5FILE_NAME1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file1 = H5Fcreate(H5FILE_NAME1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space1 = H5Screate_simple(NDIMS, dset1_dims, NULL);
dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
H5Dclose(dset1);
H5Sclose(space1);
@@ -60,10 +60,9 @@ main(void) {
H5Fclose(file1);
/* Store reference in dataset in separate file "refer_extern2.h5" */
file2 = H5Fcreate(H5FILE_NAME2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file2 = H5Fcreate(H5FILE_NAME2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space2 = H5Screate_simple(NDIMS, dset2_dims, NULL);
dset2 = H5Dcreate2(file2, "references", H5T_STD_REF, space2, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
dset2 = H5Dcreate2(file2, "references", H5T_STD_REF, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite(dset2, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf);
H5Dclose(dset2);
H5Sclose(space2);
@@ -91,4 +90,3 @@ main(void) {
return 0;
}

View File

@@ -11,15 +11,15 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This program illustrates how references to objects can be used.
* Program creates a dataset and a group in a file. It also creates
* second dataset, and references to the first dataset and the group
* are stored in it.
* Program reopens the file and reads dataset with the references.
* References are used to open the objects. Information about the
* objects is displayed.
*/
/*
* This program illustrates how references to objects can be used.
* Program creates a dataset and a group in a file. It also creates
* second dataset, and references to the first dataset and the group
* are stored in it.
* Program reopens the file and reads dataset with the references.
* References are used to open the objects. Information about the
* objects is displayed.
*/
#include <stdlib.h>
@@ -28,120 +28,119 @@
#define H5FILE_NAME "refere.h5"
int
main(void) {
hid_t fid; /* File, group, datasets, datatypes */
hid_t gid_a; /* and dataspaces identifiers */
hid_t did_b, sid_b, tid_b;
hid_t did_r, tid_r, sid_r;
H5O_type_t obj_type;
herr_t status;
main(void)
{
hid_t fid; /* File, group, datasets, datatypes */
hid_t gid_a; /* and dataspaces identifiers */
hid_t did_b, sid_b, tid_b;
hid_t did_r, tid_r, sid_r;
H5O_type_t obj_type;
herr_t status;
hobj_ref_t *wbuf; /* buffer to write to disk */
hobj_ref_t *rbuf; /* buffer to read from disk */
hobj_ref_t *wbuf; /* buffer to write to disk */
hobj_ref_t *rbuf; /* buffer to read from disk */
hsize_t dim_r[1];
hsize_t dim_b[2];
hsize_t dim_r[1];
hsize_t dim_b[2];
/*
* Create a file using default properties.
*/
fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a file using default properties.
*/
fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create group "A" in the file.
*/
gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create group "A" in the file.
*/
gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create dataset "B" in the file.
*/
dim_b[0] = 2;
dim_b[1] = 6;
sid_b = H5Screate_simple(2, dim_b, NULL);
did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create dataset "B" in the file.
*/
dim_b[0] = 2;
dim_b[1] = 6;
sid_b = H5Screate_simple(2, dim_b, NULL);
did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create dataset "R" to store references to the objects "A" and "B".
*/
dim_r[0] = 2;
sid_r = H5Screate_simple(1, dim_r, NULL);
tid_r = H5Tcopy(H5T_STD_REF_OBJ);
did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create dataset "R" to store references to the objects "A" and "B".
*/
dim_r[0] = 2;
sid_r = H5Screate_simple(1, dim_r, NULL);
tid_r = H5Tcopy(H5T_STD_REF_OBJ);
did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Allocate write and read buffers.
*/
wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
/*
* Allocate write and read buffers.
*/
wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
/*
* Create references to the group "A" and dataset "B"
* and store them in the wbuf.
*/
H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, (hid_t)-1);
H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, (hid_t)-1);
/*
* Create references to the group "A" and dataset "B"
* and store them in the wbuf.
*/
H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, (hid_t)-1);
H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, (hid_t)-1);
/*
* Write dataset R using default transfer properties.
*/
status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
/*
* Write dataset R using default transfer properties.
*/
status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
/*
* Close all objects.
*/
H5Gclose(gid_a);
/*
* Close all objects.
*/
H5Gclose(gid_a);
H5Sclose(sid_b);
H5Dclose(did_b);
H5Sclose(sid_b);
H5Dclose(did_b);
H5Tclose(tid_r);
H5Sclose(sid_r);
H5Dclose(did_r);
H5Tclose(tid_r);
H5Sclose(sid_r);
H5Dclose(did_r);
H5Fclose(fid);
H5Fclose(fid);
/*
* Reopen the file.
*/
fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
/*
* Reopen the file.
*/
fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
/*
* Open and read dataset "R".
*/
did_r = H5Dopen2(fid, "R", H5P_DEFAULT);
status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
/*
* Open and read dataset "R".
*/
did_r = H5Dopen2(fid, "R", H5P_DEFAULT);
status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
/*
* Find the type of referenced objects.
*/
/*
* Find the type of referenced objects.
*/
status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[0], &obj_type);
if(obj_type == H5O_TYPE_GROUP)
if (obj_type == H5O_TYPE_GROUP)
printf("First dereferenced object is a group. \n");
status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[1], &obj_type);
if(obj_type == H5O_TYPE_DATASET)
if (obj_type == H5O_TYPE_DATASET)
printf("Second dereferenced object is a dataset. \n");
/*
* Get datatype of the dataset "B"
*/
did_b = H5Rdereference2(did_r, H5P_DEFAULT, H5R_OBJECT, &rbuf[1]);
tid_b = H5Dget_type(did_b);
if(H5Tequal(tid_b, H5T_NATIVE_FLOAT))
printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
printf("\n");
/*
* Get datatype of the dataset "B"
*/
did_b = H5Rdereference2(did_r, H5P_DEFAULT, H5R_OBJECT, &rbuf[1]);
tid_b = H5Dget_type(did_b);
if (H5Tequal(tid_b, H5T_NATIVE_FLOAT))
printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
printf("\n");
/*
* Close all objects and free memory buffers.
*/
H5Dclose(did_r);
H5Dclose(did_b);
H5Tclose(tid_b);
H5Fclose(fid);
free(rbuf);
free(wbuf);
return 0;
}
/*
* Close all objects and free memory buffers.
*/
H5Dclose(did_r);
H5Dclose(did_b);
H5Tclose(tid_b);
H5Fclose(fid);
free(rbuf);
free(wbuf);
return 0;
}

View File

@@ -26,78 +26,80 @@
#define H5FILE_NAME "Select.h5"
#define MSPACE1_RANK 1 /* Rank of the first dataset in memory */
#define MSPACE1_DIM 50 /* Dataset size in memory */
#define MSPACE1_RANK 1 /* Rank of the first dataset in memory */
#define MSPACE1_DIM 50 /* Dataset size in memory */
#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
#define MSPACE2_DIM 4 /* Dataset size in memory */
#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
#define MSPACE2_DIM 4 /* Dataset size in memory */
#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
#define FSPACE_DIM1 8 /* Dimension sizes of the dataset as it is
stored in the file */
#define FSPACE_DIM2 12
#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
#define FSPACE_DIM1 \
8 /* Dimension sizes of the dataset as it is \
stored in the file */
#define FSPACE_DIM2 12
/* We will read dataset back from the file
to the dataset in memory with these
dataspace parameters. */
#define MSPACE_RANK 2
#define MSPACE_DIM1 8
#define MSPACE_DIM2 9
/* We will read dataset back from the file
to the dataset in memory with these
dataspace parameters. */
#define MSPACE_RANK 2
#define MSPACE_DIM1 8
#define MSPACE_DIM2 9
#define NPOINTS 4 /* Number of points that will be selected
and overwritten */
#define NPOINTS \
4 /* Number of points that will be selected \
and overwritten */
int
main (void)
main(void)
{
hid_t file, dataset; /* File and dataset identifiers */
hid_t mid1, mid2, mid, fid; /* Dataspace identifiers */
hid_t plist; /* Dataset property list identifier */
hid_t file, dataset; /* File and dataset identifiers */
hid_t mid1, mid2, mid, fid; /* Dataspace identifiers */
hid_t plist; /* Dataset property list identifier */
hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
(in memory) */
hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset
hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset
(in memory */
hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
/* Dimension sizes of the dataset (on disk) */
hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
dataset in memory when we
read selection from the
dataset on the disk */
hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
/* Dimension sizes of the dataset (on disk) */
hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
dataset in memory when we
read selection from the
dataset on the disk */
hsize_t start[2]; /* Start of hyperslab */
hsize_t stride[2]; /* Stride of hyperslab */
hsize_t count[2]; /* Block count */
hsize_t block[2]; /* Block sizes */
hsize_t start[2]; /* Start of hyperslab */
hsize_t stride[2]; /* Stride of hyperslab */
hsize_t count[2]; /* Block count */
hsize_t block[2]; /* Block sizes */
hsize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
from the file dataspace */
herr_t ret;
unsigned i,j;
int fillvalue = 0; /* Fill value for the dataset */
hsize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
from the file dataspace */
herr_t ret;
unsigned i, j;
int fillvalue = 0; /* Fill value for the dataset */
int matrix_out[MSPACE_DIM1][MSPACE_DIM2]; /* Buffer to read from the
dataset */
int vector[MSPACE1_DIM];
int values[] = {53, 59, 61, 67}; /* New values to be written */
int matrix_out[MSPACE_DIM1][MSPACE_DIM2]; /* Buffer to read from the
dataset */
int vector[MSPACE1_DIM];
int values[] = {53, 59, 61, 67}; /* New values to be written */
/*
* Buffers' initialization.
*/
vector[0] = vector[MSPACE1_DIM - 1] = -1;
for(i = 1; i < MSPACE1_DIM - 1; i++)
vector[i] = i;
/*
* Buffers' initialization.
*/
vector[0] = vector[MSPACE1_DIM - 1] = -1;
for (i = 1; i < MSPACE1_DIM - 1; i++)
vector[i] = i;
/*
* Create a file.
*/
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a file.
*/
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create property list for a dataset and set up fill values.
*/
plist = H5Pcreate(H5P_DATASET_CREATE);
ret = H5Pset_fill_value(plist, H5T_NATIVE_INT, &fillvalue);
/*
* Create property list for a dataset and set up fill values.
*/
plist = H5Pcreate(H5P_DATASET_CREATE);
ret = H5Pset_fill_value(plist, H5T_NATIVE_INT, &fillvalue);
/*
* Create dataspace for the dataset in the file.
@@ -114,11 +116,15 @@ main (void)
* Select hyperslab for the dataset in the file, using 3x2 blocks,
* (4,3) stride and (2,4) count starting at the position (0,1).
*/
start[0] = 0; start[1] = 1;
stride[0] = 4; stride[1] = 3;
count[0] = 2; count[1] = 4;
block[0] = 3; block[1] = 2;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
start[0] = 0;
start[1] = 1;
stride[0] = 4;
stride[1] = 3;
count[0] = 2;
count[1] = 4;
block[0] = 3;
block[1] = 2;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Create dataspace for the first dataset.
@@ -134,7 +140,7 @@ main (void)
stride[0] = 1;
count[0] = 48;
block[0] = 1;
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
/*
* Write selection from the vector buffer to the dataset in the file.
@@ -149,7 +155,7 @@ main (void)
* 0 41 42 0 43 44 0 45 46 0 47 48
* 0 0 0 0 0 0 0 0 0 0 0 0
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector);
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector);
/*
* Reset the selection for the file dataspace fid.
@@ -164,10 +170,14 @@ main (void)
/*
* Select sequence of NPOINTS points in the file dataspace.
*/
coord[0][0] = 0; coord[0][1] = 0;
coord[1][0] = 3; coord[1][1] = 3;
coord[2][0] = 3; coord[2][1] = 5;
coord[3][0] = 5; coord[3][1] = 6;
coord[0][0] = 0;
coord[0][1] = 0;
coord[1][0] = 3;
coord[1][1] = 3;
coord[2][0] = 3;
coord[2][1] = 5;
coord[3][0] = 5;
coord[3][1] = 6;
ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS, (const hsize_t *)coord);
@@ -229,11 +239,15 @@ main (void)
* 0 59 0 61
*
*/
start[0] = 1; start[1] = 2;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 3; count[1] = 4;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
start[0] = 1;
start[1] = 2;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 3;
count[1] = 4;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Add second selected hyperslab to the selection.
@@ -248,11 +262,15 @@ main (void)
* 19 20
* 0 61
*/
start[0] = 2; start[1] = 4;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 6; count[1] = 5;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block);
start[0] = 2;
start[1] = 4;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 6;
count[1] = 5;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block);
/*
* Create memory dataspace.
@@ -263,30 +281,37 @@ main (void)
* Select two hyperslabs in memory. Hyperslabs has the same
* size and shape as the selected hyperslabs for the file dataspace.
*/
start[0] = 0; start[1] = 0;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 3; count[1] = 4;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block);
start[0] = 0;
start[1] = 0;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 3;
count[1] = 4;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block);
start[0] = 1; start[1] = 2;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 6; count[1] = 5;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block);
start[0] = 1;
start[1] = 2;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 6;
count[1] = 5;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block);
/*
* Initialize data buffer.
*/
for (i = 0; i < MSPACE_DIM1; i++) {
for (j = 0; j < MSPACE_DIM2; j++)
for (j = 0; j < MSPACE_DIM2; j++)
matrix_out[i][j] = 0;
}
/*
* Read data back to the buffer matrix_out.
*/
ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid,
H5P_DEFAULT, matrix_out);
ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid, H5P_DEFAULT, matrix_out);
/*
* Display the result. Memory dataset is:
@@ -300,8 +325,8 @@ main (void)
* 0 0 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0 0 0
*/
for(i = 0; i < MSPACE_DIM1; i++) {
for(j = 0; j < MSPACE_DIM2; j++)
for (i = 0; i < MSPACE_DIM1; i++) {
for (j = 0; j < MSPACE_DIM2; j++)
printf("%3d ", matrix_out[i][j]);
printf("\n");
}
@@ -329,4 +354,3 @@ main (void)
return 0;
}

View File

@@ -27,29 +27,13 @@
#include "hdf5.h"
#define NUM_DATASETS 40
const char* DSETNAME[] = {
"dataset0", "dataset1",
"dataset2", "dataset3",
"dataset4", "dataset5",
"dataset6", "dataset7",
"dataset8", "dataset9",
"dataset10", "dataset11",
"dataset12", "dataset13",
"dataset14", "dataset15",
"dataset16", "dataset17",
"dataset18", "dataset19",
"dataset20", "dataset21",
"dataset22", "dataset23",
"dataset24", "dataset25",
"dataset26", "dataset27",
"dataset28", "dataset29",
"dataset30", "dataset31",
"dataset32", "dataset33",
"dataset34", "dataset35",
"dataset36", "dataset37",
"dataset38", "dataset39",
NULL
};
const char *DSETNAME[] = {"dataset0", "dataset1", "dataset2", "dataset3", "dataset4", "dataset5",
"dataset6", "dataset7", "dataset8", "dataset9", "dataset10", "dataset11",
"dataset12", "dataset13", "dataset14", "dataset15", "dataset16", "dataset17",
"dataset18", "dataset19", "dataset20", "dataset21", "dataset22", "dataset23",
"dataset24", "dataset25", "dataset26", "dataset27", "dataset28", "dataset29",
"dataset30", "dataset31", "dataset32", "dataset33", "dataset34", "dataset35",
"dataset36", "dataset37", "dataset38", "dataset39", NULL};
herr_t create_standard_file(const char *filename, hid_t fcpl);
@@ -61,21 +45,24 @@ herr_t create_standard_file(const char *filename, hid_t fcpl);
*
*-------------------------------------------------------------------------
*/
int main(void)
int
main(void)
{
hid_t fcpl_id;
hid_t fcpl_id;
herr_t ret;
/* Create a file creation property list */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
if(fcpl_id < 0) goto error;
if (fcpl_id < 0)
goto error;
/* The file creation property list is the default list right now.
* Create a file using it (this is the same as creating a file with
* H5P_DEFAULT). Implicit shared messages will be disabled.
*/
ret = create_standard_file("default_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* There are five kinds of messages that can be shared: datatypes,
* dataspaces, attributes, fill values, and filter pipelines.
@@ -86,7 +73,8 @@ int main(void)
*/
/* To begin with, use only one index. */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Each index has a "minimum message size" for a message of that
* type to be shared. Since sharing a message creates some overhead,
@@ -111,7 +99,8 @@ int main(void)
* shared in this single index.
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* The other property that can be set for shared messages is the
* list/B-tree cutoff for the indexes.
@@ -128,7 +117,8 @@ int main(void)
* second the minimum B-tree size.
*/
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 30, 20);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Now create a file with this property list. After the FCPL is used,
* everything is automatic; messages will be shared and this will be
@@ -137,7 +127,8 @@ int main(void)
* written later.
*/
ret = create_standard_file("one_index_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Now try some variations on this. The FCPL hasn't been closed, so
* we don't need to re-create it.
@@ -147,36 +138,42 @@ int main(void)
* overhead).
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 1000);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = create_standard_file("only_huge_mesgs_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Or, suppose we only wanted to shared dataspaces and
* attributes (which might make sense if we were going to use committed
* datatypes). We could change the flags on the index:
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_SDSPACE_FLAG | H5O_SHMESG_ATTR_FLAG, 40);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = create_standard_file("only_dspaces_and_attrs_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* We could create a second index and put attributes in it to separate them
* from datatypes and dataspaces (and then run some performance metrics to
* see whether this improved caching performance).
*/
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 2);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_DTYPE_FLAG | H5O_SHMESG_SDSPACE_FLAG, 40);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_ATTR_FLAG, 40);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = create_standard_file("separate_indexes_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* We can try twiddling the "phase change" values and see what it does to
* the file size. Since there's only a few different messages (two
@@ -184,25 +181,30 @@ int main(void)
* save some space.
*/
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 5, 0);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = create_standard_file("small_lists_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Or we could create indexes that are never lists, but are created as
* B-trees. We do this by setting the "maximum list size" to zero.
*/
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 0, 0);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = create_standard_file("btrees_file.h5", fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Obviously there are a lot more permutations of these options possible.
* Performance will often be a tradeoff of speed for space, but will
@@ -212,10 +214,10 @@ int main(void)
* Please let The HDF Group (help@hdfgroup.org) know what you find!
*/
/* Close the property list */
ret = H5Pclose(fcpl_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
return 0;
error:
@@ -238,21 +240,22 @@ error:
herr_t
create_standard_file(const char *filename, hid_t fcpl_id)
{
hid_t file_id=-1;
hid_t type_id=-1, temp_type_id=-1;
hsize_t dims[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
hid_t space_id=-1;
hid_t attr_type_id = -1;
hid_t attr_space_id = -1;
int attr_data[] = {1,2,3,4,5,6,7,8,9,0};
hid_t dset_id=-1;
hid_t attr_id=-1;
int x;
herr_t ret;
hid_t file_id = -1;
hid_t type_id = -1, temp_type_id = -1;
hsize_t dims[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
hid_t space_id = -1;
hid_t attr_type_id = -1;
hid_t attr_space_id = -1;
int attr_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
hid_t dset_id = -1;
hid_t attr_id = -1;
int x;
herr_t ret;
/* Create the file */
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
if(file_id < 0) goto error;
if (file_id < 0)
goto error;
/* Create the datatype we'll be using. Generally, sharing messages
* is most useful when the message is complex and takes more space on
@@ -260,66 +263,80 @@ create_standard_file(const char *filename, hid_t fcpl_id)
* However, any type can be shared.
*/
temp_type_id = H5Tarray_create2(H5T_NATIVE_INT, 2, dims);
if(temp_type_id < 0) goto error;
type_id = H5Tarray_create2(temp_type_id, 2, dims);
if(type_id < 0) goto error;
if (temp_type_id < 0)
goto error;
type_id = H5Tarray_create2(temp_type_id, 2, dims);
if (type_id < 0)
goto error;
ret = H5Tclose(temp_type_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
/* Create the dataspace we'll be using.
* Again, create a more complex dataspace so that more space will
* be saved when we share it.
*/
space_id = H5Screate_simple(10, dims, dims);
if(space_id < 0) goto error;
if (space_id < 0)
goto error;
/* Create a datatype and dataspace for the attributes we'll be creating.
* The datatype will be a single integer, and each attribute will hold
* 10 integers.
*/
attr_type_id = H5Tcopy(H5T_NATIVE_INT);
if(attr_type_id < 0) goto error;
if (attr_type_id < 0)
goto error;
attr_space_id = H5Screate_simple(1, dims, dims);
if(attr_space_id < 0) goto error;
if (attr_space_id < 0)
goto error;
/* Begin using the messages many times. Do this by creating datasets
* that use this datatype, dataspace, and have this attribute.
*/
for(x = 0; x < NUM_DATASETS; ++x) {
/* Create a dataset */
dset_id = H5Dcreate2(file_id, DSETNAME[x], type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_id < 0) goto error;
for (x = 0; x < NUM_DATASETS; ++x) {
/* Create a dataset */
dset_id = H5Dcreate2(file_id, DSETNAME[x], type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if (dset_id < 0)
goto error;
/* Create an attribute on the dataset */
attr_id = H5Acreate2(dset_id, "attr_name", attr_type_id, attr_space_id, H5P_DEFAULT, H5P_DEFAULT);
if(attr_id < 0) goto error;
/* Create an attribute on the dataset */
attr_id = H5Acreate2(dset_id, "attr_name", attr_type_id, attr_space_id, H5P_DEFAULT, H5P_DEFAULT);
if (attr_id < 0)
goto error;
/* Write data to the attribute */
ret = H5Awrite(attr_id, H5T_NATIVE_INT, attr_data);
if(ret < 0) goto error;
/* Write data to the attribute */
ret = H5Awrite(attr_id, H5T_NATIVE_INT, attr_data);
if (ret < 0)
goto error;
ret = H5Aclose(attr_id);
if(ret < 0) goto error;
ret = H5Dclose(dset_id);
if(ret < 0) goto error;
ret = H5Aclose(attr_id);
if (ret < 0)
goto error;
ret = H5Dclose(dset_id);
if (ret < 0)
goto error;
}
/* Close all open IDs */
ret = H5Tclose(attr_type_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Sclose(attr_space_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Tclose(type_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Sclose(space_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
ret = H5Fclose(file_id);
if(ret < 0) goto error;
if (ret < 0)
goto error;
return 0;
error:
return -1;
}

View File

@@ -20,34 +20,32 @@
#define FILE "subset.h5"
#define DATASETNAME "IntArray"
#define RANK 2
#define RANK 2
#define DIM0_SUB 3 /* subset dimensions */
#define DIM1_SUB 4
#define DIM0_SUB 3 /* subset dimensions */
#define DIM1_SUB 4
#define DIM0 8 /* size of dataset */
#define DIM1 10
#define DIM0 8 /* size of dataset */
#define DIM1 10
int
main (void)
main(void)
{
hsize_t dims[2], dimsm[2];
int data[DIM0][DIM1]; /* data to write */
int sdata[DIM0_SUB][DIM1_SUB]; /* subset to write */
int rdata[DIM0][DIM1]; /* buffer for read */
hsize_t dims[2], dimsm[2];
int data[DIM0][DIM1]; /* data to write */
int sdata[DIM0_SUB][DIM1_SUB]; /* subset to write */
int rdata[DIM0][DIM1]; /* buffer for read */
hid_t file_id, dataset_id; /* handles */
hid_t dataspace_id, memspace_id;
hid_t file_id, dataset_id; /* handles */
hid_t dataspace_id, memspace_id;
herr_t status;
hsize_t count[2]; /* size of subset in the file */
hsize_t offset[2]; /* subset offset in the file */
hsize_t stride[2];
hsize_t block[2];
int i, j;
herr_t status;
hsize_t count[2]; /* size of subset in the file */
hsize_t offset[2]; /* subset offset in the file */
hsize_t stride[2];
hsize_t block[2];
int i, j;
/*****************************************************************
* Create a new file with default creation and access properties.*
@@ -55,53 +53,50 @@ main (void)
* and dataset. *
*****************************************************************/
file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
dims[0] = DIM0;
dims[1] = DIM1;
dataspace_id = H5Screate_simple (RANK, dims, NULL);
dataset_id = H5Dcreate2 (file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dims[0] = DIM0;
dims[1] = DIM1;
dataspace_id = H5Screate_simple(RANK, dims, NULL);
dataset_id =
H5Dcreate2(file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
for (j = 0; j < DIM0; j++) {
for (i = 0; i < DIM1; i++)
if (i< (DIM1/2))
data[j][i] = 1;
for (i = 0; i < DIM1; i++)
if (i < (DIM1 / 2))
data[j][i] = 1;
else
data[j][i] = 2;
data[j][i] = 2;
}
status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
printf ("\nData Written to File:\n");
for (i = 0; i<DIM0; i++){
for (j = 0; j<DIM1; j++)
printf (" %i", data[i][j]);
printf ("\n");
printf("\nData Written to File:\n");
for (i = 0; i < DIM0; i++) {
for (j = 0; j < DIM1; j++)
printf(" %i", data[i][j]);
printf("\n");
}
status = H5Sclose (dataspace_id);
status = H5Dclose (dataset_id);
status = H5Fclose (file_id);
status = H5Sclose(dataspace_id);
status = H5Dclose(dataset_id);
status = H5Fclose(file_id);
/*****************************************************
* Reopen the file and dataset and write a subset of *
* values to the dataset.
*****************************************************/
file_id = H5Fopen (FILE, H5F_ACC_RDWR, H5P_DEFAULT);
dataset_id = H5Dopen2 (file_id, DATASETNAME, H5P_DEFAULT);
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
dataset_id = H5Dopen2(file_id, DATASETNAME, H5P_DEFAULT);
/* Specify size and shape of subset to write. */
offset[0] = 1;
offset[1] = 2;
count[0] = DIM0_SUB;
count[1] = DIM1_SUB;
count[0] = DIM0_SUB;
count[1] = DIM1_SUB;
stride[0] = 1;
stride[1] = 1;
@@ -112,40 +107,36 @@ main (void)
/* Create memory space with size of subset. Get file dataspace
and select subset from file dataspace. */
dimsm[0] = DIM0_SUB;
dimsm[1] = DIM1_SUB;
memspace_id = H5Screate_simple (RANK, dimsm, NULL);
dimsm[0] = DIM0_SUB;
dimsm[1] = DIM1_SUB;
memspace_id = H5Screate_simple(RANK, dimsm, NULL);
dataspace_id = H5Dget_space (dataset_id);
status = H5Sselect_hyperslab (dataspace_id, H5S_SELECT_SET, offset,
stride, count, block);
dataspace_id = H5Dget_space(dataset_id);
status = H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, offset, stride, count, block);
/* Write a subset of data to the dataset, then read the
entire dataset back from the file. */
printf ("\nWrite subset to file specifying:\n");
printf (" offset=1x2 stride=1x1 count=3x4 block=1x1\n");
printf("\nWrite subset to file specifying:\n");
printf(" offset=1x2 stride=1x1 count=3x4 block=1x1\n");
for (j = 0; j < DIM0_SUB; j++) {
for (i = 0; i < DIM1_SUB; i++)
sdata[j][i] = 5;
for (i = 0; i < DIM1_SUB; i++)
sdata[j][i] = 5;
}
status = H5Dwrite (dataset_id, H5T_NATIVE_INT, memspace_id,
dataspace_id, H5P_DEFAULT, sdata);
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, memspace_id, dataspace_id, H5P_DEFAULT, sdata);
status = H5Dread (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, rdata);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
printf ("\nData in File after Subset is Written:\n");
for (i = 0; i<DIM0; i++){
for (j = 0; j<DIM1; j++)
printf (" %i", rdata[i][j]);
printf ("\n");
printf("\nData in File after Subset is Written:\n");
for (i = 0; i < DIM0; i++) {
for (j = 0; j < DIM1; j++)
printf(" %i", rdata[i][j]);
printf("\n");
}
status = H5Sclose (memspace_id);
status = H5Sclose (dataspace_id);
status = H5Dclose (dataset_id);
status = H5Fclose (file_id);
status = H5Sclose(memspace_id);
status = H5Sclose(dataspace_id);
status = H5Dclose(dataset_id);
status = H5Fclose(file_id);
}

View File

@@ -23,85 +23,73 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds-eiger.h5"
#define DATASET "VDS-Eiger"
#define VDSDIM0 5
#define VDSDIM1 10
#define VDSDIM2 10
#define DIM0 5
#define DIM1 10
#define DIM2 10
#define RANK 3
#define FILE "vds-eiger.h5"
#define DATASET "VDS-Eiger"
#define VDSDIM0 5
#define VDSDIM1 10
#define VDSDIM2 10
#define DIM0 5
#define DIM1 10
#define DIM2 10
#define RANK 3
int
main (void)
main(void)
{
hid_t file, src_space, vspace,
dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM1},
dims[3] = {DIM0, DIM1, DIM2},
start[3], /* Hyperslab parameters */
stride[3],
count[3],
block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3],
count_out[3],
block_out[3];
hid_t file, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM1},
dims[3] = {DIM0, DIM1, DIM2}, start[3], /* Hyperslab parameters */
stride[3], count[3], block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3], count_out[3], block_out[3];
int i;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
src_space = H5Screate_simple (RANK, dims, NULL);
src_space = H5Screate_simple(RANK, dims, NULL);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
start[0] = 0;
start[1] = 0;
start[2] = 0;
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = DIM0;
stride[1] = 1;
stride[2] = 1;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
block[0] = DIM0;
block[1] = DIM1;
block[2] = DIM2;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
block[0] = DIM0;
block[1] = DIM1;
block[2] = DIM2;
/*
* Build the mappings
*
*/
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual (dcpl, vspace, "f-%b.h5", "/A", src_space);
/* Create a virtual dataset */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (vspace);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
/*
* Build the mappings
*
*/
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual(dcpl, vspace, "f-%b.h5", "/A", src_space);
/* Create a virtual dataset */
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(vspace);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -110,79 +98,82 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %d\n", (int)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %d\n", (int)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset ");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("H5S_ALL \n");
}
/* EIP read data back */
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* Get selection in the source dataset */
printf(" Selection in the source dataset ");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("H5S_ALL \n");
}
/* EIP read data back */
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -22,80 +22,55 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds-exc.h5"
#define DATASET "VDS-Excalibur"
#define VDSDIM0 0
#define VDSDIM1 15
#define VDSDIM2 6
#define KDIM0 0
#define KDIM1 2
#define KDIM2 6
#define NDIM0 0
#define NDIM1 3
#define NDIM2 6
#define RANK 3
#define FILE "vds-exc.h5"
#define DATASET "VDS-Excalibur"
#define VDSDIM0 0
#define VDSDIM1 15
#define VDSDIM2 6
#define KDIM0 0
#define KDIM1 2
#define KDIM2 6
#define NDIM0 0
#define NDIM1 3
#define NDIM2 6
#define RANK 3
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5",
"d.h5",
"e.h5",
"f.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5", "e.h5", "f.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C",
"D",
"E",
"F"
};
const char *SRC_DATASET[] = {"A", "B", "C", "D", "E", "F"};
int
main (void)
main(void)
{
hid_t file, space, ksrc_space, nsrc_space, vspace,
src_space,
dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
vdsdims_max[3] = {H5S_UNLIMITED,VDSDIM1, VDSDIM2},
kdims[3] = {KDIM0, KDIM1, KDIM2},
kdims_max[3] = {H5S_UNLIMITED, KDIM1, KDIM2},
ndims[3] = {NDIM0, NDIM1, NDIM2},
ndims_max[3] = {H5S_UNLIMITED, NDIM1, NDIM2},
start[3], /* Hyperslab parameters */
stride[3],
count[3],
block[3];
hsize_t start_out[3],
stride_out[3],
count_out[3],
block_out[3];
hid_t file, space, ksrc_space, nsrc_space, vspace, src_space, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM2},
kdims[3] = {KDIM0, KDIM1, KDIM2}, kdims_max[3] = {H5S_UNLIMITED, KDIM1, KDIM2},
ndims[3] = {NDIM0, NDIM1, NDIM2}, ndims_max[3] = {H5S_UNLIMITED, NDIM1, NDIM2},
start[3], /* Hyperslab parameters */
stride[3], count[3], block[3];
hsize_t start_out[3], stride_out[3], count_out[3], block_out[3];
int k = 2;
int n = 3;
int i;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
space = H5Screate_simple (RANK, vdsdims, vdsdims_max);
space = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for A, C, and E datasets. */
ksrc_space = H5Screate_simple (RANK, kdims, kdims_max);
ksrc_space = H5Screate_simple(RANK, kdims, kdims_max);
/* Create dataspaces for B, D, and F datasets. */
nsrc_space = H5Screate_simple (RANK, ndims, ndims_max);
nsrc_space = H5Screate_simple(RANK, ndims, ndims_max);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
@@ -109,42 +84,40 @@ main (void)
block[1] = k;
block[2] = VDSDIM2;
/*
* Build the mappings for A, C and E source datasets.
* Unlimited hyperslab selection is the same in the source datasets.
* Unlimited hyperslab selections in the virtual dataset have different offsets.
*/
status = H5Sselect_hyperslab (ksrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)((k+n)*i);
status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual (dcpl, space, SRC_FILE[2*i], SRC_DATASET[2*i], ksrc_space);
}
/*
* Build the mappings for A, C and E source datasets.
* Unlimited hyperslab selection is the same in the source datasets.
* Unlimited hyperslab selections in the virtual dataset have different offsets.
*/
status = H5Sselect_hyperslab(ksrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)((k + n) * i);
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i], SRC_DATASET[2 * i], ksrc_space);
}
/* Reinitialize start[1] and block[1] to build the second set of mappings. */
start[1] = 0;
block[1] = n;
/*
* Build the mappings for B, D and F source datasets.
* Unlimited hyperslab selection is the same in the source datasets.
* Unlimited hyperslab selections in the virtual dataset have different offsets.
*/
status = H5Sselect_hyperslab (nsrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)(k+(k+n)*i);
status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual (dcpl, space, SRC_FILE[2*i+1], SRC_DATASET[2*i+1], nsrc_space);
}
/* Create a virtual dataset */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (space);
status = H5Sclose (nsrc_space);
status = H5Sclose (ksrc_space);
status = H5Dclose (dset);
status = H5Fclose (file);
/* Reinitialize start[1] and block[1] to build the second set of mappings. */
start[1] = 0;
block[1] = n;
/*
* Build the mappings for B, D and F source datasets.
* Unlimited hyperslab selection is the same in the source datasets.
* Unlimited hyperslab selections in the virtual dataset have different offsets.
*/
status = H5Sselect_hyperslab(nsrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)(k + (k + n) * i);
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i + 1], SRC_DATASET[2 * i + 1], nsrc_space);
}
/* Create a virtual dataset */
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(space);
status = H5Sclose(nsrc_space);
status = H5Sclose(ksrc_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -153,85 +126,92 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf("Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* EIP read data back */
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* EIP read data back */
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -23,77 +23,53 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds-exclim.h5"
#define DATASET "VDS-Excaliburlim"
#define VDSDIM0 3
#define VDSDIM1 15
#define VDSDIM2 6
#define KDIM0 3
#define KDIM1 2
#define KDIM2 6
#define NDIM0 3
#define NDIM1 3
#define NDIM2 6
#define RANK 3
#define FILE "vds-exclim.h5"
#define DATASET "VDS-Excaliburlim"
#define VDSDIM0 3
#define VDSDIM1 15
#define VDSDIM2 6
#define KDIM0 3
#define KDIM1 2
#define KDIM2 6
#define NDIM0 3
#define NDIM1 3
#define NDIM2 6
#define RANK 3
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5",
"d.h5",
"e.h5",
"f.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5", "e.h5", "f.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C",
"D",
"E",
"F"
};
const char *SRC_DATASET[] = {"A", "B", "C", "D", "E", "F"};
int
main (void)
main(void)
{
hid_t file, space, ksrc_space, nsrc_space, vspace,
src_space,
dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
kdims[3] = {KDIM0, KDIM1, KDIM2},
ndims[3] = {NDIM0, NDIM1, NDIM2},
start[3], /* Hyperslab parameters */
stride[3],
count[3],
block[3];
hsize_t start_out[3],
stride_out[3],
count_out[3],
block_out[3];
hid_t file, space, ksrc_space, nsrc_space, vspace, src_space, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, kdims[3] = {KDIM0, KDIM1, KDIM2},
ndims[3] = {NDIM0, NDIM1, NDIM2}, start[3], /* Hyperslab parameters */
stride[3], count[3], block[3];
hsize_t start_out[3], stride_out[3], count_out[3], block_out[3];
int k = 2;
int n = 3;
int i;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
space = H5Screate_simple (RANK, vdsdims, NULL);
space = H5Screate_simple(RANK, vdsdims, NULL);
/* Create dataspaces for A, C, and E datasets. */
ksrc_space = H5Screate_simple (RANK, kdims, NULL);
ksrc_space = H5Screate_simple(RANK, kdims, NULL);
/* Create dataspaces for B, D, and F datasets. */
nsrc_space = H5Screate_simple (RANK, ndims, NULL);
nsrc_space = H5Screate_simple(RANK, ndims, NULL);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
@@ -107,40 +83,38 @@ main (void)
block[1] = k;
block[2] = VDSDIM2;
/*
* Build the mappings for A, C and E source datasets.
*
*/
status = H5Sselect_hyperslab (ksrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)((k+n)*i);
status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual (dcpl, space, SRC_FILE[2*i], SRC_DATASET[2*i], ksrc_space);
}
/*
* Build the mappings for A, C and E source datasets.
*
*/
status = H5Sselect_hyperslab(ksrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)((k + n) * i);
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i], SRC_DATASET[2 * i], ksrc_space);
}
/* Reinitialize start[0] and block[1] */
start[0] = 0;
block[1] = n;
/*
* Build the mappings for B, D and F source datasets.
*
*/
status = H5Sselect_hyperslab (nsrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)(k+(k+n)*i);
status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual (dcpl, space, SRC_FILE[2*i+1], SRC_DATASET[2*i+1], nsrc_space);
}
/* Create a virtual dataset */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (space);
status = H5Sclose (nsrc_space);
status = H5Sclose (ksrc_space);
status = H5Dclose (dset);
status = H5Fclose (file);
/* Reinitialize start[0] and block[1] */
start[0] = 0;
block[1] = n;
/*
* Build the mappings for B, D and F source datasets.
*
*/
status = H5Sselect_hyperslab(nsrc_space, H5S_SELECT_SET, start, NULL, count, block);
for (i = 0; i < 3; i++) {
start[1] = (hsize_t)(k + (k + n) * i);
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i + 1], SRC_DATASET[2 * i + 1], nsrc_space);
}
/* Create a virtual dataset */
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(space);
status = H5Sclose(nsrc_space);
status = H5Sclose(ksrc_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -149,85 +123,92 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf("Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if(H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%d, %d, %d] \n", (int)start_out[0], (int)start_out[1], (int)start_out[2]);
printf(" stride = [%d, %d, %d] \n", (int)stride_out[0], (int)stride_out[1], (int)stride_out[2]);
printf(" count = [%d, %d, %d] \n", (int)count_out[0], (int)count_out[1], (int)count_out[2]);
printf(" block = [%d, %d, %d] \n", (int)block_out[0], (int)block_out[1], (int)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* EIP read data back */
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%d, %d, %d] \n", (int)start_out[0], (int)start_out[1],
(int)start_out[2]);
printf(" stride = [%d, %d, %d] \n", (int)stride_out[0], (int)stride_out[1],
(int)stride_out[2]);
printf(" count = [%d, %d, %d] \n", (int)count_out[0], (int)count_out[1],
(int)count_out[2]);
printf(" block = [%d, %d, %d] \n", (int)block_out[0], (int)block_out[1],
(int)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* EIP read data back */
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -26,185 +26,162 @@
#include <stdio.h>
#include <stdlib.h>
#define VFILE "vds-percival-unlim-maxmin.h5"
#define DATASET "VDS-Percival-unlim-maxmin"
#define VDSDIM0 H5S_UNLIMITED
#define VDSDIM1 10
#define VDSDIM2 10
#define VFILE "vds-percival-unlim-maxmin.h5"
#define DATASET "VDS-Percival-unlim-maxmin"
#define VDSDIM0 H5S_UNLIMITED
#define VDSDIM1 10
#define VDSDIM2 10
#define DIM0 H5S_UNLIMITED
#define DIM0_1 4 /* Initial size of the source datasets */
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
#define DIM0 H5S_UNLIMITED
#define DIM0_1 4 /* Initial size of the source datasets */
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5",
"d.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C",
"D"
};
const char *SRC_DATASET[] = {"A", "B", "C", "D"};
int
main (void)
main(void)
{
hid_t vfile, file, src_space, mem_space, vspace,
vdset, dset; /* Handles */
hid_t dcpl, dapl;
herr_t status;
hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2},
vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0_1, DIM1, DIM2},
memdims[3] = {DIM0_1, DIM1, DIM2},
extdims[3] = {0, DIM1, DIM2}, /* Dimensions of the extended source datasets */
chunk_dims[3] = {DIM0_1, DIM1, DIM2},
dims_max[3] = {DIM0, DIM1, DIM2},
vdsdims_out[3],
vdsdims_max_out[3],
start[3], /* Hyperslab parameters */
stride[3],
count[3],
src_count[3],
block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3],
count_out[3],
block_out[3];
hid_t vfile, file, src_space, mem_space, vspace, vdset, dset; /* Handles */
hid_t dcpl, dapl;
herr_t status;
hsize_t vdsdims[3] = {4 * DIM0_1, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0_1, DIM1, DIM2}, memdims[3] = {DIM0_1, DIM1, DIM2},
extdims[3] = {0, DIM1, DIM2}, /* Dimensions of the extended source datasets */
chunk_dims[3] = {DIM0_1, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2}, vdsdims_out[3],
vdsdims_max_out[3], start[3], /* Hyperslab parameters */
stride[3], count[3], src_count[3], block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3], count_out[3], block_out[3];
int i, j;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
int wdata[DIM0_1*DIM1*DIM2];
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
int wdata[DIM0_1 * DIM1 * DIM2];
/*
* Create source files and datasets. This step is optional.
*/
for (i=0; i < PLANE_STRIDE; i++) {
for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1;
for (j = 0; j < DIM0_1 * DIM1 * DIM2; j++)
wdata[j] = i + 1;
/*
* Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple (RANK, dims, dims_max);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk (dcpl, RANK, chunk_dims);
dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
wdata);
status = H5Sclose (src_space);
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
file = H5Fcreate(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple(RANK, dims, dims_max);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk(dcpl, RANK, chunk_dims);
dset = H5Dcreate2(file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
status = H5Sclose(src_space);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
}
vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
vfile = H5Fcreate(VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
src_space = H5Screate_simple (RANK, dims, dims_max);
src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
stride[1] = 1;
stride[2] = 1;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
stride[1] = 1;
stride[2] = 1;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
src_count[0] = H5S_UNLIMITED;
src_count[1] = 1;
src_count[2] = 1;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
/*
* Build the mappings
*
*/
status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i=0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i = 0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual(dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
start[0]++;
}
H5Sselect_none(vspace);
/* Create a virtual dataset */
vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (vspace);
status = H5Sclose (src_space);
status = H5Pclose (dcpl);
vdset = H5Dcreate2(vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(vspace);
status = H5Sclose(src_space);
status = H5Pclose(dcpl);
/* Let's add data to the source datasets and check new dimensions for VDS */
/* We will add only one plane to the first source dataset, two planes to the
second one, three to the third, and four to the forth. */
for (i=0; i < PLANE_STRIDE; i++) {
for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < (i+1)*DIM1*DIM2; j++) wdata[j] = 10*(i+1);
for (j = 0; j < (i + 1) * DIM1 * DIM2; j++)
wdata[j] = 10 * (i + 1);
/*
* Open the source files and datasets. Appen data to each dataset and
* close all resources.
*/
file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT);
extdims[0] = DIM0_1+i+1;
status = H5Dset_extent (dset, extdims);
src_space = H5Dget_space (dset);
start[0] = DIM0_1;
start[1] = 0;
start[2] = 0;
count[0] = 1;
count[1] = 1;
count[2] = 1;
block[0] = i+1;
block[1] = DIM1;
block[2] = DIM2;
file = H5Fopen(SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
dset = H5Dopen2(file, SRC_DATASET[i], H5P_DEFAULT);
extdims[0] = DIM0_1 + i + 1;
status = H5Dset_extent(dset, extdims);
src_space = H5Dget_space(dset);
start[0] = DIM0_1;
start[1] = 0;
start[2] = 0;
count[0] = 1;
count[1] = 1;
count[2] = 1;
block[0] = i + 1;
block[1] = DIM1;
block[2] = DIM2;
memdims[0] = i+1;
mem_space = H5Screate_simple(RANK, memdims, NULL);
status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT,
wdata);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
}
memdims[0] = i + 1;
mem_space = H5Screate_simple(RANK, memdims, NULL);
status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Dwrite(dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
}
status = H5Dclose (vdset);
status = H5Fclose (vfile);
status = H5Dclose(vdset);
status = H5Fclose(vfile);
/*
* Now we begin the read section of this example.
@@ -213,108 +190,115 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
vfile = H5Fopen(VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Open VDS using different access properties to use max or
* min extents depending on the sizes of the underlying datasets
*/
dapl = H5Pcreate (H5P_DATASET_ACCESS);
dapl = H5Pcreate(H5P_DATASET_ACCESS);
for(i = 0; i < 2; i++) {
status = H5Pset_virtual_view (dapl, i ? H5D_VDS_LAST_AVAILABLE : H5D_VDS_FIRST_MISSING);
vdset = H5Dopen2 (vfile, DATASET, dapl);
for (i = 0; i < 2; i++) {
status = H5Pset_virtual_view(dapl, i ? H5D_VDS_LAST_AVAILABLE : H5D_VDS_FIRST_MISSING);
vdset = H5Dopen2(vfile, DATASET, dapl);
/* Let's get space of the VDS and its dimension; we should get 32(or 20)x10x10 */
vspace = H5Dget_space (vdset);
H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
printf ("VDS dimensions, bounds = H5D_VDS_%s: ", i ? "LAST_AVAILABLE" : "FIRST_MISSING");
for (j=0; j<RANK; j++)
printf (" %d ", (int)vdsdims_out[j]);
printf ("\n");
vspace = H5Dget_space(vdset);
H5Sget_simple_extent_dims(vspace, vdsdims_out, vdsdims_max_out);
printf("VDS dimensions, bounds = H5D_VDS_%s: ", i ? "LAST_AVAILABLE" : "FIRST_MISSING");
for (j = 0; j < RANK; j++)
printf(" %d ", (int)vdsdims_out[j]);
printf("\n");
/* Close */
status = H5Dclose (vdset);
status = H5Sclose (vspace);
status = H5Dclose(vdset);
status = H5Sclose(vspace);
}
status = H5Pclose (dapl);
status = H5Pclose(dapl);
vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT);
vdset = H5Dopen2(vfile, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (vdset);
dcpl = H5Dget_create_plist(vdset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab(src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (vdset);
status = H5Fclose (vfile);
status = H5Pclose(dcpl);
status = H5Dclose(vdset);
status = H5Fclose(vfile);
return 0;
}

View File

@@ -24,190 +24,167 @@
#include <stdio.h>
#include <stdlib.h>
#define VFILE "vds-percival-unlim.h5"
#define DATASET "VDS-Percival-unlim"
#define VDSDIM0 H5S_UNLIMITED
#define VDSDIM1 10
#define VDSDIM2 10
#define VFILE "vds-percival-unlim.h5"
#define DATASET "VDS-Percival-unlim"
#define VDSDIM0 H5S_UNLIMITED
#define VDSDIM1 10
#define VDSDIM2 10
#define DIM0 H5S_UNLIMITED
#define DIM0_1 10 /* Initial size of the datasets */
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
#define DIM0 H5S_UNLIMITED
#define DIM0_1 10 /* Initial size of the datasets */
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5",
"d.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C",
"D"
};
const char *SRC_DATASET[] = {"A", "B", "C", "D"};
int
main (void)
main(void)
{
hid_t vfile, file, src_space, mem_space, vspace,
vdset, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2},
vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0_1, DIM1, DIM2},
extdims[3] = {2*DIM0_1, DIM1, DIM2},
chunk_dims[3] = {DIM0_1, DIM1, DIM2},
dims_max[3] = {DIM0, DIM1, DIM2},
vdsdims_out[3],
vdsdims_max_out[3],
start[3], /* Hyperslab parameters */
stride[3],
count[3],
src_count[3],
block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3],
count_out[3],
block_out[3];
hid_t vfile, file, src_space, mem_space, vspace, vdset, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {4 * DIM0_1, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0_1, DIM1, DIM2}, extdims[3] = {2 * DIM0_1, DIM1, DIM2},
chunk_dims[3] = {DIM0_1, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2}, vdsdims_out[3],
vdsdims_max_out[3], start[3], /* Hyperslab parameters */
stride[3], count[3], src_count[3], block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3], count_out[3], block_out[3];
int i, j, k;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
int wdata[DIM0_1*DIM1*DIM2];
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
int wdata[DIM0_1 * DIM1 * DIM2];
int rdata[80][10][10];
int a_rdata[20][10][10];
/*
* Create source files and datasets. This step is optional.
*/
for (i=0; i < PLANE_STRIDE; i++) {
for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1;
for (j = 0; j < DIM0_1 * DIM1 * DIM2; j++)
wdata[j] = i + 1;
/*
* Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple (RANK, dims, dims_max);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk (dcpl, RANK, chunk_dims);
dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
wdata);
status = H5Sclose (src_space);
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
file = H5Fcreate(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple(RANK, dims, dims_max);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_chunk(dcpl, RANK, chunk_dims);
dset = H5Dcreate2(file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
status = H5Sclose(src_space);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
}
vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
vfile = H5Fcreate(VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
src_space = H5Screate_simple (RANK, dims, dims_max);
src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
stride[1] = 1;
stride[2] = 1;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
stride[1] = 1;
stride[2] = 1;
count[0] = H5S_UNLIMITED;
count[1] = 1;
count[2] = 1;
src_count[0] = H5S_UNLIMITED;
src_count[1] = 1;
src_count[2] = 1;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
/*
* Build the mappings
*
*/
status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i=0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i = 0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual(dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
start[0]++;
}
H5Sselect_none(vspace);
/* Create a virtual dataset */
vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (vspace);
status = H5Sclose (src_space);
status = H5Pclose (dcpl);
vdset = H5Dcreate2(vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(vspace);
status = H5Sclose(src_space);
status = H5Pclose(dcpl);
/* Let's get space of the VDS and its dimension; we should get 40x10x10 */
vspace = H5Dget_space (vdset);
H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
printf ("VDS dimensions first time \n");
printf (" Current: ");
for (i=0; i<RANK; i++)
printf (" %d ", (int)vdsdims_out[i]);
printf ("\n");
vspace = H5Dget_space(vdset);
H5Sget_simple_extent_dims(vspace, vdsdims_out, vdsdims_max_out);
printf("VDS dimensions first time \n");
printf(" Current: ");
for (i = 0; i < RANK; i++)
printf(" %d ", (int)vdsdims_out[i]);
printf("\n");
/* Let's add data to the source datasets and check new dimensions for VDS */
for (i=0; i < PLANE_STRIDE; i++) {
for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = 10*(i+1);
for (j = 0; j < DIM0_1 * DIM1 * DIM2; j++)
wdata[j] = 10 * (i + 1);
/*
* Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT);
status = H5Dset_extent (dset, extdims);
src_space = H5Dget_space (dset);
start[0] = DIM0_1;
start[1] = 0;
start[2] = 0;
count[0] = 1;
count[1] = 1;
count[2] = 1;
block[0] = DIM0_1;
block[1] = DIM1;
block[2] = DIM2;
file = H5Fopen(SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
dset = H5Dopen2(file, SRC_DATASET[i], H5P_DEFAULT);
status = H5Dset_extent(dset, extdims);
src_space = H5Dget_space(dset);
start[0] = DIM0_1;
start[1] = 0;
start[2] = 0;
count[0] = 1;
count[1] = 1;
count[2] = 1;
block[0] = DIM0_1;
block[1] = DIM1;
block[2] = DIM2;
mem_space = H5Screate_simple(RANK, dims, NULL);
status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT,
wdata);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
}
status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Dwrite(dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
}
status = H5Dclose (vdset);
status = H5Fclose (vfile);
status = H5Dclose(vdset);
status = H5Fclose(vfile);
/*
* Now we begin the read section of this example.
@@ -216,86 +193,94 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT);
vfile = H5Fopen(VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
vdset = H5Dopen2(vfile, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (vdset);
dcpl = H5Dget_create_plist(vdset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab(src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/*
* Read data from VDS.
*/
vspace = H5Dget_space (vdset);
H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
printf ("VDS dimensions second time \n");
printf (" Current: ");
for (i=0; i<RANK; i++)
printf (" %d ", (int)vdsdims_out[i]);
printf ("\n");
vspace = H5Dget_space(vdset);
H5Sget_simple_extent_dims(vspace, vdsdims_out, vdsdims_max_out);
printf("VDS dimensions second time \n");
printf(" Current: ");
for (i = 0; i < RANK; i++)
printf(" %d ", (int)vdsdims_out[i]);
printf("\n");
/* Read all VDS data */
@@ -312,53 +297,50 @@ main (void)
block[1] = vdsdims_out[1];
block[2] = vdsdims_out[2];
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, NULL, count, block);
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, NULL, count, block);
mem_space = H5Screate_simple(RANK, vdsdims_out, NULL);
status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT,
rdata);
printf (" All data: \n");
for (i=0; i < (int)vdsdims_out[0]; i++) {
for (j=0; j < (int)vdsdims_out[1]; j++) {
printf ("(%d, %d, 0)", i, j);
for (k=0; k < (int)vdsdims_out[2]; k++)
printf (" %d ", rdata[i][j][k]);
printf ("\n");
status = H5Dread(vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, rdata);
printf(" All data: \n");
for (i = 0; i < (int)vdsdims_out[0]; i++) {
for (j = 0; j < (int)vdsdims_out[1]; j++) {
printf("(%d, %d, 0)", i, j);
for (k = 0; k < (int)vdsdims_out[2]; k++)
printf(" %d ", rdata[i][j][k]);
printf("\n");
}
}
/* Read VDS, but only data mapeed to dataset a.h5 */
start[0] = 0;
start[1] = 0;
start[2] = 0;
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE;
stride[1] = 1;
stride[2] = 1;
count[0] = 2*DIM0_1;
count[1] = 1;
count[2] = 1;
block[0] = 1;
block[1] = vdsdims_out[1];
block[2] = vdsdims_out[2];
dims[0] = 2*DIM0_1;
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
mem_space = H5Screate_simple(RANK, dims, NULL);
status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT,
a_rdata);
printf (" All data: \n");
for (i=0; i < 2*DIM0_1; i++) {
for (j=0; j < (int)vdsdims_out[1]; j++) {
printf ("(%d, %d, 0)", i, j);
for (k=0; k < (int)vdsdims_out[2]; k++)
printf (" %d ", a_rdata[i][j][k]);
printf ("\n");
count[0] = 2 * DIM0_1;
count[1] = 1;
count[2] = 1;
block[0] = 1;
block[1] = vdsdims_out[1];
block[2] = vdsdims_out[2];
dims[0] = 2 * DIM0_1;
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
mem_space = H5Screate_simple(RANK, dims, NULL);
status = H5Dread(vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, a_rdata);
printf(" All data: \n");
for (i = 0; i < 2 * DIM0_1; i++) {
for (j = 0; j < (int)vdsdims_out[1]; j++) {
printf("(%d, %d, 0)", i, j);
for (k = 0; k < (int)vdsdims_out[2]; k++)
printf(" %d ", a_rdata[i][j][k]);
printf("\n");
}
}
/*
* Close and release resources.
*/
status = H5Sclose(mem_space);
status = H5Pclose (dcpl);
status = H5Dclose (vdset);
status = H5Fclose (vfile);
status = H5Pclose(dcpl);
status = H5Dclose(vdset);
status = H5Fclose(vfile);
return 0;
}

View File

@@ -25,145 +25,126 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds-percival.h5"
#define DATASET "VDS-Percival"
#define FILE "vds-percival.h5"
#define DATASET "VDS-Percival"
/* later
#define VDSDIM0 H5S_UNLIMITED
*/
#define VDSDIM0 40
#define VDSDIM1 10
#define VDSDIM2 10
#define VDSDIM0 40
#define VDSDIM1 10
#define VDSDIM2 10
/* later
#define DIM0 H5S_UNLIMITED
*/
#define DIM0 10
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
#define DIM0 10
#define DIM1 10
#define DIM2 10
#define RANK 3
#define PLANE_STRIDE 4
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5",
"d.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C",
"D"
};
const char *SRC_DATASET[] = {"A", "B", "C", "D"};
int
main (void)
main(void)
{
hid_t file, src_space, vspace,
dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0, DIM1, DIM2},
dims_max[3] = {DIM0, DIM1, DIM2},
start[3], /* Hyperslab start parameter for VDS */
stride[3],
count[3],
src_count[3],
block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3],
count_out[3],
block_out[3];
hid_t file, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
dims[3] = {DIM0, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2},
start[3], /* Hyperslab start parameter for VDS */
stride[3], count[3], src_count[3], block[3];
hsize_t start_out[3], /* Hyperslab parameter out */
stride_out[3], count_out[3], block_out[3];
int i, j;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
int wdata[DIM0*DIM1*DIM2];
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
int wdata[DIM0 * DIM1 * DIM2];
/*
* Create source files and datasets. This step is optional.
*/
for (i=0; i < PLANE_STRIDE; i++) {
for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < DIM0*DIM1*DIM2; j++) wdata[j] = i+1;
for (j = 0; j < DIM0 * DIM1 * DIM2; j++)
wdata[j] = i + 1;
/*
* Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple (RANK, dims, NULL);
dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
wdata);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
file = H5Fcreate(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
src_space = H5Screate_simple(RANK, dims, NULL);
dset = H5Dcreate2(file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
}
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
src_space = H5Screate_simple (RANK, dims, dims_max);
src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/* Initialize hyperslab values */
start[0] = 0;
start[1] = 0;
start[2] = 0;
start[0] = 0;
start[1] = 0;
start[2] = 0;
stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */
stride[1] = 1;
stride[2] = 1;
/* later
count[0] = H5S_UNLIMITED;
*/
count[0] = VDSDIM0/4;
/* later
count[0] = H5S_UNLIMITED;
*/
count[0] = VDSDIM0 / 4;
count[1] = 1;
count[2] = 1;
/* later
src_count[0] = H5S_UNLIMITED;
*/
/* later
src_count[0] = H5S_UNLIMITED;
*/
src_count[0] = DIM0;
src_count[1] = 1;
src_count[2] = 1;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
block[0] = 1;
block[1] = DIM1;
block[2] = DIM2;
/*
* Build the mappings
*
*/
status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i=0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, src_count, block);
for (i = 0; i < PLANE_STRIDE; i++) {
status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
status = H5Pset_virtual(dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space);
start[0]++;
}
H5Sselect_none(vspace);
/* Create a virtual dataset */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (vspace);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(vspace);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -172,82 +153,89 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
printf(" Source filename %s\n", filename);
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset \n");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
/* Get source file name */
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
printf(" Source dataset name %s\n", dsetname);
/* Get source dataset name */
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/* Get selection in the source dataset */
printf(" Selection in the source dataset \n");
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
if (H5Sis_regular_hyperslab(src_space)) {
status = H5Sget_regular_hyperslab(src_space, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
}
}
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
free(dsetname);
}
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -27,61 +27,59 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds-simpleIO.h5"
#define DATASET "VDS"
#define DIM1 6
#define DIM0 4
#define RANK 2
#define SRC_FILE "a.h5"
#define SRC_DATASET "/A"
#define FILE "vds-simpleIO.h5"
#define DATASET "VDS"
#define DIM1 6
#define DIM0 4
#define RANK 2
#define SRC_FILE "a.h5"
#define SRC_DATASET "/A"
int
main (void)
main(void)
{
hid_t file, space, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[2] = {DIM0, DIM1}, /* Virtual dataset dimension */
dims[2] = {DIM0, DIM1}; /* Source dataset dimensions */
int wdata[DIM0][DIM1], /* Write buffer for source dataset */
rdata[DIM0][DIM1], /* Read buffer for virtual dataset */
i, j;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
hid_t file, space, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[2] = {DIM0, DIM1}, /* Virtual dataset dimension */
dims[2] = {DIM0, DIM1}; /* Source dataset dimensions */
int wdata[DIM0][DIM1], /* Write buffer for source dataset */
rdata[DIM0][DIM1], /* Read buffer for virtual dataset */
i, j;
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
/*
* Initialize data.
*/
for (i = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++) wdata[i][j] = i+1;
for (i = 0; i < DIM0; i++)
for (j = 0; j < DIM1; j++)
wdata[i][j] = i + 1;
/*
* Create the source file and the dataset. Write data to the source dataset
* and close all resources.
*/
/*
* Create the source file and the dataset. Write data to the source dataset
* and close all resources.
*/
file = H5Fcreate (SRC_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space = H5Screate_simple (RANK, dims, NULL);
dset = H5Dcreate2 (file, SRC_DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
wdata[0]);
status = H5Sclose (space);
status = H5Dclose (dset);
status = H5Fclose (file);
file = H5Fcreate(SRC_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space = H5Screate_simple(RANK, dims, NULL);
dset = H5Dcreate2(file, SRC_DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata[0]);
status = H5Sclose(space);
status = H5Dclose(dset);
status = H5Fclose(file);
/* Create file in which virtual dataset will be stored. */
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
vspace = H5Screate_simple (RANK, vdsdims, NULL);
vspace = H5Screate_simple(RANK, vdsdims, NULL);
/* Set VDS creation property. */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
/*
* Build the mappings.
@@ -89,16 +87,15 @@ main (void)
* In the virtual dataset we select the first, the second and the third rows
* and map each row to the data in the corresponding source dataset.
*/
src_space = H5Screate_simple (RANK, dims, NULL);
status = H5Pset_virtual (dcpl, vspace, SRC_FILE, SRC_DATASET, src_space);
src_space = H5Screate_simple(RANK, dims, NULL);
status = H5Pset_virtual(dcpl, vspace, SRC_FILE, SRC_DATASET, src_space);
/* Create a virtual dataset. */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (vspace);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(vspace);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -107,60 +104,60 @@ main (void)
/*
* Open the file and virtual dataset.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find the number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find the number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset ");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
/* Make sure it is ALL selection and then print selection. */
if(H5Sget_select_type(vspace) == H5S_SEL_ALL) {
printf("Selection is H5S_ALL \n");
if (H5Sget_select_type(vspace) == H5S_SEL_ALL) {
printf("Selection is H5S_ALL \n");
}
/* Get source file name. */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name. */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset. */
printf(" Selection in the source dataset ");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
/* Make sure it is ALL selection and then print selection. */
if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("Selection is H5S_ALL \n");
if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("Selection is H5S_ALL \n");
}
H5Sclose(vspace);
H5Sclose(src_space);
@@ -170,26 +167,24 @@ main (void)
/*
* Read the data using the default properties.
*/
status = H5Dread (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
rdata[0]);
status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata[0]);
/*
* Output the data to the screen.
*/
printf (" VDS Data:\n");
for (i=0; i<DIM0; i++) {
printf (" [");
for (j=0; j<DIM1; j++)
printf (" %3d", rdata[i][j]);
printf ("]\n");
printf(" VDS Data:\n");
for (i = 0; i < DIM0; i++) {
printf(" [");
for (j = 0; j < DIM1; j++)
printf(" %3d", rdata[i][j]);
printf("]\n");
}
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -35,88 +35,74 @@
#include <stdio.h>
#include <stdlib.h>
#define FILE "vds.h5"
#define DATASET "VDS"
#define VDSDIM1 6
#define VDSDIM0 4
#define DIM0 6
#define RANK1 1
#define RANK2 2
#define FILE "vds.h5"
#define DATASET "VDS"
#define VDSDIM1 6
#define VDSDIM0 4
#define DIM0 6
#define RANK1 1
#define RANK2 2
const char *SRC_FILE[] = {
"a.h5",
"b.h5",
"c.h5"
};
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5"};
const char *SRC_DATASET[] = {
"A",
"B",
"C"
};
const char *SRC_DATASET[] = {"A", "B", "C"};
int
main (void)
main(void)
{
hid_t file, space, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[2] = {VDSDIM0, VDSDIM1}, /* Virtual datasets dimension */
dims[1] = {DIM0}, /* Source datasets dimensions */
start[2], /* Hyperslab parameters */
stride[2],
count[2],
block[2];
hsize_t start_out[2],
stride_out[2],
count_out[2],
block_out[2];
int wdata[DIM0], /* Write buffer for source dataset */
rdata[VDSDIM0][VDSDIM1], /* Read buffer for virtual dataset */
i, j, k, l;
int fill_value = -1; /* Fill value for VDS */
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char *filename;
char *dsetname;
hid_t file, space, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
hsize_t vdsdims[2] = {VDSDIM0, VDSDIM1}, /* Virtual datasets dimension */
dims[1] = {DIM0}, /* Source datasets dimensions */
start[2], /* Hyperslab parameters */
stride[2], count[2], block[2];
hsize_t start_out[2], stride_out[2], count_out[2], block_out[2];
int wdata[DIM0], /* Write buffer for source dataset */
rdata[VDSDIM0][VDSDIM1], /* Read buffer for virtual dataset */
i, j, k, l;
int fill_value = -1; /* Fill value for VDS */
H5D_layout_t layout; /* Storage layout */
size_t num_map; /* Number of mappings */
ssize_t len; /* Length of the string; also a return value */
char * filename;
char * dsetname;
hsize_t nblocks;
hsize_t *buf; /* Buffer to hold hyperslab coordinates */
hsize_t * buf; /* Buffer to hold hyperslab coordinates */
/*
* Create source files and datasets. This step is optional.
*/
for (i=0; i < 3; i++) {
for (i = 0; i < 3; i++) {
/*
* Initialize data for i-th source dataset.
*/
for (j = 0; j < DIM0; j++) wdata[j] = i+1;
for (j = 0; j < DIM0; j++)
wdata[j] = i + 1;
/*
* Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space = H5Screate_simple (RANK1, dims, NULL);
dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
wdata);
status = H5Sclose (space);
status = H5Dclose (dset);
status = H5Fclose (file);
file = H5Fcreate(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space = H5Screate_simple(RANK1, dims, NULL);
dset = H5Dcreate2(file, SRC_DATASET[i], H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
status = H5Sclose(space);
status = H5Dclose(dset);
status = H5Fclose(file);
}
/* Create file in which virtual dataset will be stored. */
file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
space = H5Screate_simple (RANK2, vdsdims, NULL);
space = H5Screate_simple(RANK2, vdsdims, NULL);
/* Set VDS creation property. */
dcpl = H5Pcreate (H5P_DATASET_CREATE);
status = H5Pset_fill_value (dcpl, H5T_NATIVE_INT, &fill_value);
dcpl = H5Pcreate(H5P_DATASET_CREATE);
status = H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill_value);
/* Initialize hyperslab values. */
start[0] = 0;
@@ -132,21 +118,20 @@ main (void)
* In the virtual dataset we select the first, the second and the third rows
* and map each row to the data in the corresponding source dataset.
*/
src_space = H5Screate_simple (RANK1, dims, NULL);
src_space = H5Screate_simple(RANK1, dims, NULL);
for (i = 0; i < 3; i++) {
start[0] = (hsize_t)i;
/* Select i-th row in the virtual dataset; selection in the source datasets is the same. */
status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual (dcpl, space, SRC_FILE[i], SRC_DATASET[i], src_space);
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
status = H5Pset_virtual(dcpl, space, SRC_FILE[i], SRC_DATASET[i], src_space);
}
/* Create a virtual dataset. */
dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
dcpl, H5P_DEFAULT);
status = H5Sclose (space);
status = H5Sclose (src_space);
status = H5Dclose (dset);
status = H5Fclose (file);
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
status = H5Sclose(space);
status = H5Sclose(src_space);
status = H5Dclose(dset);
status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -155,80 +140,84 @@ main (void)
/*
* Open the file and virtual dataset.
*/
file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
dcpl = H5Dget_create_plist (dset);
dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
layout = H5Pget_layout (dcpl);
layout = H5Pget_layout(dcpl);
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
printf(" Wrong layout found \n");
/*
* Find the number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Find the number of mappings.
*/
status = H5Pget_virtual_count(dcpl, &num_map);
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
/*
* Get mapping parameters for each mapping.
*/
/*
* Get mapping parameters for each mapping.
*/
for (i = 0; i < (int)num_map; i++) {
printf(" Mapping %d \n", i);
printf(" Selection in the virtual dataset ");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
/* Make sure that this is a hyperslab selection and then print information. */
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
nblocks = H5Sget_select_hyper_nblocks (vspace);
buf = (hsize_t *)malloc(sizeof(hsize_t)*2*RANK2*nblocks);
status = H5Sget_select_hyper_blocklist (vspace, (hsize_t)0, nblocks, buf);
for (l=0; l<nblocks; l++) {
nblocks = H5Sget_select_hyper_nblocks(vspace);
buf = (hsize_t *)malloc(sizeof(hsize_t) * 2 * RANK2 * nblocks);
status = H5Sget_select_hyper_blocklist(vspace, (hsize_t)0, nblocks, buf);
for (l = 0; l < nblocks; l++) {
printf("(");
for (k=0; k<RANK2-1; k++)
for (k = 0; k < RANK2 - 1; k++)
printf("%d,", (int)buf[k]);
printf("%d ) - (", (int)buf[k]);
for (k=0; k<RANK2-1; k++)
printf("%d,", (int)buf[RANK2+k]);
printf("%d)\n", (int)buf[RANK2+k]);
for (k = 0; k < RANK2 - 1; k++)
printf("%d,", (int)buf[RANK2 + k]);
printf("%d)\n", (int)buf[RANK2 + k]);
}
/* We also can use new APIs to get start, stride, count and block */
/* We also can use new APIs to get start, stride, count and block */
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1]);
printf(" stride = [%llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1]);
printf(" count = [%llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1]);
printf(" block = [%llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1]);
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
printf(" start = [%llu, %llu] \n", (unsigned long long)start_out[0],
(unsigned long long)start_out[1]);
printf(" stride = [%llu, %llu] \n", (unsigned long long)stride_out[0],
(unsigned long long)stride_out[1]);
printf(" count = [%llu, %llu] \n", (unsigned long long)count_out[0],
(unsigned long long)count_out[1]);
printf(" block = [%llu, %llu] \n", (unsigned long long)block_out[0],
(unsigned long long)block_out[1]);
}
}
/* Get source file name. */
len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1);
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
printf(" Source filename %s\n", filename);
/* Get source dataset name. */
len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len*sizeof(char)+1);
H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1);
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
printf(" Source dataset name %s\n", dsetname);
/* Get selection in the source dataset. */
printf(" Selection in the source dataset ");
src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
/* Make sure it is ALL selection and then print the coordinates. */
if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("(0) - (%d) \n", DIM0-1);
if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("(0) - (%d) \n", DIM0 - 1);
}
H5Sclose(vspace);
H5Sclose(src_space);
@@ -240,26 +229,24 @@ main (void)
/*
* Read the data using the default properties.
*/
status = H5Dread (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
rdata[0]);
status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata[0]);
/*
* Output the data to the screen.
*/
printf (" VDS Data:\n");
for (i=0; i<VDSDIM0; i++) {
printf (" [");
for (j=0; j<VDSDIM1; j++)
printf (" %3d", rdata[i][j]);
printf ("]\n");
printf(" VDS Data:\n");
for (i = 0; i < VDSDIM0; i++) {
printf(" [");
for (j = 0; j < VDSDIM1; j++)
printf(" %3d", rdata[i][j]);
printf("]\n");
}
/*
* Close and release resources.
*/
status = H5Pclose (dcpl);
status = H5Dclose (dset);
status = H5Fclose (file);
status = H5Pclose(dcpl);
status = H5Dclose(dset);
status = H5Fclose(file);
return 0;
}

View File

@@ -18,28 +18,28 @@
#include "hdf5.h"
#define H5FILE_NAME "SDS.h5"
#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "IntArray"
#define NX 5 /* dataset dimensions */
#define NY 6
#define RANK 2
#define NX 5 /* dataset dimensions */
#define NY 6
#define RANK 2
int
main (void)
main(void)
{
hid_t file, dataset; /* file and dataset handles */
hid_t datatype, dataspace; /* handles */
hsize_t dimsf[2]; /* dataset dimensions */
herr_t status;
int data[NX][NY]; /* data to write */
int i, j;
hid_t file, dataset; /* file and dataset handles */
hid_t datatype, dataspace; /* handles */
hsize_t dimsf[2]; /* dataset dimensions */
herr_t status;
int data[NX][NY]; /* data to write */
int i, j;
/*
* Data and output buffer initialization.
*/
for(j = 0; j < NX; j++)
for(i = 0; i < NY; i++)
data[j][i] = i + j;
for (j = 0; j < NX; j++)
for (i = 0; i < NY; i++)
data[j][i] = i + j;
/*
* 0 1 2 3 4 5
* 1 2 3 4 5 6
@@ -59,8 +59,8 @@ main (void)
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
dimsf[0] = NX;
dimsf[1] = NY;
dimsf[0] = NX;
dimsf[1] = NY;
dataspace = H5Screate_simple(RANK, dimsf, NULL);
/*
@@ -68,14 +68,13 @@ main (void)
* We will store little endian INT numbers.
*/
datatype = H5Tcopy(H5T_NATIVE_INT);
status = H5Tset_order(datatype, H5T_ORDER_LE);
status = H5Tset_order(datatype, H5T_ORDER_LE);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
dataset = H5Dcreate2(file, DATASETNAME, datatype, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset = H5Dcreate2(file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write the data to the dataset using default transfer properties.
@@ -92,4 +91,3 @@ main (void)
return 0;
}

File diff suppressed because it is too large Load Diff