Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_partial_set_dist_fact.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 * expssd - ex_put_partial_set_dist_fact
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 offset index (1-based) of first dist factor to
18 write
19 * int num_to_put number of dist factors to write.
20 * void* set_dist_fact array of dist factors for set
21
22 * exit conditions -
23 *
24 * revision history -
25 *
26 *
27 *****************************************************************************/
28
29 #include "exodusII.h" // for ex_err, ex_name_of_object, etc
30 #include "exodusII_int.h" // for exi_check_valid_file_id, etc
31
32 /*!
33 * writes the partial distribution factors for a single set
34 * \param exoid exodus file id
35 * \param set_type set type
36 * \param set_id set id
37 * \param offset index (1-based) of first dist factor to write
38 * \param num_to_put number of dist factors to write.
39 * \param *set_dist_fact array of dist factors for set
40 */
41
42 int ex_put_partial_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id,
43 int64_t offset, int64_t num_to_put, const void *set_dist_fact)
44 {
45 int status;
46 int dimid, set_id_ndx;
47 int dist_id;
48 size_t start[1], count[1];
49 char errmsg[MAX_ERR_LENGTH];
50 char *factptr = NULL;
51
52 EX_FUNC_ENTER();
53
54 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
55 EX_FUNC_LEAVE(EX_FATAL);
56 }
57
58 /* first check if any sets are specified */
59 if ((status = nc_inq_dimid(exoid, exi_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
60 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %ss specified in file id %d",
61 ex_name_of_object(set_type), exoid);
62 ex_err_fn(exoid, __func__, errmsg, status);
63 EX_FUNC_LEAVE(EX_FATAL);
64 }
65
66 /* Lookup index of set id in VAR_*S_IDS array */
67 set_id_ndx = exi_id_lkup(exoid, set_type, set_id);
68 if (set_id_ndx <= 0) {
69 ex_get_err(NULL, NULL, &status);
70
71 if (status != 0) {
72 if (status == EX_NULLENTITY) {
73 snprintf(errmsg, MAX_ERR_LENGTH,
74 "Warning: no data allowed for NULL %s %" PRId64 " in file id %d",
75 ex_name_of_object(set_type), set_id, exoid);
76 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
77 EX_FUNC_LEAVE(EX_WARN);
78 }
79 snprintf(errmsg, MAX_ERR_LENGTH,
80 "ERROR: failed to locate %s id %" PRId64 " in VAR_*S_IDS array in file id %d",
81 ex_name_of_object(set_type), set_id, exoid);
82 ex_err_fn(exoid, __func__, errmsg, status);
83 EX_FUNC_LEAVE(EX_FATAL);
84 }
85 }
86
87 /* setup more pointers based on set_type */
88 if (set_type == EX_NODE_SET) {
89 /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
90 factptr = VAR_FACT_NS(set_id_ndx);
91 }
92 else if (set_type == EX_EDGE_SET) {
93 factptr = VAR_FACT_ES(set_id_ndx);
94 }
95 else if (set_type == EX_FACE_SET) {
96 factptr = VAR_FACT_FS(set_id_ndx);
97 }
98 else if (set_type == EX_SIDE_SET) {
99 factptr = VAR_FACT_SS(set_id_ndx);
100 }
101 if (set_type == EX_ELEM_SET) {
102 factptr = VAR_FACT_ELS(set_id_ndx);
103 }
104
105 /* find id of distribution factors variable
106 */
107
108 if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) {
109 /* this test is only needed for node set because we're using
110 DIM_NUM_NOD_NS instead of DIM_NUM_DF_NS*/
111 if (status == NC_ENOTVAR) {
112 snprintf(errmsg, MAX_ERR_LENGTH,
113 "Warning: no dist factors defined for %s %" PRId64 " in file id %d",
114 ex_name_of_object(set_type), set_id, exoid);
115 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
116 EX_FUNC_LEAVE(EX_WARN);
117 }
118 snprintf(errmsg, MAX_ERR_LENGTH,
119 "ERROR: failed to locate dist factors list for %s %" PRId64 " in file id %d",
120 ex_name_of_object(set_type), set_id, exoid);
121 ex_err_fn(exoid, __func__, errmsg, status);
122 EX_FUNC_LEAVE(EX_FATAL);
123 }
124
125 start[0] = offset - 1;
126 count[0] = num_to_put;
127 if (num_to_put == 0) {
128 start[0] = 0;
129 }
130
131 /* write out the distribution factors array */
132 if (exi_comp_ws(exoid) == 4) {
133 status = nc_put_vara_float(exoid, dist_id, start, count, set_dist_fact);
134 }
135 else {
136 status = nc_put_vara_double(exoid, dist_id, start, count, set_dist_fact);
137 }
138
139 if (status != NC_NOERR) {
140 snprintf(errmsg, MAX_ERR_LENGTH,
141 "ERROR: failed to store dist factors for %s %" PRId64 " in file id %d",
142 ex_name_of_object(set_type), set_id, exoid);
143 ex_err_fn(exoid, __func__, errmsg, status);
144 EX_FUNC_LEAVE(EX_FATAL);
145 }
146 EX_FUNC_LEAVE(EX_NOERR);
147 }