| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021, 2024 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 |
* expvan - ex_put_variable_names |
| 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 num_vars # of variables to read |
| 17 |
* char* var_names ptr array of variable names |
| 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_FATAL, etc |
| 28 |
|
| 29 |
static int ex_put_var_names_int(int exoid, ex_entity_type obj_type, int num_vars, char *tname, |
| 30 |
char *dnumvar, char *vnames, int *varid) |
| 31 |
{ |
| 32 |
int status; |
| 33 |
int dimid; |
| 34 |
|
| 35 |
if ((status = nc_inq_dimid(exoid, dnumvar, &dimid)) != NC_NOERR) { |
| 36 |
if (status != NC_NOERR) { |
| 37 |
/* ex_put_reduction_variable_param was not called. Call it now */ |
| 38 |
EX_FUNC_UNLOCK(); |
| 39 |
ex_put_reduction_variable_param(exoid, obj_type, num_vars); |
| 40 |
EX_FUNC_ENTER(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
if ((status = nc_inq_varid(exoid, vnames, varid)) != NC_NOERR) { |
| 45 |
if (status == NC_ENOTVAR) { |
| 46 |
char errmsg[MAX_ERR_LENGTH]; |
| 47 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s variable names defined in file id %d", tname, |
| 48 |
exoid); |
| 49 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 50 |
} |
| 51 |
else { |
| 52 |
char errmsg[MAX_ERR_LENGTH]; |
| 53 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s name variable names not found in file id %d", |
| 54 |
tname, exoid); |
| 55 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 56 |
} |
| 57 |
return EX_FATAL; |
| 58 |
} |
| 59 |
return EX_NOERR; |
| 60 |
} |
| 61 |
|
| 62 |
/*! |
| 63 |
\ingroup ResultsData |
| 64 |
|
| 65 |
The function ex_put_variable_names() writes the names of the results |
| 66 |
variables to the database. The maximum length of the names returned is |
| 67 |
specified by the return value from ex_inquire_int()(exoid, |
| 68 |
EX_INQ_MAX_READ_NAME_LENGTH). The function ex_put_variable_param() |
| 69 |
must be called before this function is invoked. |
| 70 |
|
| 71 |
\return In case of an error, ex_put_variable_names() returns a negative |
| 72 |
number; a warning will return a positive number. Possible causes of |
| 73 |
errors include: |
| 74 |
- data file not properly opened with call to ex_create() or ex_open() |
| 75 |
- data file not initialized properly with call to ex_put_init(). |
| 76 |
- invalid variable type specified. |
| 77 |
- ex_put_variable_param() was not called previously or was |
| 78 |
called with zero variables of the specified type. |
| 79 |
- ex_put_variable_names() has been called previously for the |
| 80 |
specified variable type. |
| 81 |
|
| 82 |
\param[in] exoid exodus file ID returned from a previous call to |
| 83 |
ex_create() or ex_open(). |
| 84 |
\param[in] obj_type Variable indicating the type of variable which is |
| 85 |
described. |
| 86 |
Use one of the options in the table below. |
| 87 |
\param[in] num_vars The number of var_type variables that will be written |
| 88 |
to the database. |
| 89 |
\param[in] var_names Array of pointers to num_vars variable names. |
| 90 |
|
| 91 |
| ex_entity_type| description | |
| 92 |
|---------------|---------------------------| |
| 93 |
| #EX_GLOBAL | Global entity type | |
| 94 |
| #EX_NODAL | Nodal entity type | |
| 95 |
| #EX_NODE_SET | Node Set entity type | |
| 96 |
| #EX_EDGE_BLOCK | Edge Block entity type | |
| 97 |
| #EX_EDGE_SET | Edge Set entity type | |
| 98 |
| #EX_FACE_BLOCK | Face Block entity type | |
| 99 |
| #EX_FACE_SET | Face Set entity type | |
| 100 |
| #EX_ELEM_BLOCK | Element Block entity type| |
| 101 |
| #EX_ELEM_SET | Element Set entity type | |
| 102 |
| #EX_SIDE_SET | Side Set entity type | |
| 103 |
|
| 104 |
The following coding will write out the names associated with the |
| 105 |
nodal variables: |
| 106 |
~~~{.c} |
| 107 |
int num_nod_vars, error, exoid; |
| 108 |
char *var_names[2]; |
| 109 |
|
| 110 |
\comment{write results variables parameters and names} |
| 111 |
num_nod_vars = 2; |
| 112 |
|
| 113 |
var_names[0] = "disx"; |
| 114 |
var_names[1] = "disy"; |
| 115 |
|
| 116 |
error = ex_put_variable_param (exoid, EX_NODAL, num_nod_vars); |
| 117 |
error = ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names); |
| 118 |
~~~ |
| 119 |
|
| 120 |
*/ |
| 121 |
|
| 122 |
int ex_put_reduction_variable_names(int exoid, ex_entity_type obj_type, int num_vars, |
| 123 |
char *const var_names[]) |
| 124 |
{ |
| 125 |
int varid; |
| 126 |
|
| 127 |
EX_FUNC_ENTER(); |
| 128 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 129 |
EX_FUNC_LEAVE(EX_FATAL); |
| 130 |
} |
| 131 |
|
| 132 |
switch (obj_type) { |
| 133 |
case EX_GLOBAL: |
| 134 |
ex_put_var_names_int(exoid, obj_type, num_vars, "global", DIM_NUM_GLO_VAR, VAR_NAME_GLO_VAR, |
| 135 |
&varid); |
| 136 |
break; |
| 137 |
case EX_ASSEMBLY: |
| 138 |
ex_put_var_names_int(exoid, obj_type, num_vars, "assembly", DIM_NUM_ASSEMBLY_RED_VAR, |
| 139 |
VAR_NAME_ASSEMBLY_RED_VAR, &varid); |
| 140 |
break; |
| 141 |
case EX_BLOB: |
| 142 |
ex_put_var_names_int(exoid, obj_type, num_vars, "blob", DIM_NUM_BLOB_RED_VAR, |
| 143 |
VAR_NAME_BLOB_RED_VAR, &varid); |
| 144 |
break; |
| 145 |
case EX_EDGE_BLOCK: |
| 146 |
ex_put_var_names_int(exoid, obj_type, num_vars, "edge", DIM_NUM_EDG_RED_VAR, |
| 147 |
VAR_NAME_EDG_RED_VAR, &varid); |
| 148 |
break; |
| 149 |
case EX_FACE_BLOCK: |
| 150 |
ex_put_var_names_int(exoid, obj_type, num_vars, "face", DIM_NUM_FAC_RED_VAR, |
| 151 |
VAR_NAME_FAC_RED_VAR, &varid); |
| 152 |
break; |
| 153 |
case EX_ELEM_BLOCK: |
| 154 |
ex_put_var_names_int(exoid, obj_type, num_vars, "element", DIM_NUM_ELE_RED_VAR, |
| 155 |
VAR_NAME_ELE_RED_VAR, &varid); |
| 156 |
break; |
| 157 |
case EX_NODE_SET: |
| 158 |
ex_put_var_names_int(exoid, obj_type, num_vars, "node set", DIM_NUM_NSET_RED_VAR, |
| 159 |
VAR_NAME_NSET_RED_VAR, &varid); |
| 160 |
break; |
| 161 |
case EX_EDGE_SET: |
| 162 |
ex_put_var_names_int(exoid, obj_type, num_vars, "edge set", DIM_NUM_ESET_RED_VAR, |
| 163 |
VAR_NAME_ESET_RED_VAR, &varid); |
| 164 |
break; |
| 165 |
case EX_FACE_SET: |
| 166 |
ex_put_var_names_int(exoid, obj_type, num_vars, "face set", DIM_NUM_FSET_RED_VAR, |
| 167 |
VAR_NAME_FSET_RED_VAR, &varid); |
| 168 |
break; |
| 169 |
case EX_SIDE_SET: |
| 170 |
ex_put_var_names_int(exoid, obj_type, num_vars, "side set", DIM_NUM_SSET_RED_VAR, |
| 171 |
VAR_NAME_SSET_RED_VAR, &varid); |
| 172 |
break; |
| 173 |
case EX_ELEM_SET: |
| 174 |
ex_put_var_names_int(exoid, obj_type, num_vars, "element set", DIM_NUM_ELSET_RED_VAR, |
| 175 |
VAR_NAME_ELSET_RED_VAR, &varid); |
| 176 |
break; |
| 177 |
default: { |
| 178 |
char errmsg[MAX_ERR_LENGTH]; |
| 179 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid variable type %d specified in file id %d", |
| 180 |
obj_type, exoid); |
| 181 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 182 |
EX_FUNC_LEAVE(EX_FATAL); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
/* write EXODUS variable names */ |
| 187 |
int status = exi_put_names(exoid, varid, num_vars, var_names, obj_type, "variable", __func__); |
| 188 |
EX_FUNC_LEAVE(status); |
| 189 |
} |