title: hdf5: Check to create group
body: <p>I would like automatically create a group, if a group does not yet exist. I am however not successfull in checking if the group exists. </p>
  
  <h3>Failing attempt 1</h3>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "H5Cpp.h"
  
  int main(void)
  {
    H5::H5File file("test.h5",H5F_ACC_TRUNC);
  
    std::string group_name = "/test";
  
    H5::Group group = file.createGroup(group_name.c_str());
  
    if ( !file.attrExists(group_name.c_str()) )
      H5::Group group = file.createGroup(group_name.c_str());
  
    return 0;
  }
  </code></pre>
  
  <p>Compilation with</p>
  
  <pre><code>$ h5c++ -o test test.cpp
  </code></pre>
  
  <p>Fails because <code>file.attrExists(name)</code> always returns <code>false</code>. For reference, the error occurs at <code>createGroup</code>:</p>
  
  <pre><code>... 
  
  #006: H5L.c line 1733 in H5L_link_cb(): name already exists
    major: Symbol table
    minor: Object already exists
  </code></pre>
  
  <h3>Failing attempt 2</h3>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "H5Cpp.h"
  
  int main(void)
  {
    H5::H5File file("test.h5",H5F_ACC_TRUNC);
  
    std::string group_name = "/test";
  
    try         { H5::Group group = file.openGroup  (group_name.c_str()); }
    catch (...) { H5::Group group = file.createGroup(group_name.c_str()); }
  
    return 0;
  }
  </code></pre>
  
  <p>Compilation with</p>
  
  <pre><code>$ h5c++ -o test test.cpp
  </code></pre>
  
  <p>Somehow, the <code>catch</code> is not successful, and an error is produced when <code>openGroup</code> fails:</p>
  
  <pre><code>...
  
  #005: H5Gloc.c line 385 in H5G_loc_find_cb(): object 'test' doesn't exist
    major: Symbol table
    minor: Object not found
  </code></pre>