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 *
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
2007-02-07 22:56:24 +08:00
|
|
|
* 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. *
|
2004-02-10 23:42:55 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
|
|
|
* This example reads hyperslab from the SDS.h5 file
|
1998-02-09 02:38:20 +08:00
|
|
|
* created by h5_write.c program into two-dimensional
|
2005-08-14 04:53:35 +08:00
|
|
|
* plane of the three-dimensional array.
|
|
|
|
* Information about dataset in the SDS.h5 file is obtained.
|
1998-02-09 02:38:20 +08:00
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1998-02-09 02:38:20 +08:00
|
|
|
#include "hdf5.h"
|
|
|
|
|
2001-06-06 02:00:37 +08:00
|
|
|
#define H5FILE_NAME "SDS.h5"
|
2005-08-14 04:53:35 +08:00
|
|
|
#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
|
1998-02-09 02:38:20 +08:00
|
|
|
#define RANK 2
|
|
|
|
#define RANK_OUT 3
|
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
int
|
|
|
|
main (void)
|
1998-02-09 02:38:20 +08:00
|
|
|
{
|
1998-09-01 03:21:23 +08:00
|
|
|
hid_t file, dataset; /* handles */
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t datatype, dataspace;
|
|
|
|
hid_t memspace;
|
2001-09-26 01:46:32 +08:00
|
|
|
H5T_class_t t_class; /* data type class */
|
1998-09-01 03:21:23 +08:00
|
|
|
H5T_order_t order; /* data order */
|
|
|
|
size_t size; /*
|
2005-08-14 04:53:35 +08:00
|
|
|
* size of the data element
|
1998-09-01 03:21:23 +08:00
|
|
|
* stored in file
|
|
|
|
*/
|
|
|
|
hsize_t dimsm[3]; /* memory space dimensions */
|
2005-08-14 04:53:35 +08:00
|
|
|
hsize_t dims_out[2]; /* dataset dimensions */
|
|
|
|
herr_t status;
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
int data_out[NX][NY][NZ ]; /* output buffer */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
hsize_t count[2]; /* size of the hyperslab in the file */
|
2004-12-29 22:26:20 +08:00
|
|
|
hsize_t offset[2]; /* hyperslab offset in the file */
|
1998-09-01 03:21:23 +08:00
|
|
|
hsize_t count_out[3]; /* size of the hyperslab in memory */
|
2004-12-29 22:26:20 +08:00
|
|
|
hsize_t offset_out[3]; /* hyperslab offset in memory */
|
1998-09-01 03:21:23 +08:00
|
|
|
int i, j, k, status_n, rank;
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
for (j = 0; j < NX; j++) {
|
|
|
|
for (i = 0; i < NY; i++) {
|
|
|
|
for (k = 0; k < NZ ; k++)
|
|
|
|
data_out[j][i][k] = 0;
|
|
|
|
}
|
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);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Get datatype and dataspace handles and then query
|
|
|
|
* dataset class, order, size, rank and dimensions.
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
datatype = H5Dget_type(dataset); /* datatype handle */
|
2001-09-26 01:46:32 +08:00
|
|
|
t_class = H5Tget_class(datatype);
|
|
|
|
if (t_class == H5T_INTEGER) printf("Data set has INTEGER type \n");
|
1998-09-01 03:21:23 +08:00
|
|
|
order = H5Tget_order(datatype);
|
|
|
|
if (order == H5T_ORDER_LE) printf("Little endian order \n");
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
size = H5Tget_size(datatype);
|
1999-11-18 05:58:38 +08:00
|
|
|
printf(" Data size is %d \n", (int)size);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
dataspace = H5Dget_space(dataset); /* dataspace handle */
|
1998-09-01 11:35:23 +08:00
|
|
|
rank = H5Sget_simple_extent_ndims(dataspace);
|
|
|
|
status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
printf("rank %d, dimensions %lu x %lu \n", rank,
|
|
|
|
(unsigned long)(dims_out[0]), (unsigned long)(dims_out[1]));
|
1998-02-09 02:38:20 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
|
|
|
* Define hyperslab in the dataset.
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
|
|
|
offset[0] = 1;
|
|
|
|
offset[1] = 2;
|
|
|
|
count[0] = NX_SUB;
|
|
|
|
count[1] = NY_SUB;
|
2005-08-14 04:53:35 +08:00
|
|
|
status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,
|
1998-09-01 03:21:23 +08:00
|
|
|
count, NULL);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Define the memory dataspace.
|
|
|
|
*/
|
|
|
|
dimsm[0] = NX;
|
|
|
|
dimsm[1] = NY;
|
|
|
|
dimsm[2] = NZ ;
|
2005-08-14 04:53:35 +08:00
|
|
|
memspace = H5Screate_simple(RANK_OUT,dimsm,NULL);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
|
|
|
* Define memory hyperslab.
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
|
|
|
offset_out[0] = 3;
|
|
|
|
offset_out[1] = 0;
|
|
|
|
offset_out[2] = 0;
|
|
|
|
count_out[0] = NX_SUB;
|
|
|
|
count_out[1] = NY_SUB;
|
|
|
|
count_out[2] = 1;
|
2005-08-14 04:53:35 +08:00
|
|
|
status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
|
1998-09-01 03:21:23 +08:00
|
|
|
count_out, NULL);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Read data from hyperslab in the file into the hyperslab in
|
1998-09-01 03:21:23 +08:00
|
|
|
* memory and display.
|
|
|
|
*/
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 0 0 0 0 0 0 0
|
|
|
|
* 0 0 0 0 0 0 0
|
|
|
|
* 0 0 0 0 0 0 0
|
2005-08-14 04:53:35 +08:00
|
|
|
* 3 4 5 6 0 0 0
|
1998-09-01 03:21:23 +08:00
|
|
|
* 4 5 6 7 0 0 0
|
|
|
|
* 5 6 7 8 0 0 0
|
|
|
|
* 0 0 0 0 0 0 0
|
|
|
|
*/
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Tclose(datatype);
|
|
|
|
H5Dclose(dataset);
|
|
|
|
H5Sclose(dataspace);
|
|
|
|
H5Sclose(memspace);
|
|
|
|
H5Fclose(file);
|
1998-02-09 02:38:20 +08:00
|
|
|
|
1998-09-01 03:21:23 +08:00
|
|
|
return 0;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|