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-18 03:32: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-12 00:52:27 +08:00
|
|
|
* This example shows how to work with extendible dataset.
|
1998-02-09 02:38:20 +08:00
|
|
|
* In the current version of the library dataset MUST be
|
|
|
|
* chunked.
|
2005-08-14 04:53:35 +08:00
|
|
|
*
|
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 "SDSextendible.h5"
|
2005-08-14 04:53:35 +08:00
|
|
|
#define DATASETNAME "ExtendibleArray"
|
1998-02-09 02:38:20 +08:00
|
|
|
#define RANK 2
|
|
|
|
#define NX 10
|
2005-08-14 04:53:35 +08:00
|
|
|
#define NY 5
|
1998-02-09 02:38:20 +08:00
|
|
|
|
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; /* handles */
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t dataspace, dataset;
|
|
|
|
hid_t filespace;
|
|
|
|
hid_t cparms;
|
1998-09-01 03:21:23 +08:00
|
|
|
hsize_t dims[2] = { 3, 3}; /*
|
2005-08-14 04:53:35 +08:00
|
|
|
* dataset dimensions
|
1998-09-01 03:21:23 +08:00
|
|
|
* at the creation time
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
hsize_t dims1[2] = { 3, 3}; /* data1 dimensions */
|
|
|
|
hsize_t dims2[2] = { 7, 1}; /* data2 dimensions */
|
|
|
|
hsize_t dims3[2] = { 2, 2}; /* data3 dimensions */
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
|
|
|
|
hsize_t chunk_dims[2] ={2, 5};
|
|
|
|
hsize_t size[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;
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
int data1[3][3] = { {1, 1, 1}, /* data to write */
|
|
|
|
{1, 1, 1},
|
2005-08-14 04:53:35 +08:00
|
|
|
{1, 1, 1} };
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
int data2[7] = { 2, 2, 2, 2, 2, 2, 2};
|
|
|
|
|
|
|
|
int data3[2][2] = { {3, 3},
|
|
|
|
{3, 3} };
|
2003-08-05 02:25:41 +08:00
|
|
|
int fillvalue = 0;
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Create the data space with unlimited dimensions.
|
1998-09-01 03:21:23 +08:00
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims, maxdims);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new file. If file exists its contents will be overwritten.
|
|
|
|
*/
|
2001-06-06 02:00:37 +08:00
|
|
|
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1998-09-01 03:21:23 +08:00
|
|
|
* Modify dataset creation properties, i.e. enable chunking.
|
|
|
|
*/
|
2001-10-04 01:57:56 +08:00
|
|
|
cparms = H5Pcreate(H5P_DATASET_CREATE);
|
1998-09-01 03:21:23 +08:00
|
|
|
status = H5Pset_chunk( cparms, RANK, chunk_dims);
|
2003-08-05 02:25:41 +08:00
|
|
|
status = H5Pset_fill_value (cparms, H5T_NATIVE_INT, &fillvalue );
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new dataset within the file using cparms
|
|
|
|
* creation properties.
|
|
|
|
*/
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
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-12 00:24:11 +08:00
|
|
|
dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT,
|
|
|
|
cparms, H5P_DEFAULT);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extend the dataset. This call assures that dataset is at least 3 x 3.
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
size[0] = 3;
|
|
|
|
size[1] = 3;
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
status = H5Dset_extent(dataset, size);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select a hyperslab.
|
|
|
|
*/
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
filespace = H5Dget_space(dataset);
|
1998-09-01 03:21:23 +08:00
|
|
|
offset[0] = 0;
|
|
|
|
offset[1] = 0;
|
|
|
|
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
|
2005-08-14 04:53:35 +08:00
|
|
|
dims1, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the data to the hyperslab.
|
|
|
|
*/
|
|
|
|
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];
|
2005-08-14 04:53:35 +08:00
|
|
|
size[0] = dims[0];
|
|
|
|
size[1] = dims[1];
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
status = H5Dset_extent(dataset, size);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select a hyperslab.
|
|
|
|
*/
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
filespace = H5Dget_space(dataset);
|
1998-09-01 03:21:23 +08:00
|
|
|
offset[0] = 3;
|
|
|
|
offset[1] = 0;
|
|
|
|
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
|
2005-08-14 04:53:35 +08:00
|
|
|
dims2, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define memory space
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims2, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the data to the hyperslab.
|
|
|
|
*/
|
|
|
|
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];
|
2005-08-14 04:53:35 +08:00
|
|
|
size[0] = dims[0];
|
|
|
|
size[1] = dims[1];
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
status = H5Dset_extent(dataset, size);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select a hyperslab
|
|
|
|
*/
|
[svn-r14192] Description:
Deprecate H5Dextend in favor of H5Dset_extent (without using API
versioning, due to changed behavior) and switch internal usage to H5Dset_extent
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-08 23:26:02 +08:00
|
|
|
filespace = H5Dget_space(dataset);
|
1998-09-01 03:21:23 +08:00
|
|
|
offset[0] = 0;
|
|
|
|
offset[1] = 3;
|
2005-08-14 04:53:35 +08:00
|
|
|
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
|
|
|
|
dims3, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define memory space.
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims3, NULL);
|
1998-09-01 03:21:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the data to the hyperslab.
|
|
|
|
*/
|
|
|
|
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
|
|
|
|
H5P_DEFAULT, data3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resulting dataset
|
2005-08-14 04:53:35 +08:00
|
|
|
*
|
2015-06-17 02:32:04 +08:00
|
|
|
* 1 1 1 3 3
|
|
|
|
* 1 1 1 3 3
|
|
|
|
* 1 1 1 0 0
|
1998-09-01 03:21:23 +08:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Close/release resources.
|
|
|
|
*/
|
|
|
|
H5Dclose(dataset);
|
|
|
|
H5Sclose(dataspace);
|
|
|
|
H5Sclose(filespace);
|
2001-10-04 01:57:56 +08:00
|
|
|
H5Pclose(cparms);
|
1998-09-01 03:21:23 +08:00
|
|
|
H5Fclose(file);
|
|
|
|
|
|
|
|
return 0;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|