| 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 |
* |
| 10 |
* exgpem - ex_get_partial_elem_map |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int map_id element map id |
| 16 |
* int ent_start first entry in map |
| 17 |
* int ent_count number of entries in map |
| 18 |
* |
| 19 |
* exit conditions - |
| 20 |
* int* elem_map element map |
| 21 |
* |
| 22 |
* revision history - |
| 23 |
* |
| 24 |
* |
| 25 |
*****************************************************************************/ |
| 26 |
|
| 27 |
#include "exodusII.h" // for ex_err, etc |
| 28 |
#include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc |
| 29 |
|
| 30 |
/* |
| 31 |
* reads the element map with specified ID |
| 32 |
*/ |
| 33 |
|
| 34 |
int ex_get_partial_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id, |
| 35 |
int64_t ent_start, int64_t ent_count, void_int *map) |
| 36 |
{ |
| 37 |
int dimid, var_id, id_ndx, status; |
| 38 |
size_t num_mobj, start[1], count[1]; |
| 39 |
char errmsg[MAX_ERR_LENGTH]; |
| 40 |
const char *dim_map_size; |
| 41 |
const char *dim_num_maps; |
| 42 |
|
| 43 |
EX_FUNC_ENTER(); |
| 44 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 45 |
EX_FUNC_LEAVE(EX_FATAL); |
| 46 |
} |
| 47 |
|
| 48 |
switch (map_type) { |
| 49 |
case EX_NODE_MAP: |
| 50 |
dim_map_size = DIM_NUM_NODES; |
| 51 |
dim_num_maps = DIM_NUM_NM; |
| 52 |
break; |
| 53 |
case EX_EDGE_MAP: |
| 54 |
dim_map_size = DIM_NUM_EDGE; |
| 55 |
dim_num_maps = DIM_NUM_EDM; |
| 56 |
break; |
| 57 |
case EX_FACE_MAP: |
| 58 |
dim_map_size = DIM_NUM_FACE; |
| 59 |
dim_num_maps = DIM_NUM_FAM; |
| 60 |
break; |
| 61 |
case EX_ELEM_MAP: |
| 62 |
dim_map_size = DIM_NUM_ELEM; |
| 63 |
dim_num_maps = DIM_NUM_EM; |
| 64 |
break; |
| 65 |
default: |
| 66 |
snprintf(errmsg, MAX_ERR_LENGTH, "Bad map type (%d) specified", map_type); |
| 67 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 68 |
EX_FUNC_LEAVE(EX_FATAL); |
| 69 |
} |
| 70 |
|
| 71 |
/* See if file contains any elements...*/ |
| 72 |
if (nc_inq_dimid(exoid, dim_map_size, &dimid) != NC_NOERR) { |
| 73 |
EX_FUNC_LEAVE(EX_NOERR); |
| 74 |
} |
| 75 |
|
| 76 |
if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) { |
| 77 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of mesh objects in file id %d", |
| 78 |
exoid); |
| 79 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 80 |
EX_FUNC_LEAVE(EX_FATAL); |
| 81 |
} |
| 82 |
|
| 83 |
/* Check input parameters for a valid range of numbers */ |
| 84 |
if (ent_start <= 0 || ent_start > (int64_t)num_mobj) { |
| 85 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: start count is invalid in file id %d", exoid); |
| 86 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 87 |
EX_FUNC_LEAVE(EX_FATAL); |
| 88 |
} |
| 89 |
|
| 90 |
if (ent_count < 0) { |
| 91 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid count value in file id %d", exoid); |
| 92 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 93 |
EX_FUNC_LEAVE(EX_FATAL); |
| 94 |
} |
| 95 |
|
| 96 |
if (ent_start + ent_count - 1 > (int64_t)num_mobj) { |
| 97 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 98 |
"ERROR: start+count-1 is larger than element count in file id %d", exoid); |
| 99 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 100 |
EX_FUNC_LEAVE(EX_FATAL); |
| 101 |
} |
| 102 |
|
| 103 |
/* first check if any maps have been defined */ |
| 104 |
if ((status = nc_inq_dimid(exoid, dim_num_maps, &dimid)) != NC_NOERR) { |
| 105 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined in file id %d", |
| 106 |
ex_name_of_object(map_type), exoid); |
| 107 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 108 |
EX_FUNC_LEAVE(EX_WARN); |
| 109 |
} |
| 110 |
|
| 111 |
/* Lookup index of element map id property array */ |
| 112 |
id_ndx = exi_id_lkup(exoid, map_type, map_id); |
| 113 |
if (id_ndx <= 0) { |
| 114 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 115 |
"ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d", |
| 116 |
ex_name_of_object(map_type), map_id, exoid); |
| 117 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 118 |
EX_FUNC_LEAVE(EX_FATAL); |
| 119 |
} |
| 120 |
|
| 121 |
/* inquire id's of previously defined dimensions and variables */ |
| 122 |
if ((status = nc_inq_varid(exoid, exi_name_of_map(map_type, id_ndx), &var_id)) != NC_NOERR) { |
| 123 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " in file id %d", |
| 124 |
ex_name_of_object(map_type), map_id, exoid); |
| 125 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 126 |
EX_FUNC_LEAVE(EX_FATAL); |
| 127 |
} |
| 128 |
|
| 129 |
/* read in the map */ |
| 130 |
start[0] = ent_start - 1; |
| 131 |
count[0] = ent_count; |
| 132 |
if (count[0] == 0) { |
| 133 |
start[0] = 0; |
| 134 |
} |
| 135 |
|
| 136 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 137 |
status = nc_get_vara_longlong(exoid, var_id, start, count, map); |
| 138 |
} |
| 139 |
else { |
| 140 |
status = nc_get_vara_int(exoid, var_id, start, count, map); |
| 141 |
} |
| 142 |
|
| 143 |
if (status == -1) { |
| 144 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s in file id %d", |
| 145 |
ex_name_of_object(map_type), exoid); |
| 146 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 147 |
EX_FUNC_LEAVE(EX_FATAL); |
| 148 |
} |
| 149 |
EX_FUNC_LEAVE(EX_NOERR); |
| 150 |
} |