SORTIE Core C++ Documentation
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
clHarvestInterface Class Reference

Harvest Interface - Version 1.1. More...

#include <HarvestInterface.h>

Inheritance diagram for clHarvestInterface:
clBehaviorBase clWorkerBase

Public Member Functions

 clHarvestInterface (clSimManager *p_oSimManager)
 Constructor.
 
 ~clHarvestInterface ()
 Destructor.
 
void Action ()
 Performs the harvest.
 
void GetData (xercesc::DOMDocument *p_oDoc)
 Performs setup.
 
void SetNameData (char *cNameString)
 Captures the namestring passed to this behavior.
 
void RegisterTreeDataMembers ()
 Registers any new data members requested by the user.
 
- Public Member Functions inherited from clBehaviorBase
virtual float GetBehaviorVersion ()
 Gets the behavior version number.
 
 clBehaviorBase (clSimManager *p_oSimManager)
 Constructor.
 
virtual ~clBehaviorBase ()
 Destructor.
 
virtual short int ValidateVersionNumber (float fTestVersion)
 Makes sure that the version number of a file passed is between the minimum and current version numbers.
 
virtual void SetSpeciesTypeCombos (short int iNumCombos, stcSpeciesTypeCombo *p_whatCombos)
 Sets the species/type combos for a behavior.
 
virtual short int GetNewTreeInts ()
 Gets the number of new tree integer data members this behavior wants to register.
 
virtual short int GetNewTreeFloats ()
 Gets the number of new tree float data members this behavior wants to register.
 
virtual short int GetNewTreeChars ()
 Gets the number of new tree character data members this behavior wants to register.
 
virtual short int GetNewTreeBools ()
 Gets the number of new tree bool data members this behavior wants to register.
 
virtual short int GetNumSpeciesTypeCombos ()
 Gets the number of species/type combos to which this behavior applies.
 
virtual short int GetNumBehaviorSpecies ()
 Gets the number of unique tree species to which this behavior applies.
 
struct stcSpeciesTypeCombo GetSpeciesTypeCombo (short int iIndex)
 Gets one of this behavior's type/species combos.
 
virtual short int GetBehaviorSpecies (short int iIndex)
 Gets one of the behavior's species.
 
short int GetBehaviorListNumber ()
 Gets the behavior list number for this behavior, which differentiates between multiple copies of the behavior in the behavior list.
 
void SetBehaviorListNumber (short int iNumber)
 Sets the behavior list number for this behavior, which differentiates between multiple copies of the behavior in the behavior list.
 
virtual DOMElement * GetParentParametersElement (xercesc::DOMDocument *p_oDoc)
 Formats the string for species/types query.
 
- Public Member Functions inherited from clWorkerBase
 clWorkerBase (clSimManager *p_oSimManager)
 Constructor.
 
virtual ~clWorkerBase ()
 Destructor.
 
char * GetName ()
 Gets the object's namestring.
 
void DoObjectSetup (xercesc::DOMDocument *p_oDoc, fileType iFileType)
 Triggers the setup process.
 
virtual void TimestepCleanup ()
 Performs any necessary cleanup operations at the end of a timestep.
 
virtual void EndOfRunCleanup ()
 Performs any necessary cleanup operations at the end of a run.
 
virtual void DoCommand (char *cCommand, char *cArguments)
 If a behavior has registered a command line command with the sim manager, this allows it to be called.
 

Protected Types

enum  member_type {
  notassigned, isfloat, isint, ischar,
  isbool
}
 Enum for types of tree data members. More...
 

Protected Member Functions

void ResetResultsGrid ()
 Resets all the values in the Harvest Results grid.
 
void SetupResultsGrid ()
 Sets up the "Harvest Results grid" and gets all the return codes.
 

Protected Attributes

enum
clHarvestInterface::member_type
mp_iMemberType
 Array for holding tree data member types.
 
char ** mp_cNewTreeDataMembers
 Array of labels for any new tree data members that this interface is to create.
 
char ** mp_cFileColumns
 Array of columns in the files.
 
char m_cExecutable [MAX_FILENAME_SIZE]
 Path to user executable.
 
char m_cInputFile [MAX_FILENAME_SIZE]
 Path and filename of the input file to the harvest executable that this behavior will prepare.
 
