1 /*
2 * Copyright (c) 2005-2017 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 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of NTESS nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35 /*****************************************************************************
36 *
37 * exgnam - ex_get_name
38 *
39 * entry conditions -
40 * input parameters:
41 * int exoid exodus file id
42 * const char *type entity type - M, E, S
43 * int entity_id id of entity name to read
44 *
45 * exit conditions -
46 * char* name ptr to name
47 *
48 * revision history -
49 *
50 *
51 *****************************************************************************/
52
53 #include "exodusII.h" // for ex_inquire_int, etc
54 #include "exodusII_int.h" // for EX_FATAL, etc
55 #include "vtk_netcdf.h" // for NC_NOERR, nc_inq_varid
56 #include <stdio.h>
57
58 /*
59 * reads the specified entity name from the database
60 */
61
ex_get_name(int exoid,ex_entity_type obj_type,ex_entity_id entity_id,char * name)62 int ex_get_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, char *name)
63 {
64 int status;
65 int varid, ent_ndx;
66 char errmsg[MAX_ERR_LENGTH];
67 char *vobj = NULL;
68
69 EX_FUNC_ENTER();
70 ex_check_valid_file_id(exoid, __func__);
71
72 switch (obj_type) {
73 case EX_ELEM_BLOCK: vobj = VAR_NAME_EL_BLK; break;
74 case EX_EDGE_BLOCK: vobj = VAR_NAME_ED_BLK; break;
75 case EX_FACE_BLOCK: vobj = VAR_NAME_FA_BLK; break;
76 case EX_NODE_SET: vobj = VAR_NAME_NS; break;
77 case EX_SIDE_SET: vobj = VAR_NAME_SS; break;
78 case EX_EDGE_SET: vobj = VAR_NAME_ES; break;
79 case EX_FACE_SET: vobj = VAR_NAME_FS; break;
80 case EX_ELEM_SET: vobj = VAR_NAME_ELS; break;
81 case EX_NODE_MAP: vobj = VAR_NAME_NM; break;
82 case EX_EDGE_MAP: vobj = VAR_NAME_EDM; break;
83 case EX_FACE_MAP: vobj = VAR_NAME_FAM; break;
84 case EX_ELEM_MAP: vobj = VAR_NAME_EM; break;
85 default:
86 /* invalid variable type */
87 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid type specified in file id %d", exoid);
88 ex_err(__func__, errmsg, EX_BADPARAM);
89 EX_FUNC_LEAVE(EX_FATAL);
90 }
91
92 if ((status = nc_inq_varid(exoid, vobj, &varid)) == NC_NOERR) {
93 /* If this is a null entity, then 'ent_ndx' will be negative.
94 * We don't care in this __func__, so make it positive and continue...
95 */
96 ent_ndx = ex_id_lkup(exoid, obj_type, entity_id);
97 if (ent_ndx < 0) {
98 ent_ndx = -ent_ndx;
99 }
100
101 /* read the name */
102 {
103 int db_name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
104 int api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
105 int name_size = db_name_size < api_name_size ? db_name_size : api_name_size;
106
107 status = ex_get_name_internal(exoid, varid, ent_ndx - 1, name, name_size, obj_type, __func__);
108 if (status != NC_NOERR) {
109 EX_FUNC_LEAVE(EX_FATAL);
110 }
111 }
112 }
113 else {
114 /* Name variable does not exist on the database; probably since this is an
115 * older version of the database. Return an empty array...
116 */
117 name[0] = '\0';
118 }
119 EX_FUNC_LEAVE(EX_NOERR);
120 }
121