Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_time.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, exi_comp_ws, etc
11
12 /*!
13 \ingroup ResultsData
14
15 The function ex_put_time() writes the time value for a specified time
16 step.
17
18 Because time values are floating point values, the application code
19 must declare the array passed to be the appropriate type (float or
20 double) to match the compute word size passed in ex_create() or
21 ex_open().
22
23 \return In case of an error, ex_put_time() returns a negative number;
24 a warning will return a positive number. Possible causes of errors
25 include:
26 - data file not properly opened with call to ex_create() or ex_open()
27 - data file opened for read only.
28
29 \param[in] exoid exodus file ID returned from a previous call to
30 ex_create() or ex_open().
31 \param[in] time_step The time step number. This is essentially a counter
32 that is
33 incremented only when results variables are output to
34 the data
35 file. The first time step is 1.
36 \param[in] time_value The time at the specified time step.
37
38 The following code segment will write out the simulation time value at
39 simulation time step n:
40
41 ~~~{.c}
42 int error, exoid, n;
43 float time_value;
44
45 \comment{write time value}
46 error = ex_put_time (exoid, n, &time_value);
47 ~~~
48
49 */
50
51 int ex_put_time(int exoid, int time_step, const void *time_value)
52 {
53 int status;
54 int varid;
55 size_t start[1];
56 char errmsg[MAX_ERR_LENGTH];
57 struct exi_file_item *file = NULL;
58
59 EX_FUNC_ENTER();
60
61 file = exi_find_file_item(exoid);
62 if (!file) {
63 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unknown file id %d.", exoid);
64 ex_err_fn(exoid, __func__, errmsg, EX_BADFILEID);
65 EX_FUNC_LEAVE(EX_FATAL);
66 }
67
68 varid = file->time_varid;
69 if (varid < 0) {
70 /* inquire previously defined variable */
71 if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
72 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time variable in file id %d",
73 exoid);
74 ex_err_fn(exoid, __func__, errmsg, status);
75 EX_FUNC_LEAVE(EX_FATAL);
76 }
77 file->time_varid = varid;
78 }
79
80 /* store time value */
81 start[0] = --time_step;
82
83 if (exi_comp_ws(exoid) == 4) {
84 status = nc_put_var1_float(exoid, varid, start, time_value);
85 }
86 else {
87 status = nc_put_var1_double(exoid, varid, start, time_value);
88 }
89
90 if (status != NC_NOERR) {
91 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store time value in file id %d", exoid);
92 ex_err_fn(exoid, __func__, errmsg, status);
93 EX_FUNC_LEAVE(EX_FATAL);
94 }
95
96 EX_FUNC_LEAVE(EX_NOERR);
97 }