char m_cTreesToCutFile [MAX_FILENAME_SIZE]
 Path and filename of the file of the trees to cut that is created by the harvest executable.
 
char m_cTreesToUpdateFile [MAX_FILENAME_SIZE]
 Path and filename of the file of the trees to update that is created by the harvest executable - empty string if not needed.
 
char m_cBatchFileIn [MAX_FILENAME_SIZE]
 Path and filename of the batch parameters input file that this will read - empty string if not needed.
 
char m_cBatchParamsOut [MAX_FILENAME_SIZE]
 Path and filename of the parameters output file that this will write in the event of a batch - empty string if not needed.
 
char m_cArguments [MAX_ARGUMENT_LENGTH]
 Argument string to pass to the user executable - empty string if not needed.
 
bool ** mp_bAppliesToTrees
 Which trees this behavior is applied to.
 
int * mp_iColumnTranslation
 Initial values for the new float data members (if any).
 
bool * mp_bUserDefinedColumn
 Which of the file columns are user-defined new tree data members.
 
int m_iNextTimestepToHarvest
 The next timestep a harvest will be performed.
 
int m_iPeriod
 How often, in timesteps, harvests occur.
 
int m_iNumFileColumns
 Number of columns in the text files.
 
int m_iNumSpecies
 Total number of species, for the destructor.
 
short int m_iNumAllowedCutRanges
 Number of cut ranges allowed in "Harvest Results" grid - this comes from the class clDisturbance.
 
deadCode m_iReasonCode
 Reason code to pass to the tree population when trees are killed.
 
short int m_iHarvestTypeCode
 Harvest Type data member code in "Harvest Results" grid.
 
short int ** mp_iDenCutCodes
 Cut Density data member codes in "Harvest Results" grid.
 
short int ** mp_iBaCutCodes
 Cut Basal Area data member codes in "Harvest Results" grid.
 
clGridmp_oResultsGrid
 Harvest results grid, with same format as in clDisturbance.
 
- Protected Attributes inherited from clBehaviorBase
short int m_iNumSpeciesTypeCombos
 How many type/species combos a behavior will act on.
 
short int m_iNumBehaviorSpecies
 How many distinct species are in the combo list - important for filling species-specific values from parameter file.
 
short int * mp_iWhatSpecies
 List of distinct species - for filling species-specific values from parameter file.
 
stcSpeciesTypeCombomp_whatSpeciesTypeCombos
 Array of species/type combos that the behavior will act on.
 
short int m_iNewTreeInts
 The number of new tree integer data members this behavior wants to add.
 
short int m_iNewTreeFloats
 The number of new tree float data members this behavior wants to add.
 
short int m_iNewTreeChars
 The number of new tree character data members this behavior wants to add.
 
short int m_iNewTreeBools
 The number of new tree boolean data members this behavior wants to add.
 
short int m_iBehaviorListNumber
 The number of this behavior in the behavior list, to differentiate between possible multiple copies of this behavior.
 
float m_fVersionNumber
 Version number - this will be rounded to 2 digits after the decimal place.
 
std::string m_sXMLRoot
 XML root that encloses the parameters for this behavior.
 
float m_fMinimumVersionNumber
 Minimum version number - this behavior will run parameter data for a file marked between this number and the current version number, inclusive.
 
- Protected Attributes inherited from clWorkerBase
char m_cNameString [MAX_NAMESTRING_SIZE]
 Object's identifying namestring.
 
int * mp_iAllowedFileTypes
 List of the input file types this object can handle.
 
int m_iNumAllowedTypes
 Number of input file types this object can handle.
 

Additional Inherited Members

- Static Protected Attributes inherited from clWorkerBase
static clSimManagermp_oSimManager
 Pointer to the simulation manager object.
 

Detailed Description

Harvest Interface - Version 1.1.

This behavior serves as an interface between SORTIE and a user-written executable for harvesting. (Although code that did something besides harvesting is certainly possible for the creative programmer as well.)

This behavior executes on a user-defined cycle. When it executes, it gathers all eligible trees and writes them to a text file. It then calls the user executable. It expects the executable to create a file (with a pre-arranged name) with the list of trees to cut.

