Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_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 *
10 * expvnm - ex_put_variable_name
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int obj_type variable type: G,N, or E
16 * int var_num variable number name to write 1..num_var
17 * char* var_name ptr of variable name
18 *
19 * exit conditions -
20 *
21 * revision history -
22 *
23 *
24 *****************************************************************************/
25
26 #include "exodusII.h" // for ex_err, etc
27 #include "exodusII_int.h" // for EX_WARN, etc
28
29 /*!
30 \ingroup ResultsData
31
32 * writes the name of a particular results variable to the database
33 * \param exoid exodus file id
34 * \param obj_type variable type
35 * \param var_num variable number name to write 1..num_var
36 * \param *var_name ptr of variable name
37 */
38
39 int ex_put_reduction_variable_name(int exoid, ex_entity_type obj_type, int var_num,
40 const char *var_name)
41 {
42 int status;
43 int varid;
44 char errmsg[MAX_ERR_LENGTH];
45 const char *vname;
46
47 EX_FUNC_ENTER();
48
49 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
50 EX_FUNC_LEAVE(EX_FATAL);
51 }
52
53 /* inquire previously defined variables */
54 switch (obj_type) {
55 case EX_GLOBAL: vname = VAR_NAME_GLO_VAR; break;
56 case EX_EDGE_BLOCK: vname = VAR_NAME_EDG_RED_VAR; break;
57 case EX_FACE_BLOCK: vname = VAR_NAME_FAC_RED_VAR; break;
58 case EX_ELEM_BLOCK: vname = VAR_NAME_ELE_RED_VAR; break;
59 case EX_NODE_SET: vname = VAR_NAME_NSET_RED_VAR; break;
60 case EX_EDGE_SET: vname = VAR_NAME_ESET_RED_VAR; break;
61 case EX_FACE_SET: vname = VAR_NAME_FSET_RED_VAR; break;
62 case EX_SIDE_SET: vname = VAR_NAME_SSET_RED_VAR; break;
63 case EX_ELEM_SET: vname = VAR_NAME_ELSET_RED_VAR; break;
64 default:
65 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid variable type (%d) given for file id %d",
66 obj_type, exoid);
67 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
68 EX_FUNC_LEAVE(EX_WARN);
69 }
70
71 if ((status = nc_inq_varid(exoid, vname, &varid)) != NC_NOERR) {
72 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %s variables names stored in file id %d",
73 ex_name_of_object(obj_type), exoid);
74 ex_err_fn(exoid, __func__, errmsg, status);
75 EX_FUNC_LEAVE(EX_WARN);
76 }
77
78 /* write EXODUS variable name */
79 status = exi_put_name(exoid, varid, var_num - 1, var_name, obj_type, "variable", __func__);
80
81 EX_FUNC_LEAVE(status);
82 }