1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  *  This example illustrates how to create and close a group.
16  *  It is used in the HDF5 Tutorial.
17  */
18 
19 #include <iostream>
20 #include <string>
21 
22 #include "H5Cpp.h"
23 
24 #ifndef H5_NO_NAMESPACE
25     using namespace H5;
26 #ifndef H5_NO_STD
27     using std::cout;
28     using std::endl;
29 #endif  // H5_NO_STD
30 #endif
31 
32 const H5std_string FILE_NAME("h5tutr_group.h5");
33 
main(void)34 int main(void)
35 {
36     // Try block to detect exceptions raised by any of the calls inside it
37     try
38     {
39         // Turn off the auto-printing when failure occurs so that we can
40         // handle the errors appropriately
41         Exception::dontPrint();
42 
43         // Create a new file using default property lists.
44         H5File file(FILE_NAME, H5F_ACC_TRUNC);
45 
46         // Create a group named "/MygGroup" in the file
47         Group group(file.createGroup("/MyGroup"));
48 
49         // File and group will be closed as their instances go out of scope.
50 
51     } // end of try block
52 
53     // catch failure caused by the H5File operations
54     catch(FileIException error)
55     {
56         error.printError();
57         return -1;
58     }
59     // catch failure caused by the Group operations
60     catch(GroupIException error)
61     {
62         error.printError();
63         return -1;
64     }
65 
66     return 0;
67 }
68