Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_info.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 #include "exodusII.h" // for ex_err, etc
10 #include "exodusII_int.h" // for EX_FATAL, exi_trim, etc
11
12 /*!
13 \ingroup Utilities
14
15 The function ex_get_info() reads information records from the
16 database. The records are #MAX_LINE_LENGTH character
17 strings. Memory must be allocated for the information records before
18 this call is made. The number of records can be determined by invoking
19 ex_inquire() or ex_inquire_int().
20
21 \returns In case of an error, ex_get_info() returns a negative number;
22 a warning will return a positive number. Possible causes of errors
23 include:
24 - data file not properly opened with call to ex_create() or ex_open()
25 - a warning value is returned if no information records were stored.
26
27 \param[in] exoid exodus file ID returned from a previous call to ex_create()
28 or ex_open().
29 \param[out] info Returned array containing the information records.
30
31 The following code segment will determine the number of information
32 records and read them from an open exodus file :
33
34 ~~~{.c}
35 int error, exoid, num_info;
36 char *info[MAXINFO];
37
38 \comment{read information records}
39 num_info = ex_inquire_int (exoid,EX_INQ_INFO);
40 for (i=0; i < num_info; i++) {
41 info[i] = (char *) calloc ((EX_MAX_LINE_LENGTH+1), sizeof(char));
42 }
43 error = ex_get_info (exoid, info);
44 ~~~
45
46 */
47
48 int ex_get_info(int exoid, char **info)
49 {
50 int status;
51
52 EX_FUNC_ENTER();
53 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
54 EX_FUNC_LEAVE(EX_FATAL);
55 }
56
57 /* inquire previously defined dimensions and variables */
58 int rootid = exoid & EX_FILE_ID_MASK;
59 int dimid;
60 if ((status = nc_inq_dimid(rootid, DIM_NUM_INFO, &dimid)) != NC_NOERR) {
61 char errmsg[MAX_ERR_LENGTH];
62 snprintf(errmsg, MAX_ERR_LENGTH,
63 "Warning: failed to locate number of info records in file id %d", rootid);
64 ex_err_fn(exoid, __func__, errmsg, status);
65 EX_FUNC_LEAVE(EX_WARN);
66 }
67
68 size_t num_info;
69 if ((status = nc_inq_dimlen(rootid, dimid, &num_info)) != NC_NOERR) {
70 char errmsg[MAX_ERR_LENGTH];
71 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of info records in file id %d",
72 rootid);
73 ex_err_fn(exoid, __func__, errmsg, status);
74 EX_FUNC_LEAVE(EX_FATAL);
75 }
76
77 /* do this only if there are any information records */
78 if (num_info > 0) {
79 int varid;
80 if ((status = nc_inq_varid(rootid, VAR_INFO, &varid)) != NC_NOERR) {
81 char errmsg[MAX_ERR_LENGTH];
82 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate info record data in file id %d",
83 rootid);
84 ex_err_fn(exoid, __func__, errmsg, status);
85 EX_FUNC_LEAVE(EX_FATAL);
86 }
87
88 /* read the information records */
89 for (size_t i = 0; i < num_info; i++) {
90 size_t start[] = {i, 0};
91 size_t count[] = {1, MAX_LINE_LENGTH + 1};
92
93 if ((status = nc_get_vara_text(rootid, varid, start, count, info[i])) != NC_NOERR) {
94 char errmsg[MAX_ERR_LENGTH];
95 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get info record data in file id %d",
96 rootid);
97 ex_err_fn(exoid, __func__, errmsg, status);
98 EX_FUNC_LEAVE(EX_FATAL);
99 }
100 info[i][MAX_LINE_LENGTH] = '\0';
101 exi_trim(info[i]);
102 }
103 }
104 EX_FUNC_LEAVE(EX_NOERR);
105 }