File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NorwegianOats Class Reference

#include <NorwegianOats.h>

Inheritance diagram for NorwegianOats:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 NorwegianOats (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
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)
 
void GetCropType (TTypesOfCrops a_toc)
 
TTypesOfCrops GetCropType ()
 
FarmManagementCategory LookUpManagementCategory (int a_todo)
 
bool GetForceSpringOK ()
 

Additional Inherited Members

- Public Attributes inherited from Crop
TTypesOfVegetation m_tov
 
- 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...
 
bool StartUpCrop (int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
 
Holds the translation between the farm operation enum for each cropand the farm management category associated with it More...
 
bool AphidDamage (LE *a_field)
 Compares aphid numbers per m2 with a threshold to return true if threshold is exceeded. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_base_elements_no
 
Landscapem_OurLandscape
 
bool m_forcespringpossible = false
 Used to signal that the crop can be forced to start in spring. More...
 
TTypesOfCrops m_toc
 The Crop type in terms of the TTypesOfCrops list (smaller list than tov, no country designation) More...
 
int m_CropClassification
 Contains information on whether this is a winter crop, spring crop, or catch crop that straddles the year boundary (0,1,2) More...
 
vector< FarmManagementCategorym_ManagementCategories
 Holds the translation between the farm operation enum for each crop and the farm management category associated with it. More...
 
- Static Protected Attributes inherited from Crop
static int m_date_modifier = 0
 Holds a value that shifts test pesticide use by this many days in crops modified to use it. More...
 

Constructor & Destructor Documentation

◆ NorwegianOats()

NorwegianOats::NorwegianOats ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
52  : Crop(a_tov, a_toc, a_L)
53  {
55  m_ddegstoharvest = 1400; // this is hard coded for each crop that uses this
57  }

References Calendar::DayInYear(), g_date, Crop::m_ddegstoharvest, Crop::m_first_date, and SetUpFarmCategoryInformation().

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35  m_farm = a_farm;
36  m_field = a_field;
37  m_ev = a_ev;
38  int d1;
39 
40  bool done = false;
41 
42  switch (m_ev->m_todo)
43  {
44  case no_oats_start:
45  {
46  a_field->ClearManagementActionSum();
47 
48  // Set up the date management stuff
49  // Could save the start day in case it is needed later
50  // m_field->m_startday = m_ev->m_startday;
51  m_last_date = g_date->DayInYear(30, 8);
52  // Start and stop dates for all events after harvest
53  int noDates = 2;
54  m_field->SetMDates(0, 0, g_date->DayInYear(20, 8));
55  // Determined by harvest date - used to see if at all possible
56  m_field->SetMDates(1, 0, g_date->DayInYear(10, 8));
57  m_field->SetMDates(0, 1, g_date->DayInYear(10, 8));
58  m_field->SetMDates(1, 1, g_date->DayInYear(30, 8));
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 
63  if (m_ev->m_startday > g_date->DayInYear(1, 7))
64  {
65  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
66  {
67  char veg_type[20];
68  sprintf(veg_type, "%d", m_ev->m_next_tov);
69  g_msg->Warn(WARN_BUG, "NorwegianOats::Do(): : Harvest too late for the next crop to start!!! The next crop is: ", veg_type);
70  exit(1);
71  }
72  // Now fix any late finishing problems
73  for (int i = 0; i < noDates; i++) {
74  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
75  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
76  }
77  if (m_field->GetMDates(1, i) >= m_ev->m_startday){
78  m_field->SetMConstants(i, 0);
79  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
80  }
81  }
82  }
83  // Now no operations can be timed after the start of the next crop.
84 
85  if (!m_ev->m_first_year)
86  {
87  int today = g_date->Date();
88  // Are we before July 1st?
89  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
90  if (today < d1)
91  {
92  // Yes, too early. We assumme this is because the last crop was late
93  g_msg->Warn(WARN_BUG, "NorwegianOats::Do(): " "Crop start attempt between 1st Jan & 1st July", "");
94  exit(1);
95  }
96  else
97  {
98  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
99  if (today > d1)
100  {
101  // Yes too late - should not happen - raise an error
102  char veg_type[20];
103  sprintf(veg_type, "%d", m_ev->m_field->GetPreviousTov(m_ev->m_field->GetRotIndex()));
104  g_msg->Warn(WARN_BUG, "NorwegianOats::Do(): " "Crop start attempt after last possible start date", veg_type);
105  exit(1);
106  }
107  }
108  }
109  else
110  {
112  break;
113  }
114 
115 
116  // End single block date checking code. Please see next line
117  // comment as well.
118  // Reinit d1 to first possible starting date.
119  d1 = g_date->OldDays() + g_date->DayInYear(7, 9);
120  if (g_date->Date() > d1) {
121  d1 = g_date->Date();
122  }
123  // OK, let's go.
125  }
126  break;
127 
129  if (m_ev->m_lock || m_farm->DoIt(70)) // was 70
130  {
131  if (!m_farm->AutumnPlough(m_field, 0.0, g_date->DayInYear(07, 11) - g_date->DayInYear())) {
133  break;
134  }
136  }
137  SimpleEvent(g_date->OldDays() + g_date->DayInYear(21, 4) + 365, no_oats_spring_plough, false);
138  break;
139 
142  {
143  if (!m_farm->SpringPlough(m_field, 0.0, g_date->DayInYear(1, 5) - g_date->DayInYear())) {
145  break;
146  }
147  }
148  {
149  d1 = g_date->Date();
150  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 5)) {
151  d1 = g_date->OldDays() + g_date->DayInYear(1, 5);
152  }
154  }
155  break;
156 
158  if (!m_farm->SpringHarrow(m_field, 0.0,
159  g_date->DayInYear(10, 5) - g_date->DayInYear())) {
161  break;
162  }
163  d1 = g_date->Date();
164  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 5)) {
165  d1 = g_date->OldDays() + g_date->DayInYear(1, 5);
166  }
167  SimpleEvent(d1, no_oats_spring_sow, false);
168  break;
169 
170  case no_oats_spring_sow:
171  if (!m_farm->SpringSow(m_field, 0.0,
172  g_date->DayInYear(17, 5) - g_date->DayInYear())) {
173  SimpleEvent(g_date->Date() + 1, no_oats_spring_sow, true);
174  break;
175  }
176  {
177  int d1 = g_date->Date();
178  SimpleEvent(d1, no_oats_spring_roll, false);
179  }
180  break;
181 
182  case no_oats_spring_roll:
183  if (m_ev->m_lock || m_farm->DoIt(50))
184  {
185  if (!m_farm->SpringRoll(m_field, 0.0,
186  g_date->DayInYear(20, 5) - g_date->DayInYear())) {
188  break;
189  }
190  }
191  ChooseNextCrop(2);
193  break;
194 
195 
196  case no_oats_harvest:
198  if (!m_farm->Harvest(m_field, 0.0, -1)) {
199  SimpleEvent(g_date->Date() + 1, no_oats_harvest, true);
200  break;
201  }
202  }
203  SimpleEvent(g_date->Date() + 14, no_oats_haybailing, false);
204  break;
205 
206  case no_oats_haybailing:
207  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
208  SimpleEvent(g_date->Date() + 1, no_oats_haybailing, true);
209  break;
210  }
211  // END MAIN THREAD
212  done = true;
213  break;
214 
215  default:
216  g_msg->Warn(WARN_BUG, "NorwegianOats::Do(): "
217  "Unknown event type! ", "");
218  exit(1);
219  }
220  return done;
221 }

