| 1 |
/* |
| 2 |
* Copyright(C) 1999-2022 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_NOERR, EX_FATAL, etc |
| 11 |
|
| 12 |
/*! |
| 13 |
The function ex_get_map() reads the element order map |
| 14 |
from the database. If an element order map is not stored in the data |
| 15 |
file, a default array (1,2,3,. .. num_elem) is returned. Memory |
| 16 |
must be allocated for the element map array ({num_elem} in length) |
| 17 |
before this call is made. |
| 18 |
|
| 19 |
\return In case of an error, ex_get_map() returns a negative number; a |
| 20 |
warning will return a positive number. Possible causes of errors |
| 21 |
include: |
| 22 |
- data file not properly opened with call to ex_create() or ex_open() |
| 23 |
- if an element order map is not stored, a default map and a |
| 24 |
warning value are returned. |
| 25 |
|
| 26 |
\param[in] exoid exodus file ID returned from a previous call to |
| 27 |
ex_create() or ex_open(). |
| 28 |
\param[out] elem_map Returned element order map. |
| 29 |
|
| 30 |
The following code will read an element order map from an open exodus |
| 31 |
file : |
| 32 |
|
| 33 |
~~~{.c} |
| 34 |
int *elem_map, error, exoid; |
| 35 |
|
| 36 |
\comment{read element order map} |
| 37 |
elem_map = (int *)calloc(num_elem, sizeof(int)); |
| 38 |
|
| 39 |
error = ex_get_map(exoid, elem_map); |
| 40 |
~~~ |
| 41 |
|
| 42 |
*/ |
| 43 |
|
| 44 |
int ex_get_map(int exoid, void_int *elem_map) |
| 45 |
{ |
| 46 |
int status; |
| 47 |
|
| 48 |
EX_FUNC_ENTER(); |
| 49 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 50 |
EX_FUNC_LEAVE(EX_FATAL); |
| 51 |
} |
| 52 |
|
| 53 |
/* inquire id's of previously defined dimensions and variables */ |
| 54 |
|
| 55 |
/* See if file contains any elements...*/ |
| 56 |
int numelemdim; |
| 57 |
if (nc_inq_dimid(exoid, DIM_NUM_ELEM, &numelemdim) != NC_NOERR) { |
| 58 |
EX_FUNC_LEAVE(EX_NOERR); |
| 59 |
} |
| 60 |
|
| 61 |
size_t num_elem; |
| 62 |
if ((status = nc_inq_dimlen(exoid, numelemdim, &num_elem)) != NC_NOERR) { |
| 63 |
char errmsg[MAX_ERR_LENGTH]; |
| 64 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of elements in file id %d", |
| 65 |
exoid); |
| 66 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 67 |
EX_FUNC_LEAVE(EX_FATAL); |
| 68 |
} |
| 69 |
|
| 70 |
int mapid; |
| 71 |
if (nc_inq_varid(exoid, VAR_MAP, &mapid) != NC_NOERR) { |
| 72 |
/* generate default map of 1..n, where n is num_elem */ |
| 73 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 74 |
int64_t *lmap = (int64_t *)elem_map; |
| 75 |
for (size_t i = 0; i < num_elem; i++) { |
| 76 |
lmap[i] = i + 1; |
| 77 |
} |
| 78 |
} |
| 79 |
else { |
| 80 |
int *lmap = (int *)elem_map; |
| 81 |
for (size_t i = 0; i < num_elem; i++) { |
| 82 |
lmap[i] = i + 1; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
EX_FUNC_LEAVE(EX_NOERR); |
| 87 |
} |
| 88 |
|
| 89 |
/* read in the element order map */ |
| 90 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 91 |
status = nc_get_var_longlong(exoid, mapid, elem_map); |
| 92 |
} |
| 93 |
else { |
| 94 |
status = nc_get_var_int(exoid, mapid, elem_map); |
| 95 |
} |
| 96 |
|
| 97 |
if (status != NC_NOERR) { |
| 98 |
char errmsg[MAX_ERR_LENGTH]; |
| 99 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get element order map in file id %d", exoid); |
| 100 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 101 |
EX_FUNC_LEAVE(EX_FATAL); |
| 102 |
} |
| 103 |
|
| 104 |
EX_FUNC_LEAVE(EX_NOERR); |
| 105 |
} |