Debian Codegraph @

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