ALMaSS Rabbit ODdox  1.00
The rabbit model description following ODdox protocol
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CropData Class Reference

#include <plants.h>

Public Member Functions

double GetLAtotalDiff (double a_ddegs, double a_yddegs, int a_plant, int a_phase)
 
double GetLAgreenDiff (double a_ddegs, double a_yddegs, int a_plant, int a_phase)
 
double GetHeightDiff (double a_ddegs, double a_yddegs, int a_plant, int a_phase)
 
double GetStartValue (int a_veg_type, int a_phase, int a_type)
 
bool StartValid (int a_veg_type, int a_phase)
 
int GetNumCrops ()
 
int VegTypeToCurveNum (TTypesOfVegetation VegReference)
 
double GetWeedPercent (TTypesOfVegetation a_letype)
 
double GetBugPercentA (TTypesOfVegetation a_letype)
 
double GetBugPercentB (TTypesOfVegetation a_letype)
 
double GetBugPercentC (TTypesOfVegetation a_letype)
 
double GetBugPercentD (TTypesOfVegetation a_letype)
 
bool GetNutStatus (int a_plant_num)
 
bool GetNutStatusExt (int a_plant)
 
 CropData (const char *a_cropcurvefile)
 
 ~CropData ()
 

Private Member Functions

double FindDiff (double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type)
 
unsigned int FindCropNum (const char *a_cropcurvefile)
 
void SetVegNum (unsigned int a_i, const char *a_cropcurvefile)
 
void MakeBugPercentArray (void)
 
void ReadBugPercentageFile (void)
 

Private Attributes

vector< CropGrowth * > m_growth
 
vector< int > m_numbers
 
int m_num_crops
 
FILE * m_ifile
 
double * m_weed_percent
 
double * m_bug_percent_a
 
double * m_bug_percent_b
 
double * m_bug_percent_c
 
int * m_bug_percent_d
 

Detailed Description

Definition at line 80 of file plants.h.

Constructor & Destructor Documentation

CropData::CropData ( const char *  a_cropcurvefile)

Definition at line 174 of file plants.cpp.

References FindCropNum(), FloatToDouble(), m_growth, m_ifile, MaxNoInflections, and SetVegNum().

175 {
176  // Just finds out how many veg curves there are.
177  unsigned int NoPlants = FindCropNum( a_vegcurvefile );
178 
179  for ( unsigned int i=0; i<NoPlants; i++) {
180  CropGrowth* temp;
181  temp = new CropGrowth;
182  m_growth[ i ] = temp;
183  SetVegNum( i, a_vegcurvefile );
184 
185  for (unsigned int j=0; j<5; j++) { // for each growth phase
186  // 'Local' index into crop growth curves.
187  int lk = 0;
188  for (unsigned int k=0; k<MaxNoInflections; k++) {
189  // for each inflection point
190  int entry;
191  fscanf( m_ifile, "%d", &entry );
192  float f1=0,f2=0,f0=0;
193  if ( entry == -1 ) {
194  // Crop start data.
195  m_growth[ i ]->m_start_valid[j] = true;
196  fscanf( m_ifile, "%g %g %g",&f1,&f0,&f2);
197  FloatToDouble(m_growth[ i ]->m_start[j][1],f1);
198  FloatToDouble(m_growth[ i ]->m_start[j][0],f0);
199  FloatToDouble(m_growth[ i ]->m_start[j][2],f2);
200  } else {
201  // Add inflection point to normal growth curves.
202  m_growth[ i ]->m_dds[j][lk] = (double)entry;
203  fscanf( m_ifile, "%g %g %g",&f1,&f0,&f2);
204  FloatToDouble(m_growth[ i ]->m_slopes[j][1][lk],f1);
205  FloatToDouble(m_growth[ i ]->m_slopes[j][0][lk],f0);
206  FloatToDouble(m_growth[ i ]->m_slopes[j][2][lk],f2);
207  lk++;
208  }
209  } // MaxNoInflections
210  } // Growth Phases
211  } // NoPlants
212  fclose( m_ifile );
213 }
FILE * m_ifile
Definition: plants.h:84
unsigned int FindCropNum(const char *a_cropcurvefile)
Definition: plants.cpp:124
void FloatToDouble(double &, float)
vector< CropGrowth * > m_growth
Definition: plants.h:81
void SetVegNum(unsigned int a_i, const char *a_cropcurvefile)
Definition: plants.cpp:149
const unsigned int MaxNoInflections
Definition: plants.h:39
CropData::~CropData ( )

