1 /*
2 * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract
3 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
4 * retains certain rights in this software.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of Sandia Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36 #include <string.h>
37 #include "exodusII.h"
38 #include "exodusII_int.h"
39
40 /*!
41
42 The function ex_put_time() writes the time value for a specified time
43 step.
44
45 Because time values are floating point values, the application code
46 must declare the array passed to be the appropriate type (\c float or
47 \c double) to match the compute word size passed in ex_create() or
48 ex_open().
49
50 \return In case of an error, ex_put_time() returns a negative number;
51 a warning will return a positive number. Possible causes of errors
52 include:
53 - data file not properly opened with call to ex_create() or ex_open()
54 - data file opened for read only.
55
56 \param[in] exoid exodus file ID returned from a previous call to ex_create() or ex_open().
57 \param[in] time_step The time step number. This is essentially a counter that is
58 incremented only when results variables are output to the data
59 file. The first time step is 1.
60 \param[in] time_value The time at the specified time step.
61
62 The following code segment will write out the simulation time value at
63 simulation time step n:
64
65 \code
66 int error, exoid, n;
67 float time_value;
68
69 \comment{write time value}
70 error = ex_put_time (exoid, n, &time_value);
71 \endcode
72
73 */
74
ex_put_time(int exoid,int time_step,const void * time_value)75 int ex_put_time (int exoid,
76 int time_step,
77 const void *time_value)
78 {
79 int status;
80 int varid;
81 size_t start[1];
82 char errmsg[MAX_ERR_LENGTH];
83
84 exerrval = 0; /* clear error code */
85
86 /* inquire previously defined variable */
87 if ((status = nc_inq_varid(exoid, VAR_WHOLE_TIME, &varid)) != NC_NOERR) {
88 exerrval = status;
89 sprintf(errmsg,
90 "Error: failed to locate time variable in file id %d", exoid);
91 ex_err("ex_put_time",errmsg,exerrval);
92 return (EX_FATAL);
93 }
94
95 /* store time value */
96 start[0] = --time_step;
97
98 if (ex_comp_ws(exoid) == 4) {
99 status = nc_put_var1_float(exoid, varid, start, time_value);
100 } else {
101 status = nc_put_var1_double(exoid, varid, start, time_value);
102 }
103
104 if (status != NC_NOERR) {
105 exerrval = status;
106 sprintf(errmsg,
107 "Error: failed to store time value in file id %d", exoid);
108 ex_err("ex_put_time",errmsg,exerrval);
109 return (EX_FATAL);
110 }
111
112
113 return (EX_NOERR);
114 }
115