libMesh
output.C
Go to the documentation of this file.
1 #include <fstream>
2 #include <unistd.h>
3 
4 #include "libmesh/libmesh_common.h"
5 
6 #include "output.h"
7 
8 // Bring in everything from the libMesh namespace
9 using namespace libMesh;
10 
11 void start_output(unsigned int timesteps,
12  std::string filename,
13  std::string varname)
14 {
15  // Truncate then append if we're doing a restart
16  if (timesteps)
17  {
18  std::ifstream infile (filename.c_str());
19  char buf[1025];
20  if (!infile.is_open())
21  libmesh_error_msg("Error opening file " << filename);
22 
23  // Count off the lines we want to save, including
24  // the original header
25  for (unsigned int i=0; i != timesteps+1; ++i)
26  infile.getline(buf, 1024);
27  if (!infile.good())
28  libmesh_error_msg("Error reading line from file " << filename);
29  unsigned int length = infile.tellg();
30  infile.close();
31 
32  // Then throw away the rest
33  int err = truncate(filename.c_str(), length);
34  if (err != 0)
35  libmesh_error_msg("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 }
OStreamProxy err
void start_output(unsigned int timesteps, std::string filename, std::string varname)
Definition: output.C:11
The libMesh namespace provides an interface to certain functionality in the library.
OStreamProxy out