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 * expmp - ex_get_attr_param
38 *
39 * entry conditions -
40 * input parameters:
41 * int exoid exodus file id
42 * int obj_type block/set type (node, edge, face, elem)
43 * int obj_id block/set id (ignored for NODAL)
44 * int num_attrs number of attributes
45 *
46 * exit conditions -
47 *
48 *
49 *****************************************************************************/
50
51 #include "exodusII.h" // for ex_err, etc
52 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
53 #include "vtk_netcdf.h" // for NC_NOERR, nc_inq_dimid, etc
54 #include <inttypes.h> // for PRId64
55 #include <stddef.h> // for size_t
56 #include <stdio.h>
57
58 /*!
59 * \undoc retrieves the number of attributes.
60 */
61
ex_get_attr_param(int exoid,ex_entity_type obj_type,ex_entity_id obj_id,int * num_attrs)62 int ex_get_attr_param(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int *num_attrs)
63 {
64 int status;
65 int dimid;
66
67 char errmsg[MAX_ERR_LENGTH];
68 const char *dnumobjatt;
69
70 int obj_id_ndx;
71 size_t lnum_attr_per_entry;
72
73 EX_FUNC_ENTER();
74 ex_check_valid_file_id(exoid, __func__);
75
76 /* Determine index of obj_id in vobjids array */
77 if (obj_type == EX_NODAL) {
78 obj_id_ndx = 0;
79 }
80 else {
81 obj_id_ndx = ex_id_lkup(exoid, obj_type, obj_id);
82 if (obj_id_ndx <= 0) {
83 ex_get_err(NULL, NULL, &status);
84
85 if (status != 0) {
86 if (status == EX_NULLENTITY) {
87 *num_attrs = 0;
88 EX_FUNC_LEAVE(EX_NOERR);
89 }
90 snprintf(errmsg, MAX_ERR_LENGTH,
91 "Warning: failed to locate %s id %" PRId64 " in id array in file id %d",
92 ex_name_of_object(obj_type), obj_id, exoid);
93 ex_err(__func__, errmsg, status);
94 EX_FUNC_LEAVE(EX_WARN);
95 }
96 }
97 }
98
99 switch (obj_type) {
100 case EX_SIDE_SET: dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); break;
101 case EX_NODE_SET: dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); break;
102 case EX_EDGE_SET: dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); break;
103 case EX_FACE_SET: dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); break;
104 case EX_ELEM_SET: dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); break;
105 case EX_NODAL: dnumobjatt = DIM_NUM_ATT_IN_NBLK; break;
106 case EX_EDGE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); break;
107 case EX_FACE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); break;
108 case EX_ELEM_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); break;
109 default:
110 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad block type (%d) specified for file id %d",
111 obj_type, exoid);
112 ex_err(__func__, errmsg, EX_BADPARAM);
113 EX_FUNC_LEAVE(EX_FATAL);
114 }
115
116 if ((status = nc_inq_dimid(exoid, dnumobjatt, &dimid)) != NC_NOERR) {
117 /* dimension is undefined */
118 *num_attrs = 0;
119 }
120 else {
121 if ((status = nc_inq_dimlen(exoid, dimid, &lnum_attr_per_entry)) != NC_NOERR) {
122 snprintf(errmsg, MAX_ERR_LENGTH,
123 "ERROR: failed to get number of attributes in %s %" PRId64 " in file id %d",
124 ex_name_of_object(obj_type), obj_id, exoid);
125 ex_err(__func__, errmsg, status);
126 EX_FUNC_LEAVE(EX_FATAL);
127 }
128 *num_attrs = lnum_attr_per_entry;
129 }
130 EX_FUNC_LEAVE(EX_NOERR);
131 }
132