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

NLCarrots class
. More...

#include <NLCarrots.h>

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and only method for a crop management plan. All farm actions go through here. More...
 
 NLCarrots ()
 
- 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
 

Detailed Description

NLCarrots class
.

See NLCarrots.h::NLCarrotsToDo for a complete list of all possible events triggered codes by the carrots management plan. When triggered these events are handled by Farm and are available as information for other objects such as animal and bird models.

Constructor & Destructor Documentation

◆ NLCarrots()

NLCarrots::NLCarrots ( )
inline
75  {
76  // When we start it off, the first possible date for a farm operation is 20th October
77  // This information is used by other crops when they decide how much post processing of
78  // the management is allowed after harvest before the next crop starts.
79  m_first_date=g_date->DayInYear( 1,12 );
80  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

The one and only method for a crop management plan. All farm actions go through here.

Called every time something is done to the crop by the farmer in the first instance it is always called with a_ev->todo set to start, but susequently will be called whenever the farmer wants to carry out a new operation.
This method details all the management and relationships between operations necessary to grow and ALMaSS crop - in this case conventional carrots.

Reimplemented from Crop.

65 {
66  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
67  int d1 = 0;
68  // Depending what event has occured jump to the correct bit of code
69  switch (a_ev->m_todo)
70  {
71  case nl_ca_start:
72  {
73  // nl_ca_start just sets up all the starting conditions and reference dates that are needed to start a nl_ca
74  NL_CA_WINTER_PLOUGH = false;
75  NL_CA_HERBI1 = false;
76  NL_CA_HERBI2 = false;
77  NL_CA_FUNGI1 = false;
78  NL_CA_FUNGI2 = false;
79 
80 
81  // Set up the date management stuff
82  // The next bit of code just allows for altering dates after harvest if it is necessary
83  // to allow for a crop which starts its management early.
84 
85  // 2 start and stop dates for all 'movable' events for this crop
86  int noDates = 1;
87  a_field->SetMDates(0, 0, g_date->DayInYear(1, 10)); // first possible day of harvest
88  a_field->SetMDates(1, 0, g_date->DayInYear(15, 11)); // last possible day of harvest
89 
90  a_field->SetMConstants(0, 1);
91 
92  // Check the next crop for early start, unless it is a spring crop
93  // in which case we ASSUME that no checking is necessary!!!!
94  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
95 
96  //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)
97  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
98  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
99 
100  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
101  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
102  {
103  g_msg->Warn(WARN_BUG, "NLCarrots::Do(): ", "Harvest too late for the next crop to start!!!");
104  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
105  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
106  }
107  // Now fix any late finishing problems
108  for (int i = 0; i < noDates; i++) {
109  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
110  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
111  }
112  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
113  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)
114  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
115  }
116  }
117  }
118  // Now no operations can be timed after the start of the next crop.
119 
120  if (!a_ev->m_first_year) {
121  // Are we before July 1st?
122  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
123  if (g_date->Date() < d1) {
124  // Yes, too early. We assumme this is because the last crop was late
125  printf("Poly: %d\n", a_field->GetPoly());
126  g_msg->Warn(WARN_BUG, "NLCarrots::Do(): ", "Crop start attempt between 1st Jan & 1st July");
127  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
128  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
129  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
130  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
131  }
132  else {
133  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
134  if (g_date->Date() > d1) {
135  // Yes too late - should not happen - raise an error
136  g_msg->Warn(WARN_BUG, "NLCarrots::Do(): ", "Crop start attempt after last possible start date");
137  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
138  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
139  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
140  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
141  }
142  }
143  }
144  else {
145  // Is the first year
146  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes
147  // Code for first spring treatment used
148  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 4), nl_ca_spring_sow, false, a_farm, a_field);
149  break;
150  }
151  }//if
152 
153  // End single block date checking code. Please see next line comment as well.
154  // Reinit d1 to first possible starting date.
155  d1 = g_date->OldDays() + g_date->DayInYear(1, 10);
156  // OK, let's go.
157  // Here we queue up the first event - this differs depending on whether we have field on snady or clay soils
158  SimpleEvent_(d1, nl_ca_winter_plough_clay, false, a_farm, a_field);
159  }
160  break;
161 
162  // This is the first real farm operation
164  if (!a_farm->SpringPlough(a_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
165  SimpleEvent_(g_date->Date() + 1, nl_ca_spring_plough_sandy, true, a_farm, a_field);
166  break;
167  }
168  if (a_farm->IsStockFarmer()) //Stock Farmer
169  {
170  SimpleEvent_(g_date->Date() + 7, nl_ca_ferti_s1, false, a_farm, a_field);
171  }
172  else SimpleEvent_(g_date->Date() + 7, nl_ca_ferti_p1, false, a_farm, a_field);
173  break;
175  if (a_field->GetSoilType() != 2 && a_field->GetSoilType() != 6) // on clay soils (NL KLEI & VEEN)
176  {
177  if (a_ev->m_lock || a_farm->DoIt_prob(0.95))
178  {
179  if (!a_farm->WinterPlough(a_field, 0.0, g_date->DayInYear(1, 12) - g_date->DayInYear())) {
180  SimpleEvent_(g_date->Date() + 1, nl_ca_winter_plough_clay, true, a_farm, a_field);
181  break;
182  }
183  else
184  {
185  NL_CA_WINTER_PLOUGH = true;
186  if (a_farm->IsStockFarmer()) //Stock Farmer
187  {
188  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3) + 365, nl_ca_ferti_s1, false, a_farm, a_field);
189  }
190  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3) + 365, nl_ca_ferti_p1, false, a_farm, a_field);
191  break;
192  }
193  }
194  SimpleEvent_(g_date->Date() + 1, nl_ca_winter_deep_harrow_clay, false, a_farm, a_field);
195  break;
196  }
197  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3) + 365, nl_ca_spring_plough_sandy, false, a_farm, a_field);
198  break;
200  if (!a_farm->StubbleCultivatorHeavy(a_field, 0.0, g_date->DayInYear(1, 12) - g_date->DayInYear())) {
201  SimpleEvent_(g_date->Date() + 1, nl_ca_winter_deep_harrow_clay, true, a_farm, a_field);
202  break;
203  }
204  if (a_farm->IsStockFarmer()) //Stock Farmer
205  {
206  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3) + 365, nl_ca_ferti_s1, false, a_farm, a_field);
207  }
208  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 3) + 365, nl_ca_ferti_p1, false, a_farm, a_field);
209  break;
210  case nl_ca_ferti_p1:
211  if (a_ev->m_lock || a_farm->DoIt_prob(0.95))
212  {
213  if (!a_farm->FP_NPK(a_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
214  SimpleEvent_(g_date->Date() + 1, nl_ca_ferti_p1, true, a_farm, a_field);
215  break;
216  }
217  }
218  d1 = g_date->Date() + 1;
219  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 4)) {
220  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
221  }
222  SimpleEvent_(d1, nl_ca_preseeding_cultivator, false, a_farm, a_field);
223  break;
224  case nl_ca_ferti_s1:
225  if (a_ev->m_lock || a_farm->DoIt_prob(0.95))
226  {
227  if (!a_farm->FA_NPK(a_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
228  SimpleEvent_(g_date->Date() + 1, nl_ca_ferti_s1, true, a_farm, a_field);
229  break;
230  }
231  }
232  d1 = g_date->Date() + 1;
233  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 4)) {
234  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
235  }
236  SimpleEvent_(d1, nl_ca_preseeding_cultivator, false, a_farm, a_field);
237  break;
238 
240  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(25, 4) - g_date->DayInYear())) {
241  SimpleEvent_(g_date->Date() + 3, nl_ca_preseeding_cultivator, true, a_farm, a_field);
242  break;
243  }
244  SimpleEvent_(g_date->Date() + 3, nl_ca_bed_forming, false, a_farm, a_field);
245  break;
246  case nl_ca_bed_forming:
247  if (!a_farm->BedForming(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
248  SimpleEvent_(g_date->Date() + 1, nl_ca_bed_forming, true, a_farm, a_field);
249  break;
250  }
251  SimpleEvent_(g_date->Date() + 1, nl_ca_spring_sow, false, a_farm, a_field);
252  break;
253  case nl_ca_spring_sow:
254  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(15, 5) - g_date->DayInYear())) {
255  SimpleEvent_(g_date->Date() + 1, nl_ca_spring_sow, true, a_farm, a_field);
256  break;
257  }
258  // Here is a fork leading to four parallel events
259  SimpleEvent_(g_date->Date() + 3, nl_ca_herbicide1, false, a_farm, a_field); // Herbicide thread
260  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), nl_ca_fungicide1, false, a_farm, a_field); // Fungicide thread = MAIN THREAD
261  if (a_farm->IsStockFarmer()) //Stock Farmer
262  {
263  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), nl_ca_ferti_s2, false, a_farm, a_field); // Fertilizers thread
264  }
265  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 6), nl_ca_ferti_p2, false, a_farm, a_field);
266  break;
267  case nl_ca_ferti_p2:
268  if (a_ev->m_lock || a_farm->DoIt_prob(0.80))
269  {
270  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 7) - g_date->DayInYear())) {
271  SimpleEvent_(g_date->Date() + 1, nl_ca_ferti_p2, true, a_farm, a_field);
272  break;
273  }
274  }
275  // End of thread
276  break;
277  case nl_ca_ferti_s2:
278  if (a_ev->m_lock || a_farm->DoIt_prob(0.80))
279  {
280  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(30, 7) - g_date->DayInYear())) {
281  SimpleEvent_(g_date->Date() + 1, nl_ca_ferti_s2, true, a_farm, a_field);
282  break;
283  }
284  }
285  // End of thread
286  break;
287  case nl_ca_herbicide1: // The first of the pesticide managements.
288  // Here comes the herbicide thread
289  if (a_field->GetGreenBiomass() <= 0)
290  {
291  if (a_ev->m_lock || a_farm->DoIt_prob(0.80))
292  {
293  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(20, 5) - g_date->DayInYear())) {
294  SimpleEvent_(g_date->Date() + 1, nl_ca_herbicide1, true, a_farm, a_field);
295  break;
296  }
297  NL_CA_HERBI1 = true;
298  }
299  SimpleEvent_(g_date->Date() + 14, nl_ca_herbicide2, false, a_farm, a_field);
300  break;
301  }
302  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), nl_ca_herbicide2, false, a_farm, a_field);
303  break;
304  case nl_ca_herbicide2:
305  if (a_field->GetGreenBiomass() <= 0) {
306  SimpleEvent_(g_date->Date() + 1, nl_ca_herbicide2, false, a_farm, a_field);
307  }
308  else
309  {
310  if (a_ev->m_lock || (a_farm->DoIt_prob(1.00) && NL_CA_HERBI1 == 1))
311  {
312  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(5, 6) - g_date->DayInYear())) {
313  SimpleEvent_(g_date->Date() + 1, nl_ca_herbicide2, true, a_farm, a_field);
314  break;
315  }
316  NL_CA_HERBI2 = true;
317  }
318  SimpleEvent_(g_date->Date() + 14, nl_ca_herbicide3, false, a_farm, a_field);
319  break;
320  }
321  break;
322  case nl_ca_herbicide3:
323  if (a_ev->m_lock || (a_farm->DoIt_prob(0.75) && NL_CA_HERBI2 == 1))
324  {
325  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(20, 6) - g_date->DayInYear())) {
326  SimpleEvent_(g_date->Date() + 1, nl_ca_herbicide3, true, a_farm, a_field);
327  break;
328  }
329  }
330  // End of thread
331  break;
332  case nl_ca_fungicide1:
333  // Here comes the fungicide thread
334  if (a_ev->m_lock || a_farm->DoIt_prob(0.80))
335  {
336  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(30, 7) - g_date->DayInYear())) {
337  SimpleEvent_(g_date->Date() + 1, nl_ca_fungicide1, true, a_farm, a_field);
338  break;
339  }
340  NL_CA_FUNGI1 = true;
341  }
342  SimpleEvent_(g_date->Date() + 21, nl_ca_fungicide2, false, a_farm, a_field);
343  break;
344  case nl_ca_fungicide2:
345  if (a_ev->m_lock || (a_farm->DoIt_prob(1.00) && NL_CA_FUNGI1 == 1))
346  {
347  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(30, 8) - g_date->DayInYear())) {
348  SimpleEvent_(g_date->Date() + 1, nl_ca_fungicide2, true, a_farm, a_field);
349  break;
350  }
351  NL_CA_FUNGI2 = true;
352  }
353  SimpleEvent_(g_date->Date() + 21, nl_ca_fungicide3, false, a_farm, a_field);
354  break;
355  case nl_ca_fungicide3:
356  if (a_ev->m_lock || (a_farm->DoIt_prob(0.75) && NL_CA_FUNGI2 == 1)) // 60% of all farmers
357  {
358  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
359  SimpleEvent_(g_date->Date() + 1, nl_ca_fungicide3, true, a_farm, a_field);
360  break;
361  }
362  }
363  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(25, 9), nl_ca_harvest, false, a_farm, a_field);
364  break;
365  case nl_ca_harvest:
366  if (a_field->GetMConstants(0) == 0) {
367  if (!a_farm->Harvest(a_field, 0.0, -1)) { // raise an error
368  g_msg->Warn(WARN_BUG, "NLCarrots::Do(): failure in 'Harvest' execution", "");
369  exit(1);
370  }
371  }
372  else {
373  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
374  SimpleEvent_(g_date->Date() + 1, nl_ca_harvest, true, a_farm, a_field);
375  break;
376  }
377  }
378  done = true;
379  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
380  // END of MAIN THREAD
381  break;
382  default:
383  g_msg->Warn(WARN_BUG, "NLCarrots::Do(): "
384  "Unknown event type! ", "");
385  exit(1);
386  }
387  return done;
388 }

