Debian Codegraph @

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