ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
MaizeStrigling.cpp
Go to the documentation of this file.
1 //
2 // MaizeStrigling.cpp
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, University of Aarhus
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 #include "../../Landscape/ls.h"
28 #include "../../Landscape/cropprogs/MaizeStrigling.h"
29 
30 extern CfgFloat cfg_ins_app_prop1;
31 extern CfgFloat cfg_herbi_app_prop;
32 extern CfgFloat cfg_fungi_app_prop1;
33 extern CfgFloat cfg_greg_app_prop;
34 
35 extern Landscape* g_landscape_p;
36 
37 bool MaizeStrigling::Do( Farm *a_farm, LE *a_field, FarmEvent *a_ev )
38 {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42  int d1=0;
43 
44  bool done = false;
45  switch ( m_ev->m_todo ) {
46  case mas_start:
47  {
50  // Set up the date management stuff
51  m_last_date=g_date->DayInYear(30,11);
52  // Start and stop dates for all events after harvest
53  int noDates= 2;
54  m_field->SetMDates(0,0,g_date->DayInYear(10,10));
55  // 0,0 determined by harvest date - used to see if at all possible
56  m_field->SetMDates(1,0,g_date->DayInYear(10,11));
57  m_field->SetMDates(0,1,g_date->DayInYear(15,10));
58  m_field->SetMDates(1,1,g_date->DayInYear(30,11));
59  // Check the next crop for early start, unless it is a spring crop
60  // in which case we ASSUME that no checking is necessary!!!!
61  // So DO NOT implement a crop that runs over the year boundary
62  if (m_ev->m_startday>g_date->DayInYear(1,7))
63  {
64  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
65  {
67  g_msg->Warn( WARN_BUG, "Maize::Do(): Harvest too late for the next crop to start!!!", (g_landscape_p->VegtypeToString(l_tov)) );
68  exit( 1 );
69  }
70  // Now fix any late finishing problems
71  for (int i=0; i<noDates; i++)
72  {
73  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
74  m_field->SetMDates(0,i,m_ev->m_startday-1);
75  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
76  m_field->SetMDates(1,i,m_ev->m_startday-1);
77  }
78  }
79  // Now no operations can be timed after the start of the next crop.
80 
81  if ( ! m_ev->m_first_year )
82  {
83  int today=g_date->Date();
84  // Are we before July 1st?
85  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
86  if (today < d1)
87  {
88  // Yes, too early. We assumme this is because the last crop was late
89  g_msg->Warn( WARN_BUG, "Maize::Do(): "
90  "Crop start attempt between 1st Jan & 1st July", "" );
91  exit( 1 );
92  }
93  else
94  {
95  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
96  if (today > d1)
97  {
98  // Yes too late - should not happen - raise an error
99  g_msg->Warn( WARN_BUG, "Maize::Do(): "
100  "Crop start attempt after last possible start date", "" );
101  exit( 1 );
102  }
103  }
104  }
105  else
106  {
107  SimpleEvent( g_date->OldDays() + g_date->DayInYear(25,4),
108  mas_spring_plough, false );
109  break;
110  }
111  // End single block date checking code. Please see next line
112  // comment as well.
113  // Reinit d1 to first possible starting date.
114  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
115  if ( g_date->Date() > d1 ) {
116  d1 = g_date->Date();
117  }
118  // OK, let's go.
119  if ( m_farm->DoIt( 50 ))
120  {
121  SimpleEvent( d1, mas_fa_manure_a, false );
122  }
123  else
124  {
125  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 3 ) + 365,
126  mas_fa_manure_b, false );
127  }
128  break;
129  }
130 
131  case mas_fa_manure_a:
132  if (!m_farm->FA_Manure( m_field, 0.0,
133  g_date->DayInYear( 30, 11 ) - g_date->DayInYear())) {
134  SimpleEvent( g_date->Date() + 1, mas_fa_manure_a, false );
135  break;
136  }
137  SimpleEvent( g_date->Date(), mas_autumn_plough, false );
138  break;
139 
140  case mas_autumn_plough:
141  if (!m_farm->AutumnPlough( m_field, 0.0,
142  g_date->DayInYear( 30, 11 ) - g_date->DayInYear())) {
143  SimpleEvent( g_date->Date() + 1, mas_autumn_plough, false );
144  break;
145  }
146  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 4 ) + 365,
147  mas_spring_harrow, false );
148  break;
149 
150  case mas_fa_manure_b:
151  if (!m_farm->FA_Manure( m_field, 0.0,
152  g_date->DayInYear( 25, 4 ) - g_date->DayInYear())) {
153  SimpleEvent( g_date->Date() + 1, mas_fa_manure_b, false );
154  break;
155  }
156  {
157  d1 = g_date->OldDays() + g_date->DayInYear( 1, 4 );
158  if ( g_date->Date()+1 > d1 ) {
159  d1 = g_date->Date()+1;
160  }
161  SimpleEvent( d1, mas_fa_slurry_one, false );
162  }
163  break;
164 
165  case mas_fa_slurry_one:
166  if (!m_farm->FA_Slurry( m_field, 0.0,
167  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
168  SimpleEvent( g_date->Date() + 1, mas_fa_slurry_one, false );
169  break;
170  }
171  SimpleEvent( g_date->Date() + 1, mas_spring_plough, false );
172  break;
173 
174  case mas_spring_plough:
175  if (!m_farm->SpringPlough( m_field, 0.0,
176  g_date->DayInYear( 1, 5 ) - g_date->DayInYear())) {
177  SimpleEvent( g_date->Date() + 1, mas_spring_plough, false );
178  break;
179  }
180  SimpleEvent( g_date->Date(), mas_spring_harrow, false );
181  break;
182 
183  case mas_spring_harrow:
184  if (!m_farm->SpringHarrow( m_field, 0.0,
185  g_date->DayInYear( 10, 5 ) - g_date->DayInYear())) {
186  SimpleEvent( g_date->Date() + 1, mas_spring_harrow, false );
187  break;
188  }
189  {
190  d1 = g_date->OldDays() + g_date->DayInYear( 25, 4 );
191  if ( g_date->Date() > d1 ) {
192  d1 = g_date->Date();
193  }
194  SimpleEvent( d1, mas_spring_sow, false );
195  }
196  break;
197 
198  case mas_spring_sow:
199  if (!m_farm->SpringSow( m_field, 0.0,
200  g_date->DayInYear( 15, 5 ) - g_date->DayInYear())) {
201  SimpleEvent( g_date->Date() + 1, mas_spring_sow, false );
202  break;
203  }
204  MAIZEStrigling_SOW_DATE = g_date->Date();
205  SimpleEvent( g_date->Date(), mas_fa_npk, false );
206  break;
207 
208  case mas_fa_npk:
209  if (!m_farm->FA_NPK( m_field, 0.0,
210  g_date->DayInYear( 20, 5 ) - g_date->DayInYear())) {
211  SimpleEvent( g_date->Date() + 1, mas_fa_npk, false );
212  break;
213  }
214  if ( m_farm->DoIt( 70 )) {
215  {
216  d1 = g_date->OldDays() + g_date->DayInYear( 1, 5 );
217  if ( MAIZEStrigling_SOW_DATE + 5 > d1 ) {
218  d1 = MAIZEStrigling_SOW_DATE + 5;
219  }
220  SimpleEvent( d1, mas_herbi_one, false );
221  }
222  } else {
223  {
224  d1 = g_date->OldDays() + g_date->DayInYear( 2, 5 );
225  if ( MAIZEStrigling_SOW_DATE + 7 > d1 ) {
226  d1 = MAIZEStrigling_SOW_DATE + 7;
227  }
228  SimpleEvent( d1, mas_row_one, false );
229  }
230  }
231  break;
232 
233  case mas_herbi_one:
234  if ( m_ev->m_lock || m_farm->DoIt( (int) (100*cfg_herbi_app_prop.value() ))) {
235  if (!m_farm->HerbicideTreat( m_field, 0.0,
236  g_date->DayInYear( 25, 5 ) - g_date->DayInYear())) {
237  SimpleEvent( g_date->Date() + 1, mas_herbi_one, false );
238  break;
239  }
240  }
241  MAIZEStrigling_HERBI_ONE_DATE = g_date->Date();
242  {
243  d1 = g_date->OldDays() + g_date->DayInYear( 1, 5 );
244  if ( MAIZEStrigling_SOW_DATE + 5 > d1 ) {
245  d1 = MAIZEStrigling_SOW_DATE + 5;
246  }
247  SimpleEvent( d1, mas_fa_slurry_two, false );
248  }
249  break;
250 
251  case mas_row_one:
252  if (!m_farm->RowCultivation( m_field, 0.0,
253  g_date->DayInYear( 25, 5 ) - g_date->DayInYear())) {
254  SimpleEvent( g_date->Date() + 1, mas_row_one, false );
255  break;
256  }
257  {
258  d1 = g_date->OldDays() + g_date->DayInYear( 1, 5 );
259  if ( MAIZEStrigling_SOW_DATE + 5 > d1 ) {
260  d1 = MAIZEStrigling_SOW_DATE + 5;
261  }
262  SimpleEvent( d1, mas_fa_slurry_two, false );
263  }
264  break;
265 
266  case mas_fa_slurry_two:
267  if (!m_farm->FA_Slurry( m_field, 0.0,
268  g_date->DayInYear( 25, 5 ) - g_date->DayInYear())) {
269  SimpleEvent( g_date->Date() + 1, mas_fa_slurry_two, false );
270  break;
271  }
272  if ( m_farm->DoIt( 86 )) {
273  {
274  d1 = g_date->OldDays() + g_date->DayInYear( 10, 5 );
275  if ( MAIZEStrigling_HERBI_ONE_DATE + 10 > d1 ) {
277  }
278  SimpleEvent( d1, mas_herbi_two, false );
279  }
280  } else {
281  {
282  d1 = g_date->OldDays() + g_date->DayInYear( 21, 5 );
283  if ( g_date->Date() + 1 > d1 ) {
284  d1 = g_date->Date() + 1;
285  }
286  SimpleEvent( d1, mas_row_two, false );
287  }
288  }
289  break;
290 
291  case mas_herbi_two:
292  if ( m_ev->m_lock || m_farm->DoIt( (int) (100*cfg_herbi_app_prop.value() ))) {
293  if (!m_farm->HerbicideTreat( m_field, 0.0,
294  g_date->DayInYear( 5, 6 ) - g_date->DayInYear())) {
295  SimpleEvent( g_date->Date() + 1, mas_herbi_two, false );
296  break;
297  }
298  }
299  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 7 ),
300  mas_water_one, false );
301  break;
302 
303  case mas_row_two:
304  if (!m_farm->RowCultivation( m_field, 0.0,
305  g_date->DayInYear( 20, 6 ) - g_date->DayInYear())) {
306  SimpleEvent( g_date->Date() + 1, mas_row_two, false );
307  break;
308  }
309  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 7 ),
310  mas_water_one, false );
311  break;
312 
313  case mas_water_one:
314  if ( m_ev->m_lock || m_farm->DoIt( 30 )) {
315  if (!m_farm->Water( m_field, 0.0,
316  g_date->DayInYear( 15, 7 ) - g_date->DayInYear())) {
317  SimpleEvent( g_date->Date() + 1, mas_water_one, false );
318  break;
319  }
320  }
321  {
322  d1 = g_date->OldDays() + g_date->DayInYear( 16, 7 );
323  if ( g_date->Date() + 7 > d1 ) {
324  d1 = g_date->Date() + 7;
325  }
326  SimpleEvent( d1, mas_water_two, false );
327  }
328  break;
329 
330  case mas_water_two:
331  if (!m_farm->Water( m_field, 0.0,
332  g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
333  SimpleEvent( g_date->Date() + 1, mas_water_two, false );
334  break;
335  }
336  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 10 ),
337  mas_harvest, false );
338  break;
339 
340  case mas_harvest:
341  if (!m_farm->Harvest( m_field, 0.0,
342  m_field->GetMDates(1,0) - g_date->DayInYear())) {
343  SimpleEvent( g_date->Date() + 1, mas_harvest, false );
344  break;
345  }
346  {
347  d1 = g_date->OldDays() + m_field->GetMDates(0,1);
348  if ( g_date->Date() > d1 ) {
349  d1 = g_date->Date();
350  }
351  SimpleEvent( d1, mas_stubble, false );
352  }
353  break;
354 
355  case mas_stubble:
356  if ( m_ev->m_lock || m_farm->DoIt( 25 )) {
357  if (!m_farm->StubbleHarrowing( m_field, 0.0,
358  m_field->GetMDates(1,1) -
359  g_date->DayInYear())) {
360  SimpleEvent( g_date->Date() + 1, mas_stubble, false );
361  break;
362  }
363  }
364  d1=g_date->DayInYear();
365  done = true;
366  break;
367 
368  default:
369  g_msg->Warn( WARN_BUG, "Maize::Do(): "
370  "Unknown event type! ", "" );
371  exit( 1 );
372  }
373 
374  return done;
375 }
376 
377 
MAIZEStrigling_SOW_DATE
#define MAIZEStrigling_SOW_DATE
Definition: MaizeStrigling.h:32
mas_fa_manure_b
Definition: MaizeStrigling.h:38
Farm::FA_Slurry
virtual bool FA_Slurry(LE *a_field, double a_user, int a_days)
Spready slurry on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:965
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::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: farmfuncs.cpp:1156
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: farmfuncs.cpp:1769
mas_fa_slurry_one
Definition: MaizeStrigling.h:40
mas_start
Definition: MaizeStrigling.h:36
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Landscape::VegtypeToString
std::string VegtypeToString(TTypesOfVegetation a_veg)
Definition: Landscape.cpp:4235
FarmEvent
A struct to hold the information required to trigger a farm event.
Definition: farm.h:463
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
mas_spring_sow
Definition: MaizeStrigling.h:43
mas_spring_plough
Definition: MaizeStrigling.h:41
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:1036
mas_water_one
Definition: MaizeStrigling.h:48
mas_herbi_two
Definition: MaizeStrigling.h:53
mas_fa_npk
Definition: MaizeStrigling.h:44
cfg_fungi_app_prop1
CfgFloat cfg_fungi_app_prop1
mas_stubble
Definition: MaizeStrigling.h:51
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Farm::FA_NPK
virtual bool FA_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer to a_field owned by an stock farmer.
Definition: farmfuncs.cpp:917
mas_herbi_one
Definition: MaizeStrigling.h:52
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
Landscape
The landscape class containing all environmental and topographical data.
Definition: Landscape.h:112
mas_fa_slurry_two
Definition: MaizeStrigling.h:46
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
mas_row_one
Definition: MaizeStrigling.h:45
mas_fa_manure_a
Definition: MaizeStrigling.h:37
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
cfg_greg_app_prop
CfgFloat cfg_greg_app_prop
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: farm.h:471
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
MAIZEStrigling_HERBI_ONE_DATE
#define MAIZEStrigling_HERBI_ONE_DATE
Definition: MaizeStrigling.h:33
mas_autumn_plough
Definition: MaizeStrigling.h:39
mas_spring_harrow
Definition: MaizeStrigling.h:42
Farm::RowCultivation
virtual bool RowCultivation(LE *a_field, double a_user, int a_days)
Carry out a harrowing between crop rows on a_field.
Definition: farmfuncs.cpp:1510
MaizeStrigling::Do
bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
Definition: MaizeStrigling.cpp:37
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: farmfuncs.cpp:1717
Crop::m_last_date
int m_last_date
Definition: farm.h:542
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: farmfuncs.cpp:132
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the spring on a_field.
Definition: farmfuncs.cpp:546
Farm
The base class for all farm types.
Definition: farm.h:767
mas_row_two
Definition: MaizeStrigling.h:47
mas_water_two
Definition: MaizeStrigling.h:49
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
mas_harvest
Definition: MaizeStrigling.h:50
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
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: farmfuncs.cpp:471