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
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* This program illustrates how references to objects can be used.
|
2005-08-14 04:53:35 +08:00
|
|
|
* Program creates a dataset and a group in a file. It also creates
|
|
|
|
* second dataset, and references to the first dataset and the group
|
1999-07-07 04:43:00 +08:00
|
|
|
* are stored in it.
|
1999-06-26 02:11:09 +08:00
|
|
|
* Program reopens the file and reads dataset with the references.
|
1999-07-07 04:43:00 +08:00
|
|
|
* References are used to open the objects. Information about the
|
|
|
|
* objects is displayed.
|
2005-08-14 04:53:35 +08:00
|
|
|
*/
|
1999-06-26 02:11:09 +08:00
|
|
|
|
1999-07-02 03:16:36 +08:00
|
|
|
#include <stdlib.h>
|
2001-04-04 02:33:07 +08:00
|
|
|
|
|
|
|
#include "hdf5.h"
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2001-06-06 02:00:37 +08:00
|
|
|
#define H5FILE_NAME "refere.h5"
|
1999-06-26 02:11:09 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t fid; /* File, group, datasets, datatypes */
|
1999-07-07 04:43:00 +08:00
|
|
|
hid_t gid_a; /* and dataspaces identifiers */
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t did_b, sid_b, tid_b;
|
1999-06-26 02:11:09 +08:00
|
|
|
hid_t did_r, tid_r, sid_r;
|
2011-07-19 06:26:21 +08:00
|
|
|
hid_t dapl_id; /* Dataset access property list */
|
2007-09-14 09:52:38 +08:00
|
|
|
H5O_type_t obj_type;
|
1999-06-26 02:11:09 +08:00
|
|
|
herr_t status;
|
|
|
|
|
|
|
|
hobj_ref_t *wbuf; /* buffer to write to disk */
|
|
|
|
hobj_ref_t *rbuf; /* buffer to read from disk */
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
hsize_t dim_r[1];
|
1999-06-26 02:11:09 +08:00
|
|
|
hsize_t dim_b[2];
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Create a file using default properties.
|
|
|
|
*/
|
2001-06-06 02:00:37 +08:00
|
|
|
fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* Create group "A" in the file.
|
1999-06-26 02:11:09 +08:00
|
|
|
*/
|
2007-08-24 04:25:25 +08:00
|
|
|
gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2011-07-19 06:26:21 +08:00
|
|
|
/*
|
|
|
|
* Create dataset access property list
|
|
|
|
*/
|
|
|
|
dapl_id = H5Pcreate(H5P_DATASET_ACCESS);
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Create dataset "B" in the file.
|
|
|
|
*/
|
|
|
|
dim_b[0] = 2;
|
|
|
|
dim_b[1] = 6;
|
2005-08-14 04:53:35 +08:00
|
|
|
sid_b = H5Screate_simple(2, dim_b, NULL);
|
[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
|
|
|
did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* Create dataset "R" to store references to the objects "A" and "B".
|
1999-06-26 02:11:09 +08:00
|
|
|
*/
|
|
|
|
dim_r[0] = 2;
|
|
|
|
sid_r = H5Screate_simple(1, dim_r, NULL);
|
|
|
|
tid_r = H5Tcopy(H5T_STD_REF_OBJ);
|
[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
|
|
|
did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Allocate write and read buffers.
|
|
|
|
*/
|
[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
|
|
|
wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
|
|
|
|
rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1999-06-26 02:11:09 +08:00
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* Create references to the group "A" and dataset "B"
|
1999-06-26 02:11:09 +08:00
|
|
|
* and store them in the wbuf.
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, -1);
|
1999-06-26 02:11:09 +08:00
|
|
|
H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, -1);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Write dataset R using default transfer 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
|
|
|
status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
|
|
|
* Close all objects.
|
1999-06-26 02:11:09 +08:00
|
|
|
*/
|
1999-07-07 04:43:00 +08:00
|
|
|
H5Gclose(gid_a);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1999-06-26 02:11:09 +08:00
|
|
|
H5Sclose(sid_b);
|
|
|
|
H5Dclose(did_b);
|
|
|
|
|
|
|
|
H5Tclose(tid_r);
|
|
|
|
H5Sclose(sid_r);
|
|
|
|
H5Dclose(did_r);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
1999-06-26 02:11:09 +08:00
|
|
|
H5Fclose(fid);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Reopen the file.
|
|
|
|
*/
|
2001-06-06 02:00:37 +08:00
|
|
|
fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Open and read dataset "R".
|
|
|
|
*/
|
[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
|
|
|
did_r = H5Dopen2(fid, "R", H5P_DEFAULT);
|
[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
|
|
|
status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* Find the type of referenced objects.
|
1999-06-26 02:11:09 +08:00
|
|
|
*/
|
2007-09-14 09:52:38 +08:00
|
|
|
status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[0], &obj_type);
|
[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
|
|
|
if(obj_type == H5O_TYPE_GROUP)
|
2007-09-14 09:52:38 +08:00
|
|
|
printf("First dereferenced object is a group. \n");
|
|
|
|
|
|
|
|
status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[1], &obj_type);
|
[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
|
|
|
if(obj_type == H5O_TYPE_DATASET)
|
2007-09-14 09:52:38 +08:00
|
|
|
printf("Second dereferenced object is a dataset. \n");
|
1999-06-26 02:11:09 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-06-26 02:11:09 +08:00
|
|
|
* Get datatype of the dataset "B"
|
|
|
|
*/
|
2011-07-19 06:26:21 +08:00
|
|
|
did_b = H5Rdereference(did_r, dapl_id, H5R_OBJECT, &rbuf[1]);
|
1999-06-26 02:11:09 +08:00
|
|
|
tid_b = H5Dget_type(did_b);
|
|
|
|
if(H5Tequal(tid_b, H5T_NATIVE_FLOAT))
|
1999-07-07 04:43:00 +08:00
|
|
|
printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
|
1999-06-26 02:11:09 +08:00
|
|
|
printf("\n");
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
/*
|
1999-07-07 04:43:00 +08:00
|
|
|
* Close all objects and free memory buffers.
|
1999-06-26 02:11:09 +08:00
|
|
|
*/
|
2011-07-19 06:26:21 +08:00
|
|
|
H5Pclose(dapl_id);
|
1999-07-07 04:43:00 +08:00
|
|
|
H5Dclose(did_r);
|
1999-06-26 02:11:09 +08:00
|
|
|
H5Dclose(did_b);
|
|
|
|
H5Tclose(tid_b);
|
|
|
|
H5Fclose(fid);
|
1999-07-07 04:43:00 +08:00
|
|
|
free(rbuf);
|
|
|
|
free(wbuf);
|
1999-06-26 02:11:09 +08:00
|
|
|
|
[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
|
|
|
return 0;
|
1999-06-26 02:11:09 +08:00
|
|
|
}
|
|
|
|
|