Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_get_all_times.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, VAR_WHOLE_TIME, etc
11
12 /*!
13 \ingroup ResultsData
14
15 The function ex_get_all_times() reads the time values for all time
16 steps. Memory must be allocated for the time values array before this
17 function is invoked. The storage requirements (equal to the number of
18 time steps) can be determined by using the ex_inquire() or
19 ex_inquire_int() routines.
20
21 Because time values are floating point values, the application code
22 must declare the array passed to be the appropriate type (float or
23 double) to match the compute word size passed in ex_create() or
24 ex_open().
25
26 \return In case of an error, ex_get_all_times() returns a negative
27 number; a warning will return a positive number. Possible causes of
28 errors include:
29 - data file not properly opened with call to ex_create() or ex_open()
30 - no time steps have been stored in the file.
31
32 \param[in] exoid exodus file ID returned from a previous call to
33 ex_create() or ex_open().
34 \param[out] time_values Returned array of times. These are the time values at
35 all time steps.
36
37 The following code segment will read the time values for all time
38 steps stored in the data file:
39
40 ~~~{.c}
41 int error, exoid, num_time_steps;
42 float *time_values;
43
44 \comment{determine how many time steps are stored}
45 num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME);
46
47 \comment{read time values at all time steps}
48 time_values = (float *) calloc(num_time_steps, sizeof(float));
49
50 error = ex_get_all_times(exoid, time_values);
51 ~~~
52
53 */
54
55 int ex_get_all_times(int exoid, void *time_values)
56 {
57 int varid;
58 int status;
59 char errmsg[MAX_ERR_LENGTH];
60
61 EX_FUNC_ENTER();
62 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
63 EX_FUNC_LEAVE(EX_FATAL);
64 }
65
66 if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
67 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time variable %s in file id %d",
68 VAR_WHOLE_TIME, exoid);
69 ex_err_fn(exoid, __func__, errmsg, status);
70 EX_FUNC_LEAVE(EX_FATAL);
71 }
72
73 /*read time values */
74 if (exi_comp_ws(exoid) == 4) {
75 status = nc_get_var_float(exoid, varid, time_values);
76 }
77 else {
78 status = nc_get_var_double(exoid, varid, time_values);
79 }
80
81 if (status != NC_NOERR) {
82 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get time values from file id %d", exoid);
83 ex_err_fn(exoid, __func__, errmsg, status);
84 EX_FUNC_LEAVE(EX_FATAL);
85 }
86
87 EX_FUNC_LEAVE(EX_NOERR);
88 }