Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020, 2022, 2023, 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 *
10 * exclos - ex_close
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 *
16 * exit conditions -
17 *
18 * revision history -
19 *
20 *
21 *****************************************************************************/
22
23 #include "exodusII.h" // for ex_err, etc
24 #include "exodusII_int.h" // for exi_get_counter_list, etc
25
26 /*!
27 \ingroup Utilities
28
29 The function ex_close() updates and then closes an open exodus file.
30
31 \return In case of an error, ex_close() returns a negative number; a
32 warning will return a positive number. Possible causes of errors
33 include:
34 - data file not properly opened with call to ex_create() or ex_open()
35
36 \param exoid exodus file ID returned from a previous call to ex_create()
37 or ex_open().
38
39 The following code segment closes an open exodus file:
40
41 ~~~{.c}
42 int error,exoid;
43 error = ex_close (exoid);
44 ~~~
45
46 */
47 int ex_close(int exoid)
48 {
49 char errmsg[MAX_ERR_LENGTH];
50 int status;
51 int status1;
52 int status2;
53
54 EX_FUNC_ENTER();
55
56 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
57 EX_FUNC_LEAVE(EX_FATAL);
58 }
59
60 #ifndef NDEBUG
61 struct exi_file_item *file = exi_find_file_item(exoid);
62 assert(!file->in_define_mode && file->persist_define_mode == 0);
63 #endif
64
65 /*
66 * NOTE: If using netcdf-4, exoid must refer to the root group.
67 * Need to determine whether there are any groups and if so,
68 * call exi_rm_file_item and exi_rm_stat_ptr on each group.
69 */
70
71 /*
72 * Get exoid of root group
73 */
74
75 if ((status1 = nc_sync(exoid)) != NC_NOERR) {
76 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to update file id %d", exoid);
77 ex_err_fn(exoid, __func__, errmsg, status1);
78 }
79
80 int root_id = exoid & EX_FILE_ID_MASK;
81 if ((status2 = nc_close(root_id)) != NC_NOERR) {
82 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to close file id %d", root_id);
83 ex_err_fn(root_id, __func__, errmsg, status2);
84 }
85
86 /* Even if we have failures above due to nc_sync() or nc_close(), we still need to clean up our
87 * internal datastructures.
88 */
89
90 exi_rm_file_item(exoid, exi_get_counter_list(EX_ELEM_BLOCK));
91 exi_rm_file_item(exoid, exi_get_counter_list(EX_FACE_BLOCK));
92 exi_rm_file_item(exoid, exi_get_counter_list(EX_EDGE_BLOCK));
93 exi_rm_file_item(exoid, exi_get_counter_list(EX_NODE_SET));
94 exi_rm_file_item(exoid, exi_get_counter_list(EX_EDGE_SET));
95 exi_rm_file_item(exoid, exi_get_counter_list(EX_FACE_SET));
96 exi_rm_file_item(exoid, exi_get_counter_list(EX_SIDE_SET));
97 exi_rm_file_item(exoid, exi_get_counter_list(EX_ELEM_SET));
98 exi_rm_file_item(exoid, exi_get_counter_list(EX_NODE_MAP));
99 exi_rm_file_item(exoid, exi_get_counter_list(EX_EDGE_MAP));
100 exi_rm_file_item(exoid, exi_get_counter_list(EX_FACE_MAP));
101 exi_rm_file_item(exoid, exi_get_counter_list(EX_ELEM_MAP));
102 exi_rm_file_item(exoid, exi_get_counter_list(EX_ASSEMBLY));
103 exi_rm_file_item(exoid, exi_get_counter_list(EX_BLOB));
104
105 exi_rm_stat_ptr(exoid, &exoII_ed);
106 exi_rm_stat_ptr(exoid, &exoII_fa);
107 exi_rm_stat_ptr(exoid, &exoII_eb);
108 exi_rm_stat_ptr(exoid, &exoII_ns);
109 exi_rm_stat_ptr(exoid, &exoII_es);
110 exi_rm_stat_ptr(exoid, &exoII_fs);
111 exi_rm_stat_ptr(exoid, &exoII_ss);
112 exi_rm_stat_ptr(exoid, &exoII_els);
113 exi_rm_stat_ptr(exoid, &exoII_nm);
114 exi_rm_stat_ptr(exoid, &exoII_edm);
115 exi_rm_stat_ptr(exoid, &exoII_fam);
116 exi_rm_stat_ptr(exoid, &exoII_em);
117
118 exi_conv_exit(exoid);
119
120 status = EX_NOERR;
121 if (status1 != NC_NOERR || status2 != NC_NOERR) {
122 status = EX_FATAL;
123 }
124 EX_FUNC_LEAVE(status);
125 }