libMesh
Functions
output.h File Reference

Go to the source code of this file.

Functions

void start_output (unsigned int timesteps, std::string filename, std::string varname)
 

Function Documentation

void start_output ( unsigned int  timesteps,
std::string  filename,
std::string  varname 
)

Definition at line 11 of file output.C.

References libMesh::err, and libMesh::out.

Referenced by write_output_headers().

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
OStreamProxy out