ALMaSS Rabbit ODdox  1.1
The rabbit model description following ODdox protocol
plants.h
Go to the documentation of this file.
1 //
2 // plants.h
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, Aarhus University
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 
29 #ifndef PLANTS_H
30  #define PLANTS_H
31 
32 #include <vector>
33 #include <algorithm>
34 #include <cstdio>
35 #include <fstream>
36 #include "tov_declaration.h"
37 #include "tole_declaration.h"
38 
39 using namespace std;
40 
41 const unsigned int MaxNoInflections = 15;
42 
51 typedef enum {
52  janfirst = 0,
53  sow,
58 }
60 
61 
62 
63 // 0: Leaf area green.
64 // 1: Leaf area total.
65 // 2: Height.
66 
67 class CropGrowth {
68 public:
69  bool m_lownut; // Low nutrient status.
70  double m_dds[ 5 ] [ MaxNoInflections ]; // DDegs at inflection
71  double m_slopes[ 5 ] [ 3 ] [ MaxNoInflections ];
72  double m_start[ 5 ] [ 3 ];
73  bool m_start_valid[ 5 ];
74 
75  CropGrowth( void );
76 };
77 
78 extern class PlantGrowthData * g_crops;
79 
80 
82  vector < CropGrowth * > m_growth;
83  vector < int > m_numbers;
85  //FILE * m_ifile;
86  ifstream m_ifile;
87  double * m_weed_percent;
88  double * m_bug_percent_a;
89  double * m_bug_percent_b;
90  double * m_bug_percent_c;
92 
93  double FindDiff( double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type );
94  unsigned int FindCropNum( ifstream& ist );
95  //void SetVegNum( unsigned int a_i, const char * a_cropcurvefile );
96  void SetVegNum( unsigned int a_i, ifstream& ist,const char * a_cropcurvefile );
97 
98 
99  void MakeBugPercentArray( void );
100  void ReadBugPercentageFile( void );
101 
102 public:
103 
104  // NOTICE: These functions take *plant numbers* like in the
105  // CropGrowth.txt file, *NOT* indices into the m_growth array.
107  double GetLAgreenDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase) {
108  return FindDiff(a_ddegs, a_yddegs, a_plant, a_phase, 0);
109  }
111  double GetLAtotalDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase) {
112  return FindDiff(a_ddegs, a_yddegs, a_plant, a_phase, 1);
113  }
115  double GetHeightDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase) {
116  return FindDiff(a_ddegs, a_yddegs, a_plant, a_phase, 2);
117  }
118 
119  // The versions below allow scaling of the curve on calling
121  double GetLAgreenDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler) { return a_scaler* GetLAgreenDiff(a_ddegs, a_yddegs, a_plant, a_phase); }
123  double GetLAtotalDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler) { return a_scaler* GetLAtotalDiff(a_ddegs, a_yddegs, a_plant, a_phase); }
125  double GetHeightDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler) { return a_scaler* GetHeightDiff(a_ddegs, a_yddegs, a_plant, a_phase); }
126 
127  double GetStartValue(int a_veg_type, int a_phase, int a_type) {
128  return m_growth[m_numbers[a_veg_type]]->m_start[a_phase][a_type];
129  }
130 
131  bool StartValid( int a_veg_type, int a_phase );
132 
133  /* { return m_growth[ m_numbers[ a_veg_type ]]-> m_start_valid[ a_phase ]; } */
134  // Number of different crops read from disk.
135  int GetNumCrops() {
136  return m_num_crops;
137  }
138 
139  // Translation between growth curve file crop numbers and the internal
140  // representation.
141  //TTypesOfVegetation TranslateFileVegTypes( int a_filetype );
142  //int BackTranslateFileVegTypes( TTypesOfVegetation a_systemtype );
143  int VegTypeToCurveNum( TTypesOfVegetation VegReference );
144 
145  // **cjt** added 30/01/2004
146  double GetWeedPercent( TTypesOfVegetation a_letype ) {
147  return m_weed_percent[ a_letype ];
148  }
149 
150  // **cjt** added 27/05/2003
151  double GetBugPercentA( TTypesOfVegetation a_letype ) {
152  return m_bug_percent_a[ a_letype ];
153  }
154 
155  // **cjt** added 27/05/2003
156  double GetBugPercentB( TTypesOfVegetation a_letype ) {
157  return m_bug_percent_b[ a_letype ];
158  }
159 
160  // **cjt** added 27/05/2003
161  double GetBugPercentC( TTypesOfVegetation a_letype ) {
162  return m_bug_percent_c[ a_letype ];
163  }
164 
165  // **cjt** added 12/03/2003
166  double GetBugPercentD( TTypesOfVegetation a_letype ) {
167  return (double) m_bug_percent_d[ a_letype ];
168  }
169 
170  bool GetNutStatus( int a_plant_num ) {
171  return m_growth[ a_plant_num ]->m_lownut;
172  }
173 
174  bool GetNutStatusExt( int a_plant ) {
175  return m_growth[ m_numbers[ a_plant ]]->m_lownut;
176  }
177 
178  PlantGrowthData( const char * a_cropcurvefile );
179  ~PlantGrowthData();
180 };
181 
184 {
185 public:
186  PollenNectarDevelopmentCurve(vector<int>* a_index, vector<double>* a_slopes) {
187  m_index = *a_index;
188  m_data = *a_slopes;
189  }
191 
193  double GetData(int a_index) {
194  return m_data[a_index];
195  }
196  inline int closest(int a_value) {
197  // returns the vector index for m_index where the value contained is the first number greater than a_value
198  return int(std::distance(m_index.begin(), upper_bound(m_index.begin(), m_index.end(), a_value)));
199  }
200 protected:
204  vector <double> m_data;
206  vector <int> m_index;
207 };
208 
210 public:
213 };
214 
216 public:
218  PollenNectarQuality(double a_quantity, double a_quality);
219  double m_quantity;
220  double m_quality;
221 };
222 
225 {
226 public:
227  PollenNectarDevelopmentData(string a_tovinputfile, string a_toleinputfile, Landscape* a_land);
229  double toleGetPollen(int a_tole, int a_index) { return m_tolePollenCurves[int(a_tole)]->GetData(a_index); }
230  double toleGetNectar(int a_tole, int a_index) { return m_toleNectarCurves[int(a_tole)]->GetData(a_index); }
231  double tovGetPollen(int a_tov, int a_index) { return m_tovPollenCurves[int(a_tov)]->GetData(a_index); }
232  double tovGetNectar(int a_tov, int a_index) { return m_tovNectarCurves[int(a_tov)]->GetData(a_index); }
233  int tovGetNPCurveNum(TTypesOfVegetation a_tov) { return m_tov_pollencurvetable[a_tov]; }
234  int toleGetNPCurveNum(TTypesOfVegetation a_tov) { return m_tole_pollencurvetable[a_tov]; }
235  PollenNectarDevelopmentCurveSet GetPollenNectarCurvePtr(int a_almassLEref);
236  PollenNectarDevelopmentCurveSet tovGetPollenNectarCurvePtr(int a_tov_ref);
237 protected:
238  vector<PollenNectarDevelopmentCurve*> m_tovPollenCurves;
239  vector<PollenNectarDevelopmentCurve*> m_tovNectarCurves;
240  vector<PollenNectarDevelopmentCurve*> m_tolePollenCurves;
241  vector<PollenNectarDevelopmentCurve*> m_toleNectarCurves;
244 };
245 
246 #endif // PLANTS_H
247 
PollenNectarDevelopmentCurve::closest
int closest(int a_value)
Definition: plants.h:196
PlantGrowthData::GetBugPercentB
double GetBugPercentB(TTypesOfVegetation a_letype)
Definition: plants.h:156
PollenNectarDevelopmentData::m_tov_pollencurvetable
vector< int > m_tov_pollencurvetable
Definition: plants.h:242
PlantGrowthData::m_bug_percent_b
double * m_bug_percent_b
Definition: plants.h:89
PlantGrowthData::GetBugPercentA
double GetBugPercentA(TTypesOfVegetation a_letype)
Definition: plants.h:151
PlantGrowthData::m_bug_percent_a
double * m_bug_percent_a
Definition: plants.h:88
PlantGrowthData::GetLAgreenDiff
double GetLAgreenDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase)
Get the differential in LA green for the day degrees experienced.
Definition: plants.h:107
g_crops
class PlantGrowthData * g_crops
Definition: plants.cpp:41
PollenNectarQuality
Definition: plants.h:215
PlantGrowthData::GetLAtotalDiff
double GetLAtotalDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase)
Get the differential in LA total for the day degrees experienced.
Definition: plants.h:111
PlantGrowthData::GetNumCrops
int GetNumCrops()
Definition: plants.h:135
PlantGrowthData::m_ifile
ifstream m_ifile
Definition: plants.h:86
PollenNectarDevelopmentCurveSet
Definition: plants.h:209
PollenNectarDevelopmentData::m_tolePollenCurves
vector< PollenNectarDevelopmentCurve * > m_tolePollenCurves
Definition: plants.h:240
PollenNectarDevelopmentData::toleGetPollen
double toleGetPollen(int a_tole, int a_index)
Definition: plants.h:229
PollenNectarDevelopmentCurve::PollenNectarDevelopmentCurve
PollenNectarDevelopmentCurve(vector< int > *a_index, vector< double > *a_slopes)
Definition: plants.h:186
PollenNectarDevelopmentCurveSet::m_pollencurveptr
PollenNectarDevelopmentCurve * m_pollencurveptr
Definition: plants.h:211
PlantGrowthData::m_bug_percent_d
int * m_bug_percent_d
Definition: plants.h:91
PlantGrowthData::m_bug_percent_c
double * m_bug_percent_c
Definition: plants.h:90
PollenNectarDevelopmentData::m_toleNectarCurves
vector< PollenNectarDevelopmentCurve * > m_toleNectarCurves
Definition: plants.h:241
PlantGrowthData::GetLAgreenDiffScaled
double GetLAgreenDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler)
Get the differential in LA green for the day degrees experienced, scalable depending on plant growth ...
Definition: plants.h:121
PlantGrowthData::GetWeedPercent
double GetWeedPercent(TTypesOfVegetation a_letype)
Definition: plants.h:146
vegphase_foobar
Definition: plants.h:57
harvest1
Definition: plants.h:55
PollenNectarDevelopmentCurve::GetData
double GetData(int a_index)
The basic return function for the curve - day indexed.
Definition: plants.h:193
CropGrowth
Definition: plants.h:67
PlantGrowthData::GetBugPercentC
double GetBugPercentC(TTypesOfVegetation a_letype)
Definition: plants.h:161
PlantGrowthData::m_num_crops
int m_num_crops
Definition: plants.h:84
Landscape
The landscape class containing all environmental and topographical data.
Definition: landscape.h:112
PollenNectarDevelopmentData::toleGetNPCurveNum
int toleGetNPCurveNum(TTypesOfVegetation a_tov)
Definition: plants.h:234
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
PollenNectarQuality::m_quantity
double m_quantity
Definition: plants.h:219
Growth_Phases
Growth_Phases
Growth phase indicator.
Definition: plants.h:51
PlantGrowthData::m_growth
vector< CropGrowth * > m_growth
Definition: plants.h:82
PlantGrowthData::m_numbers
vector< int > m_numbers
Definition: plants.h:83
PollenNectarDevelopmentData::m_tovNectarCurves
vector< PollenNectarDevelopmentCurve * > m_tovNectarCurves
Definition: plants.h:239
PollenNectarDevelopmentCurve::m_CurveRefNum
int m_CurveRefNum
a reference to identify this precise curve - needs external management
Definition: plants.h:202
PlantGrowthData::GetNutStatus
bool GetNutStatus(int a_plant_num)
Definition: plants.h:170
PollenNectarDevelopmentData::tovGetNectar
double tovGetNectar(int a_tov, int a_index)
Definition: plants.h:232
PlantGrowthData::m_weed_percent
double * m_weed_percent
Definition: plants.h:87
PollenNectarDevelopmentData::tovGetNPCurveNum
int tovGetNPCurveNum(TTypesOfVegetation a_tov)
Definition: plants.h:233
PollenNectarDevelopmentData
A standard class to manage a range of pollen and nectar development curves based on indexed rates.
Definition: plants.h:224
PollenNectarDevelopmentCurve
A standard class to contain a pollen or nectar curve based on indexed rates.
Definition: plants.h:183
PlantGrowthData::GetHeightDiff
double GetHeightDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase)
Get the differential in veg height for the day degrees experienced.
Definition: plants.h:115
PlantGrowthData::GetStartValue
double GetStartValue(int a_veg_type, int a_phase, int a_type)
Definition: plants.h:127
PlantGrowthData::GetHeightDiffScaled
double GetHeightDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler)
Get the differential in veg height for the day degrees experienced, scalable depending on plant growt...
Definition: plants.h:125
PollenNectarDevelopmentData::tovGetPollen
double tovGetPollen(int a_tov, int a_index)
Definition: plants.h:231
PlantGrowthData::GetBugPercentD
double GetBugPercentD(TTypesOfVegetation a_letype)
Definition: plants.h:166
PlantGrowthData
Definition: plants.h:81
PollenNectarDevelopmentCurveSet::m_nectarcurveptr
PollenNectarDevelopmentCurve * m_nectarcurveptr
Definition: plants.h:212
PlantGrowthData::GetNutStatusExt
bool GetNutStatusExt(int a_plant)
Definition: plants.h:174
PollenNectarDevelopmentData::m_tovPollenCurves
vector< PollenNectarDevelopmentCurve * > m_tovPollenCurves
Definition: plants.h:238
PlantGrowthData::GetLAtotalDiffScaled
double GetLAtotalDiffScaled(double a_ddegs, double a_yddegs, int a_plant, int a_phase, double a_scaler)
Get the differential in LA total for the day degrees experienced, scalable depending on plant growth ...
Definition: plants.h:123
harvest2
Definition: plants.h:56
PollenNectarDevelopmentData::toleGetNectar
double toleGetNectar(int a_tole, int a_index)
Definition: plants.h:230
janfirst
Definition: plants.h:52
CropGrowth::m_lownut
bool m_lownut
Definition: plants.h:69
PollenNectarDevelopmentData::m_tole_pollencurvetable
vector< int > m_tole_pollencurvetable
Definition: plants.h:243
tov_declaration.h
PollenNectarDevelopmentCurve::m_data
vector< double > m_data
The slopes used.
Definition: plants.h:204
tole_declaration.h
PollenNectarDevelopmentCurve::~PollenNectarDevelopmentCurve
~PollenNectarDevelopmentCurve()
Definition: plants.h:190
MaxNoInflections
const unsigned int MaxNoInflections
Definition: plants.h:41
marchfirst
Definition: plants.h:54
sow
Definition: plants.h:53
PollenNectarQuality::m_quality
double m_quality
Definition: plants.h:220
PollenNectarDevelopmentCurve::m_index
vector< int > m_index
the index values to the slopes
Definition: plants.h:206