2004-02-10 23:42:55 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2004-02-10 23:42:55 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-15 00:54:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
|
|
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2004-02-10 23:42:55 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1998-02-11 02:06:11 +08:00
|
|
|
* This example shows how to read data from a chunked dataset.
|
2005-08-14 04:53:35 +08:00
|
|
|
* We will read from the file created by h5_extend_write.c
|
1998-02-11 02:06:11 +08:00
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1998-02-11 02:06:11 +08:00
|
|
|
#include "hdf5.h"
|
|
|
|
|
2001-06-06 02:00:37 +08:00
|
|
|
#define H5FILE_NAME "SDSextendible.h5"
|
2005-08-14 04:53:35 +08:00
|
|
|
#define DATASETNAME "ExtendibleArray"
|
1998-02-11 02:06:11 +08:00
|
|
|
#define RANK 2
|
1998-02-13 22:26:11 +08:00
|
|
|
#define RANKC 1
|
|
|
|
#define NX 10
|
2005-08-14 04:53:35 +08:00
|
|
|
#define NY 5
|
1998-02-11 02:06:11 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
int
|
|
|
|
main (void)
|
1998-02-11 02:06:11 +08:00
|
|
|
{
|
1998-09-01 03:21:23 +08:00
|
|
|
hid_t file; /* handles */
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t dataset;
|
|
|
|
hid_t filespace;
|
|
|
|
hid_t memspace;
|
|
|
|
hid_t cparms;
|
|
|
|
hsize_t dims[2]; /* dataset and chunk dimensions*/
|
1998-09-01 03:21:23 +08:00
|
|
|
hsize_t chunk_dims[2];
|
|
|
|
hsize_t col_dims[1];
|
|
|
|
hsize_t count[2];
|
2004-12-29 22:26:20 +08:00
|
|
|
hsize_t offset[2];
|
1998-09-01 03:21:23 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
herr_t status, status_n;
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
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;
|
2005-09-09 13:05:57 +08:00
|
|
|
int i, j;
|
1998-02-11 02:06:11 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Open the file and the dataset.
|
|
|
|
*/
|
2001-06-06 02:00:37 +08:00
|
|
|
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
|
[svn-r14193] Description:
Make H5Dopen versioned and change all internal usage to use H5Dopen2
Add simple regression test for H5Dopen1
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-09 03:59:36 +08:00
|
|
|
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Get dataset rank and dimension.
|
|
|
|
*/
|
|
|
|
|
|
|
|
filespace = H5Dget_space(dataset); /* Get filespace handle first. */
|
1998-09-01 11:35:23 +08:00
|
|
|
rank = H5Sget_simple_extent_ndims(filespace);
|
|
|
|
status_n = H5Sget_simple_extent_dims(filespace, dims, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
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);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Read dataset back and display.
|
|
|
|
*/
|
|
|
|
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
|
|
|
|
H5P_DEFAULT, data_out);
|
1998-02-11 02:06:11 +08:00
|
|
|
printf("\n");
|
|
|
|
printf("Dataset: \n");
|
1998-09-01 03:21:23 +08:00
|
|
|
for (j = 0; j < dims[0]; j++) {
|
|
|
|
for (i = 0; i < dims[1]; i++) printf("%d ", data_out[j][i]);
|
|
|
|
printf("\n");
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
1998-09-01 03:21:23 +08:00
|
|
|
|
2004-12-29 22:26:20 +08:00
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Sclose(memspace);
|
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
2005-08-14 04:53:35 +08:00
|
|
|
* dataset rank 2, dimensions 10 x 5
|
|
|
|
* chunk rank 2, dimensions 2 x 5
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
* Dataset:
|
2005-08-14 04:53:35 +08:00
|
|
|
* 1 1 1 3 3
|
|
|
|
* 1 1 1 3 3
|
|
|
|
* 1 1 1 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
|
|
|
* 2 0 0 0 0
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the third column from the dataset.
|
|
|
|
* First define memory dataspace, then define hyperslab
|
|
|
|
* and read it into column array.
|
|
|
|
*/
|
|
|
|
col_dims[0] = 10;
|
|
|
|
memspace = H5Screate_simple(RANKC, col_dims, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define the column (hyperslab) to read.
|
|
|
|
*/
|
|
|
|
offset[0] = 0;
|
|
|
|
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);
|
1998-02-11 02:06:11 +08:00
|
|
|
printf("\n");
|
1998-09-01 03:21:23 +08:00
|
|
|
printf("Third column: \n");
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
printf("%d \n", column[i]);
|
|
|
|
}
|
|
|
|
|
2004-12-29 22:26:20 +08:00
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Sclose(memspace);
|
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Third column:
|
|
|
|
* 1
|
|
|
|
* 1
|
|
|
|
* 1
|
|
|
|
* 0
|
|
|
|
* 0
|
|
|
|
* 0
|
|
|
|
* 0
|
|
|
|
* 0
|
|
|
|
* 0
|
|
|
|
* 0
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-12-29 22:26:20 +08:00
|
|
|
* Get creation properties list.
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
2004-12-29 22:26:20 +08:00
|
|
|
cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */
|
1998-09-01 03:21:23 +08:00
|
|
|
|
2004-12-29 22:26:20 +08:00
|
|
|
if (H5D_CHUNKED == H5Pget_layout(cparms)) {
|
1998-09-01 03:21:23 +08:00
|
|
|
|
2004-12-29 22:26:20 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define chunk in the file (hyperslab) to read.
|
|
|
|
*/
|
|
|
|
offset[0] = 2;
|
|
|
|
offset[1] = 0;
|
|
|
|
count[0] = chunk_dims[0];
|
|
|
|
count[1] = chunk_dims[1];
|
2005-08-14 04:53:35 +08:00
|
|
|
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
|
2004-12-29 22:26:20 +08:00
|
|
|
count, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read chunk back and display.
|
|
|
|
*/
|
|
|
|
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]);
|
|
|
|
printf("\n");
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
2004-12-29 22:26:20 +08:00
|
|
|
/*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Chunk:
|
|
|
|
* 1 1 1 0 0
|
|
|
|
* 2 0 0 0 0
|
2004-12-29 22:26:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Sclose(memspace);
|
|
|
|
}
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Pclose(cparms);
|
|
|
|
H5Dclose(dataset);
|
|
|
|
H5Sclose(filespace);
|
|
|
|
H5Fclose(file);
|
|
|
|
|
|
|
|
return 0;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|