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