3a4,7
> #include <list>
> #include <map>
> #include <iostream>
> 
5a10,12
> #include "TimberClassStruct.h"
> #include "AxsDefStruct.h"
> 
7a15,16
> using namespace std;
> 
10,20c19,21
<     void harvest(int period);
<     void derive_percentage_target(int period);
<     void derive_percentage_target(int period);
<     void harvest_update_activity(TIMBER_CLASS *timber_class, double harea, double vph,
<                                  int period);
<     double harvest_adjacency(TIMBER_CLASS *timber_class, int period);
<     double harvest_volume_shortfall(TIMBER_CLASS *timber_class, double vph, int period);
<     double harvest_area_shortfall(TIMBER_CLASS *timber_class, int period);
<     double calculate_green_up(AXSDEF *axs, TIMBER_CLASS *timber_class, int period);
<     void debug_display_agearea(AXSDEF *axs, char *where);
<     double calculate_old_growth(AXSDEF *axs, TIMBER_CLASS *timber_class, int period/*, double totalMatureAxsArea*/);
---
>     void harvest();
>     void derive_percentage_target();
>     void derive_percentage_target();
21a23,37
>     void harvest_update_activity(TimberClassStruct *pTimberClass, const double harea, const double vph);
> 
>     void harvest_insert_agedist(TimberClassStruct *pTimberClass, map<int, AGEDIST*>* pAgeDistList, const double volume, const double area);
> 
>     AGEDIST* harvest_create_agedist(TimberClassStruct* pTimberClass, map<int, AGEDIST*>* pAgeDistList);
> 
>     void harvest_update_group_list(TimberClassStruct* pTimberClass, const double volume, const double area);
> 
>     double harvest_adjacency(TimberClassStruct *timber_class);
>     double harvest_volume_shortfall(TimberClassStruct *timber_class, double vph);
>     double harvest_area_shortfall(TimberClassStruct *timber_class);
>     double calculate_green_up(AxsDefStruct *axs, TimberClassStruct *timber_class);
>     void debug_display_agearea(AxsDefStruct *axs, char *where);
>     double calculate_old_growth(AxsDefStruct *axs, TimberClassStruct *timber_class/*, double totalMatureAxsArea*/);
> 
24,25c40,41
<     double doAxsListLessThanGreaterThan(TIMBER_CLASS *timber_class, LIST_PTR* axsList, int period, double result, int axsFactorCount);
<     double harvest_constraints(TIMBER_CLASS *timber_class, int period);
---
>     void doAxsListLessThanGreaterThan(TimberClassStruct *timber_class, vector<AxsDefStruct*>& pAxsList, double& result);
>     double harvest_constraints(TimberClassStruct *timber_class);
27c43
<     inline double harvest_adjacency(TIMBER_CLASS *timber_class, int period)
---
>     inline double harvest_adjacency(TimberClassStruct *timber_class)
29c45,47
<         if (timber_class->parent_block->AdjacencyDelay > FssimApp::getApp()->m_periodLength[period])
---
>         FssimApp* pApp = FssimApp::getApp();
> 
>         if (timber_class->parent_block->AdjacencyDelay > pApp->m_periodLength[pApp->m_currentPeriod])
31c49
<             return(0.0);
---
>             return 0.0;
32a51,52
>         return(timber_class->MerchArea);
>     }
34c54,73
<         return (timber_class->MerchArea);
---
>     inline AGEDIST* harvest_create_agedist(TimberClassStruct* pTimberClass, map<int, AGEDIST*>* pAgeDistList)
>     {
>         AGEDIST* pAgeDist = new AGEDIST;
>         if (0 == pAgeDist)
>         {
>             cerr << endl << endl << "ERROR: harvest_update_activity(): Could not allocate new AGEDIST structure" << endl << endl;
>             throw bad_alloc();
>         }
>         pAgeDist->age = pTimberClass->age;
> 
> #ifdef _TSB_AGE_DEBUG
>         cout << endl << "created agedist with age: " << pAgeDist->age << endl;
> #endif
> 
>         pAgeDist->width = pTimberClass->width;
>         pAgeDist->area = 0.0;
>         pAgeDist->volume = 0.0;
>         (*pAgeDistList)[pAgeDist->age] = pAgeDist;
> 
>         return pAgeDist;
37c76,77
<     inline double calculate_green_up(AXSDEF *axs, TIMBER_CLASS *timber_class, int period)
---
>     inline void harvest_insert_agedist(TimberClassStruct* pTimberClass, map<int, AGEDIST*>* pAgeDistList,
>                                        const double volume, const double area)
38a79,104
>         AGEDIST* pAgeDist = 0;
>         map<int, AGEDIST*>::iterator foundIter = pAgeDistList->find(pTimberClass->age);
>         if (foundIter != pAgeDistList->end())
>         {
>             pAgeDist = foundIter->second;
>             if ( pAgeDist->width != pTimberClass->width )
>             {
>                 pAgeDist = harvest_create_agedist(pTimberClass, pAgeDistList);
>             }
>         }
>         else
>         {
>             pAgeDist = harvest_create_agedist(pTimberClass, pAgeDistList);
>         }
>         pAgeDist->area += area;
>         pAgeDist->volume += volume;
> 
> #ifdef _TSB_HARVEST_DEBUG_OFF
>         cout << endl << "harvest update activity: agedist area: "
>              << pAgeDist->area << endl << "agedist volume: " << pAgeDist->volume << endl;
> #endif
> 
>     }
> 
>     inline double calculate_green_up(AxsDefStruct *axs, TimberClassStruct *timber_class)
>     {
41c107,110
<         if (axs->Age<pApp->m_periodLength[period])
---
> 
>         int period = pApp->m_currentPeriod;
> 
>         if (axs->Age < pApp->m_periodLength[period])
43c112
<             cout << endl << "WARNING: axs->age(" << axs->Age << ") < PeriodLength("
---
>             cerr << endl << "WARNING: axs->age(" << axs->Age << ") < PeriodLength("
50,51c119,120
<             tmp = (axs->BaseArea*axs->Percent/100.0) - func_area_lt(axs->AgeArea,
<                    axs->Age-pApp->m_periodLength[period], period);
---
>             tmp = (axs->BaseArea * axs->Percent / 100.0)
>                   - func_area_lt(axs->pAgeArea, axs->Age - pApp->m_periodLength[period]);
52a122
> 
57a128
> 
61c132
<     inline void debug_display_agearea(AXSDEF *axs, char *where)
---
>     inline void debug_display_agearea(AxsDefStruct *axs, char *where)
63d133
<         int i = 0;
64a135
> 
66c137,138
<         for( i=0; i<axs->NumAgeAreaElements; ++i )
---
> 
>         for( int i = 0; i < axs->NumAgeAreaElements; ++i )
68c140,142
<             if ( axs->AgeArea[i] > 0.0f )
---
>             // should be 0.0 for double, but was 0.0f in v4.0.x
>             //if ( (*axs->pAgeArea)[i] > 0.0 )
>             if ( (*axs->pAgeArea)[i] > 0.0f )
70c144
<                 fprintf(pApp->m_pFileTrace, "\nAgeArea[%3d]: %8.2f", i, axs->AgeArea[i]);
---
>                 fprintf(pApp->m_pFileTrace, "\nAgeArea[%3d]: %8.2f", i, (*axs->pAgeArea)[i]);
76c150
<     inline double calculate_old_growth(AXSDEF *axs, TIMBER_CLASS *timber_class, int period)
---
>     inline double calculate_old_growth(AxsDefStruct* axs, TimberClassStruct *timber_class)
80,83c154
<         //v4.0.2, Kevin Belanger moved outside to just before harvest function calls calculate_old_growth
<         //double totalMatureAxsArea = func_area_ge(axs->AgeArea, axs->NumAgeAreaElements,
<         //                                 (axs->Age - pApp->m_periodLength[period]),
<         //                                 period, timber_class->width);
---
>         int period = pApp->m_currentPeriod;
86,87c157,158
<         double totalMatureAxsArea = func_area_ge(axs->AgeArea, axs->NumAgeAreaElements,
<                                                  (axs->Age - pApp->m_periodLength[period]), period);
---
>         double totalMatureAxsArea = func_area_ge(axs->pAgeArea, axs->NumAgeAreaElements,
>                                                  (axs->Age - pApp->m_periodLength[period]));
91,93c162,163
<         double currentClassAndOlderArea = func_area_ge(axs->AgeArea, axs->NumAgeAreaElements,
<                                                         (timber_class->age - timber_class->width + 1),
<                                                         period);
---
>         double currentClassAndOlderArea = func_area_ge(axs->pAgeArea, axs->NumAgeAreaElements,
>                                                         (timber_class->age - timber_class->width + 1));
95,96c165
< 
< #ifdef _TSB_AXS_DEBUG
---
> #ifdef _TSB_HARVEST_CONSTRAINTS_DEBUG
99d167
< 
102c170
<              << setw(20) << "axs->BaseArea = " << setw(3) << axs->BaseArea
---
>              << setw(20) << "axs->BaseArea = " << setw(8) << axs->BaseArea
103a172
> 
109c178
<             if (axs->AgeArea[i] > 0)
---
>             if ((*axs->pAgeArea)[i] > 0.0)
111,112c180,181
<                 cout << setw(24) << "AgeArea["  << i << "] = "
<                      << setw(3) << axs->AgeArea[i] << endl;
---
>                 cout << setw(24) << "AgeArea[" << i << "] = "
>                      << setw(8) << (*axs->pAgeArea)[i] << endl;
118,119c187,188
<         if ( ( (totalMatureAxsArea - desiredArea) > FssimApp::m_kRoundError ) &&
<              ( (totalMatureAxsArea - currentClassAndOlderArea) > FssimApp::m_kRoundError ) )
---
>         if ( ( (totalMatureAxsArea - desiredArea) > FssimUtil::m_kRoundError ) &&
>              ( (totalMatureAxsArea - currentClassAndOlderArea) > FssimUtil::m_kRoundError ) )
135,138c204,207
<         cout << setw(30) << "totalMatureAxsArea = " << setw(3) << totalMatureAxsArea
<              << setw(30) << "desiredArea = " << setw(3) << desiredArea << endl
<              << setw(30) << "currentClassAndOlderArea = " << setw(3) << currentClassAndOlderArea
<              << setw(30) << "harvestableArea = " << setw(3) << harvestableArea << endl;
---
>         cout << setw(30) << "totalMatureAxsArea = " << setw(8) << totalMatureAxsArea
>              << setw(30) << "desiredArea = " << setw(8) << desiredArea << endl
>              << setw(30) << "currentClassAndOlderArea = " << setw(8) << currentClassAndOlderArea
>              << setw(30) << "harvestableArea = " << setw(8) << harvestableArea << endl;
