Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_reduction_variable_param.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 #include "exodusII.h" // for ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
11
12 /*!
13 \ingroup ResultsData
14
15 The function ex_get_reduction_variable_param() reads the number of global,
16 nodal, or element variables stored in the database.
17
18 \return In case of an error, ex_get_reduction_variable_param() returns a negative
19 number; a warning will return a positive number. Possible causes of
20 errors include:
21 - data file not properly opened with call to ex_create() or ex_open()
22 - invalid variable type specified.
23
24 \param[in] exoid exodus file ID returned from a previous call to
25 ex_create() or ex_open().
26 \param[in] obj_type Variable indicating the type of reduction variable which is
27 described. Use one
28 of the options in the table below.
29 \param[out] num_vars Returned number of var_type variables that are stored
30 in the database.
31
32 | ex_entity_type| description |
33 |---------------|---------------------------|
34 | #EX_GLOBAL | Global entity type |
35 | #EX_NODE_SET | Node Set entity type |
36 | #EX_EDGE_BLOCK | Edge Block entity type |
37 | #EX_EDGE_SET | Edge Set entity type |
38 | #EX_FACE_BLOCK | Face Block entity type |
39 | #EX_FACE_SET | Face Set entity type |
40 | #EX_ELEM_BLOCK | Element Block entity type|
41 | #EX_ELEM_SET | Element Set entity type |
42 | #EX_SIDE_SET | Side Set entity type |
43
44 As an example, the following coding will determine the number of
45 global variables stored in the data file:
46
47 ~~~{.c}
48 int num_glo_vars, error, exoid;
49
50 \comment{read global variables parameters}
51 error = ex_get_variable_param(exoid, EX_GLOBAL, &num_glo_vars);
52 ~~~
53
54 */
55
56 int ex_get_reduction_variable_param(int exoid, ex_entity_type obj_type, int *num_vars)
57 {
58 int dimid;
59 size_t dimlen;
60 char errmsg[MAX_ERR_LENGTH];
61 const char *dnumvar;
62 int status;
63
64 EX_FUNC_ENTER();
65 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
66 EX_FUNC_LEAVE(EX_FATAL);
67 }
68
69 *num_vars = 0;
70
71 switch (obj_type) {
72 case EX_GLOBAL: dnumvar = DIM_NUM_GLO_VAR; break;
73 case EX_ASSEMBLY: dnumvar = DIM_NUM_ASSEMBLY_RED_VAR; break;
74 case EX_BLOB: dnumvar = DIM_NUM_BLOB_RED_VAR; break;
75 case EX_EDGE_BLOCK: dnumvar = DIM_NUM_EDG_RED_VAR; break;
76 case EX_FACE_BLOCK: dnumvar = DIM_NUM_FAC_RED_VAR; break;
77 case EX_ELEM_BLOCK: dnumvar = DIM_NUM_ELE_RED_VAR; break;
78 case EX_NODE_SET: dnumvar = DIM_NUM_NSET_RED_VAR; break;
79 case EX_EDGE_SET: dnumvar = DIM_NUM_ESET_RED_VAR; break;
80 case EX_FACE_SET: dnumvar = DIM_NUM_FSET_RED_VAR; break;
81 case EX_SIDE_SET: dnumvar = DIM_NUM_SSET_RED_VAR; break;
82 case EX_ELEM_SET: dnumvar = DIM_NUM_ELSET_RED_VAR; break;
83 default:
84 snprintf(errmsg, MAX_ERR_LENGTH,
85 "Warning: invalid reduction variable type %d requested from file id %d", obj_type,
86 exoid);
87 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
88 EX_FUNC_LEAVE(EX_WARN);
89 }
90
91 if ((status = nc_inq_dimid(exoid, dnumvar, &dimid)) != NC_NOERR) {
92 *num_vars = 0;
93 if (status == NC_EBADDIM) {
94 EX_FUNC_LEAVE(EX_NOERR); /* no reduction variables defined */
95 }
96
97 snprintf(errmsg, MAX_ERR_LENGTH,
98 "ERROR: failed to locate %s reduction variable names in file id %d",
99 ex_name_of_object(obj_type), exoid);
100 ex_err_fn(exoid, __func__, errmsg, status);
101 EX_FUNC_LEAVE(EX_FATAL);
102 }
103
104 if ((status = nc_inq_dimlen(exoid, dimid, &dimlen)) != NC_NOERR) {
105 snprintf(errmsg, MAX_ERR_LENGTH,
106 "ERROR: failed to get number of %s reduction variables in file id %d",
107 ex_name_of_object(obj_type), exoid);
108 ex_err_fn(exoid, __func__, errmsg, status);
109 EX_FUNC_LEAVE(EX_FATAL);
110 }
111 *num_vars = dimlen;
112
113 EX_FUNC_LEAVE(EX_NOERR);
114 }