diff options
Diffstat (limited to 'c++/src/cpplus_RM/compound_8cpp-example.html')
-rw-r--r-- | c++/src/cpplus_RM/compound_8cpp-example.html | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/c++/src/cpplus_RM/compound_8cpp-example.html b/c++/src/cpplus_RM/compound_8cpp-example.html new file mode 100644 index 0000000..6fe31d3 --- /dev/null +++ b/c++/src/cpplus_RM/compound_8cpp-example.html @@ -0,0 +1,304 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> +<meta http-equiv="X-UA-Compatible" content="IE=9"/> +<meta name="generator" content="Doxygen 1.8.5"/> +<title>HDF5 C++ API: compound.cpp</title> +<link href="tabs.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="jquery.js"></script> +<script type="text/javascript" src="dynsections.js"></script> +<link href="search/search.css" rel="stylesheet" type="text/css"/> +<script type="text/javascript" src="search/search.js"></script> +<script type="text/javascript"> + $(document).ready(function() { searchBox.OnSelectItem(0); }); +</script> +<link href="doxygen.css" rel="stylesheet" type="text/css" /> +</head> +<body> +<div id="top"><!-- do not remove this div, it is closed by doxygen! --> +<div id="titlearea"> +<table cellspacing="0" cellpadding="0"> + <tbody> + <tr style="height: 56px;"> + <td id="projectlogo"><img alt="Logo" src="hdf_logo.jpg"/></td> + <td style="padding-left: 0.5em;"> + <div id="projectname">HDF5 C++ API +  <span id="projectnumber">1.8.13</span> + </div> + </td> + </tr> + </tbody> +</table> +</div> +<!-- end header part --> +<!-- Generated by Doxygen 1.8.5 --> +<script type="text/javascript"> +var searchBox = new SearchBox("searchBox", "search",false,'Search'); +</script> + <div id="navrow1" class="tabs"> + <ul class="tablist"> + <li><a href="index.html"><span>Main Page</span></a></li> + <li><a href="annotated.html"><span>Classes</span></a></li> + <li><a href="examples.html"><span>Examples</span></a></li> + <li> + <div id="MSearchBox" class="MSearchBoxInactive"> + <span class="left"> + <img id="MSearchSelect" src="search/mag_sel.png" + onmouseover="return searchBox.OnSearchSelectShow()" + onmouseout="return searchBox.OnSearchSelectHide()" + alt=""/> + <input type="text" id="MSearchField" value="Search" accesskey="S" + onfocus="searchBox.OnSearchFieldFocus(true)" + onblur="searchBox.OnSearchFieldFocus(false)" + onkeyup="searchBox.OnSearchFieldChange(event)"/> + </span><span class="right"> + <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> + </span> + </div> + </li> + </ul> + </div> +</div><!-- top --> +<!-- window showing the filter options --> +<div id="MSearchSelectWindow" + onmouseover="return searchBox.OnSearchSelectShow()" + onmouseout="return searchBox.OnSearchSelectHide()" + onkeydown="return searchBox.OnSearchSelectKey(event)"> +<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Pages</a></div> + +<!-- iframe showing the search results (closed by default) --> +<div id="MSearchResultsWindow"> +<iframe src="javascript:void(0)" frameborder="0" + name="MSearchResults" id="MSearchResults"> +</iframe> +</div> + +<div class="header"> + <div class="headertitle"> +<div class="title">compound.cpp</div> </div> +</div><!--header--> +<div class="contents"> +<dl class="section user"><dt></dt><dd>This example shows how to create a compound datatype, write an array which has the compound datatype to the file, and read back fields' subsets.</dd></dl> +<div class="fragment"><div class="line"><span class="comment">/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *</span></div> +<div class="line"><span class="comment"> * Copyright by The HDF Group. *</span></div> +<div class="line"><span class="comment"> * Copyright by the Board of Trustees of the University of Illinois. *</span></div> +<div class="line"><span class="comment"> * All rights reserved. *</span></div> +<div class="line"><span class="comment"> * *</span></div> +<div class="line"><span class="comment"> * This file is part of HDF5. The full HDF5 copyright notice, including *</span></div> +<div class="line"><span class="comment"> * terms governing use, modification, and redistribution, is contained in *</span></div> +<div class="line"><span class="comment"> * the files COPYING and Copyright.html. COPYING can be found at the root *</span></div> +<div class="line"><span class="comment"> * of the source code distribution tree; Copyright.html can be found at the *</span></div> +<div class="line"><span class="comment"> * root level of an installed copy of the electronic HDF5 document set and *</span></div> +<div class="line"><span class="comment"> * is linked from the top-level documents page. It can also be found at *</span></div> +<div class="line"><span class="comment"> * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *</span></div> +<div class="line"><span class="comment"> * access to either file, you may request a copy from help@hdfgroup.org. *</span></div> +<div class="line"><span class="comment"> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */</span></div> +<div class="line"></div> +<div class="line"><span class="comment">/*</span></div> +<div class="line"><span class="comment"> * This example shows how to create a compound datatype,</span></div> +<div class="line"><span class="comment"> * write an array which has the compound datatype to the file,</span></div> +<div class="line"><span class="comment"> * and read back fields' subsets.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"></div> +<div class="line"><span class="preprocessor">#ifdef OLD_HEADER_FILENAME</span></div> +<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include <iostream.h></span></div> +<div class="line"><span class="preprocessor">#else</span></div> +<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include <iostream></span></div> +<div class="line"><span class="preprocessor">#endif</span></div> +<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include <string></span></div> +<div class="line"></div> +<div class="line"><span class="preprocessor">#ifndef H5_NO_NAMESPACE</span></div> +<div class="line"><span class="preprocessor"></span><span class="preprocessor">#ifndef H5_NO_STD</span></div> +<div class="line"><span class="preprocessor"></span> <span class="keyword">using</span> std::cout;</div> +<div class="line"> <span class="keyword">using</span> std::endl;</div> +<div class="line"><span class="preprocessor">#endif // H5_NO_STD</span></div> +<div class="line"><span class="preprocessor"></span><span class="preprocessor">#endif</span></div> +<div class="line"><span class="preprocessor"></span></div> +<div class="line"><span class="preprocessor">#include "H5Cpp.h"</span></div> +<div class="line"></div> +<div class="line"><span class="preprocessor">#ifndef H5_NO_NAMESPACE</span></div> +<div class="line"><span class="preprocessor"></span> <span class="keyword">using namespace </span>H5;</div> +<div class="line"><span class="preprocessor">#endif</span></div> +<div class="line"><span class="preprocessor"></span></div> +<div class="line"><span class="keyword">const</span> H5std_string FILE_NAME( <span class="stringliteral">"SDScompound.h5"</span> );</div> +<div class="line"><span class="keyword">const</span> H5std_string DATASET_NAME( <span class="stringliteral">"ArrayOfStructures"</span> );</div> +<div class="line"><span class="keyword">const</span> H5std_string MEMBER1( <span class="stringliteral">"a_name"</span> );</div> +<div class="line"><span class="keyword">const</span> H5std_string MEMBER2( <span class="stringliteral">"b_name"</span> );</div> +<div class="line"><span class="keyword">const</span> H5std_string MEMBER3( <span class="stringliteral">"c_name"</span> );</div> +<div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> LENGTH = 10;</div> +<div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> RANK = 1;</div> +<div class="line"></div> +<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div> +<div class="line">{</div> +<div class="line"> <span class="comment">/* First structure and dataset*/</span></div> +<div class="line"> <span class="keyword">typedef</span> <span class="keyword">struct </span>s1_t {</div> +<div class="line"> <span class="keywordtype">int</span> a;</div> +<div class="line"> <span class="keywordtype">float</span> b;</div> +<div class="line"> <span class="keywordtype">double</span> c;</div> +<div class="line"> } s1_t;</div> +<div class="line"></div> +<div class="line"> <span class="comment">/* Second structure (subset of s1_t) and dataset*/</span></div> +<div class="line"> <span class="keyword">typedef</span> <span class="keyword">struct </span>s2_t {</div> +<div class="line"> <span class="keywordtype">double</span> c;</div> +<div class="line"> <span class="keywordtype">int</span> a;</div> +<div class="line"> } s2_t;</div> +<div class="line"></div> +<div class="line"> <span class="comment">// Try block to detect exceptions raised by any of the calls inside it</span></div> +<div class="line"> <span class="keywordflow">try</span></div> +<div class="line"> {</div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Initialize the data</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <span class="keywordtype">int</span> i;</div> +<div class="line"> s1_t s1[LENGTH];</div> +<div class="line"> <span class="keywordflow">for</span> (i = 0; i< LENGTH; i++)</div> +<div class="line"> {</div> +<div class="line"> s1[i].a = i;</div> +<div class="line"> s1[i].b = i*i;</div> +<div class="line"> s1[i].c = 1./(i+1);</div> +<div class="line"> }</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Turn off the auto-printing when failure occurs so that we can</span></div> +<div class="line"><span class="comment"> * handle the errors appropriately</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a name="a0"></a><a class="code" href="class_h5_1_1_exception.html#ad49f16300979996c094c2e4f57868414">Exception::dontPrint</a>();</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create the data space.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> hsize_t dim[] = {LENGTH}; <span class="comment">/* Dataspace dimensions */</span></div> +<div class="line"> <a name="_a1"></a><a class="code" href="class_h5_1_1_data_space.html">DataSpace</a> space( RANK, dim );</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create the file.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a name="_a2"></a><a class="code" href="class_h5_1_1_h5_file.html">H5File</a>* file = <span class="keyword">new</span> <a class="code" href="class_h5_1_1_h5_file.html">H5File</a>( FILE_NAME, H5F_ACC_TRUNC );</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create the memory datatype.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a name="_a3"></a><a class="code" href="class_h5_1_1_comp_type.html">CompType</a> mtype1( <span class="keyword">sizeof</span>(s1_t) );</div> +<div class="line"> mtype1.insertMember( MEMBER1, HOFFSET(s1_t, a), <a name="a4"></a><a class="code" href="class_h5_1_1_pred_type.html#a3308bcd537696a8d728cd3b443f2fc7b">PredType::NATIVE_INT</a>);</div> +<div class="line"> mtype1.insertMember( MEMBER3, HOFFSET(s1_t, c), <a name="a5"></a><a class="code" href="class_h5_1_1_pred_type.html#a4d04943f071e75f43cd423ce13119b9f">PredType::NATIVE_DOUBLE</a>);</div> +<div class="line"> mtype1.insertMember( MEMBER2, HOFFSET(s1_t, b), <a name="a6"></a><a class="code" href="class_h5_1_1_pred_type.html#aa1840efa5f3728f370bfdb475b010c02">PredType::NATIVE_FLOAT</a>);</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create the dataset.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a name="_a7"></a><a class="code" href="class_h5_1_1_data_set.html">DataSet</a>* dataset;</div> +<div class="line"> dataset = <span class="keyword">new</span> <a class="code" href="class_h5_1_1_data_set.html">DataSet</a>(file-><a name="a8"></a><a class="code" href="class_h5_1_1_common_f_g.html#a12a4af21ca0231d4f2c4008b12177bb1">createDataSet</a>(DATASET_NAME, mtype1, space));</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Write data to the dataset;</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> dataset-><a name="a9"></a><a class="code" href="class_h5_1_1_data_set.html#a3ce98e7a626fd32a23d1bcc41537326f">write</a>( s1, mtype1 );</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Release resources</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <span class="keyword">delete</span> dataset;</div> +<div class="line"> <span class="keyword">delete</span> file;</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Open the file and the dataset.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> file = <span class="keyword">new</span> <a class="code" href="class_h5_1_1_h5_file.html">H5File</a>( FILE_NAME, H5F_ACC_RDONLY );</div> +<div class="line"> dataset = <span class="keyword">new</span> <a class="code" href="class_h5_1_1_data_set.html">DataSet</a> (file-><a name="a10"></a><a class="code" href="class_h5_1_1_common_f_g.html#a6a2557f173c32577db9feeb1b77d4e40">openDataSet</a>( DATASET_NAME ));</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create a datatype for s2</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a class="code" href="class_h5_1_1_comp_type.html">CompType</a> mtype2( <span class="keyword">sizeof</span>(s2_t) );</div> +<div class="line"></div> +<div class="line"> mtype2.insertMember( MEMBER3, HOFFSET(s2_t, c), <a class="code" href="class_h5_1_1_pred_type.html#a4d04943f071e75f43cd423ce13119b9f">PredType::NATIVE_DOUBLE</a>);</div> +<div class="line"> mtype2.insertMember( MEMBER1, HOFFSET(s2_t, a), <a class="code" href="class_h5_1_1_pred_type.html#a3308bcd537696a8d728cd3b443f2fc7b">PredType::NATIVE_INT</a>);</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Read two fields c and a from s1 dataset. Fields in the file</span></div> +<div class="line"><span class="comment"> * are found by their names "c_name" and "a_name".</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> s2_t s2[LENGTH];</div> +<div class="line"> dataset-><a name="a11"></a><a class="code" href="class_h5_1_1_data_set.html#a2f0278a519122419ae9981666277c9bb">read</a>( s2, mtype2 );</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Display the fields</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> cout << endl << <span class="stringliteral">"Field c : "</span> << endl;</div> +<div class="line"> <span class="keywordflow">for</span>( i = 0; i < LENGTH; i++)</div> +<div class="line"> cout << s2[i].c << <span class="stringliteral">" "</span>;</div> +<div class="line"> cout << endl;</div> +<div class="line"></div> +<div class="line"> cout << endl << <span class="stringliteral">"Field a : "</span> << endl;</div> +<div class="line"> <span class="keywordflow">for</span>( i = 0; i < LENGTH; i++)</div> +<div class="line"> cout << s2[i].a << <span class="stringliteral">" "</span>;</div> +<div class="line"> cout << endl;</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Create a datatype for s3.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <a class="code" href="class_h5_1_1_comp_type.html">CompType</a> mtype3( <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>) );</div> +<div class="line"></div> +<div class="line"> mtype3.insertMember( MEMBER2, 0, <a class="code" href="class_h5_1_1_pred_type.html#aa1840efa5f3728f370bfdb475b010c02">PredType::NATIVE_FLOAT</a>);</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Read field b from s1 dataset. Field in the file is found by its name.</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <span class="keywordtype">float</span> s3[LENGTH]; <span class="comment">// Third "structure" - used to read float field of s1</span></div> +<div class="line"> dataset-><a class="code" href="class_h5_1_1_data_set.html#a2f0278a519122419ae9981666277c9bb">read</a>( s3, mtype3 );</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Display the field</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> cout << endl << <span class="stringliteral">"Field b : "</span> << endl;</div> +<div class="line"> <span class="keywordflow">for</span>( i = 0; i < LENGTH; i++)</div> +<div class="line"> cout << s3[i] << <span class="stringliteral">" "</span>;</div> +<div class="line"> cout << endl;</div> +<div class="line"></div> +<div class="line"> <span class="comment">/*</span></div> +<div class="line"><span class="comment"> * Release resources</span></div> +<div class="line"><span class="comment"> */</span></div> +<div class="line"> <span class="keyword">delete</span> dataset;</div> +<div class="line"> <span class="keyword">delete</span> file;</div> +<div class="line"> } <span class="comment">// end of try block</span></div> +<div class="line"></div> +<div class="line"> <span class="comment">// catch failure caused by the H5File operations</span></div> +<div class="line"> <span class="keywordflow">catch</span>( <a name="_a12"></a><a class="code" href="class_h5_1_1_file_i_exception.html">FileIException</a> error )</div> +<div class="line"> {</div> +<div class="line"> error.<a name="a13"></a><a class="code" href="class_h5_1_1_exception.html#ad5bf0f93b4156d6366110dd5e08342a2">printError</a>();</div> +<div class="line"> <span class="keywordflow">return</span> -1;</div> +<div class="line"> }</div> +<div class="line"></div> +<div class="line"> <span class="comment">// catch failure caused by the DataSet operations</span></div> +<div class="line"> <span class="keywordflow">catch</span>( <a name="_a14"></a><a class="code" href="class_h5_1_1_data_set_i_exception.html">DataSetIException</a> error )</div> +<div class="line"> {</div> +<div class="line"> error.<a class="code" href="class_h5_1_1_exception.html#ad5bf0f93b4156d6366110dd5e08342a2">printError</a>();</div> +<div class="line"> <span class="keywordflow">return</span> -1;</div> +<div class="line"> }</div> +<div class="line"></div> +<div class="line"> <span class="comment">// catch failure caused by the DataSpace operations</span></div> +<div class="line"> <span class="keywordflow">catch</span>( <a name="_a15"></a><a class="code" href="class_h5_1_1_data_space_i_exception.html">DataSpaceIException</a> error )</div> +<div class="line"> {</div> +<div class="line"> error.<a class="code" href="class_h5_1_1_exception.html#ad5bf0f93b4156d6366110dd5e08342a2">printError</a>();</div> +<div class="line"> <span class="keywordflow">return</span> -1;</div> +<div class="line"> }</div> +<div class="line"></div> +<div class="line"> <span class="comment">// catch failure caused by the DataSpace operations</span></div> +<div class="line"> <span class="keywordflow">catch</span>( <a name="_a16"></a><a class="code" href="class_h5_1_1_data_type_i_exception.html">DataTypeIException</a> error )</div> +<div class="line"> {</div> +<div class="line"> error.<a class="code" href="class_h5_1_1_exception.html#ad5bf0f93b4156d6366110dd5e08342a2">printError</a>();</div> +<div class="line"> <span class="keywordflow">return</span> -1;</div> +<div class="line"> }</div> +<div class="line"></div> +<div class="line"> <span class="keywordflow">return</span> 0;</div> +<div class="line">}</div> +</div><!-- fragment --> </div><!-- contents --> +<!-- start footer part --> +<hr class="footer"/><address class="footer"><small> +Generated on Mon Jul 21 2014 10:58:44 for HDF5 C++ API by  <a href="http://www.doxygen.org/index.html"> +<img class="footer" src="doxygen.png" alt="doxygen"/> +</a> 1.8.5 +</small></address> +</body> +</html> |