The user may also ask for new tree data members to be added on the executable's behalf. If this is the case, the user executable can also write a file of trees to to update with new values for those data members. The new data members (which are all floats), and their initial values, are passed in on the behavior's parameter file call string as follows: "HarvestInterface (name1) (name2)" etc. The initial values will always be 0. (We cannot do otherwise - a SORTIE run is constantly creating new trees, but we don't know which ones they are; so this behavior will never know (outside of initial conditions) which trees are new and which have a legitimately set value of 0.)

The file SORTIE writes for the user executable is tab-delimited text and has the following format: Line 1, two columns: Current timestep, total number of timesteps Line 2, column names, 6+n columns: "X", "Y", "Species", "Type", "Diam", "Height", [any additional variables that the user wishes]. Subsequent lines, 6+n columns, one line per tree: X, Y, species number, type number, DBH/diam10, height, [any additional variables that the user wishes, including new variables they have defined]. The "Diam" value is diameter at 10 cm if the tree type is seedling, and DBH in all other cases.

The file format of the user response files is identical to that of the SORTIE file, with the same columns in the same order. Each timestep, all these files are overwritten. Any other files in the working directory are ignored. (Incidentally, the timestep line in the response file will be ignored by SORTIE, so technically it doesn't have to be anything in particular.)

The list of harvested trees will be used to update the "Harvest Results" grid. This grid is the same as that produced by the clDisturbance class; however, if clDisturbance is also trying to use this grid in the same run, they will not play nicely together and will probably overwrite each other's results (at best). For each harvested species, this grid contains members called "Cut Density_0_x" and "Cut Basal Area_0_x" where x is the species number. These are raw density/BA values for each grid cell (8 m x 8 m) and are not converted to per ha amounts. The grid also contains a data member called "Harvest Type" that equals -1 if there was no harvesting in a grid cell this timestep, or 0 (partial cut) if there were harvested trees.

The user executable runs once per timestep. It does not stay running. So it must do any necessary initialization and setup each time. The executable can be written in any language, and can do anything it wishes. The only two requirements is that it be a standalone executable, and that it produce the file of trees to harvest that SORTIE expects.

If the user executable wants input parameters through SORTIE, it can have this behavior pass them as a string argument when the executable is launched. If it uses a file for input parameters, and SORTIE is running in batch mode, the user can specify a file with parameters for each run, one set per line; this behavior will extract the line corresponding to the batch number and write it to a specified file before calling the user executable.

The name string for this behavior is "HarvestInterface"; the parameter file call string is as described above.

Author
Lora E. Murphy


Edit history:
--------------—
October 20, 2011 - Wiped the slate clean for SORTIE 7.0 (LEM)

Member Enumeration Documentation

Enum for types of tree data members.

Enumerator:
notassigned 

Not assigned a type.

isfloat 

Float data member.

isint 

Int data member.

ischar 

Char data member.

isbool 

Bool data member.

Constructor & Destructor Documentation

clHarvestInterface::clHarvestInterface ( clSimManager p_oSimManager)

Constructor.

Parameters
p_oSimManagerSim Manager object.
clHarvestInterface::~clHarvestInterface ( )

Destructor.

Member Function Documentation

void clHarvestInterface::Action ( )
virtual

Performs the harvest.

The timestep is compared to m_iNextTimestepToHarvest. If they are not equal, the behavior exits. If they are equal, then:

  • m_iNextTimestepToHarvest is incremented with the value in m_iPeriodicity
  • All trees to which this behavior applies are collected and written to an input file for the harvesting program
  • The harvesting program is called, passing the parameters and the input file of trees
  • The harvest (and possibly update) output file(s) are read into memory
  • All trees to which this behavior applies are compared to the harvest (and output) list(s) and if they're on it (by way of type, species, X, Y, and diameter being equal) they are killed (or updated).

Reimplemented from clBehaviorBase.

void clHarvestInterface::GetData ( xercesc::DOMDocument *  p_oDoc)
virtual

Performs setup.

This reads from the parameter file. It verifies the working directory and its contents. If this is a batch run and the user has asked for the batch parameter file splitting, it writes this run's parameters.

Parameters
p_oDocDOM tree of parsed input file.
Exceptions
modelErrif:
  • The user executable is missing
  • Tree data members requested in the harvest file do not exist (data members that already exist, not those being created by this interface)
  • Number of timesteps between calls to the user executable is negative
  • Set of batch parameters too short for the number of requested runs

Implements clWorkerBase.

void clHarvestInterface::RegisterTreeDataMembers ( )
virtual

Registers any new data members requested by the user.

Reimplemented from clBehaviorBase.

void clHarvestInterface::ResetResultsGrid ( )
protected

Resets all the values in the Harvest Results grid.

Harvest Type becomes -1; all others are 0.

void clHarvestInterface::SetNameData ( char *  cNameString)
virtual

Captures the namestring passed to this behavior.

This parses out any tree data members that may be riding along on the string.

Parameters
cNameStringBehavior's namestring.

Reimplemented from clBehaviorBase.

void clHarvestInterface::SetupResultsGrid ( )
protected

Sets up the "Harvest Results grid" and gets all the return codes.

Member Data Documentation

char clHarvestInterface::m_cArguments[MAX_ARGUMENT_LENGTH]
protected

Argument string to pass to the user executable - empty string if not needed.

char clHarvestInterface::m_cBatchFileIn[MAX_FILENAME_SIZE]
protected

Path and filename of the batch parameters input file that this will read - empty string if not needed.

char clHarvestInterface::m_cBatchParamsOut[MAX_FILENAME_SIZE]
protected

Path and filename of the parameters output file that this will write in the event of a batch - empty string if not needed.

char clHarvestInterface::m_cExecutable[MAX_FILENAME_SIZE]
protected

Path to user executable.

char clHarvestInterface::m_cInputFile[MAX_FILENAME_SIZE]
protected

Path and filename of the input file to the harvest executable that this behavior will prepare.

char clHarvestInterface::m_cTreesToCutFile[MAX_FILENAME_SIZE]
protected

Path and filename of the file of the trees to cut that is created by the harvest executable.

char clHarvestInterface::m_cTreesToUpdateFile[MAX_FILENAME_SIZE]
protected

Path and filename of the file of the trees to update that is created by the harvest executable - empty string if not needed.

short int clHarvestInterface::m_iHarvestTypeCode
protected

Harvest Type data member code in "Harvest Results" grid.

int clHarvestInterface::m_iNextTimestepToHarvest
protected

The next timestep a harvest will be performed.

short int clHarvestInterface::m_iNumAllowedCutRanges
protected

Number of cut ranges allowed in "Harvest Results" grid - this comes from the class clDisturbance.

int clHarvestInterface::m_iNumFileColumns
protected

Number of columns in the text files.

int clHarvestInterface::m_iNumSpecies
protected

Total number of species, for the destructor.

int clHarvestInterface::m_iPeriod
protected

How often, in timesteps, harvests occur.

deadCode clHarvestInterface::m_iReasonCode
protected

Reason code to pass to the tree population when trees are killed.

bool** clHarvestInterface::mp_bAppliesToTrees
protected

Which trees this behavior is applied to.

The first index is number of species, the second is number of types.

bool* clHarvestInterface::mp_bUserDefinedColumn
protected

Which of the file columns are user-defined new tree data members.

Array size is m_iNumFileColumns.

char** clHarvestInterface::mp_cFileColumns
protected

Array of columns in the files.

These are labels of tree data members (with the exception of the generic "Diam"). The array is sized m_iNumFileColumns.

char** clHarvestInterface::mp_cNewTreeDataMembers
protected

Array of labels for any new tree data members that this interface is to create.

The array is sized m_iNewTreeFloats.

short int** clHarvestInterface::mp_iBaCutCodes
protected

Cut Basal Area data member codes in "Harvest Results" grid.

Array size is number of cut ranges by number of species

int* clHarvestInterface::mp_iColumnTranslation
protected

Initial values for the new float data members (if any).

Array size is m_iNewTreeFloats. Translation array between file columns and user-defined data members. Array size is m_iNumFileColumns. For each column, the value is the matching array index in mp_cNewTreeDataMembers, or -1 if the column is not a new user-defined tree data member.

short int** clHarvestInterface::mp_iDenCutCodes
protected

Cut Density data member codes in "Harvest Results" grid.

Array size is number of cut ranges by number of species

enum clHarvestInterface::member_type * clHarvestInterface::mp_iMemberType
protected

Array for holding tree data member types.

Array size is m_iNumFileColumns.

clGrid* clHarvestInterface::mp_oResultsGrid
protected

Harvest results grid, with same format as in clDisturbance.


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