Definition at line 215 of file plants.cpp.

References m_growth.

216 {
217  for ( unsigned int i=0; i<m_growth.size(); i++ )
218  delete m_growth[i];
219 }
vector< CropGrowth * > m_growth
Definition: plants.h:81

Member Function Documentation

unsigned int CropData::FindCropNum ( const char *  a_cropcurvefile)
private

Definition at line 124 of file plants.cpp.

References g_msg, m_growth, m_ifile, m_num_crops, m_numbers, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by CropData().

125 {
126  int NoPlants;
127 
128  m_numbers.resize(201);
129  for ( unsigned int i=0; i<201; i++) {
130  m_numbers[ i ] = -1;
131  }
132 
133  m_ifile = fopen(a_cropcurvefile, "r" );
134  if (!m_ifile){
135  g_msg->Warn(WARN_FILE, "CropData::CropData: Unable to open file",
136  a_cropcurvefile );
137  exit(1);
138  }
139 
140  fscanf( m_ifile , "%d", &NoPlants ); // How many tables to read in
141  m_growth.resize( NoPlants );
142  m_num_crops = NoPlants;
143 
144  return NoPlants;
145 }
FILE * m_ifile
Definition: plants.h:84
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int m_num_crops
Definition: plants.h:83
double CropData::FindDiff ( double  a_ddegs,
double  a_yddegs,
int  a_plant,
int  a_phase,
int  a_type 
)
private

Definition at line 41 of file plants.cpp.

References m_growth, m_numbers, and MaxNoInflections.

Referenced by GetHeightDiff(), GetLAgreenDiff(), and GetLAtotalDiff().

43 {
44  // Check for valid plant number at runtime?
45  // This is broken for growth curves where one can risk passing
46  // more than a single inflection point in the growth curve in a
47  // single day...
48 
49  int index = m_numbers[ a_plant ];
50  unsigned int oldindex=0, newindex=0;
51 
52  if ( m_growth[ index ]->m_dds[ a_phase ][ 0 ] == 99999 ) {
53  return 0.0;
54  }
55 
56  for ( unsigned int i=0; i<MaxNoInflections; i++ ) {
57  // In other words: If the current value for summed day degrees
58  // is smaller than the X position of the *next* inflection
59  // point, then we are in the correct interval.
60  if ( m_growth[ index ]->m_dds[ a_phase ][ i+1 ] > a_ddegs ) {
61  newindex = i;
62  break;
63  // return m_growth[ index ]->m_slopes[ a_phase ][ a_type ][i];
64  }
65  }
66 
67  for ( unsigned int i=0; i<MaxNoInflections; i++ ) {
68  if ( m_growth[ index ]->m_dds[ a_phase ][ i+1 ] > a_yddegs ) {
69  oldindex = i;
70  break;
71  // return m_growth[ index ]->m_slopes[ a_phase ][ a_type ][i];
72  }
73  }
74 
75  double diff;
76 
77  if ( newindex > oldindex ) {
78  // We have passed an inflection point between today and yesterday.
79  // First add the increment from yesterdays day degree sum up to
80  // the inflection point.
81  double dddif =
82  m_growth[ index ]->m_dds[ a_phase ][ newindex ] - a_yddegs;
83  diff =
84  m_growth[ index ]->m_slopes[ a_phase ][ a_type ][oldindex]*
85  dddif;
86 
87  // Then from the inflection point up to today.
88  dddif = a_ddegs -
89  m_growth[ index ]->m_dds[ a_phase ][ newindex ];
90  diff +=
91  m_growth[ index ]->m_slopes[ a_phase ][ a_type ][ newindex ]*
92  dddif;
93  } else {
94  // No inflection point passed.
95  diff = m_growth[ index ]->m_slopes[ a_phase ][ a_type ][ newindex ] *
96  (a_ddegs - a_yddegs);
97  }
98  return diff;
99 }
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
const unsigned int MaxNoInflections
Definition: plants.h:39
double CropData::GetBugPercentA ( TTypesOfVegetation  a_letype)
inline

