ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
OSeedGrass1 Class Reference

#include <OSeedGrass1.h>

Public Member Functions

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

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
int m_count
 
int m_CropClassification
 
int m_ddegstoharvest
 
FarmEventm_ev
 
Farmm_farm
 
LE * m_field
 
int m_first_date
 
int m_last_date
 

Detailed Description

Definition at line 47 of file OSeedGrass1.h.

Constructor & Destructor Documentation

◆ OSeedGrass1()

OSeedGrass1::OSeedGrass1 ( )
inline

Definition at line 51 of file OSeedGrass1.h.

52  {
53  m_first_date=g_date->DayInYear(14,3);
54  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 36 of file OSeedGrass1.cpp.

37 {
38  // NB IF SEED GRASS IS USED IN A ROTATION IT MUST FOLLOW AN UNDERSOWN CROP!!!
39 
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43 
44  bool done = false;
45 
46  switch ( m_ev->m_todo ) {
47  case osg1_start:
48  {
49  // End date checking block.
50  SG1_WATER_DATE = g_date->Date();
51  // Set up the date management stuff
52  m_last_date=g_date->DayInYear(15,8);
53  // Start and stop dates for all events after harvest
54  int noDates= 4;
55  m_field->SetMDates(0,0,g_date->DayInYear(10,7));
56  // Determined by harvest date - used to see if at all possible
57  m_field->SetMDates(1,0,g_date->DayInYear(20,7));
58  m_field->SetMDates(0,1,g_date->DayInYear(11,7));
59  m_field->SetMDates(1,1,g_date->DayInYear(25,7));
60  m_field->SetMDates(0,2,g_date->DayInYear(26,7));
61  m_field->SetMDates(1,2,g_date->DayInYear(20,7));
62  m_field->SetMDates(0,3,g_date->DayInYear(15,7));
63  m_field->SetMDates(1,3,g_date->DayInYear(15,8));
64  // Check the next crop for early start, unless it is a spring crop
65  // in which case we ASSUME that no checking is necessary!!!!
66  // So DO NOT implement a crop that runs over the year boundary
67 
68  //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)
69  int d1;
70  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
71 
72  if (m_ev->m_startday>g_date->DayInYear(1,7))
73  {
74  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
75  {
76  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): "
77  "Harvest too late for the next crop to start!!!", "" );
78  exit( 1 );
79  }
80  // Now fix any late finishing problems
81  for (int i=0; i<noDates; i++) {
82  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
83  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
84  }
85  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
86  m_field->SetMConstants(i,0);
87  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
88  }
89  }
90  }
91  // Now no operations can be timed after the start of the next crop.
92 
93  int today=g_date->Date();
94  d1 = g_date->OldDays() + m_first_date;
95  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
96  if (today > d1)
97  {
98  // Yes too late - should not happen - raise an error
99  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): "
100  "Crop start attempt after last possible start date", "" );
101  exit( 1 );
102  }
103  }//if
104 
105  // Reinit d1 to first possible starting date.
106  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
107  if ( g_date->Date() > d1 ) {
108  d1 = g_date->Date();
109  }
110  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
111  // OK, let's go.
112  SimpleEvent( d1, osg1_ferti_zero, false );
113  break;
114  }
115 
116  case osg1_ferti_zero:
117  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
118  if (!m_farm->FP_NPK( m_field, 0.0,
119  g_date->DayInYear( 15, 4 ) -
120  g_date->DayInYear())) {
121  SimpleEvent( g_date->Date() + 1, osg1_ferti_zero, true );
122  break;
123  }
124  }
125  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
126  osg1_water_zero, false );
127  break;
128 
129  case osg1_water_zero:
130  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
131  {
132  if ( !m_farm->Water( m_field, 0.0,
133  g_date->DayInYear( 30, 5 ) -
134  g_date->DayInYear())) {
135  SimpleEvent( g_date->Date() + 1, osg1_water_zero, true );
136  break;
137  }
138  SG1_WATER_DATE = g_date->Date();
139  {
140  int d1 = g_date->Date() + 7;
141  if ( d1 > g_date->OldDays() + g_date->DayInYear( 1, 6 ))
142  d1 = g_date->OldDays() + g_date->DayInYear( 1, 6 );
143  SimpleEvent( d1, osg1_water_zero_b, true );
144  break;
145  }
146  }
147  // Didn't do first water, so skip the second one too.
148  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
149  osg1_swarth, false );
150  break;
151 
152  case osg1_water_zero_b:
153  if ( m_ev->m_lock )
154  {
155  if ( !m_farm->Water( m_field, 0.0, g_date->DayInYear( 30, 6 ) - g_date->DayInYear()))
156  {
157  SimpleEvent( g_date->Date() + 1, osg1_water_zero_b, true );
158  break;
159  }
160  SG1_WATER_DATE = g_date->Date();
161  }
162  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
163  osg1_swarth, false );
164  break;
165 
166  case osg1_swarth:
167  if ( m_ev->m_lock || m_farm->DoIt( 5 )) {
168  if ( !m_farm->Swathing( m_field, 0.0,
169  g_date->DayInYear( 15, 7 ) -
170  g_date->DayInYear())) {
171  SimpleEvent( g_date->Date() + 1, osg1_swarth, true );
172  break;
173  }
174  ChooseNextCrop (4);
175  SimpleEvent( g_date->Date() + 2, osg1_harvest, false );
176  break;
177  }
178  ChooseNextCrop (4);
179  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ), osg1_harvest, false );
180  break;
181 
182  case osg1_harvest:
183  if (m_field->GetMConstants(0)==0) {
184  if (!m_farm->Harvest( m_field, 0.0, -1)) { //raise an error
185  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'Harvest' execution", "" );
186  exit( 1 );
187  }
188  }
189  else {
190  if ( !m_farm->Harvest( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
191  SimpleEvent( g_date->Date() + 1, osg1_harvest, false );
192  break;
193  }
194  }
195 
196  SimpleEvent( g_date->Date(), osg1_strawchopping, false );
197  break;
198 
199  case osg1_strawchopping:
200  if ( m_ev->m_lock || m_farm->DoIt( 30 )) {
201  if (m_field->GetMConstants(0)==0) {
202  if (!m_farm->StrawChopping( m_field, 0.0, -1)) { //raise an error
203  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'StrawChopping' execution", "" );
204  exit( 1 );
205  }
206  }
207  else {
208  if ( !m_farm->StrawChopping( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
209  SimpleEvent( g_date->Date() + 1, osg1_strawchopping, true );
210  break;
211  }
212  }
213  done = true;
214  break;
215  }
216 
217  {
218  int d1 = g_date->Date()+1;
219  int d2 = g_date->OldDays() + m_field->GetMDates(0,1);
220  if (d1>d2) d1=d2;
221  SimpleEvent( d1, osg1_compress, false );
222  }
223  break;
224 
225  case osg1_compress:
226  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
227  if (m_field->GetMConstants(1)==0) {
228  if (!m_farm->HayTurning( m_field, 0.0, -1)) { //raise an error
229  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'HayTurning' execution", "" );
230  exit( 1 );
231  }
232  }
233  else {
234  if ( !m_farm->HayTurning( m_field, 0.0, m_field->GetMDates(1,1) - g_date->DayInYear())) {
235  SimpleEvent( g_date->Date() + 1, osg1_compress, true );
236  break;
237  }
238  }
239  }
240  {
241  int d1 = g_date->Date();
242  if ( d1 < g_date->OldDays() + m_field->GetMDates(0,3))
243  d1 = g_date->OldDays() + m_field->GetMDates(0,3);
244  SimpleEvent( d1, osg1_burn_straw, false );
245  }
246  break;
247 
248  case osg1_burn_straw:
249  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
250  if (m_field->GetMConstants(3)==0) {
251  if (!m_farm->BurnStrawStubble( m_field, 0.0, -1)) { //raise an error
252  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'BurnStrawStubble' execution", "" );
253  exit( 1 );
254  }
255  }
256  else {
257  if ( !m_farm->BurnStrawStubble( m_field, 0.0,m_field->GetMDates(1,3) - g_date->DayInYear())) {
258  SimpleEvent( g_date->Date() + 1, osg1_burn_straw, true );
259  break;
260  }
261  }
262  }
263  done = true;
264  break;
265 
266  default:
267  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): " "Unknown event type! ", "" );
268  exit( 1 );
269  }
270 
271  return done;
272 }

