Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_assembly.c

raw
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 #include "exodusII.h" // for ex_assembly, ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, etc
11
12 /*!
13 * reads the assembly parameters and optionally assembly data for one assembly
14 * \param exoid exodus file id
15 * \param *assembly ex_assembly structure
16 */
17
18 int ex_get_assembly(int exoid, ex_assembly *assembly)
19 {
20 struct exi_file_item *file = NULL;
21 int status = 0;
22 int dimid = 0;
23 size_t len = 0;
24 char errmsg[MAX_ERR_LENGTH];
25
26 EX_FUNC_ENTER();
27
28 file = exi_find_file_item(exoid);
29 if (!file) {
30 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d.", exoid);
31 ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID);
32 EX_FUNC_LEAVE(EX_FATAL);
33 }
34
35 /* First, locate varid of assembly */
36 int entlst_id = 0;
37 if ((status = nc_inq_varid(exoid, VAR_ENTITY_ASSEMBLY(assembly->id), &entlst_id)) != NC_NOERR) {
38 ex_get_err(NULL, NULL, &status);
39 if (status != 0) {
40 if (assembly->name != NULL) {
41 ex_copy_string(assembly->name, "NULL", MAX_STR_LENGTH + 1); /* NULL element type name */
42 }
43 assembly->entity_count = 0;
44 assembly->type = EX_INVALID;
45 if (status == EX_NULLENTITY) { /* NULL element assembly? */
46 EX_FUNC_LEAVE(EX_NOERR);
47 }
48 snprintf(errmsg, MAX_ERR_LENGTH,
49 "ERROR: failed to locate assembly id %" PRId64 " in id array in file id %d",
50 assembly->id, exoid);
51 ex_err_fn(exoid, __func__, errmsg, status);
52 EX_FUNC_LEAVE(EX_FATAL);
53 }
54 }
55
56 char *numentryptr = DIM_NUM_ENTITY_ASSEMBLY(assembly->id);
57 if ((status = nc_inq_dimid(exoid, numentryptr, &dimid)) != NC_NOERR) {
58 snprintf(errmsg, MAX_ERR_LENGTH,
59 "ERROR: failed to locate number of entities in assembly %" PRId64 " in file id %d",
60 assembly->id, exoid);
61 ex_err_fn(exoid, __func__, errmsg, status);
62 EX_FUNC_LEAVE(EX_FATAL);
63 }
64
65 if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
66 snprintf(errmsg, MAX_ERR_LENGTH,
67 "ERROR: failed to get number of entities in assembly %" PRId64 " in file id %d",
68 assembly->id, exoid);
69 ex_err_fn(exoid, __func__, errmsg, status);
70 EX_FUNC_LEAVE(EX_FATAL);
71 }
72
73 assembly->entity_count = len;
74
75 /* look up entity list array for this assembly id */
76 if ((status = nc_inq_varid(exoid, VAR_ENTITY_ASSEMBLY(assembly->id), &entlst_id)) != NC_NOERR) {
77 snprintf(errmsg, MAX_ERR_LENGTH,
78 "ERROR: failed to locate entity list array for assembly %" PRId64 " in file id %d",
79 assembly->id, exoid);
80 ex_err_fn(exoid, __func__, errmsg, status);
81 EX_FUNC_LEAVE(EX_FATAL);
82 }
83
84 /* Get the type of entities stored in the entity list... */
85 int type;
86 if ((status = nc_get_att_int(exoid, entlst_id, EX_ATTRIBUTE_TYPE, &type)) != NC_NOERR) {
87 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get assembly %" PRId64 " type in file id %d",
88 assembly->id, exoid);
89 ex_err_fn(exoid, __func__, errmsg, status);
90 EX_FUNC_LEAVE(EX_FATAL);
91 }
92 assembly->type = type;
93
94 /* read the name */
95 if (assembly->name != NULL) {
96 int name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
97 char tmp_name[EX_MAX_NAME] = "";
98 if ((status = nc_get_att_text(exoid, entlst_id, EX_ATTRIBUTE_NAME, tmp_name)) != NC_NOERR) {
99 snprintf(errmsg, MAX_ERR_LENGTH,
100 "ERROR: failed to read assembly name for assembly %" PRId64 " in file id %d",
101 assembly->id, exoid);
102 ex_err_fn(exoid, __func__, errmsg, status);
103 EX_FUNC_LEAVE(EX_FATAL);
104 }
105 ex_copy_string(assembly->name, tmp_name, name_size + 1);
106 }
107
108 if (assembly->entity_list != NULL) {
109 if ((status = nc_get_var_longlong(exoid, entlst_id, (long long int *)assembly->entity_list)) !=
110 NC_NOERR) {
111 snprintf(errmsg, MAX_ERR_LENGTH,
112 "ERROR: failed to read entity list for assembly %" PRId64 " in file id %d",
113 assembly->id, exoid);
114 ex_err_fn(exoid, __func__, errmsg, status);
115 EX_FUNC_LEAVE(EX_FATAL);
116 }
117 }
118 EX_FUNC_LEAVE(EX_NOERR);
119 }