Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_partial_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_is_parallel, 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 offset The initial entity (1-based) to be output
36 * \param num_to_put The number of entities to output
37 * \param *set_entry_list array of entries in set. Set to NULL to not
38 * write.
39 * \param *set_extra_list array of extras in set. Set to NULL to not
40 * write.
41 */
42
43 int ex_put_partial_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t offset,
44 int64_t num_to_put, const void_int *set_entry_list,
45 const void_int *set_extra_list)
46 {
47 int dimid, status;
48 int entry_list_id, extra_list_id, set_id_ndx;
49 size_t start[1], count[1];
50 char errmsg[MAX_ERR_LENGTH];
51 char *entryptr = NULL;
52 char *extraptr = NULL;
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 /* first check if any sets are specified */
61 if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
62 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %ss defined in file id %d",
63 ex_name_of_object(set_type), exoid);
64 ex_err_fn(exoid, __func__, errmsg, status);
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67
68 /* Lookup index of set id in VAR_*S_IDS array */
69 set_id_ndx = exi_id_lkup(exoid, set_type, set_id);
70 if (set_id_ndx <= 0) {
71 ex_get_err(NULL, NULL, &status);
72
73 if (status != 0) {
74 if (status == EX_NULLENTITY) {
75 snprintf(errmsg, MAX_ERR_LENGTH,
76 "Warning: no data allowed for NULL %s %" PRId64 " in file id %d",
77 ex_name_of_object(set_type), set_id, exoid);
78 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
79 EX_FUNC_LEAVE(EX_WARN);
80 }
81 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s id %" PRId64 " in file id %d",
82 ex_name_of_object(set_type), set_id, exoid);
83 ex_err_fn(exoid, __func__, errmsg, status);
84 EX_FUNC_LEAVE(EX_FATAL);
85 }
86 }
87 /* setup more pointers based on set_type */
88 if (set_type == EX_NODE_SET) {
89 entryptr = VAR_NODE_NS(set_id_ndx);
90 extraptr = NULL;
91 }
92 else if (set_type == EX_EDGE_SET) {
93 entryptr = VAR_EDGE_ES(set_id_ndx);
94 extraptr = VAR_ORNT_ES(set_id_ndx);
95 }
96 else if (set_type == EX_FACE_SET) {
97 entryptr = VAR_FACE_FS(set_id_ndx);
98 extraptr = VAR_ORNT_FS(set_id_ndx);
99 }
100 else if (set_type == EX_SIDE_SET) {
101 entryptr = VAR_ELEM_SS(set_id_ndx);
102 extraptr = VAR_SIDE_SS(set_id_ndx);
103 }
104 else if (set_type == EX_ELEM_SET) {
105 entryptr = VAR_ELEM_ELS(set_id_ndx);
106 extraptr = NULL;
107 }
108
109 /* inquire id's of previously defined variables */
110 if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) {
111 snprintf(errmsg, MAX_ERR_LENGTH,
112 "ERROR: failed to locate entry list for %s %" PRId64 " in file id %d",
113 ex_name_of_object(set_type), set_id, exoid);
114 ex_err_fn(exoid, __func__, errmsg, status);
115 EX_FUNC_LEAVE(EX_FATAL);
116 }
117
118 /* write out the entry list and extra list arrays */
119 if (set_entry_list != NULL || exi_is_parallel(exoid)) {
120 start[0] = offset - 1;
121 count[0] = num_to_put;
122 if (count[0] == 0) {
123 start[0] = 0;
124 }
125
126 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
127 status = nc_put_vara_longlong(exoid, entry_list_id, start, count, set_entry_list);
128 }
129 else {
130 status = nc_put_vara_int(exoid, entry_list_id, start, count, set_entry_list);
131 }
132
133 if (status != NC_NOERR) {
134 snprintf(errmsg, MAX_ERR_LENGTH,
135 "ERROR: failed to store entry list for %s %" PRId64 " in file id %d",
136 ex_name_of_object(set_type), set_id, exoid);
137 ex_err_fn(exoid, __func__, errmsg, status);
138 EX_FUNC_LEAVE(EX_FATAL);
139 }
140 }
141
142 /* only do for edge, face and side sets */
143 if (extraptr && (set_extra_list != NULL || exi_is_parallel(exoid))) {
144 if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) {
145 snprintf(errmsg, MAX_ERR_LENGTH,
146 "ERROR: failed to locate extra list for %s %" PRId64 " in file id %d",
147 ex_name_of_object(set_type), set_id, exoid);
148 ex_err_fn(exoid, __func__, errmsg, status);
149 EX_FUNC_LEAVE(EX_FATAL);
150 }
151
152 start[0] = offset - 1;
153 count[0] = num_to_put;
154 if (count[0] == 0) {
155 start[0] = 0;
156 }
157 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
158 status = nc_put_vara_longlong(exoid, extra_list_id, start, count, set_extra_list);
159 }
160 else {
161 status = nc_put_vara_int(exoid, extra_list_id, start, count, set_extra_list);
162 }
163
164 if (status != NC_NOERR) {
165 snprintf(errmsg, MAX_ERR_LENGTH,
166 "ERROR: failed to store extra list for %s %" PRId64 " in file id %d",
167 ex_name_of_object(set_type), set_id, exoid);
168 ex_err_fn(exoid, __func__, errmsg, status);
169 EX_FUNC_LEAVE(EX_FATAL);
170 }
171 }
172
173 /* warn if extra data was sent in for node sets and elem sets */
174 if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) && set_extra_list != NULL) {
175 snprintf(errmsg, MAX_ERR_LENGTH,
176 "Warning: extra list was ignored for %s %" PRId64 " in file id %d",
177 ex_name_of_object(set_type), set_id, exoid);
178 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
179 EX_FUNC_LEAVE(EX_WARN);
180 }
181
182 EX_FUNC_LEAVE(EX_NOERR);
183 }