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 * exgssd - ex_get_set_dist_fact
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int set_type type of set
16 * int set_id set id
17 *
18 * exit conditions -
19 * float* set_dist_fact array of dist factors for set
20 *
21 * revision history -
22 *
23 *
24 *****************************************************************************/
25
26 #include "exodusII.h" // for ex_err, ex_name_of_object, etc
27 #include "exodusII_int.h" // for EX_FATAL, EX_WARN, etc
28
29 /*!
30 * reads the distribution factors for a single set
31 */
32
ex_get_set_dist_fact(int exoid,ex_entity_type set_type,ex_entity_id set_id,void * set_dist_fact)33 int ex_get_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id,
34 void *set_dist_fact)
35 {
36
37 int dimid, dist_id, set_id_ndx;
38 int status;
39 char errmsg[MAX_ERR_LENGTH];
40 char *factptr = NULL;
41
42 EX_FUNC_ENTER();
43 if (ex__check_valid_file_id(exoid, __func__) == EX_FATAL) {
44 EX_FUNC_LEAVE(EX_FATAL);
45 }
46
47 /* first check if any sets are specified */
48 if ((status = nc_inq_dimid(exoid, ex__dim_num_objects(set_type), &dimid)) != NC_NOERR) {
49 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %s sets stored in file id %d",
50 ex_name_of_object(set_type), exoid);
51 ex_err_fn(exoid, __func__, errmsg, status);
52 EX_FUNC_LEAVE(EX_WARN);
53 }
54
55 /* Lookup index of set id in VAR_*S_IDS array */
56 set_id_ndx = ex__id_lkup(exoid, set_type, set_id);
57 if (set_id_ndx <= 0) {
58 ex_get_err(NULL, NULL, &status);
59
60 if (status != 0) {
61 if (status == EX_NULLENTITY) {
62 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s set %" PRId64 " is NULL in file id %d",
63 ex_name_of_object(set_type), set_id, exoid);
64 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
65 EX_FUNC_LEAVE(EX_WARN);
66 }
67 snprintf(errmsg, MAX_ERR_LENGTH,
68 "ERROR: failed to locate %s set %" PRId64 " in VAR_*S_IDS array in file id %d",
69 ex_name_of_object(set_type), set_id, exoid);
70 ex_err_fn(exoid, __func__, errmsg, status);
71 EX_FUNC_LEAVE(EX_FATAL);
72 }
73 }
74
75 /* setup more pointers based on set_type */
76 if (set_type == EX_NODE_SET) {
77 factptr = VAR_FACT_NS(set_id_ndx);
78 }
79 else if (set_type == EX_EDGE_SET) {
80 factptr = VAR_FACT_ES(set_id_ndx);
81 }
82 else if (set_type == EX_FACE_SET) {
83 factptr = VAR_FACT_FS(set_id_ndx);
84 }
85 else if (set_type == EX_SIDE_SET) {
86 factptr = VAR_FACT_SS(set_id_ndx);
87 }
88 if (set_type == EX_ELEM_SET) {
89 factptr = VAR_FACT_ELS(set_id_ndx);
90 }
91
92 /* inquire id's of previously defined dimensions and variables */
93 if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) {
94 /* not an error for node sets because this is how we check that df's exist
95 */
96 if (set_type == EX_NODE_SET) {
97 snprintf(errmsg, MAX_ERR_LENGTH,
98 "Warning: dist factors not stored for %s set %" PRId64 " in file id %d",
99 ex_name_of_object(set_type), set_id, exoid);
100 ex_err_fn(exoid, __func__, errmsg, status);
101 EX_FUNC_LEAVE(EX_WARN); /* complain - but not too loud */
102 }
103 /* is an error for other sets */
104
105 snprintf(errmsg, MAX_ERR_LENGTH,
106 "ERROR: failed to locate dist factors list for %s set %" PRId64 " in file id %d",
107 ex_name_of_object(set_type), set_id, exoid);
108 ex_err_fn(exoid, __func__, errmsg, status);
109 EX_FUNC_LEAVE(EX_FATAL);
110 }
111
112 /* read in the distribution factors array */
113 if (ex__comp_ws(exoid) == 4) {
114 status = nc_get_var_float(exoid, dist_id, set_dist_fact);
115 }
116 else {
117 status = nc_get_var_double(exoid, dist_id, set_dist_fact);
118 }
119
120 if (status != NC_NOERR) {
121 snprintf(errmsg, MAX_ERR_LENGTH,
122 "ERROR: failed to get dist factors list for %s set %" PRId64 " in file id %d",
123 ex_name_of_object(set_type), set_id, exoid);
124 ex_err_fn(exoid, __func__, errmsg, status);
125 EX_FUNC_LEAVE(EX_FATAL);
126 }
127 EX_FUNC_LEAVE(EX_NOERR);
128 }
129