Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_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_put_coord_names() writes the names of the coordinate
15 arrays to the database. Memory must be allocated for the character
16 strings before this function is invoked.
17
18 In case of an error, ex_put_coord_names() returns a negative number; a
19 warning will return a positive number. Possible causes of errors
20 include:
21 - data file not properly opened with call to ex_create() or ex_open()
22 - data file opened for read only.
23 - data file not initialized properly with call to ex_put_init().
24
25 \param[in] exoid exodus file ID returned from a previous call to
26 ex_create() or ex_open().
27 \param[in] coord_names Array containing num_dim names of length \p
28 ...max_name_length... of the nodal coordinate arrays.
29
30 The following coding will write the coordinate names to an
31 open exodus file :
32
33 ~~~{.c}
34 int error, exoid;
35
36 char *coord_names[3];
37 coord_names[0] = "xcoor";
38 coord_names[1] = "ycoor";
39 coord_names[2] = "zcoor";
40
41 error = ex_put_coord_names (exoid, coord_names);
42 ~~~
43
44 */
45
46 int ex_put_coord_names(int exoid, char *const 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 if ((status = nc_inq_dimid(exoid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) {
59 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate number of dimensions in file id %d",
60 exoid);
61 ex_err_fn(exoid, __func__, errmsg, status);
62 EX_FUNC_LEAVE(EX_FATAL);
63 }
64
65 if ((status = nc_inq_dimlen(exoid, ndimdim, &num_dim)) != NC_NOERR) {
66 snprintf(errmsg, MAX_ERR_LENGTH,
67 "ERROR: inquire failed to get number of dimensions in file id %d", exoid);
68 ex_err_fn(exoid, __func__, errmsg, status);
69 EX_FUNC_LEAVE(EX_FATAL);
70 }
71
72 if ((status = nc_inq_varid(exoid, VAR_NAME_COOR, &varid)) == -1) {
73 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate coordinate names in file id %d",
74 exoid);
75 ex_err_fn(exoid, __func__, errmsg, status);
76 EX_FUNC_LEAVE(EX_FATAL);
77 }
78
79 /* write out coordinate names */
80 status = exi_put_names(exoid, varid, num_dim, coord_names, EX_COORDINATE, "", __func__);
81
82 EX_FUNC_LEAVE(status);
83 }