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

NLCatchPeaCrop class
. More...

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

NLCatchPeaCrop class
.

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

◆ NLCatchPeaCrop()

NLCatchPeaCrop::NLCatchPeaCrop ( )
inline
59  {
60  // When we start it off, the first possible date for a farm operation is 5th November
61  // This information is used by other crops when they decide how much post processing of
62  // the management is allowed after harvest before the next crop starts.
63  m_first_date=g_date->DayInYear( 10,10 );
65  }

References Crop::m_first_date, Crop::SetCropClassification(), and tocc_Catch.

Member Function Documentation

◆ Do()

bool NLCatchPeaCrop::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 CatchPeaCrop.

Reimplemented from Crop.

57 {
58  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
59  int d1 = 0;
60  // Depending what event has occured jump to the correct bit of code
61  switch (a_ev->m_todo)
62  {
63  case nl_cpc_start:
64  {
65 
66  // Set up the date management stuff
67 
68  // Check the next crop for early start, unless it is a spring crop
69  // in which case we ASSUME that no checking is necessary!!!!
70  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
71 
72  //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)
73  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
74  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
75 
76  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
77  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
78  {
79  g_msg->Warn(WARN_BUG, "NLCatchPeaCrop::Do(): ", "Harvest too late for the next crop to start!!!");
80  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
81  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
82  }
83  }
84  // Now no operations can be timed after the start of the next crop.
85 
86  if (!a_ev->m_first_year) {
87  // Are we before July 1st?
88  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
89  // We need to skip this test if its a catch crop that preceded
90 
91  if ((g_date->Date() < d1) && (!g_farm_fixed_crop_enable.value())) { // condition preventing from getting errors regarding looping catch crop
92  // Yes, too early. We assumme this is because the last crop was late
93  printf("Poly: %d\n", a_field->GetPoly());
94  g_msg->Warn(WARN_BUG, "NLCatchPeaCrop::Do(): ", "Crop start attempt between 1st Jan & 1st July");
95  int prev = g_landscape_p->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex()));
96  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
97  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
98  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
99  }
100  else {
101  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
102  if (g_date->Date() > d1) {
103  // Yes too late - should not happen - raise an error
104  g_msg->Warn(WARN_BUG, "NLCatchPeaCrop::Do(): ", "Crop start attempt after last possible start date");
105  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
106  a_field->GetOwner()->GetPreviousCrop(a_field->GetRotIndex());
107  int almassnum = g_landscape_p->BackTranslateVegTypes(a_ev->m_next_tov);
108  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
109  }
110  }
111  }
112  else {
113  // Is the first year
114  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes
115  // Code for first spring treatment used
116  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 8), nl_cpc_stubble_cultivator, false, a_farm, a_field);
117  break;
118  }
119  }//if
120 
121  // End single block date checking code. Please see next line comment as well.
122  // Reinit d1 to first possible starting date.
123  d1 = g_date->OldDays() + g_date->DayInYear(1, 8);
124  // OK, let's go.
125  // Here we queue up the first event - this differs depending on whether we have a
126  // stock or arable farmer
127  SimpleEvent_(d1, nl_cpc_stubble_cultivator, false, a_farm, a_field);
128  }
129  break;
130 
131  // This is the first real farm operation
133  if (!a_farm->StubbleHarrowing(a_field, 0.0, g_date->DayInYear(10, 10) - g_date->DayInYear())) {
134  SimpleEvent_(g_date->Date() + 1, nl_cpc_stubble_cultivator, true, a_farm, a_field);
135  break;
136  }
137  if (a_farm->IsStockFarmer()) //Stock Farmer
138  {
139  SimpleEvent_(g_date->Date() + 5, nl_cpc_ferti_s1, false, a_farm, a_field);
140  }
141  else SimpleEvent_(g_date->Date() + 5, nl_cpc_ferti_p1, false, a_farm, a_field);
142  break;
143 
144  case nl_cpc_ferti_p1:
145  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
146  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_p1, true, a_farm, a_field);
147  break;
148  }
149  SimpleEvent_(g_date->Date() + 1, nl_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
150  break;
151  case nl_cpc_ferti_s1:
152  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
153  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_s1, true, a_farm, a_field);
154  break;
155  }
156  SimpleEvent_(g_date->Date() + 1, nl_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
157  break;
159  if (!a_farm->PreseedingCultivatorSow(a_field, 0.0, g_date->DayInYear(16, 10) - g_date->DayInYear())) {
160  SimpleEvent_(g_date->Date() + 1, nl_cpc_preseeding_cultivator_with_sow, true, a_farm, a_field);
161  break;
162  }
163  d1 = g_date->Date() + 14;
164  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 9)) {
165  d1 = g_date->OldDays() + g_date->DayInYear(1, 9);
166  }
167  if (a_field->GetSoilType() == 2 || a_field->GetSoilType() == 6) { // on sandy soils (NL ZAND & LOSS)
168  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(15, 2) + 365, nl_cpc_ferti_s2_sandy, false, a_farm, a_field);
169  }
170  else SimpleEvent_(d1, nl_cpc_ferti_s2_clay, false, a_farm, a_field);
171  break;
173  if (a_farm->IsStockFarmer())
174  {
175  if (!a_farm->FA_Manure(a_field, 0.0, g_date->DayInYear(25, 10) - g_date->DayInYear())) {
176  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_s2_clay, true, a_farm, a_field);
177  break;
178  }
179  d1 = g_date->Date() + 40;
180  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 10)) {
181  d1 = g_date->OldDays() + g_date->DayInYear(15, 10);
182  }
183  SimpleEvent_(d1, nl_cpc_winter_plough_clay, false, a_farm, a_field);
184  break;
185  }
186  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_p2_clay, false, a_farm, a_field);
187  break;
189  if (!a_farm->FP_Manure(a_field, 0.0, g_date->DayInYear(25, 10) - g_date->DayInYear())) {
190  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_p2_clay, true, a_farm, a_field);
191  break;
192  }
193  d1 = g_date->Date() + 40;
194  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 10)) {
195  d1 = g_date->OldDays() + g_date->DayInYear(15, 10);
196  }
197  SimpleEvent_(d1, nl_cpc_winter_plough_clay, false, a_farm, a_field);
198  break;
200  if (!a_farm->WinterPlough(a_field, 0.0, g_date->DayInYear(15, 12) - g_date->DayInYear())) {
201  SimpleEvent_(g_date->Date() + 1, nl_cpc_winter_plough_clay, true, a_farm, a_field);
202  break;
203  }
204  // The plan is finished on clay soils (catch crop in incorporated into soil on autumn)
205  // Calling sleep_all_day to move to the next year
206  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 1) + 365, nl_cpc_sleep_all_day, false, a_farm, a_field);
207  break;
209  if (a_farm->IsStockFarmer())
210  {
211  if (!a_farm->FA_Manure(a_field, 0.0, g_date->DayInYear(15, 3) - g_date->DayInYear())) {
212  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_s2_sandy, true, a_farm, a_field);
213  break;
214  }
215  // The plan is finished on sandy soils; spring plough (to incorporate catch crop into soil) will follow but it is called from the next crop
216  done = true;
217  break;
218  }
219  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_p2_sandy, false, a_farm, a_field);
220  break;
222  if (!a_farm->FP_Manure(a_field, 0.0, g_date->DayInYear(15, 3) - g_date->DayInYear())) {
223  SimpleEvent_(g_date->Date() + 1, nl_cpc_ferti_p2_sandy, true, a_farm, a_field);
224  break;
225  }
226  // The plan is finished on sandy soils; spring plough (to incorporate catch crop into soil) will follow but it is called from the next crop
227  done = true;
228  break;
230  if (!a_farm->SleepAllDay(a_field, 0.0, g_date->DayInYear(15, 3) - g_date->DayInYear())) {
231  SimpleEvent_(g_date->Date() + 1, nl_cpc_sleep_all_day, true, a_farm, a_field);
232  break;
233  }
234  done = true;
235  break;
236 
237 
238  default:
239  g_msg->Warn(WARN_BUG, "NLCatchPeaCrop::Do(): "
240  "Unknown event type! ", "");
241  exit(1);
242  }
243  return done;
244 }

