libMesh
Loading...
Searching...
No Matches
output.C
Go to the documentation of this file.
1#include <fstream>
2
3#include "libmesh/libmesh_common.h"
4
5#ifdef LIBMESH_HAVE_UNISTD_H
6#include <unistd.h> // needed for truncate()
7#endif
8
9#include "output.h"
10
11// Bring in everything from the libMesh namespace
12using namespace libMesh;
13
14void start_output(unsigned int timesteps,
15 std::string filename,
16 std::string varname)
17{
18 // Truncate then append if we're doing a restart
19 if (timesteps)
20 {
21 std::ifstream infile (filename.c_str());
22 char buf[1025];
23 libmesh_error_msg_if(!infile.is_open(), "Error opening file " << filename);
24
25 // Count off the lines we want to save, including
26 // the original header
27 for (unsigned int i=0; i != timesteps+1; ++i)
28 infile.getline(buf, 1024);
29 libmesh_error_msg_if(!infile.good(), "Error reading line from file " << filename);
30 unsigned int length = cast_int<unsigned int>(infile.tellg());
31 infile.close();
32
33 // Then throw away the rest
34 int err = truncate(filename.c_str(), length);
35 libmesh_error_msg_if(err != 0, "Error truncating file " << filename);
36 }
37 // Write new headers if we're starting a new simulation
38 else
39 {
40 std::ofstream outfile (filename.c_str(), std::ios_base::out);
41 outfile << varname << " = [" << std::endl;
42 }
43}
The libMesh namespace provides an interface to certain functionality in the library.
OStreamProxy err
void start_output(unsigned int timesteps, std::string filename, std::string varname)
Definition output.C:14