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

NLMaizeSpring class
. More...

#include <NLMaizeSpring.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...
 
 NLMaizeSpring ()
 
- 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

NLMaizeSpring class
.

See NLMaizeSpring.h::NLMaizeSpringToDo for a complete list of all possible events triggered codes by the mazie 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

◆ NLMaizeSpring()

NLMaizeSpring::NLMaizeSpring ( )
inline
64  {
65  // When we start it off, the first possible date for a farm operation is 5th November
66  // This information is used by other crops when they decide how much post processing of
67  // the management is allowed after harvest before the next crop starts.
68  m_first_date=g_date->DayInYear( 30,4 );
69  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

bool NLMaizeSpring::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 maize.

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_ms_start:
72  {
73  // nl_ms_start just sets up all the starting conditions and reference dates that are needed to start a nl_maize
74  NL_MS_START_FERTI = false;
75  // Set up the date management stuff
76  // The next bit of code just allows for altering dates after harvest if it is necessary
77  // to allow for a crop which starts its management early.
78 
79  // 5 start and stop dates for all 'movable' events for this crop
80  int noDates = 1;
81  a_field->SetMDates(0, 0, g_date->DayInYear(5, 10)); // last possible day of harvest
82  a_field->SetMDates(1, 0, g_date->DayInYear(10, 10)); // last possible day of straw chopping
83  // then these will be reduced in value to 0
84 
85  a_field->SetMConstants(0, 1);
86 
87  // Check the next crop for early start, unless it is a spring crop
88  // in which case we ASSUME that no checking is necessary!!!!
89  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
90 
91  //new if: do the check only for non-optimising farms and if year>0. (030713 - ms_rotation used only in the hidden year, so I modified the condition from >7 to >0)
92  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
93  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
94 
95  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
96  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
97  {
98  g_msg->Warn(WARN_BUG, "NLMaizeSpring::Do(): ", "Harvest too late for the next crop to start!!!");
99  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
100  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
101  }
102  // Now fix any late finishing problems
103  for (int i = 0; i < noDates; i++) {
104  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
105  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
106  }
107  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
108  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)
109  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
110  }
111  }
112  }
113  // Now no operations can be timed after the start of the next crop.
114 
115  if (!a_ev->m_first_year) {
116  d1 = g_date->OldDays() + 365 + m_first_date; // Add 365 for spring crop
117  if (g_date->Date() > d1) {
118  // Yes too late - should not happen - raise an error
119  g_msg->Warn(WARN_BUG, "NLMaizeSpring::Do(): ", "Crop start attempt after last possible start date");
120  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
121  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
122  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
123  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
124  exit(1);
125  }
126  }
127  else {
128  // Is the first year
129  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes
130  // Code for first spring treatment used
131  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 4), nl_ms_spring_sow, false, a_farm, a_field);
132  break;
133  }
134  }//if
135 
136  // End single block date checking code. Please see next line comment as well.
137  // Reinit d1 to first possible starting date.
138  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
139  if (g_date->Date() >= d1) d1 += 365;
140  // OK, let's go.
141  // Here we queue up the first event - this differs depending on whether we have field on snady or clay soils
142  if (a_field->GetSoilType() == 2 || a_field->GetSoilType() == 6) { // on sandy soils (NL ZAND & LOSS)
143  SimpleEvent_(d1, nl_ms_spring_plough_sandy, false, a_farm, a_field);
144  }
145  else
146  {
147  d1 = g_date->OldDays() + g_date->DayInYear(10, 4);
148  if (g_date->Date() >= d1) d1 += 365;
149  SimpleEvent_(d1, nl_ms_preseeding_cultivator, false, a_farm, a_field);
150  }
151  }
152  break;
153 
154  // This is the first real farm operation
156  if (!a_farm->SpringPlough(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
157  SimpleEvent_(g_date->Date() + 1, nl_ms_spring_plough_sandy, true, a_farm, a_field);
158  break;
159  }
160  SimpleEvent_(g_date->Date() + 10, nl_ms_preseeding_cultivator, false, a_farm, a_field);
161  break;
163  if (!a_farm->PreseedingCultivator(a_field, 0.0, g_date->DayInYear(4, 5) - g_date->DayInYear())) {
164  SimpleEvent_(g_date->Date() + 1, nl_ms_preseeding_cultivator, true, a_farm, a_field);
165  break;
166  }
167  SimpleEvent_(g_date->Date() + 1, nl_ms_spring_sow_with_ferti, false, a_farm, a_field);
168  break;
170  // 75% will do sow with firtilizer
171  if (a_ev->m_lock || a_farm->DoIt_prob(0.75))
172  {
173  if (!a_farm->SpringSowWithFerti(a_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
174  SimpleEvent_(g_date->Date() + 1, nl_ms_spring_sow_with_ferti, true, a_farm, a_field);
175  break;
176  }
177  else
178  {
179  // 75% of farmers will do this, but the other 25% won't so we need to remember whether we are in one or the other group
180  NL_MS_START_FERTI = true;
181  // Here is a fork leading to parallel events
182  SimpleEvent_(g_date->Date() + 3, nl_ms_harrow, false, a_farm, a_field);
183  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), nl_ms_herbicide1, false, a_farm, a_field); // Herbidide thread
184  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread = MAIN
185  {
186  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), nl_ms_ferti_s2, false, a_farm, a_field);
187  }
188  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), nl_ms_ferti_p2, false, a_farm, a_field);
189  break;
190  }
191  }
192  SimpleEvent_(g_date->Date() + 1, nl_ms_spring_sow, false, a_farm, a_field);
193  break;
194  case nl_ms_spring_sow:
195  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(5, 5) - g_date->DayInYear())) {
196  SimpleEvent_(g_date->Date() + 1, nl_ms_spring_sow, true, a_farm, a_field);
197  break;
198  }
199  // Here is a fork leading to parallel events
200  SimpleEvent_(g_date->Date() + 3, nl_ms_harrow, false, a_farm, a_field);
201  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), nl_ms_herbicide1, false, a_farm, a_field); // Herbidide thread
202  if (a_farm->IsStockFarmer()) //Stock Farmer // N thread = MAIN
203  {
204  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), nl_ms_ferti_s2, false, a_farm, a_field);
205  }
206  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 5), nl_ms_ferti_p2, false, a_farm, a_field);
207  break;
208  case nl_ms_ferti_p2:
209  // Here comes N thread
210  if (a_ev->m_lock || a_farm->DoIt_prob(0.60) && (NL_MS_START_FERTI==0))
211  {
212  if (!a_farm->FP_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
213  SimpleEvent_(g_date->Date() + 1, nl_ms_ferti_p2, true, a_farm, a_field);
214  break;
215  }
216  }
217  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 9), nl_ms_harvest, false, a_farm, a_field);
218  break;
219  case nl_ms_ferti_s2:
220  if (a_ev->m_lock || a_farm->DoIt_prob(0.60) && (NL_MS_START_FERTI == 0))
221  {
222  if (!a_farm->FA_AmmoniumSulphate(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
223  SimpleEvent_(g_date->Date() + 1, nl_ms_ferti_s2, true, a_farm, a_field);
224  break;
225  }
226  }
227  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(10, 9), nl_ms_harvest, false, a_farm, a_field);
228  break;
229  case nl_ms_herbicide1:
230  // Here comes the herbicide thread
231  if (a_field->GetGreenBiomass() <= 0)
232  {
233  SimpleEvent_(g_date->Date() + 1, nl_ms_herbicide1, false, a_farm, a_field);
234  }
235  else
236  {
237  if (a_ev->m_lock || a_farm->DoIt_prob(0.90))
238  {
239  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(25, 5) - g_date->DayInYear())) {
240  SimpleEvent_(g_date->Date() + 1, nl_ms_herbicide1, true, a_farm, a_field);
241  break;
242  }
243  }
244  }
245  // End of thread
246  break;
247  case nl_ms_harrow:
248  // Here comes the MAIN thread
249  if (a_ev->m_lock || a_farm->DoIt_prob(0.15))
250  {
251  if (a_field->GetGreenBiomass() <= 0)
252  {
253  if (!a_farm->ShallowHarrow(a_field, 0.0, g_date->DayInYear(15, 5) - g_date->DayInYear())) {
254  SimpleEvent_(g_date->Date() + 1, nl_ms_harrow, true, a_farm, a_field);
255  break;
256  }
257  }
258  else { SimpleEvent_(g_date->Date() + 1, nl_ms_harrow, true, a_farm, a_field); }
259  }
260  // End of thread
261  break;
262  case nl_ms_harvest:
263  // Here the MAIN thread continues
264  // We don't move harvest days
265  if (!a_farm->Harvest(a_field, 0.0, a_field->GetMDates(0, 0) - g_date->DayInYear())) {
266  SimpleEvent_(g_date->Date() + 1, nl_ms_harvest, true, a_farm, a_field);
267  break;
268  }
269  SimpleEvent_(g_date->Date() + 1, nl_ms_straw_chopping, false, a_farm, a_field);
270  break;
272  if (a_field->GetMConstants(0) == 0) {
273  if (!a_farm->StrawChopping(a_field, 0.0, -1)) { // raise an error
274  g_msg->Warn(WARN_BUG, "NLMaizeSpring::Do(): failure in 'StrawChopping' execution", "");
275  exit(1);
276  }
277  }
278  else {
279  if (!a_farm->StrawChopping(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
280  SimpleEvent_(g_date->Date() + 1, nl_ms_straw_chopping, true, a_farm, a_field);
281  break;
282  }
283  }
284  done = true;
285  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
286  // END of MAIN THREAD
287  break;
288  default:
289  g_msg->Warn(WARN_BUG, "NLMaizeSpring::Do(): "
290  "Unknown event type! ", "");
291  exit(1);
292  }
293  return done;
294 }

