trick/trick_source/sim_services/MonteCarlo/include/MonteVarFile.hh
2015-02-26 09:02:31 -06:00

88 lines
2.7 KiB
C++

/*
PURPOSE: (Monte carlo structures)
REFERENCE: (Trick Users Guide)
ASSUMPTIONS AND LIMITATIONS: (None)
PROGRAMMERS: ((Keith Vetter) (LinCom) (7/2003))
*/
/*
* $Id: MonteVarFile.hh $
*/
#ifndef _MONTEVARFILE_HH_
#define _MONTEVARFILE_HH_
#include <iostream>
#include <fstream>
#include <string>
#include "MonteVar.hh"
namespace Trick {
/**
* A variable whose values are read from a file. Values should be listed in columns. Multiple variables
* may utilize the same file, and even the same column (resulting in identical values). For example,
* the following file could be used to populate two MonteVarFiles:
*
* @code
* #values.txt: MonteVarFile variable values
* 1 10
* 2 20
* 3 30
* 4 40
* 5 50
* @endcode
*
* One could then create two variables as such:
*
* @code
* MonteVarFile *variable1 = new MonteVarFile(string("ball.obj.state.input.position[0]"), string("RUN_example/values.txt"), 1);
* MonteVarFile *variable2 = new MonteVarFile(string("ball.obj.state.input.position[1]"), string("RUN_example/values.txt"), 2);
* @endcode
*
* <code>variable1</code>'s values will progress starting from 1, through 2, 3, 4, and 5.
* <code>variable2</code>'s values will be 10, 20, 30, 40, 50.
* Note that the column number begins at 1, not 0.
*
* @author Alex Lin
* @author Donna Panter
* @author Derek Bankieris
*
* @date August 2010
*/
class MonteVarFile : public Trick::MonteVar {
protected:
/** The name of the file containing this variable's values. */
std::string file_name; /**< \n trick_units(--) */
/** The column within the file correpsonding to this variable. */
unsigned int column; /**< \n trick_units(--) */
/** The input file stream. */
std::ifstream *input_file_stream; /**< \n trick_units(--) */
/** A character buffer. */
char *buffer; /**< \n trick_units(--) */
public:
/**
* Constructs a MonteVarFile with the specified name, file name, column, and units.
*
* @param name the fully qualified name of the simulation variable to which this MonteVarFile refers
* @param file_name the name of the file containing this variable's values
* @param column the column (starting at 1) within the file corresponding to this variable
* @param unit this variable's units
*/
MonteVarFile(std::string name, std::string file_name, unsigned int column, std::string unit = "");
protected:
virtual std::string get_next_value();
} ;
} ;
#endif