| 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 |
/* Function(s) contained in this file: |
| 11 |
* ex_get_elem_map() |
| 12 |
* |
| 13 |
***************************************************************************** |
| 14 |
* Variable Index: |
| 15 |
* exoid - The NetCDF ID of an already open NemesisI file. |
| 16 |
* elem_mapi - Pointer to vector for retrieval of internal |
| 17 |
* FEM element IDs. |
| 18 |
* elem_mapb - Pointer to vector for retrieval of border |
| 19 |
* FEM element IDs. |
| 20 |
* processor - The processor the file being read was written for. |
| 21 |
*/ |
| 22 |
/*****************************************************************************/ |
| 23 |
/*****************************************************************************/ |
| 24 |
/*****************************************************************************/ |
| 25 |
|
| 26 |
#include "exodusII.h" // for ex_err, etc |
| 27 |
#include "exodusII_int.h" // for EX_FATAL, VAR_INT_E_STAT, etc |
| 28 |
|
| 29 |
int ex_get_processor_elem_maps(int exoid, void_int *elem_mapi, void_int *elem_mapb, int processor) |
| 30 |
{ |
| 31 |
char ftype[2]; |
| 32 |
int dimid, varid, status; |
| 33 |
size_t start[1], count[1]; |
| 34 |
int64_t varidx[2]; |
| 35 |
int emstat; |
| 36 |
|
| 37 |
char errmsg[MAX_ERR_LENGTH]; |
| 38 |
|
| 39 |
EX_FUNC_ENTER(); |
| 40 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 41 |
EX_FUNC_LEAVE(EX_FATAL); |
| 42 |
} |
| 43 |
|
| 44 |
/* Get the file type */ |
| 45 |
if (exi_get_file_type(exoid, ftype) != EX_NOERR) { |
| 46 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid); |
| 47 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 48 |
|
| 49 |
EX_FUNC_LEAVE(EX_FATAL); |
| 50 |
} |
| 51 |
|
| 52 |
/* Check the status of the internal element map */ |
| 53 |
if ((status = nc_inq_varid(exoid, VAR_INT_E_STAT, &varid)) != NC_NOERR) { |
| 54 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 55 |
VAR_INT_E_STAT, exoid); |
| 56 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 57 |
EX_FUNC_LEAVE(EX_FATAL); |
| 58 |
} |
| 59 |
|
| 60 |
if (ftype[0] == 'p') { |
| 61 |
start[0] = 0; |
| 62 |
} |
| 63 |
else { |
| 64 |
start[0] = processor; |
| 65 |
} |
| 66 |
|
| 67 |
if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) { |
| 68 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d", |
| 69 |
VAR_INT_E_STAT, exoid); |
| 70 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 71 |
EX_FUNC_LEAVE(EX_FATAL); |
| 72 |
} |
| 73 |
|
| 74 |
if (emstat == 1) { |
| 75 |
/* get the index */ |
| 76 |
if (ex_get_idx(exoid, VAR_ELEM_MAP_INT_IDX, varidx, processor) == -1) { |
| 77 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 78 |
"ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_INT_IDX, |
| 79 |
exoid); |
| 80 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 81 |
|
| 82 |
EX_FUNC_LEAVE(EX_FATAL); |
| 83 |
} |
| 84 |
|
| 85 |
if (varidx[1] == -1) { |
| 86 |
/* Get the size of the internal element map */ |
| 87 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_ELEMS, &dimid)) != NC_NOERR) { |
| 88 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 89 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_ELEMS, |
| 90 |
exoid); |
| 91 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 92 |
EX_FUNC_LEAVE(EX_FATAL); |
| 93 |
} |
| 94 |
|
| 95 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 96 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 97 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", |
| 98 |
DIM_NUM_INT_ELEMS, exoid); |
| 99 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 100 |
EX_FUNC_LEAVE(EX_FATAL); |
| 101 |
} |
| 102 |
|
| 103 |
varidx[1] = count[0]; |
| 104 |
} |
| 105 |
|
| 106 |
/* Get the map */ |
| 107 |
if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_INT, &varid)) != NC_NOERR) { |
| 108 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 109 |
VAR_ELEM_MAP_INT, exoid); |
| 110 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 111 |
EX_FUNC_LEAVE(EX_FATAL); |
| 112 |
} |
| 113 |
|
| 114 |
start[0] = varidx[0]; |
| 115 |
count[0] = varidx[1] - varidx[0]; |
| 116 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 117 |
status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapi); |
| 118 |
} |
| 119 |
else { |
| 120 |
status = nc_get_vara_int(exoid, varid, start, count, elem_mapi); |
| 121 |
} |
| 122 |
|
| 123 |
if (status != NC_NOERR) { |
| 124 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 125 |
VAR_ELEM_MAP_INT, exoid); |
| 126 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 127 |
EX_FUNC_LEAVE(EX_FATAL); |
| 128 |
} |
| 129 |
|
| 130 |
} /* End "if (emstat == 1)" */ |
| 131 |
|
| 132 |
/* Check the status of the internal element map */ |
| 133 |
if ((status = nc_inq_varid(exoid, VAR_BOR_E_STAT, &varid)) != NC_NOERR) { |
| 134 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 135 |
VAR_BOR_E_STAT, exoid); |
| 136 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 137 |
EX_FUNC_LEAVE(EX_FATAL); |
| 138 |
} |
| 139 |
|
| 140 |
if (ftype[0] == 'p') { |
| 141 |
start[0] = 0; |
| 142 |
} |
| 143 |
else { |
| 144 |
start[0] = processor; |
| 145 |
} |
| 146 |
|
| 147 |
if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) { |
| 148 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d", |
| 149 |
VAR_INT_E_STAT, exoid); |
| 150 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 151 |
EX_FUNC_LEAVE(EX_FATAL); |
| 152 |
} |
| 153 |
|
| 154 |
if (emstat == 1) { |
| 155 |
/* get the index */ |
| 156 |
if (ex_get_idx(exoid, VAR_ELEM_MAP_BOR_IDX, varidx, processor) == -1) { |
| 157 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 158 |
"ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_ELEM_MAP_BOR_IDX, |
| 159 |
exoid); |
| 160 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 161 |
|
| 162 |
EX_FUNC_LEAVE(EX_FATAL); |
| 163 |
} |
| 164 |
|
| 165 |
if (varidx[1] == -1) { |
| 166 |
/* Get the size of the border element map */ |
| 167 |
if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_ELEMS, &dimid)) != NC_NOERR) { |
| 168 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 169 |
"ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_ELEMS, |
| 170 |
exoid); |
| 171 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 172 |
EX_FUNC_LEAVE(EX_FATAL); |
| 173 |
} |
| 174 |
|
| 175 |
if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) { |
| 176 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 177 |
"ERROR: failed to find length of dimension \"%s\" in file ID %d", |
| 178 |
DIM_NUM_BOR_ELEMS, exoid); |
| 179 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 180 |
EX_FUNC_LEAVE(EX_FATAL); |
| 181 |
} |
| 182 |
|
| 183 |
varidx[1] = count[0]; |
| 184 |
} |
| 185 |
|
| 186 |
/* Get the map */ |
| 187 |
if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_BOR, &varid)) != NC_NOERR) { |
| 188 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d", |
| 189 |
VAR_ELEM_MAP_BOR, exoid); |
| 190 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 191 |
EX_FUNC_LEAVE(EX_FATAL); |
| 192 |
} |
| 193 |
|
| 194 |
start[0] = varidx[0]; |
| 195 |
count[0] = varidx[1] - varidx[0]; |
| 196 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 197 |
status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapb); |
| 198 |
} |
| 199 |
else { |
| 200 |
status = nc_get_vara_int(exoid, varid, start, count, elem_mapb); |
| 201 |
} |
| 202 |
|
| 203 |
if (status != NC_NOERR) { |
| 204 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d", |
| 205 |
VAR_ELEM_MAP_BOR, exoid); |
| 206 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 207 |
EX_FUNC_LEAVE(EX_FATAL); |
| 208 |
} |
| 209 |
} /* End "if (emstat == 1)" */ |
| 210 |
|
| 211 |
EX_FUNC_LEAVE(EX_NOERR); |
| 212 |
} |