| 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 |
* expnv - ex_put_partial_nodal_var |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int time_step whole time step number |
| 16 |
* int nodel_var_index index of desired nodal variable |
| 17 |
* int start_node index (1-based) of first node to put |
| 18 |
* int num_nodes number of nodal points |
| 19 |
* float* nodal_var_vals array of nodal variable values |
| 20 |
* |
| 21 |
* exit conditions - |
| 22 |
* |
| 23 |
* revision history - |
| 24 |
* |
| 25 |
* |
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
#include "exodusII.h" // for ex_err, etc |
| 29 |
#include "exodusII_int.h" // for EX_WARN, exi_comp_ws, etc |
| 30 |
|
| 31 |
/*! |
| 32 |
\internal |
| 33 |
\ingroup ResultsData |
| 34 |
\note This function is called internally by ex_put_partial_var() to handle |
| 35 |
the reading of nodal variable values. |
| 36 |
|
| 37 |
* writes the values of a single nodal variable for a partial block at |
| 38 |
* one single time step to the database; assume the first time step |
| 39 |
* and nodal variable index is 1 |
| 40 |
* \param exoid exodus file id |
| 41 |
* \param time_step whole time step number |
| 42 |
* \param nodal_var_index index of desired nodal variable |
| 43 |
* \param start_node index of first node to write data for (1-based) |
| 44 |
* \param num_nodes number of nodal points |
| 45 |
* \param nodal_var_vals array of nodal variable values |
| 46 |
*/ |
| 47 |
|
| 48 |
int exi_put_partial_nodal_var(int exoid, int time_step, int nodal_var_index, int64_t start_node, |
| 49 |
int64_t num_nodes, const void *nodal_var_vals) |
| 50 |
|
| 51 |
{ |
| 52 |
int status; |
| 53 |
int varid; |
| 54 |
size_t start[3], count[3]; |
| 55 |
char errmsg[MAX_ERR_LENGTH]; |
| 56 |
|
| 57 |
EX_FUNC_ENTER(); |
| 58 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 59 |
EX_FUNC_LEAVE(EX_FATAL); |
| 60 |
} |
| 61 |
|
| 62 |
if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) { |
| 63 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d", |
| 64 |
nodal_var_index, exoid); |
| 65 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 66 |
EX_FUNC_LEAVE(EX_WARN); |
| 67 |
} |
| 68 |
|
| 69 |
start[0] = --time_step; |
| 70 |
start[1] = --start_node; |
| 71 |
|
| 72 |
count[0] = 1; |
| 73 |
count[1] = num_nodes; |
| 74 |
if (num_nodes == 0) { |
| 75 |
start[1] = 0; |
| 76 |
} |
| 77 |
|
| 78 |
if (exi_comp_ws(exoid) == 4) { |
| 79 |
status = nc_put_vara_float(exoid, varid, start, count, nodal_var_vals); |
| 80 |
} |
| 81 |
else { |
| 82 |
status = nc_put_vara_double(exoid, varid, start, count, nodal_var_vals); |
| 83 |
} |
| 84 |
|
| 85 |
if (status != NC_NOERR) { |
| 86 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store nodal variables in file id %d", exoid); |
| 87 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 88 |
EX_FUNC_LEAVE(EX_FATAL); |
| 89 |
} |
| 90 |
EX_FUNC_LEAVE(EX_NOERR); |
| 91 |
} |