| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023, 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 |
#include "exodusII.h" // for ex_err, etc |
| 10 |
#include "exodusII_int.h" // for EX_WARN, exi_comp_ws, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
\internal |
| 14 |
\ingroup ResultsData |
| 15 |
\note This function is called internally by ex_put_var_time() to handle |
| 16 |
the writing of nodal variable values. |
| 17 |
|
| 18 |
The function exi_put_nodal_var_time() writes the values of a single nodal |
| 19 |
variable for multiple time steps. The function ex_put_variable_param() |
| 20 |
must be invoked before this call is made. |
| 21 |
|
| 22 |
Because nodal variables are floating point values, the application |
| 23 |
code must declare the array passed to be the appropriate type |
| 24 |
(float or double) to match the compute word size passed in |
| 25 |
ex_create() or ex_open(). |
| 26 |
|
| 27 |
\return In case of an error, exi_put_nodal_var() returns a negative number; a |
| 28 |
warning will return a positive number. Possible causes of errors |
| 29 |
include: |
| 30 |
- data file not properly opened with call to ex_create() or ex_open() |
| 31 |
- data file opened for read only. |
| 32 |
- data file not initialized properly with call to ex_put_init(). |
| 33 |
- ex_put_variable_param() not called previously specifying the number of |
| 34 |
nodal variables. |
| 35 |
|
| 36 |
\param[in] exoid exodus file ID returned from a previous call to |
| 37 |
ex_create() or |
| 38 |
ex_open(). |
| 39 |
|
| 40 |
\param[in] nodal_var_index The index of the nodal variable. The first |
| 41 |
variable has an index of 1. |
| 42 |
|
| 43 |
\param[in] num_nodes The number of nodal points. |
| 44 |
|
| 45 |
\param[in] beg_time_step The beginning time step number, as described under ex_put_time(). |
| 46 |
This is counter that is incremented when results variables |
| 47 |
are output. The first time step is 1. |
| 48 |
|
| 49 |
\param[in] end_time_step The ending time step number, as described under ex_put_time(). |
| 50 |
This is counter that is incremented when results variables |
| 51 |
are output. The first time step is 1. |
| 52 |
|
| 53 |
\param[in] nodal_var_vals Array of num_nodes values of the |
| 54 |
nodal_var_index-th nodal |
| 55 |
variable for the time_step-th time step. |
| 56 |
|
| 57 |
As an example, the following code segment writes all the nodal |
| 58 |
variables for a single time step: |
| 59 |
|
| 60 |
~~~{.c} |
| 61 |
int num_nod_vars, num_nodes, error, exoid, time_step; |
| 62 |
float *nodal_var_vals; |
| 63 |
|
| 64 |
\comment{write nodal variables} |
| 65 |
nodal_var_vals = (float *) calloc(num_nodes, sizeof(float)); |
| 66 |
for (k=1; k <= num_nod_vars; k++) { |
| 67 |
for (j=0; j < num_nodes; j++) { |
| 68 |
\comment{application code fills in this array} |
| 69 |
nodal_var_vals[j] = 10.0; |
| 70 |
} |
| 71 |
error = ex_put_var_time(exoid, EX_NODAL, k, 0, num_nodes, beg_time_step, end_time_step |
| 72 |
nodal_var_vals); |
| 73 |
} |
| 74 |
~~~ |
| 75 |
|
| 76 |
*/ |
| 77 |
|
| 78 |
int exi_put_nodal_var_time(int exoid, int nodal_var_index, int64_t num_nodes, int beg_time_step, |
| 79 |
int end_time_step, const void *nodal_var_vals) |
| 80 |
|
| 81 |
{ |
| 82 |
int status; |
| 83 |
int varid; |
| 84 |
size_t start[2], count[2]; |
| 85 |
char errmsg[MAX_ERR_LENGTH]; |
| 86 |
|
| 87 |
if ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) { |
| 88 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: could not find nodal variable %d in file id %d", |
| 89 |
nodal_var_index, exoid); |
| 90 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 91 |
return EX_WARN; |
| 92 |
} |
| 93 |
start[0] = --beg_time_step; |
| 94 |
start[1] = 0; |
| 95 |
|
| 96 |
count[0] = end_time_step - beg_time_step; |
| 97 |
count[1] = num_nodes; |
| 98 |
|
| 99 |
if (exi_comp_ws(exoid) == 4) { |
| 100 |
status = nc_put_vara_float(exoid, varid, start, count, nodal_var_vals); |
| 101 |
} |
| 102 |
else { |
| 103 |
status = nc_put_vara_double(exoid, varid, start, count, nodal_var_vals); |
| 104 |
} |
| 105 |
|
| 106 |
if (status != NC_NOERR) { |
| 107 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store nodal variables in file id %d", exoid); |
| 108 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 109 |
return EX_FATAL; |
| 110 |
} |
| 111 |
return EX_NOERR; |
| 112 |
} |