1998-02-14 06:04:07 +08:00
|
|
|
/*
|
|
|
|
* This example shows how to create groups within the file and
|
|
|
|
* datasets within the file and groups.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1998-02-10 23:22:51 +08:00
|
|
|
#include "hdf5.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define FILE "DIR.h5"
|
|
|
|
#define RANK 2
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
|
|
|
|
hid_t file, dir;
|
|
|
|
hid_t dataset, dataspace;
|
|
|
|
|
|
|
|
herr_t status;
|
1998-07-09 04:41:14 +08:00
|
|
|
hsize_t dims[2];
|
|
|
|
hsize_t size[1];
|
1998-02-10 23:22:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a file.
|
|
|
|
*/
|
1998-02-26 03:13:49 +08:00
|
|
|
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
1998-02-10 23:22:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create two groups in a file.
|
|
|
|
*/
|
|
|
|
dir = H5Gcreate(file, "/IntData", 0);
|
|
|
|
status = H5Gclose(dir);
|
|
|
|
|
|
|
|
dir = H5Gcreate(file,"/FloatData", 0);
|
|
|
|
status = H5Gclose(dir);
|
|
|
|
|
1998-02-14 06:04:07 +08:00
|
|
|
/*
|
|
|
|
* Create dataspace for the character string
|
|
|
|
*/
|
|
|
|
size[0] = 80;
|
1998-02-26 02:48:33 +08:00
|
|
|
dataspace = H5Screate_simple(1, size, NULL);
|
1998-02-14 06:04:07 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create dataset "String" in the root group.
|
|
|
|
*/
|
1998-02-26 03:13:49 +08:00
|
|
|
dataset = H5Dcreate(file, "String", H5T_NATIVE_CHAR, dataspace, H5P_DEFAULT);
|
1998-02-14 06:04:07 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create dataset "String" in the /IntData group.
|
|
|
|
*/
|
|
|
|
dataset = H5Dcreate(file, "/IntData/String", H5T_NATIVE_CHAR, dataspace,
|
1998-02-26 03:13:49 +08:00
|
|
|
H5P_DEFAULT);
|
1998-02-14 06:04:07 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
1998-02-10 23:22:51 +08:00
|
|
|
/*
|
1998-02-14 06:04:07 +08:00
|
|
|
* Create dataset "String" in the /FloatData group.
|
|
|
|
*/
|
|
|
|
dataset = H5Dcreate(file, "/FloatData/String", H5T_NATIVE_CHAR, dataspace,
|
1998-02-26 03:13:49 +08:00
|
|
|
H5P_DEFAULT);
|
1998-02-26 02:48:33 +08:00
|
|
|
H5Sclose(dataspace);
|
1998-02-14 06:04:07 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create IntArray dataset in the /IntData group by specifying full path.
|
1998-02-10 23:22:51 +08:00
|
|
|
*/
|
|
|
|
dims[0] = 2;
|
|
|
|
dims[1] = 3;
|
1998-02-26 02:48:33 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims, NULL);
|
1998-02-14 06:04:07 +08:00
|
|
|
dataset = H5Dcreate(file, "/IntData/IntArray", H5T_NATIVE_INT, dataspace,
|
1998-02-26 03:13:49 +08:00
|
|
|
H5P_DEFAULT);
|
1998-02-26 02:48:33 +08:00
|
|
|
H5Sclose(dataspace);
|
1998-02-10 23:22:51 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/*
|
1998-02-14 06:04:07 +08:00
|
|
|
* Set current group to /IntData and attach to the dataset String.
|
1998-02-10 23:22:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
status = H5Gset (file, "/IntData");
|
1998-02-14 06:04:07 +08:00
|
|
|
dataset = H5Dopen(file, "String");
|
|
|
|
if (dataset > 0) printf("String dataset in /IntData group is found\n");
|
1998-02-10 23:22:51 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set current group to /FloatData.
|
|
|
|
*/
|
|
|
|
status = H5Gset (file, "/FloatData");
|
|
|
|
|
|
|
|
/*
|
1998-02-14 06:04:07 +08:00
|
|
|
* Create two datasets FlatArray and DoubleArray.
|
1998-02-10 23:22:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
dims[0] = 5;
|
|
|
|
dims[1] = 10;
|
1998-02-26 02:48:33 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims, NULL);
|
1998-02-26 03:13:49 +08:00
|
|
|
dataset = H5Dcreate(file, "FloatArray", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT);
|
1998-02-26 02:48:33 +08:00
|
|
|
H5Sclose(dataspace);
|
1998-02-10 23:22:51 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
dims[0] = 4;
|
|
|
|
dims[1] = 6;
|
1998-02-26 02:48:33 +08:00
|
|
|
dataspace = H5Screate_simple(RANK, dims, NULL);
|
1998-02-14 06:04:07 +08:00
|
|
|
dataset = H5Dcreate(file, "DoubleArray", H5T_NATIVE_DOUBLE, dataspace,
|
1998-02-26 03:13:49 +08:00
|
|
|
H5P_DEFAULT);
|
1998-02-26 02:48:33 +08:00
|
|
|
H5Sclose(dataspace);
|
1998-02-10 23:22:51 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
|
|
|
|
/*
|
1998-02-14 06:04:07 +08:00
|
|
|
* Attach to /FloatData/String dataset.
|
1998-02-10 23:22:51 +08:00
|
|
|
*/
|
|
|
|
|
1998-02-14 06:04:07 +08:00
|
|
|
dataset = H5Dopen(file, "/FloatData/String");
|
|
|
|
if (dataset > 0) printf("/FloatData/String dataset is found\n");
|
1998-02-10 23:22:51 +08:00
|
|
|
H5Dclose(dataset);
|
|
|
|
H5Fclose(file);
|
|
|
|
|
|
|
|
}
|