References Landscape::BackTranslateVegTypes(), g_landscape_p, Farm::GetType(), Farm::IsStockFarmer(), Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, nl_ca_bed_forming, nl_ca_ferti_p1, nl_ca_ferti_p2, nl_ca_ferti_s1, nl_ca_ferti_s2, NL_CA_FUNGI1, NL_CA_FUNGI2, nl_ca_fungicide1, nl_ca_fungicide2, nl_ca_fungicide3, nl_ca_harvest, NL_CA_HERBI1, NL_CA_HERBI2, nl_ca_herbicide1, nl_ca_herbicide2, nl_ca_herbicide3, nl_ca_preseeding_cultivator, nl_ca_spring_plough_sandy, nl_ca_spring_sow, nl_ca_start, nl_ca_winter_deep_harrow_clay, NL_CA_WINTER_PLOUGH, nl_ca_winter_plough_clay, Crop::SimpleEvent_(), Farm::SpringPlough(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: farmfuncs.cpp:444
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
nl_ca_ferti_p1
Definition: NLCarrots.h:45
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
NL_CA_WINTER_PLOUGH
#define NL_CA_WINTER_PLOUGH
A flag used to indicate autumn ploughing status.
Definition: NLCarrots.h:28
nl_ca_fungicide3
Definition: NLCarrots.h:57
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
nl_ca_spring_sow
Definition: NLCarrots.h:49
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
nl_ca_ferti_s1
Definition: NLCarrots.h:46
nl_ca_herbicide2
Definition: NLCarrots.h:53
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
nl_ca_harvest
Definition: NLCarrots.h:58
nl_ca_start
Definition: NLCarrots.h:40
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
nl_ca_preseeding_cultivator
Definition: NLCarrots.h:47
nl_ca_winter_deep_harrow_clay
Definition: NLCarrots.h:44
nl_ca_fungicide2
Definition: NLCarrots.h:56
nl_ca_herbicide1
Definition: NLCarrots.h:52
NL_CA_HERBI2
#define NL_CA_HERBI2
Definition: NLCarrots.h:30
nl_ca_ferti_s2
Definition: NLCarrots.h:51
NL_CA_FUNGI1
#define NL_CA_FUNGI1
Definition: NLCarrots.h:31
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
nl_ca_spring_plough_sandy
Definition: NLCarrots.h:42
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
NL_CA_HERBI1
#define NL_CA_HERBI1
Definition: NLCarrots.h:29
nl_ca_fungicide1
Definition: NLCarrots.h:55
nl_ca_winter_plough_clay
Definition: NLCarrots.h:43
nl_ca_bed_forming
Definition: NLCarrots.h:48
nl_ca_herbicide3
Definition: NLCarrots.h:54
NL_CA_FUNGI2
#define NL_CA_FUNGI2
Definition: NLCarrots.h:32
nl_ca_ferti_p2
Definition: NLCarrots.h:50
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
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