Definition at line 129 of file plants.h.

129  {
130  return m_bug_percent_a[ a_letype ];
131  }
double * m_bug_percent_a
Definition: plants.h:86
double CropData::GetBugPercentB ( TTypesOfVegetation  a_letype)
inline

Definition at line 134 of file plants.h.

134  {
135  return m_bug_percent_b[ a_letype ];
136  }
double * m_bug_percent_b
Definition: plants.h:87
double CropData::GetBugPercentC ( TTypesOfVegetation  a_letype)
inline

Definition at line 139 of file plants.h.

139  {
140  return m_bug_percent_c[ a_letype ];
141  }
double * m_bug_percent_c
Definition: plants.h:88
double CropData::GetBugPercentD ( TTypesOfVegetation  a_letype)
inline

Definition at line 144 of file plants.h.

144  {
145  return (double) m_bug_percent_d[ a_letype ];
146  }
int * m_bug_percent_d
Definition: plants.h:89
double CropData::GetHeightDiff ( double  a_ddegs,
double  a_yddegs,
int  a_plant,
int  a_phase 
)

Definition at line 116 of file plants.cpp.

References FindDiff().

Referenced by VegElement::DoDevelopment(), and VegElement::ForceGrowthSpringTest().

118 {
119  return FindDiff( a_ddegs , a_yddegs, a_plant, a_phase, 2 );
120 }
double FindDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type)
Definition: plants.cpp:41
double CropData::GetLAgreenDiff ( double  a_ddegs,
double  a_yddegs,
int  a_plant,
int  a_phase 
)

Definition at line 102 of file plants.cpp.

References FindDiff().

Referenced by VegElement::DoDevelopment(), and VegElement::ForceGrowthSpringTest().

104 {
105  return FindDiff( a_ddegs, a_yddegs, a_plant, a_phase, 0 );
106 }
double FindDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type)
Definition: plants.cpp:41
double CropData::GetLAtotalDiff ( double  a_ddegs,
double  a_yddegs,
int  a_plant,
int  a_phase 
)

Definition at line 109 of file plants.cpp.

References FindDiff().

Referenced by VegElement::DoDevelopment(), UnsprayedFieldMargin::DoDevelopment(), and VegElement::ForceGrowthSpringTest().

111 {
112  return FindDiff( a_ddegs, a_yddegs, a_plant, a_phase, 1 );
113 }
double FindDiff(double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type)
Definition: plants.cpp:41
int CropData::GetNumCrops ( )
inline

Definition at line 113 of file plants.h.

Referenced by CropRotation::GetFirstCrop().

113  {
114  return m_num_crops;
115  }
int m_num_crops
Definition: plants.h:83
bool CropData::GetNutStatus ( int  a_plant_num)
inline

Definition at line 148 of file plants.h.

Referenced by CropRotation::GetFirstCrop().

148  {
149  return m_growth[ a_plant_num ]->m_lownut;
150  }
vector< CropGrowth * > m_growth
Definition: plants.h:81
bool CropData::GetNutStatusExt ( int  a_plant)
inline

Definition at line 152 of file plants.h.

152  {
153  return m_growth[ m_numbers[ a_plant ]]->m_lownut;
154  }
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
double CropData::GetStartValue ( int  a_veg_type,
int  a_phase,
int  a_type 
)
inline

Definition at line 105 of file plants.h.

Referenced by VegElement::ForceGrowthInitialize(), and VegElement::SetGrowthPhase().

105  {
106  return m_growth[ m_numbers[ a_veg_type ]]->m_start[ a_phase ] [ a_type ];
107  }
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
double CropData::GetWeedPercent ( TTypesOfVegetation  a_letype)
inline

Definition at line 124 of file plants.h.

124  {
125  return m_weed_percent[ a_letype ];
126  }
double * m_weed_percent
Definition: plants.h:85
void CropData::MakeBugPercentArray ( void  )
private
void CropData::ReadBugPercentageFile ( void  )
private
void CropData::SetVegNum ( unsigned int  a_i,
const char *  a_cropcurvefile 
)
private

Definition at line 149 of file plants.cpp.

References g_msg, m_growth, m_ifile, m_numbers, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by CropData().