References Farm::BurnStrawStubble(), Crop::ChooseNextCrop(), Farm::DoIt(), Farm::FP_NPK(), Farm::GetType(), Farm::Harvest(), Farm::HayTurning(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, osg1_burn_straw, osg1_compress, osg1_ferti_zero, osg1_harvest, osg1_start, osg1_strawchopping, osg1_swarth, osg1_water_zero, osg1_water_zero_b, SG1_WATER_DATE, Crop::SimpleEvent(), Farm::StrawChopping(), Farm::Swathing(), tof_OptimisingFarm, and Farm::Water().


The documentation for this class was generated from the following files:
SG1_WATER_DATE
#define SG1_WATER_DATE
Definition: OSeedGrass1.h:31
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
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Farm::FP_NPK
virtual bool FP_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer, on a_field owned by an arable farmer.
Definition: farmfuncs.cpp:629
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
tof_OptimisingFarm
Definition: farm.h:273
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
osg1_ferti_zero
Definition: OSeedGrass1.h:35
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
osg1_swarth
Definition: OSeedGrass1.h:38
osg1_harvest
Definition: OSeedGrass1.h:39
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
osg1_compress
Definition: OSeedGrass1.h:41
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: farmfuncs.cpp:2132
osg1_start
Definition: OSeedGrass1.h:34
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
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
osg1_water_zero_b
Definition: OSeedGrass1.h:37
osg1_burn_straw
Definition: OSeedGrass1.h:42
Farm::BurnStrawStubble
virtual bool BurnStrawStubble(LE *a_field, double a_user, int a_days)
Burn stubble on a_field.
Definition: farmfuncs.cpp:2236
osg1_strawchopping
Definition: OSeedGrass1.h:40
Farm::Swathing
virtual bool Swathing(LE *a_field, double a_user, int a_days)
Cut the crop on a_field and leave it lying (probably rape)
Definition: farmfuncs.cpp:1744
osg1_water_zero
Definition: OSeedGrass1.h:36
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: farmfuncs.cpp:2159
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539