References Landscape::BackTranslateVegTypes(), g_landscape_p, Farm::GetType(), Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, nl_ms_ferti_p2, nl_ms_ferti_s2, nl_ms_harrow, nl_ms_harvest, nl_ms_herbicide1, nl_ms_preseeding_cultivator, nl_ms_spring_plough_sandy, nl_ms_spring_sow, nl_ms_spring_sow_with_ferti, nl_ms_start, NL_MS_START_FERTI, nl_ms_straw_chopping, 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
nl_ms_preseeding_cultivator
Definition: NLMaizeSpring.h:39
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
nl_ms_ferti_s2
Definition: NLMaizeSpring.h:44
nl_ms_spring_sow_with_ferti
Definition: NLMaizeSpring.h:40
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
nl_ms_herbicide1
Definition: NLMaizeSpring.h:45
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
nl_ms_ferti_p2
Definition: NLMaizeSpring.h:43
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
nl_ms_harrow
Definition: NLMaizeSpring.h:42
nl_ms_spring_plough_sandy
Definition: NLMaizeSpring.h:38
NL_MS_START_FERTI
#define NL_MS_START_FERTI
A flag used to indicate autumn ploughing status.
Definition: NLMaizeSpring.h:28
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
nl_ms_spring_sow
Definition: NLMaizeSpring.h:41
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
nl_ms_harvest
Definition: NLMaizeSpring.h:46
nl_ms_straw_chopping
Definition: NLMaizeSpring.h:47
nl_ms_start
Definition: NLMaizeSpring.h:36
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