1998-01-31 07:32:28 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 1998 Spizella Software
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke <matzke@llnl.gov>
|
|
|
|
|
* Friday, January 30, 1998
|
|
|
|
|
*
|
1998-03-05 00:20:23 +08:00
|
|
|
|
* Purpose: Tests extendible datasets.
|
1998-01-31 07:32:28 +08:00
|
|
|
|
*/
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <hdf5.h>
|
1998-06-06 05:03:49 +08:00
|
|
|
|
#include <stdlib.h>
|
1998-01-31 07:32:28 +08:00
|
|
|
|
|
1998-05-29 07:02:29 +08:00
|
|
|
|
#define TEST_FILE_NAME "extend.h5"
|
1998-01-31 07:32:28 +08:00
|
|
|
|
#define NX 100 /* USE AN EVEN NUMBER!*/
|
|
|
|
|
#define NY 100 /* USE AN EVEN NUMBER!*/
|
|
|
|
|
|
1998-05-29 07:02:29 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: cleanup
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Cleanup temporary test files
|
|
|
|
|
*
|
|
|
|
|
* Return: none
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Albert Cheng
|
|
|
|
|
* May 28, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
cleanup(void)
|
|
|
|
|
{
|
1998-06-06 05:03:49 +08:00
|
|
|
|
if (!getenv ("HDF5_NOCLEANUP")) {
|
|
|
|
|
remove(TEST_FILE_NAME);
|
|
|
|
|
}
|
1998-05-29 07:02:29 +08:00
|
|
|
|
}
|
1998-06-06 05:03:49 +08:00
|
|
|
|
|
1998-01-31 07:32:28 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
|
|
|
|
*
|
1998-03-05 00:20:23 +08:00
|
|
|
|
* Purpose: Tests extendible datasets
|
1998-01-31 07:32:28 +08:00
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(non-zero)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, January 30, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main (void)
|
|
|
|
|
{
|
1998-04-09 05:43:02 +08:00
|
|
|
|
hid_t file, dataset, mem_space, file_space, cparms;
|
|
|
|
|
herr_t status;
|
|
|
|
|
int i, j, k, m;
|
|
|
|
|
static int buf1[NY][NX], buf2[NX/2][NY/2];
|
|
|
|
|
static const hsize_t dims[2] = {NX, NY};
|
|
|
|
|
static const hsize_t half_dims[2] = {NX/2, NY/2};
|
|
|
|
|
static const hsize_t chunk_dims[2] = {NX/2, NY/2};
|
|
|
|
|
static hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
|
|
|
|
|
static hsize_t size[2];
|
|
|
|
|
hssize_t offset[2];
|
1998-01-31 07:32:28 +08:00
|
|
|
|
|
|
|
|
|
/* Initialize buffer and space */
|
|
|
|
|
for (i=0; i<NX; i++) {
|
|
|
|
|
for (j=0; j<NY; j++) {
|
|
|
|
|
buf1[i][j] = i*NY+j;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-02-26 02:48:33 +08:00
|
|
|
|
mem_space = H5Screate_simple (2, dims, maxdims);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (mem_space>=0);
|
|
|
|
|
|
|
|
|
|
/* Create the file */
|
1998-05-29 07:02:29 +08:00
|
|
|
|
file = H5Fcreate (TEST_FILE_NAME, H5F_ACC_TRUNC|H5F_ACC_DEBUG,
|
1998-05-22 23:05:53 +08:00
|
|
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (file>=0);
|
|
|
|
|
|
|
|
|
|
/* Create the dataset which is originally NX by NY */
|
1998-02-26 03:13:49 +08:00
|
|
|
|
cparms = H5Pcreate (H5P_DATASET_CREATE);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (cparms>=0);
|
1998-02-26 03:13:49 +08:00
|
|
|
|
status = H5Pset_chunk (cparms, 2, chunk_dims);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (status>=0);
|
|
|
|
|
dataset = H5Dcreate (file, "dataset", H5T_NATIVE_INT, mem_space, cparms);
|
|
|
|
|
assert (dataset>=0);
|
1998-05-01 13:16:50 +08:00
|
|
|
|
H5Pclose (cparms);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
|
|
|
|
|
/* Write the data */
|
|
|
|
|
for (i=0; i<5; i++) {
|
|
|
|
|
for (j=0; j<5; j++) {
|
|
|
|
|
|
|
|
|
|
/* Extend the dataset */
|
|
|
|
|
offset[0] = i * NX;
|
|
|
|
|
offset[1] = j * NY;
|
|
|
|
|
size[0] = offset[0] + NX;
|
|
|
|
|
size[1] = offset[1] + NY;
|
|
|
|
|
status = H5Dextend (dataset, size);
|
|
|
|
|
assert (status>=0);
|
|
|
|
|
|
|
|
|
|
/* Select a hyperslab */
|
|
|
|
|
file_space = H5Dget_space (dataset);
|
|
|
|
|
assert (file_space>=0);
|
1998-07-07 05:01:59 +08:00
|
|
|
|
status = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, NULL, dims, NULL);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (status>=0);
|
|
|
|
|
|
|
|
|
|
/* Write to the hyperslab */
|
|
|
|
|
status = H5Dwrite (dataset, H5T_NATIVE_INT, mem_space, file_space,
|
1998-02-26 03:13:49 +08:00
|
|
|
|
H5P_DEFAULT, buf1);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (status>=0);
|
1998-02-26 02:48:33 +08:00
|
|
|
|
H5Sclose (file_space);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-02-26 02:48:33 +08:00
|
|
|
|
H5Sclose (mem_space);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the data */
|
1998-02-26 02:48:33 +08:00
|
|
|
|
mem_space = H5Screate_simple (2, half_dims, NULL);
|
1998-01-31 11:47:38 +08:00
|
|
|
|
file_space = H5Dget_space (dataset);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
for (i=0; i<10; i++) {
|
|
|
|
|
for (j=0; j<10; j++) {
|
|
|
|
|
|
|
|
|
|
/* Select a hyperslab */
|
|
|
|
|
offset[0] = i * NX/2;
|
|
|
|
|
offset[1] = j * NY/2;
|
|
|
|
|
assert (file_space>=0);
|
1998-07-07 05:01:59 +08:00
|
|
|
|
status = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, offset, NULL, half_dims, NULL);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (status>=0);
|
|
|
|
|
|
|
|
|
|
/* Read */
|
|
|
|
|
status = H5Dread (dataset, H5T_NATIVE_INT, mem_space, file_space,
|
1998-02-26 03:13:49 +08:00
|
|
|
|
H5P_DEFAULT, buf2);
|
1998-01-31 07:32:28 +08:00
|
|
|
|
assert (status>=0);
|
|
|
|
|
|
|
|
|
|
/* Compare */
|
|
|
|
|
for (k=0; k<NX/2; k++) {
|
|
|
|
|
for (m=0; m<NY/2; m++) {
|
|
|
|
|
assert (buf2[k][m]==buf1[(i%2)*NX/2+k][(j%2)*NY/2+m]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
H5Dclose (dataset);
|
|
|
|
|
H5Fclose (file);
|
|
|
|
|
|
1998-05-29 07:02:29 +08:00
|
|
|
|
cleanup();
|
1998-02-10 03:37:40 +08:00
|
|
|
|
return 0;
|
1998-01-31 07:32:28 +08:00
|
|
|
|
}
|
|
|
|
|
|