ALMaSS Skylark ODDox  1.1
The skylark model description following ODdox protocol
DummyCropPestTesting Class Reference

#include <DummyCropPestTesting.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 DummyCropPestTesting ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop ()
 
int GetFirstDate (void)
 
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
int GetCropClassification ()
 
void SetCropClassification (int a_classification)
 

Additional Inherited Members

- Protected Member Functions inherited from Crop
void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
void SimpleEvent_ (long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
 Adds an event to this crop management without relying on member variables. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LE * m_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Constructor & Destructor Documentation

◆ DummyCropPestTesting()

DummyCropPestTesting::DummyCropPestTesting ( )
inline
66  {
67  m_first_date=g_date->DayInYear(1,3);
68  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool DummyCropPestTesting::Do ( Farm a_farm,
LE *  a_field,
FarmEvent a_ev 
)
virtual

Reimplemented from Crop.

39 {
40  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
41  int d1 = 0;
42  // Depending what event has occured jump to the correct bit of code
43  switch (a_ev->m_todo)
44  {
45  case dcpt_start:
46  {
47  // dcpt_start just sets up all the starting conditions and reference dates that are needed to start a pl_sb
48  DCPT_APRIL_PEST = 0;
49  DCPT_MAY_PEST = 0;
50  DCPT_JUNE_PEST = 0;
51  DCPT_JULY_PEST = 0;
52  DCPT_SEPT_PEST = 0;
53  DCPT_OCT_PEST = 0;
54 
55  // Set up the date management stuff
56  // The next bit of code just allows for altering dates after harvest if it is necessary
57  // to allow for a crop which starts its management early.
58 
59  // 5 start and stop dates for all 'movable' events for this crop
60  int noDates = 1;
61  a_field->SetMDates(0, 0, g_date->DayInYear(15, 11));
62  a_field->SetMDates(1, 0, g_date->DayInYear(15, 11));
63 
64  a_field->SetMConstants(0, 1);
65 
66  // Check the next crop for early start, unless it is a spring crop
67  // in which case we ASSUME that no checking is necessary!!!!
68  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
69 
70  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
71  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
72  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
73 
74  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
75  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
76  {
77  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): ", "Harvest too late for the next crop to start!!!");
78  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
79  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
80  }
81  // Now fix any late finishing problems
82  for (int i = 0; i < noDates; i++) {
83  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
84  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
85  }
86  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
87  a_field->SetMConstants(i, 0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
88  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
89  }
90  }
91  }
92  // Now no operations can be timed after the start of the next crop.
93 
94  if (!a_ev->m_first_year) {
95  int today = g_date->Date();
96  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
97  if (today > d1) {
98  // Yes too late - should not happen - raise an error
99  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): " "Crop start attempt after last possible start date", "");
100  exit(1);
101  }
102  }
103  else {
104  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3), dcpt_March_pest1, false, a_farm, a_field);
105  break;
106  }
107  }//if
108 
109  // End single block date checking code. Please see next line
110  // comment as well.
111  // Reinit d1 to first possible starting date.
112  d1 = g_date->OldDays() + 365 + g_date->DayInYear(1, 3);
113  // OK, let's go.
114  SimpleEvent_(d1, dcpt_March_pest1, false, a_farm, a_field);
115  break;
116  }
117  break;
118 
119  // This is the first real farm operation
120  case dcpt_March_pest1:
121  if (a_ev->m_lock || a_farm->DoIt(3))
122  {
123  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
124  SimpleEvent_(g_date->Date() + 1, dcpt_March_pest1, true, a_farm, a_field);
125  break;
126  }
127  }
128  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 4), dcpt_April_pest1, false, a_farm, a_field);
129  break;
130  case dcpt_April_pest1:
131  if (a_ev->m_lock || a_farm->DoIt(29)) //40% will spray just once in April
132  {
133  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
134  SimpleEvent_(g_date->Date() + 1, dcpt_April_pest1, true, a_farm, a_field);
135  break;
136  }
137  DCPT_APRIL_PEST = 1;
138  }
139  SimpleEvent_(g_date->Date() + 10, dcpt_April_pest2, false, a_farm, a_field);
140  break;
141  case dcpt_April_pest2:
142  if (a_ev->m_lock || a_farm->DoIt(1) && (DCPT_APRIL_PEST == 1)) //1.08% will spray twice in April
143  {
144  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
145  SimpleEvent_(g_date->Date() + 1, dcpt_April_pest2, true, a_farm, a_field);
146  break;
147  }
148  }
149  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), dcpt_May_pest1, false, a_farm, a_field);
150  break;
151  case dcpt_May_pest1:
152  if (a_ev->m_lock || a_farm->DoIt(22)) //38% will spray just once
153  {
154  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
155  SimpleEvent_(g_date->Date() + 1, dcpt_May_pest1, true, a_farm, a_field);
156  break;
157  }
158  DCPT_MAY_PEST = 1;
159  }
160  SimpleEvent_(g_date->Date() + 10, dcpt_May_pest2, false, a_farm, a_field);
161  break;
162  case dcpt_May_pest2:
163  if (a_ev->m_lock || a_farm->DoIt(2) && (DCPT_MAY_PEST == 1)) //11.50% will spray twice
164  {
165  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
166  SimpleEvent_(g_date->Date() + 1, dcpt_May_pest2, true, a_farm, a_field);
167  break;
168  }
169  }
170  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 6), dcpt_June_pest1, false, a_farm, a_field);
171  break;
172  case dcpt_June_pest1:
173  if (a_ev->m_lock || a_farm->DoIt(12)) //9% will spray just once
174  {
175  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
176  SimpleEvent_(g_date->Date() + 1, dcpt_June_pest1, true, a_farm, a_field);
177  break;
178  }
179  DCPT_JUNE_PEST = 1;
180  }
181  SimpleEvent_(g_date->Date() + 10, dcpt_June_pest2, false, a_farm, a_field);
182  break;
183  case dcpt_June_pest2:
184  if (a_ev->m_lock || a_farm->DoIt(0) && (DCPT_JUNE_PEST == 1)) //0.41% will spray twice
185  {
186  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
187  SimpleEvent_(g_date->Date() + 1, dcpt_June_pest2, true, a_farm, a_field);
188  break;
189  }
190  }
191  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), dcpt_July_pest1, false, a_farm, a_field);
192  break;
193  case dcpt_July_pest1:
194  if (a_ev->m_lock || a_farm->DoIt(0)) //3% will spray just once
195  {
196  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
197  SimpleEvent_(g_date->Date() + 1, dcpt_July_pest1, true, a_farm, a_field);
198  break;
199  }
200  DCPT_JULY_PEST = 1;
201  }
202  SimpleEvent_(g_date->Date() + 10, dcpt_July_pest2, false, a_farm, a_field);
203  break;
204  case dcpt_July_pest2:
205  if (a_ev->m_lock || a_farm->DoIt(0) && (DCPT_JULY_PEST == 1)) //0.95% will spray twice
206  {
207  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
208  SimpleEvent_(g_date->Date() + 1, dcpt_July_pest2, true, a_farm, a_field);
209  break;
210  }
211  }
212  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 8), dcpt_August_pest1, false, a_farm, a_field);
213  break;
214  case dcpt_August_pest1:
215  if (a_ev->m_lock || a_farm->DoIt(1)) //0.02% will spray just once
216  {
217  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
218  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
219  break;
220  }
221  }
222  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 9), dcpt_September_pest1, false, a_farm, a_field);
223  break;
225  if (a_ev->m_lock || a_farm->DoIt(3)) //2.90% will spray just once
226  {
227  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
228  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
229  break;
230  }
231  DCPT_SEPT_PEST = 1;
232  }
233  SimpleEvent_(g_date->Date() + 10, dcpt_September_pest2, false, a_farm, a_field);
234  break;
236  if (a_ev->m_lock || a_farm->DoIt(21) && (DCPT_SEPT_PEST == 1)) //2.90% will spray just once
237  {
238  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
239  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
240  break;
241  }
242  }
243  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 10), dcpt_October_pest1, false, a_farm, a_field);
244  break;
245  case dcpt_October_pest1:
246  if (a_ev->m_lock || a_farm->DoIt(4)) //1% will spray just once
247  {
248  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
249  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
250  break;
251  }
252  DCPT_OCT_PEST = 1;
253  }
254  SimpleEvent_(g_date->Date() + 10, dcpt_October_pest2, false, a_farm, a_field);
255  break;
256  case dcpt_October_pest2:
257  if (a_ev->m_lock || a_farm->DoIt(1) && (DCPT_OCT_PEST == 1)) //1% will spray just once
258  {
259  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
260  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
261  break;
262  }
263  }
264  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 11), dcpt_November_pest1, false, a_farm, a_field);
265  break;
266  case dcpt_November_pest1:
267  if (a_ev->m_lock || a_farm->DoIt(0)) //1% will spray just once
268  {
269  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 11) - g_date->DayInYear())) {
270  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
271  break;
272  }
273  }
274  done = true;
275  break;
276 
277  default:
278  g_msg->Warn( WARN_BUG, "DummyCropPestTesting::Do(): "
279  "Unknown event type! ", "" );
280  exit( 1 );
281  }
282  return done;
283 }

References Landscape::BackTranslateVegTypes(), DCPT_APRIL_PEST, dcpt_April_pest1, dcpt_April_pest2, dcpt_August_pest1, DCPT_JULY_PEST, dcpt_July_pest1, dcpt_July_pest2, DCPT_JUNE_PEST, dcpt_June_pest1, dcpt_June_pest2, dcpt_March_pest1, DCPT_MAY_PEST, dcpt_May_pest1, dcpt_May_pest2, dcpt_November_pest1, DCPT_OCT_PEST, dcpt_October_pest1, dcpt_October_pest2, DCPT_SEPT_PEST, dcpt_September_pest1, dcpt_September_pest2, dcpt_start, Farm::DoIt(), g_landscape_p, Farm::GetType(), Farm::InsecticideTreat(), FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
DCPT_APRIL_PEST
#define DCPT_APRIL_PEST
Definition: DummyCropPestTesting.h:33
dcpt_September_pest1
Definition: DummyCropPestTesting.h:52
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
DCPT_MAY_PEST
#define DCPT_MAY_PEST
Definition: DummyCropPestTesting.h:34
tof_OptimisingFarm
Definition: farm.h:273
DCPT_SEPT_PEST
#define DCPT_SEPT_PEST
Definition: DummyCropPestTesting.h:37
dcpt_July_pest1
Definition: DummyCropPestTesting.h:49
DCPT_OCT_PEST
#define DCPT_OCT_PEST
Definition: DummyCropPestTesting.h:38
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
dcpt_October_pest2
Definition: DummyCropPestTesting.h:55
dcpt_April_pest1
Definition: DummyCropPestTesting.h:43
DCPT_JULY_PEST
#define DCPT_JULY_PEST
Definition: DummyCropPestTesting.h:36
dcpt_October_pest1
Definition: DummyCropPestTesting.h:54
dcpt_June_pest2
Definition: DummyCropPestTesting.h:48
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
dcpt_September_pest2
Definition: DummyCropPestTesting.h:53
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Farm::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: farmfuncs.cpp:1348
dcpt_July_pest2
Definition: DummyCropPestTesting.h:50
DCPT_JUNE_PEST
#define DCPT_JUNE_PEST
Definition: DummyCropPestTesting.h:35
dcpt_March_pest1
Definition: DummyCropPestTesting.h:42
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
dcpt_April_pest2
Definition: DummyCropPestTesting.h:44
dcpt_November_pest1
Definition: DummyCropPestTesting.h:56
dcpt_start
Definition: DummyCropPestTesting.h:41
dcpt_August_pest1
Definition: DummyCropPestTesting.h:51
dcpt_June_pest1
Definition: DummyCropPestTesting.h:47
dcpt_May_pest2
Definition: DummyCropPestTesting.h:46
dcpt_May_pest1
Definition: DummyCropPestTesting.h:45
Crop::SimpleEvent_
void SimpleEvent_(long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
Adds an event to this crop management without relying on member variables.
Definition: farm.cpp:312