Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SerialProgram Class Reference

Implementation of the basic parts of the serial program example. More...

#include <ExampleProgram.H>

Inheritance diagram for SerialProgram:
Collaboration diagram for SerialProgram:

Public Member Functions

 SerialProgram ()
 Default constructor. More...
 
 SerialProgram (int nargs, char **args)
 Constructor designed to take the commandline args. More...
 
virtual int Initialize ()
 Initializes native data structures from commandline args. More...
 
int VerbLevel () const
 Returns verbosity level. More...
 
virtual ~SerialProgram ()
 Destructor. More...
 
virtual int Run ()
 This function implements the main function executed by the program. More...
 

Protected Attributes

std::string output_name
 Name of file for output. More...
 
std::string input_name
 Name of input file. More...
 
int verblevel
 Verbosity level. More...
 
std::ofstream Ouf
 Outfile stream for output. More...
 
std::ifstream Inf
 Infile stream for input. More...
 

Detailed Description

Implementation of the basic parts of the serial program example.

This object encapsulates the example serial program. It inherits from the IRAD::Global::Program type.

The program itself just copies a specified input file to the specified output file (or stdout if no file is given). The command line usage goes:

       sep Usage:

       sep [-h] [-v [arg] -o <filename> ] <input> 

       -h,--help
          Prints this long version of help.

              -v,--verbosity [arg]

       -o,--output <filename>
          Specifies the name of the output file.

              <input>
          Mode-dependent input: input <filename> for serial example
          program, or <number of divisions> for parallel example.

Definition at line 158 of file ExampleProgram.H.

Constructor & Destructor Documentation

SerialProgram ( )
inline

Default constructor.

Definition at line 175 of file ExampleProgram.H.

175  :
177  {};
IRAD::Global::Program< GlobalType, ComLineType > SerialProgramType
Convenience type definition for the serial program.
SerialProgram ( int  nargs,
char **  args 
)
inline

Constructor designed to take the commandline args.

Definition at line 181 of file ExampleProgram.H.

181  :
182  SerialProgramType(nargs,args)
183  {};
IRAD::Global::Program< GlobalType, ComLineType > SerialProgramType
Convenience type definition for the serial program.
virtual ~SerialProgram ( )
inlinevirtual

Destructor.

Definition at line 243 of file ExampleProgram.H.

References SerialProgram::Ouf.

243  {
244  if(Ouf){
245  Ouf.close();
246  SetOutStream(std::cout);
247  }
248  };
std::ofstream Ouf
Outfile stream for output.

Member Function Documentation

virtual int Initialize ( )
inlinevirtual

Initializes native data structures from commandline args.

Definition at line 187 of file ExampleProgram.H.

References SerialProgram::input_name, SerialProgram::output_name, and SerialProgram::verblevel.

188  {
189  int retval = SerialProgramType::Initialize();
190  if(!_command_line.GetOption("help").empty()){
191  std::ostringstream Ostr;
192  Ostr << _command_line.LongUsage() << std::endl;
193  StdOut(Ostr.str());
194  return(-1);
195  }
196  if(retval){
197  std::ostringstream Ostr;
198  Ostr << _command_line.ErrorReport() << std::endl
199  << std::endl << _command_line.ShortUsage() << std::endl;
200  ErrOut(Ostr.str());
201  return(retval);
202  }
203 
204  // Check if output file is specified
205  output_name = _command_line.GetOption("output");
206 
207  // Set input file to first argument
208  std::vector<std::string> args(_command_line.GetArgs());
209  input_name = args[0];
210 
211  // Check the verbosity level
212  std::string sverb(_command_line.GetOption("verbosity"));
213  if(sverb.empty() || sverb == ".true.")
214  verblevel = 1;
215  else {
216  std::istringstream Vin(sverb);
217  Vin >> verblevel;
218  if(verblevel < 0)
219  verblevel = 1;
220  }
221 
222  // If high verbosity, stick a configuration blurb to stdout.
223  if(verblevel > 1){
224  std::ostringstream Ostr;
225  Ostr << "Configuration:" << std::endl
226  << "verbosity = " << verblevel << std::endl
227  << "input_name = " << input_name << std::endl;
228  if(!output_name.empty())
229  Ostr << "output file = " << output_name << std::endl;
230  Ostr << std::endl;
231  StdOut(Ostr.str());
232  }
233 
234  return(0);
235  };
std::string input_name
Name of input file.
std::string output_name
Name of file for output.
int Run ( )
virtual

This function implements the main function executed by the program.

Definition at line 16 of file ExampleSerialProgram.C.

References SerialProgram::Inf, SerialProgram::input_name, SerialProgram::Ouf, and SerialProgram::output_name.

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  };
std::ifstream Inf
Infile stream for input.
std::ofstream Ouf
Outfile stream for output.
std::string input_name
Name of input file.
std::string output_name
Name of file for output.
int VerbLevel ( ) const
inline

Returns verbosity level.

Definition at line 239 of file ExampleProgram.H.

References SerialProgram::verblevel.

239 { return verblevel;};

Member Data Documentation

std::ifstream Inf
protected

Infile stream for input.

Definition at line 170 of file ExampleProgram.H.

Referenced by SerialProgram::Run().

std::string input_name
protected

Name of input file.

Definition at line 164 of file ExampleProgram.H.

Referenced by SerialProgram::Initialize(), and SerialProgram::Run().

std::ofstream Ouf
protected

Outfile stream for output.

Definition at line 168 of file ExampleProgram.H.

Referenced by SerialProgram::Run(), and SerialProgram::~SerialProgram().

std::string output_name
protected

Name of file for output.

Definition at line 162 of file ExampleProgram.H.

Referenced by SerialProgram::Initialize(), and SerialProgram::Run().

int verblevel
protected

Verbosity level.

Definition at line 166 of file ExampleProgram.H.

Referenced by SerialProgram::Initialize(), and SerialProgram::VerbLevel().


The documentation for this class was generated from the following files: