ALMaSS Rabbit ODdox  1.00
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 <cstdio>
34  #include "tov_declaration.h"
35  #include "tole_declaration.h"
36 
37 using namespace std;
38 
39 const unsigned int MaxNoInflections = 15;
40 
49 typedef enum {
50  janfirst = 0,
51  sow,
56 }
58 
59 
60 
61 // 0: Leaf area green.
62 // 1: Leaf area total.
63 // 2: Height.
64 
65 class CropGrowth {
66 public:
67  bool m_lownut; // Low nutrient status.
68  double m_dds[ 5 ] [ MaxNoInflections ]; // DDegs at inflection
69  double m_slopes[ 5 ] [ 3 ] [ MaxNoInflections ];
70  double m_start[ 5 ] [ 3 ];
71  bool m_start_valid[ 5 ];
72 
73  CropGrowth( void );
74 };
75 
76 extern class CropData * g_crops;
77 
78 
79 
80 class CropData {
81  vector < CropGrowth * > m_growth;
82  vector < int > m_numbers;
84  FILE * m_ifile;
85  double * m_weed_percent;
86  double * m_bug_percent_a;
87  double * m_bug_percent_b;
88  double * m_bug_percent_c;
90 
91  double FindDiff( double a_ddegs, double a_yddegs, int a_plant, int a_phase, int a_type );
92  unsigned int FindCropNum( const char * a_cropcurvefile );
93  void SetVegNum( unsigned int a_i, const char * a_cropcurvefile );
94  void MakeBugPercentArray( void );
95  void ReadBugPercentageFile( void );
96 
97 public:
98 
99  // NOTICE: These functions take *plant numbers* like in the
100  // CropGrowth.txt file, *NOT* indices into the m_growth array.
101  double GetLAtotalDiff( double a_ddegs, double a_yddegs, int a_plant, int a_phase );
102  double GetLAgreenDiff( double a_ddegs, double a_yddegs, int a_plant, int a_phase );
103  double GetHeightDiff( double a_ddegs, double a_yddegs, int a_plant, int a_phase );
104 
105  double GetStartValue( int a_veg_type, int a_phase, int a_type ) {
106  return m_growth[ m_numbers[ a_veg_type ]]->m_start[ a_phase ] [ a_type ];
107  }
108 
109  bool StartValid( int a_veg_type, int a_phase );
110 
111  /* { return m_growth[ m_numbers[ a_veg_type ]]-> m_start_valid[ a_phase ]; } */
112  // Number of different crops read from disk.
113  int GetNumCrops() {
114  return m_num_crops;
115  }
116 
117  // Translation between growth curve file crop numbers and the internal
118  // representation.
119  //TTypesOfVegetation TranslateFileVegTypes( int a_filetype );
120  //int BackTranslateFileVegTypes( TTypesOfVegetation a_systemtype );
121  int VegTypeToCurveNum( TTypesOfVegetation VegReference );
122 
123  // **cjt** added 30/01/2004
124  double GetWeedPercent( TTypesOfVegetation a_letype ) {
125  return m_weed_percent[ a_letype ];
126  }
127 
128  // **cjt** added 27/05/2003
129  double GetBugPercentA( TTypesOfVegetation a_letype ) {
130  return m_bug_percent_a[ a_letype ];
131  }
132 
133  // **cjt** added 27/05/2003
134  double GetBugPercentB( TTypesOfVegetation a_letype ) {
135  return m_bug_percent_b[ a_letype ];
136  }
137 
138  // **cjt** added 27/05/2003
139  double GetBugPercentC( TTypesOfVegetation a_letype ) {
140  return m_bug_percent_c[ a_letype ];
141  }
142 
143  // **cjt** added 12/03/2003
144  double GetBugPercentD( TTypesOfVegetation a_letype ) {
145  return (double) m_bug_percent_d[ a_letype ];
146  }
147 
148  bool GetNutStatus( int a_plant_num ) {
149  return m_growth[ a_plant_num ]->m_lownut;
150  }
151 
152  bool GetNutStatusExt( int a_plant ) {
153  return m_growth[ m_numbers[ a_plant ]]->m_lownut;
154  }
155 
156  CropData( const char * a_cropcurvefile );
157  ~CropData();
158 };
159 
160 #endif // PLANTS_H
161 
FILE * m_ifile
Definition: plants.h:84
double GetBugPercentA(TTypesOfVegetation a_letype)
Definition: plants.h:129
bool GetNutStatusExt(int a_plant)
Definition: plants.h:152
double GetBugPercentD(TTypesOfVegetation a_letype)
Definition: plants.h:144
TTypesOfVegetation
double * m_bug_percent_a
Definition: plants.h:86
vector< CropGrowth * > m_growth
Definition: plants.h:81
int GetNumCrops()
Definition: plants.h:113
vector< int > m_numbers
Definition: plants.h:82
double * m_bug_percent_c
Definition: plants.h:88
Definition: plants.h:51
double GetBugPercentB(TTypesOfVegetation a_letype)
Definition: plants.h:134
class CropData * g_crops
Definition: plants.cpp:39
int * m_bug_percent_d
Definition: plants.h:89
bool GetNutStatus(int a_plant_num)
Definition: plants.h:148
double * m_bug_percent_b
Definition: plants.h:87
double GetStartValue(int a_veg_type, int a_phase, int a_type)
Definition: plants.h:105
double GetWeedPercent(TTypesOfVegetation a_letype)
Definition: plants.h:124
bool m_lownut
Definition: plants.h:67
const unsigned int MaxNoInflections
Definition: plants.h:39
double * m_weed_percent
Definition: plants.h:85
Growth_Phases
Growth phase indicator.
Definition: plants.h:49
int m_num_crops
Definition: plants.h:83
double GetBugPercentC(TTypesOfVegetation a_letype)
Definition: plants.h:139