Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_id_map.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 * exgnm - ex_get_id_map
11 *
12 * entry conditions -
13 * input parameters:
14 * int exoid exodus file id
15 * int map_type type of map (node, edge, face, element)
16 *
17 * exit conditions -
18 * int* map map
19 *
20 *****************************************************************************/
21
22 #include "exodusII.h" // for ex_err, etc
23 #include "exodusII_int.h" // for EX_FATAL, EX_NOERR, etc
24
25 /*
26 * reads the id map
27 */
28
29 int ex_get_id_map(int exoid, ex_entity_type map_type, void_int *map)
30 {
31 int status;
32 char errmsg[MAX_ERR_LENGTH];
33 const char *dnumentries;
34 const char *vmap;
35 const char *tname;
36
37 EX_FUNC_ENTER();
38 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
39 EX_FUNC_LEAVE(EX_FATAL);
40 }
41
42 switch (map_type) {
43 case EX_NODE_MAP:
44 tname = "node";
45 dnumentries = DIM_NUM_NODES;
46 vmap = VAR_NODE_NUM_MAP;
47 break;
48 case EX_EDGE_MAP:
49 tname = "edge";
50 dnumentries = DIM_NUM_EDGE;
51 vmap = VAR_EDGE_NUM_MAP;
52 break;
53 case EX_FACE_MAP:
54 tname = "face";
55 dnumentries = DIM_NUM_FACE;
56 vmap = VAR_FACE_NUM_MAP;
57 break;
58 case EX_ELEM_MAP:
59 tname = "element";
60 dnumentries = DIM_NUM_ELEM;
61 vmap = VAR_ELEM_NUM_MAP;
62 break;
63 default:
64 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad map type (%d) specified for file id %d", map_type,
65 exoid);
66 ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM);
67 EX_FUNC_LEAVE(EX_FATAL);
68 }
69
70 /* See if any entries are stored in this file */
71 int dimid;
72 if (nc_inq_dimid(exoid, dnumentries, &dimid) != NC_NOERR) {
73 EX_FUNC_LEAVE(EX_NOERR);
74 }
75
76 int mapid;
77 if (nc_inq_varid(exoid, vmap, &mapid) != NC_NOERR) {
78 size_t num_entries;
79 if ((status = nc_inq_dimlen(exoid, dimid, &num_entries)) != NC_NOERR) {
80 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of %ss in file id %d", tname,
81 exoid);
82 ex_err_fn(exoid, __func__, errmsg, status);
83 EX_FUNC_LEAVE(EX_FATAL);
84 }
85
86 /* generate default map of 1..n, where n is num_entries */
87 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
88 int64_t *lmap = (int64_t *)map;
89 for (size_t i = 0; i < num_entries; i++) {
90 lmap[i] = i + 1;
91 }
92 }
93 else {
94 int *lmap = (int *)map;
95 for (size_t i = 0; i < num_entries; i++) {
96 lmap[i] = i + 1;
97 }
98 }
99
100 EX_FUNC_LEAVE(EX_NOERR);
101 }
102
103 /* read in the id map */
104 if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
105 status = nc_get_var_longlong(exoid, mapid, map);
106 }
107 else {
108 status = nc_get_var_int(exoid, mapid, map);
109 }
110
111 if (status != NC_NOERR) {
112 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s id map in file id %d", tname, exoid);
113 ex_err_fn(exoid, __func__, errmsg, status);
114 EX_FUNC_LEAVE(EX_FATAL);
115 }
116
117 EX_FUNC_LEAVE(EX_NOERR);
118 }