| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 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_FATAL, exi_comp_ws, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
* reads the coordinates of some of the nodes in the model for the specified component |
| 14 |
* Memory must be allocated for the coordinate array (coor) |
| 15 |
* before this call is made. The length of the array is at least `num_nodes` |
| 16 |
* Because the coordinates |
| 17 |
* are floating point values, the application code must declare the |
| 18 |
* array passed to be the appropriate type "float" or "double" |
| 19 |
* to match the compute word size passed in ex_create() or ex_open() |
| 20 |
* \param exoid exodus file id |
| 21 |
* \param start_node_num the starting index of the coordinates to be |
| 22 |
* returned. |
| 23 |
* \param num_nodes the number of nodes to read coordinates for. |
| 24 |
* \param component which component (1=X, 2=Y, 3=Z) |
| 25 |
* \param[out] coor Returned coordinate of the nodes for the specified component. |
| 26 |
*/ |
| 27 |
|
| 28 |
int ex_get_partial_coord_component(int exoid, int64_t start_node_num, int64_t num_nodes, |
| 29 |
int component, void *coor) |
| 30 |
{ |
| 31 |
int status; |
| 32 |
int coordid; |
| 33 |
|
| 34 |
int numnoddim, ndimdim; |
| 35 |
size_t num_nod; |
| 36 |
size_t num_dim, start[2], count[2]; |
| 37 |
char errmsg[MAX_ERR_LENGTH]; |
| 38 |
const char *which = "XYZ"; |
| 39 |
|
| 40 |
EX_FUNC_ENTER(); |
| 41 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 42 |
EX_FUNC_LEAVE(EX_FATAL); |
| 43 |
} |
| 44 |
|
| 45 |
/* inquire id's of previously defined dimensions */ |
| 46 |
|
| 47 |
if (nc_inq_dimid(exoid, DIM_NUM_NODES, &numnoddim) != NC_NOERR) { |
| 48 |
/* If not found, then this file is storing 0 nodes. |
| 49 |
Return immediately */ |
| 50 |
EX_FUNC_LEAVE(EX_NOERR); |
| 51 |
} |
| 52 |
|
| 53 |
if ((status = nc_inq_dimlen(exoid, numnoddim, &num_nod)) != NC_NOERR) { |
| 54 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of nodes in file id %d", exoid); |
| 55 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 56 |
EX_FUNC_LEAVE(EX_FATAL); |
| 57 |
} |
| 58 |
|
| 59 |
--start_node_num; |
| 60 |
if (start_node_num + num_nodes > (int64_t)num_nod) { |
| 61 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 62 |
"ERROR: start index (%" PRId64 ") + node count (%" PRId64 |
| 63 |
") is larger than total number of nodes (%zu) in file id %d", |
| 64 |
start_node_num, num_nodes, num_nod, exoid); |
| 65 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 66 |
EX_FUNC_LEAVE(EX_FATAL); |
| 67 |
} |
| 68 |
|
| 69 |
if (exi_get_dimension(exoid, DIM_NUM_DIM, "dimensions", &num_dim, &ndimdim, __func__) != |
| 70 |
NC_NOERR) { |
| 71 |
EX_FUNC_LEAVE(EX_FATAL); |
| 72 |
} |
| 73 |
|
| 74 |
if (component > (int64_t)num_dim) { |
| 75 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 76 |
"ERROR: Component (%d) is larger than number of dimensions (%zu) in file id %d", |
| 77 |
component, num_dim, exoid); |
| 78 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 79 |
EX_FUNC_LEAVE(EX_FATAL); |
| 80 |
} |
| 81 |
--component; |
| 82 |
|
| 83 |
/* read in the coordinates */ |
| 84 |
if (ex_large_model(exoid) == 0) { |
| 85 |
if ((status = nc_inq_varid(exoid, VAR_COORD, &coordid)) != NC_NOERR) { |
| 86 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate nodal coordinates in file id %d", |
| 87 |
exoid); |
| 88 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 89 |
EX_FUNC_LEAVE(EX_FATAL); |
| 90 |
} |
| 91 |
|
| 92 |
{ |
| 93 |
start[0] = component; |
| 94 |
start[1] = start_node_num; |
| 95 |
|
| 96 |
count[0] = 1; |
| 97 |
count[1] = num_nodes; |
| 98 |
if (count[1] == 0) { |
| 99 |
start[1] = 0; |
| 100 |
} |
| 101 |
|
| 102 |
if (exi_comp_ws(exoid) == 4) { |
| 103 |
status = nc_get_vara_float(exoid, coordid, start, count, coor); |
| 104 |
} |
| 105 |
else { |
| 106 |
status = nc_get_vara_double(exoid, coordid, start, count, coor); |
| 107 |
} |
| 108 |
|
| 109 |
if (status != NC_NOERR) { |
| 110 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %c coord array in file id %d", |
| 111 |
which[component], exoid); |
| 112 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 113 |
EX_FUNC_LEAVE(EX_FATAL); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
else { |
| 118 |
/* read the coordinates */ |
| 119 |
{ |
| 120 |
char *comp[] = {VAR_COORD_X, VAR_COORD_Y, VAR_COORD_Z}; |
| 121 |
start[0] = start_node_num; |
| 122 |
count[0] = num_nodes; |
| 123 |
if (count[0] == 0) { |
| 124 |
start[0] = 0; |
| 125 |
} |
| 126 |
|
| 127 |
if ((status = nc_inq_varid(exoid, comp[component], &coordid)) != NC_NOERR) { |
| 128 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 129 |
"ERROR: failed to locate %c nodal coordinates in file id %d", which[component], |
| 130 |
exoid); |
| 131 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 132 |
EX_FUNC_LEAVE(EX_FATAL); |
| 133 |
} |
| 134 |
|
| 135 |
if (exi_comp_ws(exoid) == 4) { |
| 136 |
status = nc_get_vara_float(exoid, coordid, start, count, coor); |
| 137 |
} |
| 138 |
else { |
| 139 |
status = nc_get_vara_double(exoid, coordid, start, count, coor); |
| 140 |
} |
| 141 |
|
| 142 |
if (status != NC_NOERR) { |
| 143 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %c coord array in file id %d", |
| 144 |
which[component], exoid); |
| 145 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 146 |
EX_FUNC_LEAVE(EX_FATAL); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
EX_FUNC_LEAVE(EX_NOERR); |
| 151 |
} |