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_WARN, etc
11
12 /*!
13 \ingroup ResultsData
14
15 The function ex_get_variable_names() reads the names of the results
16 variables from the database. Memory must be allocated for the name
17 array before this function is invoked.
18
19 \return In case of an error, ex_get_variable_names() returns a
20 negative number; a warning will return a positive number. Possible
21 causes of errors include:
22 - data file not properly opened with call to ex_create() or ex_open()
23 - invalid variable type specified.
24 - a warning value is returned if no variables of the specified
25 type are stored in the file.
26
27 \param[in] exoid exodus file ID returned from a previous call to
28 ex_create() or ex_open().
29 \param[in] obj_type Variable indicating the type of variable which is
30 described. Use one
31 of the options in the table below.
32 \param[in] num_vars The number of var_type variables that will be read
33 from the database.
34 \param[out] var_names Returned array of pointers to num_vars variable names.
35
36 | ex_entity_type| description |
37 |---------------|---------------------------|
38 | #EX_GLOBAL | Global entity type |
39 | #EX_NODE_SET | Node Set entity type |
40 | #EX_EDGE_BLOCK | Edge Block entity type |
41 | #EX_EDGE_SET | Edge Set entity type |
42 | #EX_FACE_BLOCK | Face Block entity type |
43 | #EX_FACE_SET | Face Set entity type |
44 | #EX_ELEM_BLOCK | Element Block entity type|
45 | #EX_ELEM_SET | Element Set entity type |
46 | #EX_SIDE_SET | Side Set entity type |
47
48 As an example, the following code segment will read the names of the
49 nodal variables stored in the data file:
50
51 ~~~{.c}
52 int error, exoid, num_assem_vars;
53 char *var_names[10];
54
55 \comment{read assembly variables parameters and names}
56 error = ex_get_reduction_variable_param(exoid, EX_ASSEMBLY, &num_assem_vars);
57 int name_len = ex_inquire_int(exoid, EX_INT_MAX_READ_NAME_LENGTH);
58 for (i=0; i < num_assem_vars; i++) {
59 var_names[i] = (char *) calloc ((name_len+1), sizeof(char));
60 }
61 error = ex_get_reduction_variable_names(exoid, EX_ASSEMBLY, num_assem_vars, var_names);
62 ~~~
63
64 */
65
ex_get_reduction_variable_names(int exoid,ex_entity_type obj_type,int num_vars,char * var_names[])66 int ex_get_reduction_variable_names(int exoid, ex_entity_type obj_type, int num_vars,
67 char *var_names[])
68 {
69 int varid, status;
70 char errmsg[MAX_ERR_LENGTH];
71 const char *vvarname;
72
73 EX_FUNC_ENTER();
74 if (ex__check_valid_file_id(exoid, __func__) == EX_FATAL) {
75 EX_FUNC_LEAVE(EX_FATAL);
76 }
77
78 switch (obj_type) {
79 case EX_ASSEMBLY: vvarname = VAR_NAME_ASSEMBLY_RED_VAR; break;
80 case EX_BLOB: vvarname = VAR_NAME_BLOB_RED_VAR; break;
81 case EX_EDGE_BLOCK: vvarname = VAR_NAME_EDG_RED_VAR; break;
82 case EX_FACE_BLOCK: vvarname = VAR_NAME_FAC_RED_VAR; break;
83 case EX_ELEM_BLOCK: vvarname = VAR_NAME_ELE_RED_VAR; break;
84 case EX_NODE_SET: vvarname = VAR_NAME_NSET_RED_VAR; break;
85 case EX_EDGE_SET: vvarname = VAR_NAME_ESET_RED_VAR; break;
86 case EX_FACE_SET: vvarname = VAR_NAME_FSET_RED_VAR; break;
87 case EX_SIDE_SET: vvarname = VAR_NAME_SSET_RED_VAR; break;
88 case EX_ELEM_SET: vvarname = VAR_NAME_ELSET_RED_VAR; break;
89 case EX_GLOBAL: vvarname = VAR_NAME_GLO_VAR; break;
90 default:
91 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: invalid variable type %d requested from file id %d",
92 obj_type, exoid);
93 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
94 EX_FUNC_LEAVE(EX_WARN);
95 }
96
97 /* inquire previously defined variables */
98 if ((status = nc_inq_varid(exoid, vvarname, &varid)) != NC_NOERR) {
99 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %s variables names stored in file id %d",
100 ex_name_of_object(obj_type), exoid);
101 ex_err_fn(exoid, __func__, errmsg, status);
102 EX_FUNC_LEAVE(EX_WARN);
103 }
104
105 /* read the variable names */
106 status = ex__get_names(exoid, varid, num_vars, var_names, obj_type, __func__);
107 if (status != NC_NOERR) {
108 EX_FUNC_LEAVE(EX_FATAL);
109 }
110 EX_FUNC_LEAVE(EX_NOERR);
111 }
112