Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_reduction_variable_name.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, etc
11
12 /*!
13 * \ingroup ResultsData
14 *
15 * reads the name of a particular results reduction variable from the database
16 */
17
18 int ex_get_reduction_variable_name(int exoid, ex_entity_type obj_type, int var_num, char *var_name)
19 {
20 int status;
21 int varid;
22 char errmsg[MAX_ERR_LENGTH];
23 const char *vname = NULL;
24
25 EX_FUNC_ENTER();
26 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
27 EX_FUNC_LEAVE(EX_FATAL);
28 }
29
30 /* inquire previously defined variables */
31
32 switch (obj_type) {
33 case EX_GLOBAL: vname = VAR_NAME_GLO_VAR; break;
34 case EX_ASSEMBLY: vname = VAR_NAME_ASSEMBLY_RED_VAR; break;
35 case EX_BLOB: vname = VAR_NAME_BLOB_RED_VAR; break;
36 case EX_EDGE_BLOCK: vname = VAR_NAME_EDG_RED_VAR; break;
37 case EX_FACE_BLOCK: vname = VAR_NAME_FAC_RED_VAR; break;
38 case EX_ELEM_BLOCK: vname = VAR_NAME_ELE_RED_VAR; break;
39 case EX_NODE_SET: vname = VAR_NAME_NSET_RED_VAR; break;
40 case EX_EDGE_SET: vname = VAR_NAME_ESET_RED_VAR; break;
41 case EX_FACE_SET: vname = VAR_NAME_FSET_RED_VAR; break;
42 case EX_SIDE_SET: vname = VAR_NAME_SSET_RED_VAR; break;
43 case EX_ELEM_SET: vname = VAR_NAME_ELSET_RED_VAR; break;
44 default:
45 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid variable type (%d) given for file id %d",
46 obj_type, exoid);
47 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
48 EX_FUNC_LEAVE(EX_FATAL);
49 }
50
51 if ((status = nc_inq_varid(exoid, vname, &varid)) != NC_NOERR) {
52 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %s variable names stored in file id %d",
53 ex_name_of_object(obj_type), exoid);
54 ex_err_fn(exoid, __func__, errmsg, status);
55 EX_FUNC_LEAVE(EX_WARN);
56 }
57
58 /* read the variable name */
59 {
60 int db_name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
61 int api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
62 int name_size = db_name_size < api_name_size ? db_name_size : api_name_size;
63
64 status = exi_get_name(exoid, varid, var_num - 1, var_name, name_size, obj_type, __func__);
65 if (status != NC_NOERR) {
66 EX_FUNC_LEAVE(EX_FATAL);
67 }
68 }
69 EX_FUNC_LEAVE(EX_NOERR);
70 }