Debian Codegraph @

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

raw
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 *
10 * expss - ex_put_set
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int set_type set type
16 * int set_id set id
17 * int* set_entry_list array of entries in set
18 * int* set_extra_list array of extras in set
19
20 * exit conditions -
21 *
22 * revision history -
23 *
24 *
25 *****************************************************************************/
26
27 #include "exodusII.h" // for ex_err, ex_name_of_object, etc
28 #include "exodusII_int.h" // for exi_check_valid_file_id, etc
29
30 /*!
31 * writes the set entry list and set extra list for a single set
32 * \param exoid exodus file id
33 * \param set_type set type
34 * \param set_id set id
35 * \param *set_entry_list array of entries in set. Set to NULL to not
36 * write.
37 * \param *set_extra_list array of extras in set. Set to NULL to not
38 * write.
39 */
40
41 int ex_put_set(int exoid, ex_entity_type set_type, ex_entity_id set_id,
42 const void_int *set_entry_list, const void_int *set_extra_list)
43 {
44 int dimid, status;
45 int entry_list_id, extra_list_id, set_id_ndx;
46 char errmsg[MAX_ERR_LENGTH];
47 char *entryptr = NULL;
48 char *extraptr = NULL;
49
50 EX_FUNC_ENTER();
51
52 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
53 EX_FUNC_LEAVE(EX_FATAL);
54 }
55
56 /* first check if any sets are specified */
57 if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
58 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %ss defined in file id %d",
59 ex_name_of_object(set_type), exoid);
60 ex_err_fn(exoid, __func__, errmsg, status);
61 EX_FUNC_LEAVE(EX_FATAL);
62 }
63
64 /* Lookup index of set id in VAR_*S_IDS array */
65 set_id_ndx = exi_id_lkup(exoid, set_type, set_id);
66 if (set_id_ndx <= 0) {
67 ex_get_err(NULL, NULL, &status);
68
69 if (status != 0) {
70 if (status == EX_NULLENTITY) {
71 snprintf(errmsg, MAX_ERR_LENGTH,
72 "Warning: no data allowed for NULL %s %" PRId64 " in file id %d",
73 ex_name_of_object(set_type), set_id, exoid);
74 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
75 EX_FUNC_LEAVE(EX_WARN);
76 }
77 snprintf(errmsg, MAX_ERR_LENGTH,
78 "ERROR: failed to locate %s id %" PRId64 " in VAR_*S_IDS array in file id %d",
79 ex_name_of_object(set_type), set_id, exoid);
80 ex_err_fn(exoid, __func__, errmsg, status);
81 EX_FUNC_LEAVE(EX_FATAL);
82 }
83 }
84
85 /* setup more pointers based on set_type */
86 if (set_type == EX_NODE_SET) {
87 entryptr = VAR_NODE_NS(set_id_ndx);
88 extraptr = NULL;
89 }
90 else if (set_type == EX_EDGE_SET) {
91 entryptr = VAR_EDGE_ES(set_id_ndx);
92 extraptr = VAR_ORNT_ES(set_id_ndx);
93 }
94 else if (set_type == EX_FACE_SET) {
95 entryptr = VAR_FACE_FS(set_id_ndx);
96 extraptr = VAR_ORNT_FS(set_id_ndx);
97 }
98 else if (set_type == EX_SIDE_SET) {
99 entryptr = VAR_ELEM_SS(set_id_ndx);
100 extraptr = VAR_SIDE_SS(set_id_ndx);
101 }
102 else if (set_type == EX_ELEM_SET) {
103 entryptr = VAR_ELEM_ELS(set_id_ndx);
104 extraptr = NULL;
105 }
106
107 /* inquire id's of previously defined variables */
108 if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) {
109 snprintf(errmsg, MAX_ERR_LENGTH,
110 "ERROR: failed to locate entry list for %s %" PRId64 " in file id %d",
111 ex_name_of_object(set_type), set_id, exoid);
112 ex_err_fn(exoid, __func__, errmsg, status);
113 EX_FUNC_LEAVE(EX_FATAL);
114 }
115
116 /* only do for edge, face and side sets */
117 if (extraptr) {
118 if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) {
119 snprintf(errmsg, MAX_ERR_LENGTH,
120 "ERROR: failed to locate extra list for %s %" PRId64 " in file id %d",
121 ex_name_of_object(set_type), set_id, exoid);
122 ex_err_fn(exoid, __func__, errmsg, status);
123 EX_FUNC_LEAVE(EX_FATAL);
124 }
125 }
126
127 /* write out the entry list and extra list arrays */
128 if (set_entry_list != NULL) {
129
130 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
131 status = nc_put_var_longlong(exoid, entry_list_id, set_entry_list);
132 }
133 else {
134 status = nc_put_var_int(exoid, entry_list_id, set_entry_list);
135 }
136
137 if (status != NC_NOERR) {
138 snprintf(errmsg, MAX_ERR_LENGTH,
139 "ERROR: failed to store entry list for %s %" PRId64 " in file id %d",
140 ex_name_of_object(set_type), set_id, exoid);
141 ex_err_fn(exoid, __func__, errmsg, status);
142 EX_FUNC_LEAVE(EX_FATAL);
143 }
144 }
145
146 /* only do for edge, face and side sets */
147 if (extraptr && set_extra_list != NULL) {
148
149 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
150 status = nc_put_var_longlong(exoid, extra_list_id, set_extra_list);
151 }
152 else {
153 status = nc_put_var_int(exoid, extra_list_id, set_extra_list);
154 }
155
156 if (status != NC_NOERR) {
157 snprintf(errmsg, MAX_ERR_LENGTH,
158 "ERROR: failed to store extra list for %s %" PRId64 " in file id %d",
159 ex_name_of_object(set_type), set_id, exoid);
160 ex_err_fn(exoid, __func__, errmsg, status);
161 EX_FUNC_LEAVE(EX_FATAL);
162 }
163 }
164
165 /* warn if extra data was sent in for node sets and elem sets */
166 if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) && set_extra_list != NULL) {
167 snprintf(errmsg, MAX_ERR_LENGTH,
168 "Warning: extra list was ignored for %s %" PRId64 " in file id %d",
169 ex_name_of_object(set_type), set_id, exoid);
170 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
171 EX_FUNC_LEAVE(EX_WARN);
172 }
173
174 EX_FUNC_LEAVE(EX_NOERR);
175 }