Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_create_group.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2022, 2024 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
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 (exi_check_valid_file_id(parent_id, __func__) != EX_NOERR) {
26 EX_FUNC_LEAVE(EX_FATAL);
27 }
28
29 if ((status = exi_redef(parent_id, __func__)) != 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 = exi_leavedef(parent_id, __func__)) != NC_NOERR) {
43 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode");
44 ex_err_fn(exoid, __func__, errmsg, status);
45 EX_FUNC_LEAVE(EX_FATAL);
46 }
47 EX_FUNC_LEAVE(exoid);
48 #else
49 EX_FUNC_ENTER();
50 snprintf(errmsg, MAX_ERR_LENGTH,
51 "ERROR: Group capabilities are not available in this netcdf "
52 "version--not netcdf4");
53 ex_err(__func__, errmsg, NC_ENOTNC4);
54 EX_FUNC_LEAVE(EX_FATAL);
55 #endif
56 }