Debian Codegraph @

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

raw
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_name
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * ex_entity_type obj_type object type -- EX_ELEM_BLOCK, ...
16 * int entity_id id of entity name to read
17 *
18 * exit conditions -
19 * char* name ptr to name
20 *
21 * revision history -
22 *
23 *
24 *****************************************************************************/
25
26 #include "exodusII.h" // for ex_inquire_int, etc
27 #include "exodusII_int.h" // for EX_FATAL, etc
28
29 /*
30 * reads the specified entity name from the database
31 */
32
33 int ex_get_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, char *name)
34 {
35
36 EX_FUNC_ENTER();
37 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
38 EX_FUNC_LEAVE(EX_FATAL);
39 }
40
41 char *vobj = NULL;
42 switch (obj_type) {
43 case EX_ASSEMBLY: {
44 ex_assembly assembly = {entity_id, name};
45 return ex_get_assembly(exoid, &assembly);
46 }
47 case EX_ELEM_BLOCK: vobj = VAR_NAME_EL_BLK; break;
48 case EX_EDGE_BLOCK: vobj = VAR_NAME_ED_BLK; break;
49 case EX_FACE_BLOCK: vobj = VAR_NAME_FA_BLK; break;
50 case EX_NODE_SET: vobj = VAR_NAME_NS; break;
51 case EX_SIDE_SET: vobj = VAR_NAME_SS; break;
52 case EX_EDGE_SET: vobj = VAR_NAME_ES; break;
53 case EX_FACE_SET: vobj = VAR_NAME_FS; break;
54 case EX_ELEM_SET: vobj = VAR_NAME_ELS; break;
55 case EX_NODE_MAP: vobj = VAR_NAME_NM; break;
56 case EX_EDGE_MAP: vobj = VAR_NAME_EDM; break;
57 case EX_FACE_MAP: vobj = VAR_NAME_FAM; break;
58 case EX_ELEM_MAP: vobj = VAR_NAME_EM; break;
59 default: {
60 /* invalid variable type */
61 char errmsg[MAX_ERR_LENGTH];
62 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid type specified in file id %d", exoid);
63 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
64 EX_FUNC_LEAVE(EX_FATAL);
65 }
66 }
67
68 int varid;
69 if (nc_inq_varid(exoid, vobj, &varid) == NC_NOERR) {
70 /* If this is a null entity, then 'ent_ndx' will be negative.
71 * We don't care in this __func__, so make it positive and continue...
72 */
73 int ent_ndx = exi_id_lkup(exoid, obj_type, entity_id);
74 if (ent_ndx < 0) {
75 ent_ndx = -ent_ndx;
76 }
77
78 /* read the name */
79 {
80 int db_name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
81 int api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
82 int name_size = db_name_size < api_name_size ? db_name_size : api_name_size;
83
84 int status = exi_get_name(exoid, varid, ent_ndx - 1, name, name_size, obj_type, __func__);
85 if (status != NC_NOERR) {
86 EX_FUNC_LEAVE(EX_FATAL);
87 }
88 }
89 }
90 else {
91 /* Name variable does not exist on the database; probably since this is an
92 * older version of the database. Return an empty array...
93 */
94 name[0] = '\0';
95 }
96 EX_FUNC_LEAVE(EX_NOERR);
97 }