2020-04-21 07:12:00 +08:00
|
|
|
Attribute Examples:
|
1998-04-24 06:26:16 +08:00
|
|
|
|
[svn-r14187] Description:
Put H5Acreate() under API versioning, with all internal usage shifted
to H5Acreate2().
Add regression tests for H5Acreate1().
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-05 06:19:07 +08:00
|
|
|
H5Acreate2 example: Show how to create an attribute for a dataset and a group
|
1998-04-24 06:26:16 +08:00
|
|
|
----------------
|
|
|
|
{
|
|
|
|
hid_t file;
|
|
|
|
hid_t group;
|
|
|
|
hid_t dataset;
|
|
|
|
hid_t attr;
|
|
|
|
hid_t dataspace;
|
|
|
|
int32 attr_data;
|
|
|
|
int rank;
|
|
|
|
size_t dimsf[2];
|
|
|
|
|
|
|
|
/* Open the file */
|
|
|
|
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
|
|
|
/* Describe the size of the array and create the data space */
|
|
|
|
rank=2;
|
|
|
|
dimsf[0] = H5S_UNLIMITED;
|
|
|
|
dimsf[1] = H5S_UNLIMITED;
|
2020-04-21 07:12:00 +08:00
|
|
|
dataspace = H5Screate_simple(rank, dimsf, NULL);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Create a dataset */
|
[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, "Dataset1", H5T_UINT8, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
<Write data to first dataset>
|
|
|
|
|
|
|
|
/* Create an attribute for the dataset */
|
[svn-r14218] Description:
Changed H5Acreate2 -> H5Acreate_by_name, to be more consistent with
other new API routines.
Re-added simpler form of H5Acreate2, which creates attributes directly
on an object.
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-31 02:13:48 +08:00
|
|
|
attr = H5Acreate2(dataset, "Attr1", H5T_INT32, H5S_SCALAR, H5P_DEFAULT, H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Write attribute information */
|
[svn-r14187] Description:
Put H5Acreate() under API versioning, with all internal usage shifted
to H5Acreate2().
Add regression tests for H5Acreate1().
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-05 06:19:07 +08:00
|
|
|
H5Awrite(attr, H5T_INT32, &attr_data);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Close attribute */
|
|
|
|
H5Aclose(attr);
|
|
|
|
|
|
|
|
/* Close dataset */
|
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/* Create a group */
|
[svn-r14187] Description:
Put H5Acreate() under API versioning, with all internal usage shifted
to H5Acreate2().
Add regression tests for H5Acreate1().
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-05 06:19:07 +08:00
|
|
|
group = H5Gcreate2(file, "/Group One", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Create an attribute for the dataset */
|
[svn-r14218] Description:
Changed H5Acreate2 -> H5Acreate_by_name, to be more consistent with
other new API routines.
Re-added simpler form of H5Acreate2, which creates attributes directly
on an object.
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-31 02:13:48 +08:00
|
|
|
attr = H5Acreate2(group, "Attr1", H5T_INT32, H5S_SCALAR, H5P_DEFAULT, H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Write attribute information */
|
[svn-r14187] Description:
Put H5Acreate() under API versioning, with all internal usage shifted
to H5Acreate2().
Add regression tests for H5Acreate1().
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-05 06:19:07 +08:00
|
|
|
H5Awrite(attr, H5T_INT32, &attr_data);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Close attribute */
|
|
|
|
H5Aclose(attr);
|
|
|
|
|
|
|
|
/* Close the group */
|
|
|
|
H5Gclose(group);
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
H5Fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
H5Aiterate example: Print all the names of attributes of a dataset, without
|
|
|
|
any buffers.
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
herr_t print_names (hid_t loc_id, const char *name, void *opdata)
|
|
|
|
{
|
|
|
|
puts (name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
H5Aiterate (dataset_or_group_id, NULL, print_names, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
H5Aread Example: Attach to an attribute of a dataset and read in attr. data
|
|
|
|
----------------
|
|
|
|
{
|
|
|
|
hid_t file;
|
|
|
|
hid_t dataset;
|
|
|
|
hid_t attr;
|
|
|
|
int32 attr_data;
|
|
|
|
|
|
|
|
/* Open the file */
|
|
|
|
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
|
|
|
/* Open the dataset */
|
[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, "Dataset1", H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Get the OID of the attribute */
|
[svn-r14217] Description:
Change H5Aopen -> H5Aopen_by_name, in order to be more consistent with
other new API routines.
Re-add H5Aopen as a simpler routine, to open attributes on a particular
object. (Much like the old H5Aopen_name routine).
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-31 00:07:20 +08:00
|
|
|
attr=H5Aopen(dataset, "Attr1", H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Read attribute */
|
|
|
|
H5Aread(attr,H5T_INT32,attr_data);
|
|
|
|
|
|
|
|
/* Close attribute dataset */
|
|
|
|
H5Aclose(attr);
|
|
|
|
|
|
|
|
/* Close first dataset */
|
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
H5Fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
H5Alink Example: Shows how to share an attribute between two datasets.
|
|
|
|
----------------
|
|
|
|
{
|
|
|
|
hid_t file;
|
|
|
|
hid_t dataset1, dataset2;
|
|
|
|
hid_t attr;
|
|
|
|
|
|
|
|
/* Open the file */
|
|
|
|
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
|
|
|
/* Open the first dataset */
|
[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
|
|
|
dataset1=H5Dopen2(file, "Dataset1", H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Open the first dataset */
|
[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
|
|
|
dataset2=H5Dopen2(file, "Dataset2", H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
|
|
|
/* Get the OID of the attribute */
|
[svn-r14217] Description:
Change H5Aopen -> H5Aopen_by_name, in order to be more consistent with
other new API routines.
Re-add H5Aopen as a simpler routine, to open attributes on a particular
object. (Much like the old H5Aopen_name routine).
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-31 00:07:20 +08:00
|
|
|
attr=H5Aopen(dataset1, "Foo", H5P_DEFAULT);
|
1998-04-24 06:26:16 +08:00
|
|
|
|
2020-04-21 07:12:00 +08:00
|
|
|
/*
|
1998-04-24 06:26:16 +08:00
|
|
|
* Create an attribute in the second dataset to the attribute in dataset1,
|
|
|
|
* changing the name of the attribute information in dataset2.
|
|
|
|
*/
|
|
|
|
H5Alink(dataset2, attr, "Bar");
|
|
|
|
|
|
|
|
/* Close attribute dataset */
|
|
|
|
H5Aclose(attr);
|
|
|
|
|
|
|
|
/* Close datasets */
|
|
|
|
H5Dclose(dataset1);
|
|
|
|
H5Dclose(dataset2);
|
|
|
|
|
|
|
|
/* Close file */
|
|
|
|
H5Fclose(file);
|
|
|
|
}
|