diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 1998-07-08 14:54:54 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 1998-07-08 14:54:54 (GMT) |
commit | bd1e676c521d881b3143829f493a28b5ced1294b (patch) | |
tree | 69c50f9fe21ce87f293d8617a6bd51b4cc1e0244 /doc/html/H5.sample_code.html | |
parent | 73345095897d9698bb1f2f7df830bf80a56dc65a (diff) | |
download | hdf5-bd1e676c521d881b3143829f493a28b5ced1294b.zip hdf5-bd1e676c521d881b3143829f493a28b5ced1294b.tar.gz hdf5-bd1e676c521d881b3143829f493a28b5ced1294b.tar.bz2 |
[svn-r467] Restructuring documentation.
Diffstat (limited to 'doc/html/H5.sample_code.html')
-rw-r--r-- | doc/html/H5.sample_code.html | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/doc/html/H5.sample_code.html b/doc/html/H5.sample_code.html new file mode 100644 index 0000000..b3e5336 --- /dev/null +++ b/doc/html/H5.sample_code.html @@ -0,0 +1,123 @@ +<html><head><title> +HDF5 Draft API Example Code +</title></head><body> + +<center> +<h1>HDF5: API Example Code</h1> +</center> + +<P>Example programs/sections of code below: +<dl COMPACT> + <dt><a href="#Example1">#1</a> + <dd>A simple example showing how to create a file. + <dt><a href="#Example2">#2</a> + <dd>A example showing how to create a homogenous multi-dimensional dataset. + <dt><a href="#Example3">#3</a> + <dd>A example showing how to read a generic dataset. +</dl> + +<hr> +<h2><a name="Example1">Simple Example showing how to create a file.</a></h2> + +<P>Notes:<br> +This example creates a new HDF5 file and allows write access. +If the file exists already, the H5F_ACC_TRUNC flag would also be necessary to +overwrite the previous file's information. + +<P>Code: + +<code> <pre> + hid_t file_id; + + file_id=<A HREF="H5.apiv2.html#File-Create">H5Fcreate</a>("example1.h5",H5F_ACC_EXCL,H5P_DEFAULT_TEMPLATE,H5P_DEFAULT_TEMPLATE); + + <A HREF="H5.apiv2.html#File-Close">H5Fclose</a>(file_id); + +</pre> </code> + +<hr> +<h2><a name="Example2">Example showing how create a homogenous multi-dimensional dataset.</a></h2> + +<P>Notes:<br> +This example creates a 4-dimensional dataset of 32-bit floating-point +numbers, corresponding to the current Scientific Dataset functionality. + +<P>Code: + +<code> <pre> + 1 hid_t file_id; /* new file's ID */ + 2 hid_t dim_id; /* new dimensionality's ID */ + 3 int rank=4; /* the number of dimensions */ + 4 hsize_t dims[4]={6,5,4,3}; /* the size of each dimension */ + 5 hid_t dataset_id; /* new dataset's ID */ + 6 float buf[6][5][4][3]; /* storage for the dataset's data */ + 7 herr_t status; /* function return status */ + 8 + 9 file_id = H5Fcreate ("example3.h5", H5F_ACC_TRUNC, H5P_DEFAULT, +10 H5P_DEFAULT); +11 assert (file_id >= 0); +12 +13 /* Create & initialize a dimensionality object */ +14 dim_id = H5Screate_simple (rank, dims); +15 assert (dim_id >= 0); +16 +17 /* Create & initialize the dataset object */ +18 dataset_id = H5Dcreate (file_id, "Simple Object", H5T_NATIVE_FLOAT, +19 dim_id, H5P_DEFAULT); +20 assert (dataset_id >= 0); +21 +22 <initialize data array> +23 +24 /* Write the entire dataset out */ +25 status = H5Dwrite (dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, +26 H5P_DEFAULT, buf); +27 assert (status >= 0); +28 +29 /* Release the IDs we've created */ +30 H5Sclose (dim_id); +31 H5Dclose (dataset_id); +32 H5Fclose (file_id); +</pre> </code> + +<hr> +<h2><a name="Example3">Example showing how read a generic dataset.</a></h2> + +<P>Notes:<br> +This example shows how to get the information for and display a generic +dataset. + +<P>Code: + +<code> <pre> + 1 hid_t file_id; /* file's ID */ + 2 hid_t dataset_id; /* dataset's ID in memory */ + 3 hid_t space_id; /* dataspace's ID in memory */ + 4 uintn nelems; /* number of elements in array */ + 5 double *buf; /* pointer to the dataset's data */ + 6 herr_t status; /* function return value */ + 7 + 8 file_id = H5Fopen ("example6.h5", H5F_ACC_RDONLY, H5P_DEFAULT); + 9 assert (file_id >= 0); +10 +11 /* Attach to a datatype object */ +12 dataset_id = H5Dopen (file_id, "dataset1"); +13 assert (dataset_id >= 0); +14 +15 /* Get the OID for the dataspace */ +16 space_id = H5Dget_space (dataset_id); +17 assert (space_id >= 0); +18 +19 /* Allocate space for the data */ +20 nelems = H5Sget_npoints (space_id); +21 buf = malloc (nelems * sizeof(double)); +22 +23 /* Read in the dataset */ +24 status = H5Dread (dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL,, H5S_ALL, +25 H5P_DEFAULT, buf); +26 assert (status >= 0); +27 +28 /* Release the IDs we've accessed */ +29 H5Sclose (space_id); +30 H5Dclose (dataset_id); +31 H5Fclose (file_id); +</pre> </code> |