References Farm::AutumnPlough(), Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMDates(), LE::GetPreviousTov(), LE::GetRotIndex(), LE::GetVegDDegs(), Farm::Harvest(), Farm::HayBailing(), Crop::m_ddegstoharvest, Crop::m_ev, Crop::m_farm, FarmEvent::m_field, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, no_oats_autumn_plough, NO_OATS_DID_AUTUMN_PLOUGH, no_oats_harvest, no_oats_haybailing, no_oats_spring_harrow, no_oats_spring_plough, no_oats_spring_roll, no_oats_spring_sow, no_oats_start, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void NorwegianOats::SetUpFarmCategoryInformation ( )
inline
58  {
59  const int elements = 2 + (no_oats_foobar - NO_OATS_BASE);
61 
62  FarmManagementCategory catlist[elements] =
63  {
64  fmc_Others, // zero element unused but must be here
65  fmc_Others,//no_oats_start = 1, // Compulsory, start event must always be 1 (one).
66  fmc_Cultivation,//no_oats_autumn_plough = NO_OATS_BASE,
67  fmc_Cultivation,//no_oats_spring_plough,
68  fmc_Cultivation,//no_oats_spring_harrow,
69  fmc_Others,//no_oats_spring_sow,
70  fmc_Others,//no_oats_spring_roll,
71  fmc_Harvest,//no_oats_harvest,
72  fmc_Others//no_oats_haybailing,
73 
74  // no foobar entry
75 
76  };
77  // Iterate over the catlist elements and copy them to vector
78  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
79 
80  }

References fmc_Cultivation, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, NO_OATS_BASE, and no_oats_foobar.

Referenced by NorwegianOats().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
Farm::SpringRoll
virtual bool SpringRoll(LE *a_field, double a_user, int a_days)
Carry out a roll event in the spring on a_field.
Definition: FarmFuncs.cpp:487
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
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:421
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
no_oats_haybailing
Definition: NorwegianOats.h:42
Crop::m_ddegstoharvest
int m_ddegstoharvest
Definition: Farm.h:504
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
LE::GetPreviousTov
virtual TTypesOfVegetation GetPreviousTov(int)
Definition: Elements.h:195
NO_OATS_BASE
#define NO_OATS_BASE
Definition: NorwegianOats.h:31
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the spring on a_field.
Definition: FarmFuncs.cpp:501
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
no_oats_spring_sow
Definition: NorwegianOats.h:39
no_oats_autumn_plough
Definition: NorwegianOats.h:36
no_oats_foobar
Definition: NorwegianOats.h:43
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
NorwegianOats::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: NorwegianOats.h:58
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
no_oats_start
Definition: NorwegianOats.h:35
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
LE::GetRotIndex
int GetRotIndex(void)
Definition: Elements.h:373
NO_OATS_DID_AUTUMN_PLOUGH
#define NO_OATS_DID_AUTUMN_PLOUGH
Definition: NorwegianOats.h:32
FarmEvent::m_field
LE * m_field
Definition: Farm.h:391
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
no_oats_spring_plough
Definition: NorwegianOats.h:37
Crop::m_ManagementCategories
vector< FarmManagementCategory > m_ManagementCategories
Holds the translation between the farm operation enum for each crop and the farm management category ...
Definition: Farm.h:530
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
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:212
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
no_oats_spring_roll
Definition: NorwegianOats.h:40
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
no_oats_harvest
Definition: NorwegianOats.h:41
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
no_oats_spring_harrow
Definition: NorwegianOats.h:38
LE::GetVegDDegs
double GetVegDDegs()
Get the total of day degrees for the crop/veg on this element.
Definition: Elements.h:410
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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:459