summaryrefslogtreecommitdiffstats
path: root/src/H5HLpublic.h
blob: db00f510c926c07244f51773b13ddeb7dccf81c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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     *
 * 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.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*-------------------------------------------------------------------------
 *
 * Created:             H5HLpublic.h
 *                      Jul 16 1997
 *                      Robb Matzke <matzke@llnl.gov>
 *
 * Purpose:             Public declarations for the H5HL (local heap) package.
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
#ifndef _H5HLpublic_H
#define _H5HLpublic_H

/* Public headers needed by this file */
#include "H5public.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif
#endif
om"> * Programmer: Robb Matzke <matzke@llnl.gov> * Friday, January 30, 1998 * * Purpose: Tests extendible datasets. */ #include <assert.h> #include <hdf5.h> #define NX 100 /* USE AN EVEN NUMBER!*/ #define NY 100 /* USE AN EVEN NUMBER!*/ /*------------------------------------------------------------------------- * Function: main * * Purpose: Tests extendible datasets * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Friday, January 30, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main (void) { 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]; /* Initialize buffer and space */ for (i=0; i<NX; i++) { for (j=0; j<NY; j++) { buf1[i][j] = i*NY+j; } } mem_space = H5Screate_simple (2, dims, maxdims); assert (mem_space>=0); /* Create the file */ file = H5Fcreate ("extend.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); assert (file>=0); /* Create the dataset which is originally NX by NY */ cparms = H5Pcreate (H5P_DATASET_CREATE); assert (cparms>=0); status = H5Pset_chunk (cparms, 2, chunk_dims); assert (status>=0); dataset = H5Dcreate (file, "dataset", H5T_NATIVE_INT, mem_space, cparms); assert (dataset>=0); /* 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); status = H5Sset_hyperslab (file_space, offset, dims, NULL); assert (status>=0); /* Write to the hyperslab */ status = H5Dwrite (dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf1); assert (status>=0); H5Sclose (file_space); } } H5Sclose (mem_space); /* Read the data */ mem_space = H5Screate_simple (2, half_dims, NULL); file_space = H5Dget_space (dataset); 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); status = H5Sset_hyperslab (file_space, offset, half_dims, NULL); assert (status>=0); /* Read */ status = H5Dread (dataset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf2); 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); return 0; }