| 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 |
* exgnm - ex_get_map |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int map_type type of map (node, edge, face, element) |
| 16 |
* int map_id map id |
| 17 |
* |
| 18 |
* exit conditions - |
| 19 |
* int* map map |
| 20 |
* |
| 21 |
* revision history - |
| 22 |
* 20060930 - David Thompson - Adapted from ex_get_node_map |
| 23 |
* |
| 24 |
*****************************************************************************/ |
| 25 |
|
| 26 |
#include "exodusII.h" // for ex_err, etc |
| 27 |
#include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc |
| 28 |
|
| 29 |
/* |
| 30 |
* reads the map with specified ID |
| 31 |
*/ |
| 32 |
|
| 33 |
int ex_get_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id, void_int *map) |
| 34 |
{ |
| 35 |
int dimid, var_id, id_ndx, status; |
| 36 |
char errmsg[MAX_ERR_LENGTH]; |
| 37 |
const char *dim_map_size; |
| 38 |
const char *dim_num_maps; |
| 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 |
switch (map_type) { |
| 46 |
case EX_NODE_MAP: |
| 47 |
dim_map_size = DIM_NUM_NODES; |
| 48 |
dim_num_maps = DIM_NUM_NM; |
| 49 |
break; |
| 50 |
case EX_EDGE_MAP: |
| 51 |
dim_map_size = DIM_NUM_EDGE; |
| 52 |
dim_num_maps = DIM_NUM_EDM; |
| 53 |
break; |
| 54 |
case EX_FACE_MAP: |
| 55 |
dim_map_size = DIM_NUM_FACE; |
| 56 |
dim_num_maps = DIM_NUM_FAM; |
| 57 |
break; |
| 58 |
case EX_ELEM_MAP: |
| 59 |
dim_map_size = DIM_NUM_ELEM; |
| 60 |
dim_num_maps = DIM_NUM_EM; |
| 61 |
break; |
| 62 |
default: |
| 63 |
snprintf(errmsg, MAX_ERR_LENGTH, "Bad map type (%d) specified", map_type); |
| 64 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 65 |
EX_FUNC_LEAVE(EX_FATAL); |
| 66 |
} |
| 67 |
|
| 68 |
/* See if any entries are stored in this file */ |
| 69 |
if (nc_inq_dimid(exoid, dim_map_size, &dimid) != NC_NOERR) { |
| 70 |
EX_FUNC_LEAVE(EX_NOERR); |
| 71 |
} |
| 72 |
|
| 73 |
/* first check if any maps have been defined */ |
| 74 |
if ((status = nc_inq_dimid(exoid, dim_num_maps, &dimid)) != NC_NOERR) { |
| 75 |
snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined in file id %d", |
| 76 |
ex_name_of_object(map_type), exoid); |
| 77 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 78 |
EX_FUNC_LEAVE(EX_WARN); |
| 79 |
} |
| 80 |
|
| 81 |
/* Lookup index of map id property array */ |
| 82 |
id_ndx = exi_id_lkup(exoid, map_type, map_id); |
| 83 |
if (id_ndx <= 0) { |
| 84 |
snprintf(errmsg, MAX_ERR_LENGTH, |
| 85 |
"ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d", |
| 86 |
ex_name_of_object(map_type), map_id, exoid); |
| 87 |
ex_err_fn(exoid, __func__, errmsg, EX_LASTERR); |
| 88 |
EX_FUNC_LEAVE(EX_FATAL); |
| 89 |
} |
| 90 |
|
| 91 |
/* inquire id's of previously defined dimensions and variables */ |
| 92 |
if ((status = nc_inq_varid(exoid, exi_name_of_map(map_type, id_ndx), &var_id)) != NC_NOERR) { |
| 93 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " in file id %d", |
| 94 |
ex_name_of_object(map_type), map_id, exoid); |
| 95 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 96 |
EX_FUNC_LEAVE(EX_FATAL); |
| 97 |
} |
| 98 |
|
| 99 |
/* read in the map */ |
| 100 |
if (ex_int64_status(exoid) & EX_MAPS_INT64_API) { |
| 101 |
status = nc_get_var_longlong(exoid, var_id, map); |
| 102 |
} |
| 103 |
else { |
| 104 |
status = nc_get_var_int(exoid, var_id, map); |
| 105 |
} |
| 106 |
|
| 107 |
if (status != NC_NOERR) { |
| 108 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s in file id %d", |
| 109 |
ex_name_of_object(map_type), exoid); |
| 110 |
ex_err_fn(exoid, __func__, errmsg, status); |
| 111 |
EX_FUNC_LEAVE(EX_FATAL); |
| 112 |
} |
| 113 |
|
| 114 |
EX_FUNC_LEAVE(EX_NOERR); |
| 115 |
} |