00001 #ifndef TreePopulationH
00002 #define TreePopulationH
00003
00004 #include "TreeSearch.h"
00005 #include "Tree.h"
00006 #include "PopulationBase.h"
00007 #include "Constants.h"
00008 #include "ModelMath.h"
00009 #include <string.h>
00010
00011 class clAllometry;
00070 class clTreePopulation : public clPopulationBase {
00071 friend class clTreeSearch;
00072 friend class clTree;
00073 friend class clTestTreePopulation;
00074 friend class clTestTreePopulation2;
00075 friend class clAllometry;
00076
00077 private:
00083 clTreePopulation(const clTreePopulation &oldPop);
00084
00085 public:
00086
00090 ~clTreePopulation();
00091
00097 clTreePopulation(clSimManager *p_oSimManager);
00098
00100 enum iTreeType {seed,
00101 seedling,
00102 sapling,
00104 adult,
00106 stump,
00108 snag,
00109 woody_debris
00110 };
00111
00114 enum iWhyDead {harvest,
00115 natural,
00116 disease,
00117 fire,
00118 insects,
00119 storm,
00120 remove
00121 };
00122
00161 clTreeSearch* Find(char *args);
00162
00184 clTree* CreateTree(float fX, float fY, int iSp, int iType, float fDiam);
00185
00216 clTree* KillTree(clTree *p_deadTree, unsigned short int iReason);
00217
00225 void BarebonesDataSetup(xercesc::DOMDocument *p_oDoc);
00226
00234 short int TranslateSpeciesNameToCode(char *cSpeciesName);
00235
00243 char* TranslateSpeciesCodeToName(int iSpecies);
00244
00259 short int RegisterInt(char *cLabel, int iSpecies, int iType);
00260
00275 short int RegisterFloat(char *cLabel, int iSpecies, int iType);
00276
00291 short int RegisterChar(char *cLabel, int iSpecies, int iType);
00292
00307 short int RegisterBool(char *cLabel, int iSpecies, int iType);
00308
00321 short int GetIntDataCode(char *cLabel, int iSpecies, int iType);
00322
00335 short int GetFloatDataCode(char *cLabel, int iSpecies, int iType);
00336
00348 short int GetCharDataCode(char *cLabel, int iSpecies, int iType);
00349
00361 short int GetBoolDataCode(char *cLabel, int iSpecies, int iType);
00362
00373 char* GetIntDataLabel(short int iCode, int iSpecies, int iType);
00374
00385 char* GetFloatDataLabel(short int iCode, int iSpecies, int iType);
00386
00397 char* GetCharDataLabel(short int iCode, int iSpecies, int iType);
00398
00409 char* GetBoolDataLabel(short int iCode, int iSpecies, int iType);
00410
00415 void DoDataUpdates();
00416
00426 float GetRandomDiam10Value(float fDiam10Seed = 0);
00427
00436 short int GetXCode(int iSpecies, int iType);
00437
00446 short int GetYCode(int iSpecies, int iType);
00447
00456 short int GetHeightCode(int iSpecies, int iType);
00457
00466 short int GetDbhCode(int iSpecies, int iType);
00467
00476 short int GetDiam10Code(int iSpecies, int iType);
00477
00485 short int GetWhyDeadCode(int iSpecies);
00486
00494 short int GetAgeCode(int iSpecies);
00495
00503 float GetMinAdultDBH(int iSpecies);
00504
00510 clAllometry* GetAllometryObject() {return mp_oAllom;};
00511
00517 int GetNumberOfSpecies() {return m_iNumSpecies;};
00518
00524 int GetNumberOfTypes() {return m_iNumTypes;};
00525
00531 int GetGridCellSize() {return m_iLengthGrids;};
00532
00539 int GetNumXCells() {return m_iNumXCells;};
00540
00547 int GetNumYCells() {return m_iNumYCells;};
00548
00553 bool GetUsesSnags() {return m_bMakeSnag;};
00554
00561 float GetXPlotLength() {return m_fPlotLengthX;};
00562
00569 float GetYPlotLength() {return m_fPlotLengthY;};
00570
00576 float GetMaxSeedlingHeight(int iSpecies) {return mp_fMaxSeedlingHeight[iSpecies];};
00577
00582 float GetMinimumAdultHeight() {return m_fMinAdultHeight;};
00583
00589 float GetNewSeedlingDiam10() {return m_fNewSeedlingDiam10;};
00590
00598 clTree* GetShortestTreeInCell(int iX, int iY);
00599
00607 clTree* GetTallestTreeInCell(int iX, int iY);
00608
00614 clTree* GetFirstStump(){return mp_oStumps;};
00615
00617
00619 protected:
00620
00621
00623 struct stcOpenSearches {
00624 clTreeSearch *p_oSearch;
00625 stcOpenSearches *p_nextSearch;
00626 } *mp_openSearches;
00628 float m_fNewSeedlingDiam10;
00630 float m_fMinAdultHeight;
00631 float m_fMaxSaplingHeight;
00634 float *mp_fMaxSeedlingHeight;
00635 float *mp_fMinAdultDbh;
00637 float m_fPlotLengthX;
00638 float m_fPlotLengthY;
00639 float *mp_fSizeClasses;
00644 int m_iNumHeightDivs;
00645 int m_iSizeHeightDivs;
00646 int m_iNumSpecies;
00647 int m_iNumTypes;
00648 int m_iNumXCells;
00650 int m_iNumYCells;
00652 int m_iNumSizeClasses;
00653 int m_iLengthGrids;
00655 bool bDoUpdates;
00657 bool *mp_bMakeStump;
00659 bool m_bMakeSnag;
00661 short int **mp_iNumTreeIntVals;
00664 short int **mp_iNumTreeFloatVals;
00667 short int **mp_iNumTreeCharVals;
00670 short int **mp_iNumTreeBoolVals;
00674 char ****mp_cIntLabels;
00677 char ****mp_cFloatLabels;
00680 char ****mp_cCharLabels;
00683 char ****mp_cBoolLabels;
00687 short int **mp_iXCode;
00689 short int **mp_iYCode;
00691 short int **mp_iHeightCode;
00693 short int **mp_iDiam10Code;
00695 short int **mp_iDbhCode;
00697 short int *mp_iAgeCode;
00699 short int *mp_iWhyDeadCode;
00705 void DataMemberRegistrations();
00706
00726 void GetData(xercesc::DOMDocument *p_oDoc);
00727
00736 void TimestepCleanup();
00737
00742 void GetPlotDimensions();
00743
00748 void SetupCalculations();
00749
00754 void CreateHashTable();
00755
00756
00770 short int RegisterDataMember(char *cLabel, int iSpecies, int iType,
00771 short int **p_iNumTreeVals, char ****p_cLabels);
00772
00787 void DoTreeDataStructureSetup();
00788
00791 struct speciesCodes {unsigned short int iCode;
00792 char cName[MAX_SPECIES_NAME_SIZE];
00793 };
00794 speciesCodes *mp_speciesCodes;
00797 clAllometry *mp_oAllom;
00798
00802 void ReadParameters(xercesc::DOMDocument *p_oDoc);
00803
00813 void CreateTreesFromInitialDensities(xercesc::DOMDocument *p_oDoc);
00814
00824 void CreateTreesFromTreeMap(xercesc::DOMDocument *p_oDoc);
00825
00831 void AddTreeToHashTable(clTree *p_oNewTree);
00832
00838 inline void UpdateTreeInHashTable(clTree *p_oChangedTree);
00839
00846 void RemoveTreeFromHashTable(clTree *p_oByeTree);
00847
00851 void EmptyHashTable();
00852
00857 void DeleteStumps();
00858
00870 void ChangeTreeType(clTree *p_oTree, enum iTreeType iNewType);
00871
00879 void SortHashTable();
00880
00891 void UpdateTree(clTree *p_oTree, short int iCode,int iValue);
00892
00931 void UpdateTree(clTree *p_oTree,short int iCode,float fValue, bool bUpdateNow, bool bUpdateAllometry);
00932
00943 void UpdateTree(clTree *p_oTree,short int iCode,char *cValue);
00944
00955 void UpdateTree(clTree *p_oTree, short int iCode, bool bValue);
00956
00957 clTree ****mp_oTreeTallest;
00964 clTree ****mp_oTreeShortest;
00971 clTree *mp_oStumps;
00973 };
00974
00975 #endif
00976