150 {
151  int ThisPlant;
152 
153  // Find out what crop and what nutrient status
154  fscanf( m_ifile, "%d", &ThisPlant);
155 
156  // Check if valid plant number (from the file).
157  if ( ThisPlant < 0 || ThisPlant > 200 ) {
158  g_msg->Warn(WARN_FILE, "CropData::FindCropNum(): Illegal plant number"
159  " specified in", a_cropcurvefile );
160  exit(1);
161  }
162 
163  m_numbers[ ThisPlant ] = a_i;
164 
165  // if greater than 100 then it is low nutrient
166  if ( ThisPlant > 100 ) {
167  m_growth[ a_i ]->m_lownut = true;
168  } else {
169  m_growth[ a_i ]->m_lownut = false;
170  }
171 }
FILE * m_ifile
Definition: plants.h:84
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
bool CropData::StartValid ( int  a_veg_type,
int  a_phase 
)

Definition at line 364 of file plants.cpp.

References m_growth, and m_numbers.

Referenced by VegElement::ForceGrowthInitialize(), and VegElement::SetGrowthPhase().

365 {
366  int a=m_numbers[ a_veg_type ];
367  CropGrowth* p=m_growth[a];
368  return p-> m_start_valid[ a_phase ];
369 }
vector< CropGrowth * > m_growth
Definition: plants.h:81
vector< int > m_numbers
Definition: plants.h:82
int CropData::VegTypeToCurveNum ( TTypesOfVegetation  VegReference)

Definition at line 231 of file plants.cpp.

References g_msg, tov_AgroChemIndustryCereal, tov_BroadBeans, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FieldPeasSilage, tov_FieldPeasStrigling, tov_FodderBeet, tov_FodderGrass, tov_Heath, tov_Lawn, tov_Maize, tov_MaizeSilage, tov_MaizeStrigling, tov_NaturalGrass, tov_NoGrowth, tov_Oats, tov_OBarleyPeaCloverGrass, tov_OCarrots, tov_OCloverGrassGrazed1, tov_OCloverGrassGrazed2, tov_OCloverGrassSilage1, tov_OFieldPeas, tov_OFieldPeasSilage, tov_OFodderBeet, tov_OGrazingPigs, tov_OMaizeSilage, tov_OOats, tov_OPermanentGrassGrazed, tov_OPotatoes, tov_OrchardCrop, tov_OSBarleySilage, tov_OSeedGrass1, tov_OSeedGrass2, tov_OSetaside, tov_OSpringBarley, tov_OSpringBarleyClover, tov_OSpringBarleyExt, tov_OSpringBarleyGrass, tov_OSpringBarleyPigs, tov_OTriticale, tov_OWinterBarley, tov_OWinterBarleyExt, tov_OWinterRape, tov_OWinterRye, tov_OWinterWheat, tov_OWinterWheatUndersown, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringBarleyCloverGrass, tov_SpringBarleyCloverGrassStrigling, tov_SpringBarleyPeaCloverGrassStrigling, tov_SpringBarleyPTreatment, tov_SpringBarleySeed, tov_SpringBarleySilage, tov_SpringBarleySKManagement, tov_SpringBarleySpr, tov_SpringBarleyStrigling, tov_SpringBarleyStriglingCulm, tov_SpringBarleyStriglingSingle, tov_SpringRape, tov_SugarBeet, tov_Triticale, tov_Wasteland, tov_WinterBarley, tov_WinterBarleyStrigling, tov_WinterRape, tov_WinterRapeStrigling, tov_WinterRye, tov_WinterRyeStrigling, tov_WinterWheat, tov_WinterWheatShort, tov_WinterWheatStrigling, tov_WinterWheatStriglingCulm, tov_WinterWheatStriglingSingle, tov_WWheatPControl, tov_WWheatPToxicControl, tov_WWheatPTreatment, tov_YoungForest, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by BeetleBank::BeetleBank(), FieldBoundary::FieldBoundary(), Heath::Heath(), HedgeBank::HedgeBank(), Hedges::Hedges(), Marsh::Marsh(), MownGrass::MownGrass(), NaturalGrassDry::NaturalGrassDry(), NaturalGrassWet::NaturalGrassWet(), Orchard::Orchard(), OrchardBand::OrchardBand(), PermanentSetaside::PermanentSetaside(), VegElement::SetVegType(), UnsprayedFieldMargin::UnsprayedFieldMargin(), VegElement::VegElement(), Wasteland::Wasteland(), and YoungForest::YoungForest().

