Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_coord_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 #include "exodusII.h" // for ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, etc
11
12 /*!
13
14 The function ex_get_coord_names() reads the names of the coordinate
15 arrays from the database. Memory must be allocated for the character
16 strings before this function is invoked.
17
18 \return In case of an error, ex_get_coord_names() returns a negative
19 number; a warning will return a positive number. Possible causes of
20 errors include:
21 - data file not properly opened with call to ex_create() or ex_open()
22 - a warning value is returned if coordinate names were not stored.
23
24 \param[in] exoid exodus file ID returned from a previous call to
25 ex_create() or ex_open().
26 \param[out] coord_names Returned pointer to a vector containing num_dim
27 names of the nodal
28 coordinate arrays.
29
30 The following code segment will read the coordinate names from an open
31 exodus file :
32
33 ~~~{.c}
34 int error, exoid;
35 char *coord_names[3];
36
37 for (i=0; i < num_dim; i++) {
38 coord_names[i] = (char *)calloc((..size of names...+1), sizeof(char));
39 }
40
41 error = ex_get_coord_names (exoid, coord_names);
42 ~~~
43
44 */
45
46 int ex_get_coord_names(int exoid, char **coord_names)
47 {
48 int status;
49 int ndimdim, varid;
50 size_t num_dim;
51 char errmsg[MAX_ERR_LENGTH];
52
53 EX_FUNC_ENTER();
54 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
55 EX_FUNC_LEAVE(EX_FATAL);
56 }
57
58 /* inquire previously defined dimensions and variables */
59
60 if ((status = nc_inq_dimid(exoid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) {
61 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of dimensions in file id %d",
62 exoid);
63 ex_err_fn(exoid, __func__, errmsg, status);
64 EX_FUNC_LEAVE(EX_FATAL);
65 }
66
67 if ((status = nc_inq_dimlen(exoid, ndimdim, &num_dim)) != NC_NOERR) {
68 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of dimensions in file id %d",
69 exoid);
70 ex_err_fn(exoid, __func__, errmsg, status);
71 EX_FUNC_LEAVE(EX_FATAL);
72 }
73
74 if ((status = nc_inq_varid(exoid, VAR_NAME_COOR, &varid)) != NC_NOERR) {
75 snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate coordinate names in file id %d",
76 exoid);
77 ex_err_fn(exoid, __func__, errmsg, status);
78 EX_FUNC_LEAVE(EX_WARN);
79 }
80
81 /* read the coordinate names */
82 status = exi_get_names(exoid, varid, num_dim, coord_names, EX_COORDINATE, __func__);
83 if (status != NC_NOERR) {
84 EX_FUNC_LEAVE(EX_FATAL);
85 }
86 EX_FUNC_LEAVE(EX_NOERR);
87 }