1 /*
2  * Copyright(C) 1999-2020 National Technology & Engineering Solutions
3  * of Sandia, LLC (NTESS).  Under the terms of Contract DE-NA0003525 with
4  * NTESS, the U.S. Government retains certain rights in this software.
5  *
6  * See packages/seacas/LICENSE for details
7  */
8 
9 #include "exodusII.h"     // for ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL
11 
12 /*!
13   \ingroup ModelDescription
14   \undoc
15 */
16 
ex_create_group(int parent_id,const char * group_name)17 int ex_create_group(int parent_id, const char *group_name)
18 {
19   char errmsg[MAX_ERR_LENGTH];
20 #if NC_HAS_HDF5
21   int exoid = -1;
22   int status;
23 
24   EX_FUNC_ENTER();
25   if (ex__check_valid_file_id(parent_id, __func__) != EX_NOERR) {
26     EX_FUNC_LEAVE(EX_FATAL);
27   }
28 
29   if ((status = nc_redef(parent_id)) != NC_NOERR) {
30     snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", parent_id);
31     ex_err_fn(exoid, __func__, errmsg, status);
32     EX_FUNC_LEAVE(EX_FATAL);
33   }
34 
35   if ((status = nc_def_grp(parent_id, group_name, &exoid)) != NC_NOERR) {
36     snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: group create failed for %s in file id %d", group_name,
37              parent_id);
38     ex_err_fn(exoid, __func__, errmsg, status);
39     EX_FUNC_LEAVE(EX_FATAL);
40   }
41 
42   if ((status = ex__leavedef(parent_id, __func__)) != NC_NOERR) {
43     EX_FUNC_LEAVE(EX_FATAL);
44   }
45   EX_FUNC_LEAVE(exoid);
46 #else
47   EX_FUNC_ENTER();
48   snprintf(errmsg, MAX_ERR_LENGTH,
49            "ERROR: Group capabilities are not available in this netcdf "
50            "version--not netcdf4");
51   ex_err(__func__, errmsg, NC_ENOTNC4);
52   EX_FUNC_LEAVE(EX_FATAL);
53 #endif
54 }
55