| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021, 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 |
* exgnam - ex_get_names |
| 11 |
* |
| 12 |
* entry conditions - |
| 13 |
* input parameters: |
| 14 |
* int exoid exodus file id |
| 15 |
* int obj_type, |
| 16 |
* |
| 17 |
* exit conditions - |
| 18 |
* char* names[] ptr array of names |
| 19 |
* |
| 20 |
* revision history - |
| 21 |
* |
| 22 |
* |
| 23 |
*****************************************************************************/ |
| 24 |
|
| 25 |
#include "exodusII.h" // for ex_err, etc |
| 26 |
#include "exodusII_int.h" // for exi_get_dimension, EX_NOERR, etc |
| 27 |
|
| 28 |
/* |
| 29 |
* reads the entity names from the database |
| 30 |
*/ |
| 31 |
|
| 32 |
int ex_get_names(int exoid, ex_entity_type obj_type, char **names) |
| 33 |
{ |
| 34 |
EX_FUNC_ENTER(); |
| 35 |
if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) { |
| 36 |
EX_FUNC_LEAVE(EX_FATAL); |
| 37 |
} |
| 38 |
|
| 39 |
int status; |
| 40 |
int varid, temp; |
| 41 |
size_t num_entity; |
| 42 |
|
| 43 |
switch (obj_type) { |
| 44 |
/* ======== ASSEMBLY ========= */ |
| 45 |
case EX_ASSEMBLY: { |
| 46 |
/* Determine number of assemblies on database */ |
| 47 |
int num_assembly = ex_inquire_int(exoid, EX_INQ_ASSEMBLY); |
| 48 |
if (num_assembly < 0) { |
| 49 |
char errmsg[MAX_ERR_LENGTH]; |
| 50 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to inquire ASSEMBLY count in file id %d", |
| 51 |
exoid); |
| 52 |
ex_err_fn(exoid, __func__, errmsg, num_assembly); |
| 53 |
return EX_FATAL; |
| 54 |
} |
| 55 |
|
| 56 |
if (ex_int64_status(exoid) & EX_IDS_INT64_API) { |
| 57 |
int64_t *ids = calloc(num_assembly, sizeof(int64_t)); |
| 58 |
ex_get_ids(exoid, EX_ASSEMBLY, ids); |
| 59 |
for (int i = 0; i < num_assembly; i++) { |
| 60 |
ex_assembly assembly = {ids[i], names[i]}; |
| 61 |
ex_get_assembly(exoid, &assembly); |
| 62 |
} |
| 63 |
free(ids); |
| 64 |
} |
| 65 |
else { |
| 66 |
int *ids = calloc(num_assembly, sizeof(int)); |
| 67 |
ex_get_ids(exoid, EX_ASSEMBLY, ids); |
| 68 |
for (int i = 0; i < num_assembly; i++) { |
| 69 |
ex_assembly assembly = {ids[i], names[i]}; |
| 70 |
ex_get_assembly(exoid, &assembly); |
| 71 |
} |
| 72 |
free(ids); |
| 73 |
} |
| 74 |
EX_FUNC_LEAVE(EX_NOERR); |
| 75 |
} |
| 76 |
/* ======== BLOCKS ========= */ |
| 77 |
case EX_EDGE_BLOCK: |
| 78 |
exi_get_dimension(exoid, DIM_NUM_ED_BLK, "edge block", &num_entity, &temp, __func__); |
| 79 |
status = nc_inq_varid(exoid, VAR_NAME_ED_BLK, &varid); |
| 80 |
break; |
| 81 |
case EX_FACE_BLOCK: |
| 82 |
exi_get_dimension(exoid, DIM_NUM_FA_BLK, "face block", &num_entity, &temp, __func__); |
| 83 |
status = nc_inq_varid(exoid, VAR_NAME_FA_BLK, &varid); |
| 84 |
break; |
| 85 |
case EX_ELEM_BLOCK: |
| 86 |
exi_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, &temp, __func__); |
| 87 |
status = nc_inq_varid(exoid, VAR_NAME_EL_BLK, &varid); |
| 88 |
break; |
| 89 |
|
| 90 |
/* ======== SETS ========= */ |
| 91 |
case EX_NODE_SET: |
| 92 |
exi_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, &temp, __func__); |
| 93 |
status = nc_inq_varid(exoid, VAR_NAME_NS, &varid); |
| 94 |
break; |
| 95 |
case EX_EDGE_SET: |
| 96 |
exi_get_dimension(exoid, DIM_NUM_ES, "edgeset", &num_entity, &temp, __func__); |
| 97 |
status = nc_inq_varid(exoid, VAR_NAME_ES, &varid); |
| 98 |
break; |
| 99 |
case EX_FACE_SET: |
| 100 |
exi_get_dimension(exoid, DIM_NUM_FS, "faceset", &num_entity, &temp, __func__); |
| 101 |
status = nc_inq_varid(exoid, VAR_NAME_FS, &varid); |
| 102 |
break; |
| 103 |
case EX_SIDE_SET: |
| 104 |
exi_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, &temp, __func__); |
| 105 |
status = nc_inq_varid(exoid, VAR_NAME_SS, &varid); |
| 106 |
break; |
| 107 |
case EX_ELEM_SET: |
| 108 |
exi_get_dimension(exoid, DIM_NUM_ELS, "elemset", &num_entity, &temp, __func__); |
| 109 |
status = nc_inq_varid(exoid, VAR_NAME_ELS, &varid); |
| 110 |
break; |
| 111 |
|
| 112 |
/* ======== MAPS ========= */ |
| 113 |
case EX_NODE_MAP: |
| 114 |
exi_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, &temp, __func__); |
| 115 |
status = nc_inq_varid(exoid, VAR_NAME_NM, &varid); |
| 116 |
break; |
| 117 |
case EX_EDGE_MAP: |
| 118 |
exi_get_dimension(exoid, DIM_NUM_EDM, "edge map", &num_entity, &temp, __func__); |
| 119 |
status = nc_inq_varid(exoid, VAR_NAME_EDM, &varid); |
| 120 |
break; |
| 121 |
case EX_FACE_MAP: |
| 122 |
exi_get_dimension(exoid, DIM_NUM_FAM, "face map", &num_entity, &temp, __func__); |
| 123 |
status = nc_inq_varid(exoid, VAR_NAME_FAM, &varid); |
| 124 |
break; |
| 125 |
case EX_ELEM_MAP: |
| 126 |
exi_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, &temp, __func__); |
| 127 |
status = nc_inq_varid(exoid, VAR_NAME_EM, &varid); |
| 128 |
break; |
| 129 |
|
| 130 |
/* invalid variable type */ |
| 131 |
default: { |
| 132 |
char errmsg[MAX_ERR_LENGTH]; |
| 133 |
snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid type specified in file id %d", exoid); |
| 134 |
ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); |
| 135 |
EX_FUNC_LEAVE(EX_FATAL); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (status == NC_NOERR) { |
| 140 |
if ((status = exi_get_names(exoid, varid, num_entity, names, obj_type, "ex_get_names")) != |
| 141 |
EX_NOERR) { |
| 142 |
EX_FUNC_LEAVE(status); |
| 143 |
} |
| 144 |
} |
| 145 |
else { |
| 146 |
/* Names variable does not exist on the database; probably since this is an |
| 147 |
* older version of the database. Return an empty array... |
| 148 |
*/ |
| 149 |
for (size_t i = 0; i < num_entity; i++) { |
| 150 |
names[i][0] = '\0'; |
| 151 |
} |
| 152 |
} |
| 153 |
EX_FUNC_LEAVE(EX_NOERR); |
| 154 |
} |