232 {
233  char error_num[20];
234 
235  switch (VegReference)
236  {
238  case tov_OSpringBarley:
240  return 101;
242  case tov_SpringBarley:
243  case tov_SpringBarleySpr:
249  return 1;
250  case tov_WinterBarley:
252  return 2;
253  case tov_OWinterBarley:
255  return 102;
256  case tov_WinterWheat:
262  case tov_WWheatPControl:
265  return 4;
266  case tov_OWinterWheat:
268  return 104;
269  case tov_WinterRye:
271  return 5;
272  case tov_OWinterRye:
273  return 105;
274  case tov_Oats:
275  return 6;
276  case tov_OOats:
277  return 106;
278  case tov_Maize:
279  case tov_MaizeSilage:
280  case tov_MaizeStrigling:
281  return 8;
282  case tov_OMaizeSilage:
283  return 108;
288  return 13;
290  case tov_OSBarleySilage:
293  return 113;
294  case tov_WinterRape:
296  return 22;
297  case tov_OWinterRape:
298  return 22;
301  return 25;
304  return 26;
305  case tov_SeedGrass1:
306  case tov_SeedGrass2:
307  case tov_OSeedGrass1:
308  case tov_OSeedGrass2:
309  return 27;
310  case tov_FodderGrass:
316  case tov_OGrazingPigs:
317  return 29;
318  case tov_OFieldPeas:
320  case tov_FieldPeas:
322  case tov_FieldPeasSilage:
323  case tov_BroadBeans:
324  return 30;
325  case tov_Carrots:
326  return 41;
327  case tov_OCarrots:
328  return 141;
329  case tov_Potatoes: return 50;
330  case tov_OPotatoes: return 150;
331  case tov_PotatoesIndustry: return 50;
332  case tov_SugarBeet:
333  case tov_FodderBeet:
334  case tov_OFodderBeet:
335  return 60;
336  // Special growth mode for green but unused elements.
337  // tov_PermanentSetaside Does not change growth phase no matter
338  // how hard one tries to do just that.
339  case tov_PermanentSetaside: return 92;
340  case tov_Heath:
341  case tov_Setaside:
342  case tov_OSetaside: return 112;
343  case tov_OrchardCrop:
344  case tov_YoungForest:
345  case tov_NaturalGrass:
346  case tov_Wasteland: return 90;
347  case tov_NoGrowth: return 91;
348  case tov_Lawn: return 94;
349  //case tov_SpringWheat: return 3;
350  case tov_OTriticale:
351  case tov_Triticale: return 7;
352  case tov_SpringRape: return 21;
353 
354  default: // No matching code so we need an error message of some kind
355  sprintf( error_num, "%d", VegReference );
356  g_msg->Warn( WARN_FILE,
357  "CropData::VegTypeToCurveNum(): Unknown vegetation type:",
358  error_num );
359  exit( 1 );
360  }
361 }
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56

Member Data Documentation

double* CropData::m_bug_percent_a
private

Definition at line 86 of file plants.h.

double* CropData::m_bug_percent_b
private

Definition at line 87 of file plants.h.

double* CropData::m_bug_percent_c
private

Definition at line 88 of file plants.h.

int* CropData::m_bug_percent_d
private

Definition at line 89 of file plants.h.

vector< CropGrowth * > CropData::m_growth
private

Definition at line 81 of file plants.h.

Referenced by CropData(), FindCropNum(), FindDiff(), SetVegNum(), StartValid(), and ~CropData().

FILE* CropData::m_ifile
private

Definition at line 84 of file plants.h.

Referenced by CropData(), FindCropNum(), and SetVegNum().

int CropData::m_num_crops
private

Definition at line 83 of file plants.h.

Referenced by FindCropNum().

vector< int > CropData::m_numbers
private

Definition at line 82 of file plants.h.

Referenced by FindCropNum(), FindDiff(), SetVegNum(), and StartValid().

double* CropData::m_weed_percent
private

Definition at line 85 of file plants.h.


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