References Landscape::BackTranslateVegTypes(), g_farm_fixed_crop_enable, g_landscape_p, Farm::GetType(), Farm::IsStockFarmer(), Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, nl_cpc_ferti_p1, nl_cpc_ferti_p2_clay, nl_cpc_ferti_p2_sandy, nl_cpc_ferti_s1, nl_cpc_ferti_s2_clay, nl_cpc_ferti_s2_sandy, nl_cpc_preseeding_cultivator_with_sow, nl_cpc_sleep_all_day, nl_cpc_start, nl_cpc_stubble_cultivator, nl_cpc_winter_plough_clay, Crop::SimpleEvent_(), Farm::StubbleHarrowing(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
nl_cpc_ferti_s2_sandy
Definition: NLCatchPeaCrop.h:42
tocc_Catch
Definition: farm.h:216
nl_cpc_ferti_s2_clay
Definition: NLCatchPeaCrop.h:39
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
Landscape::BackTranslateVegTypes
int BackTranslateVegTypes(TTypesOfVegetation VegReference)
Definition: Landscape.h:1669
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
nl_cpc_ferti_s1
Definition: NLCatchPeaCrop.h:36
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
nl_cpc_sleep_all_day
Definition: NLCatchPeaCrop.h:33
nl_cpc_start
Definition: NLCatchPeaCrop.h:32
nl_cpc_winter_plough_clay
Definition: NLCatchPeaCrop.h:40
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
nl_cpc_stubble_cultivator
Definition: NLCatchPeaCrop.h:34
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
nl_cpc_ferti_p2_clay
Definition: NLCatchPeaCrop.h:38
nl_cpc_ferti_p1
Definition: NLCatchPeaCrop.h:35
Crop::SetCropClassification
void SetCropClassification(int a_classification)
Definition: farm.h:569
nl_cpc_preseeding_cultivator_with_sow
Definition: NLCatchPeaCrop.h:37
nl_cpc_ferti_p2_sandy
Definition: NLCatchPeaCrop.h:41
g_farm_fixed_crop_enable
CfgBool g_farm_fixed_crop_enable
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
Farm::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: farmfuncs.cpp:2209
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