Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_attr_names.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 *
10 * expatn - ex_put_attr_names
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int blk_type block type (edge, face, elem)
16 * int blk_id block id
17 * char* names ptr to array of attribute names
18
19 *
20 * exit conditions -
21 *
22 * revision history -
23 *
24 *
25 *****************************************************************************/
26
27 #include "exodusII.h" // for ex_err, ex_name_of_object, etc
28 #include "exodusII_int.h" // for EX_FATAL, exi_id_lkup, etc
29
30 /*!
31 * writes the attribute names for a block
32 * \param exoid exodus file id
33 * \param blk_type block type (edge, face, elem)
34 * \param blk_id block id
35 * \param names ptr to array of attribute names
36 */
37 int ex_put_attr_names(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char *names[])
38 {
39 int varid, numattrdim, blk_id_ndx;
40 size_t num_attr;
41
42 int status;
43 char errmsg[MAX_ERR_LENGTH];
44
45 EX_FUNC_ENTER();
46 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
47 EX_FUNC_LEAVE(EX_FATAL);
48 }
49
50 blk_id_ndx = exi_id_lkup(exoid, blk_type, blk_id);
51 if (blk_id_ndx <= 0) {
52 ex_get_err(NULL, NULL, &status);
53
54 if (status != 0) {
55 if (status == EX_NULLENTITY) {
56 snprintf(errmsg, MAX_ERR_LENGTH,
57 "Warning: no attributes allowed for NULL %s %" PRId64 " in file id %d",
58 ex_name_of_object(blk_type), blk_id, exoid);
59 ex_err_fn(exoid, __func__, errmsg, EX_NULLENTITY);
60 EX_FUNC_LEAVE(EX_WARN); /* no attributes for this block */
61 }
62 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s id %" PRId64 " in %s array in file id %d",
63 ex_name_of_object(blk_type), blk_id, VAR_ID_EL_BLK, exoid);
64 ex_err_fn(exoid, __func__, errmsg, status);
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67 }
68
69 /* inquire id's of previously defined dimensions */
70 switch (blk_type) {
71 case EX_SIDE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim); break;
72 case EX_NODE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim); break;
73 case EX_EDGE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim); break;
74 case EX_FACE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim); break;
75 case EX_ELEM_SET:
76 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim);
77 break;
78 case EX_NODAL: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim); break;
79 case EX_EDGE_BLOCK:
80 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim);
81 break;
82 case EX_FACE_BLOCK:
83 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim);
84 break;
85 case EX_ELEM_BLOCK:
86 status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim);
87 break;
88 default:
89 snprintf(errmsg, MAX_ERR_LENGTH,
90 "Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type,
91 exoid);
92 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
93 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
94 }
95
96 if (status != NC_NOERR) {
97 snprintf(errmsg, MAX_ERR_LENGTH,
98 "ERROR: number of attributes not defined for %s %" PRId64 " in file id %d",
99 ex_name_of_object(blk_type), blk_id, exoid);
100 ex_err_fn(exoid, __func__, errmsg, EX_MSG);
101 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
102 }
103
104 if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
105 snprintf(errmsg, MAX_ERR_LENGTH,
106 "ERROR: failed to get number of attributes for %s %" PRId64 " in file id %d",
107 ex_name_of_object(blk_type), blk_id, exoid);
108 ex_err_fn(exoid, __func__, errmsg, status);
109 EX_FUNC_LEAVE(EX_FATAL);
110 }
111
112 switch (blk_type) {
113 case EX_SIDE_SET: status = nc_inq_varid(exoid, VAR_NAME_SSATTRIB(blk_id_ndx), &varid); break;
114 case EX_NODE_SET: status = nc_inq_varid(exoid, VAR_NAME_NSATTRIB(blk_id_ndx), &varid); break;
115 case EX_EDGE_SET: status = nc_inq_varid(exoid, VAR_NAME_ESATTRIB(blk_id_ndx), &varid); break;
116 case EX_FACE_SET: status = nc_inq_varid(exoid, VAR_NAME_FSATTRIB(blk_id_ndx), &varid); break;
117 case EX_ELEM_SET: status = nc_inq_varid(exoid, VAR_NAME_ELSATTRIB(blk_id_ndx), &varid); break;
118 case EX_NODAL: status = nc_inq_varid(exoid, VAR_NAME_NATTRIB, &varid); break;
119 case EX_EDGE_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_EATTRIB(blk_id_ndx), &varid); break;
120 case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_FATTRIB(blk_id_ndx), &varid); break;
121 case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_ATTRIB(blk_id_ndx), &varid); break;
122 default:
123 snprintf(errmsg, MAX_ERR_LENGTH,
124 "Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type,
125 exoid);
126 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
127 EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */
128 }
129
130 if (status != NC_NOERR) {
131 snprintf(errmsg, MAX_ERR_LENGTH,
132 "ERROR: failed to locate %s attribute names for %s %" PRId64 " in file id %d",
133 ex_name_of_object(blk_type), ex_name_of_object(blk_type), blk_id, exoid);
134 ex_err_fn(exoid, __func__, errmsg, status);
135 EX_FUNC_LEAVE(EX_FATAL);
136 }
137
138 /* write out the attributes */
139 status = exi_put_names(exoid, varid, num_attr, names, blk_type, "attribute", __func__);
140
141 EX_FUNC_LEAVE(status);
142 }