Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExampleSerialProgram.C
Go to the documentation of this file.
1 
9 #include "ExampleProgram.H"
10 
11 
12 namespace GridConversion {
13 
14  namespace ExampleProgram {
15 
17  {
18  // FunctionEntry("NAME"): Updates the user-defined stack and
19  // the program profiles with timing information. The placement
20  // of FunctionEntry and FunctionExit calls is at the developer's
21  // discretion.
22  FunctionEntry("Run");
23 
24  // ---------- The Program -----------------
25  // This program just "copies" the input file
26  // to the output file.
27  //
28 
29  // Open the specified input file for reading
30  Inf.open(input_name.c_str());
31  if(!Inf){
32  // If the input file failed to open, notify to
33  // the error stream and return non-zero
34  std::ostringstream Ostr;
35  Ostr << "Error: Could not open input file, '"
36  << input_name << "'.\n";
37  ErrOut(Ostr.str());
38  // don't forget to tell the profiler/stacker the
39  // function is exiting.
40  FunctionExit("Run");
41  return(1);
42  }
43 
44  // Open the specified output file for writing
45  bool use_outfile = false;
46  if(!output_name.empty()){
47  use_outfile = true;
48  Ouf.open(output_name.c_str());
49  if(!Ouf){
50  // If the output file failed to open, notify
51  // to error stream and return non-zero
52  std::ostringstream Ostr;
53  Ostr << "Error: Unable to open output file, " << output_name << ".";
54  ErrOut(Ostr.str());
55  // don't forget to tell the profiler/stacker the
56  // function is exiting.
57  FunctionExit("Run");
58  return(1);
59  }
60  }
61 
62  // Read lines from the input file and repeat them
63  // to the output file.
64  std::string line;
65  while(std::getline(Inf,line)){
66  if(use_outfile)
67  Ouf << line << std::endl;
68  else
69  StdOut(line+"\n");
70  }
71  // Close both files
72  Ouf.close();
73  Inf.close();
74 
75  //
76  // ---------- Program End -----------------
77 
78 
79  // Update the stacker/profiler that we are exiting
80  // this function.
81  FunctionExit("Run");
82  // return 0 for success
83  return(0);
84  };
85  };
86 };
std::ifstream Inf
Infile stream for input.
std::ofstream Ouf
Outfile stream for output.
virtual int Run()
This function implements the main function executed by the program.
Example program interface.
std::string input_name
Name of input file.
std::string output_name
Name of file for output.