Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2020, 2022 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 * expenm - ex_put_id_map
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * ex_entity_type obj_type
16 * int* elem_map element numbering map array
17 *
18 * exit conditions -
19 *
20 * revision history -
21 *
22 *
23 *****************************************************************************/
24
25 #include "exodusII.h" // for ex_err, etc
26 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
27
28 /*!
29 * writes out the entity numbering map to the database; this allows
30 * the entity numbers to be non-contiguous. This map is used for
31 * mapping between local and global entity ids.
32 * \param exoid exodus file id
33 * \param map_type
34 * \param map element numbering map array
35 */
36
37 int ex_put_id_map(int exoid, ex_entity_type map_type, const void_int *map)
38 {
39 int dimid, mapid, status, dims[1];
40 int map_int_type;
41 char errmsg[MAX_ERR_LENGTH];
42 const char *tname;
43 const char *dnumentries;
44 const char *vmap;
45
46 EX_FUNC_ENTER();
47 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
48 EX_FUNC_LEAVE(EX_FATAL);
49 }
50
51 switch (map_type) {
52 case EX_NODE_MAP:
53 tname = "node";
54 dnumentries = DIM_NUM_NODES;
55 vmap = VAR_NODE_NUM_MAP;
56 break;
57 case EX_EDGE_MAP:
58 tname = "edge";
59 dnumentries = DIM_NUM_EDGE;
60 vmap = VAR_EDGE_NUM_MAP;
61 break;
62 case EX_FACE_MAP:
63 tname = "face";
64 dnumentries = DIM_NUM_FACE;
65 vmap = VAR_FACE_NUM_MAP;
66 break;
67 case EX_ELEM_MAP:
68 tname = "element";
69 dnumentries = DIM_NUM_ELEM;
70 vmap = VAR_ELEM_NUM_MAP;
71 break;
72 default:
73 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad map type (%d) specified for file id %d", map_type,
74 exoid);
75 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
76 EX_FUNC_LEAVE(EX_FATAL);
77 }
78
79 /* Make sure the file contains entries */
80 if (nc_inq_dimid(exoid, dnumentries, &dimid) != NC_NOERR) {
81 EX_FUNC_LEAVE(EX_NOERR);
82 }
83
84 /* put netcdf file into define mode */
85 if (nc_inq_varid(exoid, vmap, &mapid) != NC_NOERR) {
86 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
87 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid);
88 ex_err_fn(exoid, __func__, errmsg, status);
89 EX_FUNC_LEAVE(EX_FATAL);
90 }
91
92 /* create a variable array in which to store the id map */
93 dims[0] = dimid;
94
95 /* Check type to be used for maps... */
96 map_int_type = NC_INT;
97 if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) {
98 map_int_type = NC_INT64;
99 }
100
101 if ((status = nc_def_var(exoid, vmap, map_int_type, 1, dims, &mapid)) != NC_NOERR) {
102 if (status == NC_ENAMEINUSE) {
103 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s numbering map already exists in file id %d",
104 tname, exoid);
105 ex_err_fn(exoid, __func__, errmsg, status);
106 }
107 else {
108 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create %s id map in file id %d", tname,
109 exoid);
110 ex_err_fn(exoid, __func__, errmsg, status);
111 }
112 goto error_ret; /* exit define mode and return */
113 }
114 exi_compress_variable(exoid, mapid, 1);
115
116 /* leave define mode */
117 if ((status = exi_leavedef(exoid, __func__)) != NC_NOERR) {
118 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to exit define mode");
119 ex_err_fn(exoid, __func__, errmsg, status);
120 EX_FUNC_LEAVE(EX_FATAL);
121 }
122 }
123
124 /* write out the entity numbering map */
125 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
126 status = nc_put_var_longlong(exoid, mapid, map);
127 }
128 else {
129 status = nc_put_var_int(exoid, mapid, map);
130 }
131
132 if (status != NC_NOERR) {
133 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s numbering map in file id %d", tname,
134 exoid);
135 ex_err_fn(exoid, __func__, errmsg, status);
136 EX_FUNC_LEAVE(EX_FATAL);
137 }
138
139 EX_FUNC_LEAVE(EX_NOERR);
140
141 /* Fatal error: exit definition mode and return */
142 error_ret:
143 exi_leavedef(exoid, __func__);
144 EX_FUNC_LEAVE(EX_FATAL);
145 }