Loading [MathJax]/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
NorwegianSpringBarley Class Reference

#include <NorwegianSpringBarley.h>

Inheritance diagram for NorwegianSpringBarley:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 NorwegianSpringBarley (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

◆ NorwegianSpringBarley()

NorwegianSpringBarley::NorwegianSpringBarley ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
52  : Crop(a_tov, a_toc, a_L)
53  {
56  }

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

Member Function Documentation

◆ Do()

bool NorwegianSpringBarley::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_sb_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  g_msg->Warn(WARN_BUG, "NorwegianSpringBarley::Do(): "
68  "Harvest too late for the next crop to start!!!", "");
69  exit(1);
70  }
71  // Now fix any late finishing problems
72  for (int i = 0; i < noDates; i++) {
73  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
74  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
75  }
76  if (m_field->GetMDates(1, i) >= m_ev->m_startday){
77  m_field->SetMConstants(i, 0);
78  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
79  }
80  }
81  }
82  // Now no operations can be timed after the start of the next crop.
83 
84  if (!m_ev->m_first_year)
85  {
86  int today = g_date->Date();
87  // Are we before July 1st?
88  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
89  if (today < d1)
90  {
91  // Yes, too early. We assumme this is because the last crop was late
92  g_msg->Warn(WARN_BUG, "NorwegianSpringBarley::Do(): " "Crop start attempt between 1st Jan & 1st July", "");
93  exit(1);
94  }
95  else
96  {
97  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
98  if (today > d1)
99  {
100  // Yes too late - should not happen - raise an error
101  g_msg->Warn(WARN_BUG, "NorwegianSpringBarley::Do(): " "Crop start attempt after last possible start date", "");
102  exit(1);
103  }
104  }
105  }
106  else
107  {
109  break;
110  }
111 
112 
113  // End single block date checking code. Please see next line
114  // comment as well.
115  // Reinit d1 to first possible starting date.
116  d1 = g_date->OldDays() + g_date->DayInYear(2, 11);
117  if (g_date->Date() > d1) {
118  d1 = g_date->Date();
119  }
120  // OK, let's go.
121  SimpleEvent(d1, no_sb_autumn_plough, false);
122  }
123  break;
124 
125  case no_sb_autumn_plough:
126  if (m_ev->m_lock || m_farm->DoIt(70)) // was 70
127  {
128  if (!m_farm->AutumnPlough(m_field, 0.0,
129  g_date->DayInYear(30, 11) - g_date->DayInYear())) {
131  break;
132  }
134  }
135  SimpleEvent(g_date->OldDays() + g_date->DayInYear(20, 3) + 365, no_sb_spring_plough, false);
136  break;
137 
138  case no_sb_spring_plough:
140  {
141  if (!m_farm->SpringPlough(m_field, 0.0,
142  g_date->DayInYear(10, 4) - // was 10,4
143  g_date->DayInYear())) {
145  break;
146  }
147  }
148  {
149  d1 = g_date->Date();
150  if (d1 < g_date->OldDays() + g_date->DayInYear(20, 3)) {
151  d1 = g_date->OldDays() + g_date->DayInYear(20, 3);
152  }
153  SimpleEvent(d1, no_sb_spring_harrow, false);
154  }
155  break;
156 
157  case no_sb_spring_harrow:
158  if (!m_farm->SpringHarrow(m_field, 0.0,
159  g_date->DayInYear(10, 4) - g_date->DayInYear())) { // WAS 10,4
161  break;
162  }
163  d1 = g_date->Date();
164  if (d1 < g_date->OldDays() + g_date->DayInYear(25, 3)) {
165  d1 = g_date->OldDays() + g_date->DayInYear(25, 3);
166  }
167  SimpleEvent(d1, no_sb_spring_sow, false);
168  break;
169 
170  case no_sb_spring_sow:
171  if (!m_farm->SpringSow(m_field, 0.0,
172  g_date->DayInYear(10, 4) - g_date->DayInYear())) { // WAS 10,4
173  SimpleEvent(g_date->Date() + 1, no_sb_spring_sow, true);
174  break;
175  }
176  {
177  d1 = g_date->Date();
178  if (d1 < g_date->OldDays() + g_date->DayInYear(5, 4)) {
179  d1 = g_date->OldDays() + g_date->DayInYear(5, 4);
180  }
181  SimpleEvent(d1, no_sb_spring_roll, false);
182  }
183  break;
184 
185  case no_sb_spring_roll:
186  if (m_ev->m_lock || m_farm->DoIt(0)) // was 30
187  {
188  if (!m_farm->SpringRoll(m_field, 0.0,
189  g_date->DayInYear(20, 4) - g_date->DayInYear())) {
190  SimpleEvent(g_date->Date() + 1, no_sb_spring_roll, true);
191  break;
192  }
193  }
194  ChooseNextCrop(2);
196  break;
197 
198 
199  case no_sb_harvest:
200  if (!m_farm->Harvest(m_field, 0.0, g_date->DayInYear(20, 8) - g_date->DayInYear())) {
201  SimpleEvent(g_date->Date() + 1, no_sb_harvest, true);
202  break;
203  }
205  break;
206 
207  case no_sb_haybailing:
208  if (m_field->GetMConstants(0) == 0) {
209  if (!m_farm->HayBailing(m_field, 0.0, -1)) { //raise an error
210  g_msg->Warn(WARN_BUG, "NOSpringBarley::Do(): failure in 'HayBailing' execution", "");
211  exit(1);
212  }
213  }
214  else {
215  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
216  SimpleEvent(g_date->Date() + 1, no_sb_haybailing, true);
217  break;
218  }
219  }
220  // END MAIN THREAD
221  done = true;
222  break;
223 
224  default:
225  g_msg->Warn(WARN_BUG, "NorwegianSpringBarley::Do(): "
226  "Unknown event type! ", "");
227  exit(1);
228  }
229  return done;
230 }

References Farm::AutumnPlough(), Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::Harvest(), Farm::HayBailing(), 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, no_sb_autumn_plough, NO_SB_DID_AUTUMN_PLOUGH, no_sb_harvest, no_sb_haybailing, no_sb_spring_harrow, no_sb_spring_plough, no_sb_spring_roll, no_sb_spring_sow, no_sb_start, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void NorwegianSpringBarley::SetUpFarmCategoryInformation ( )
inline
57  {
58  const int elements = 2 + (no_sb_foobar - NO_SBARLEY_BASE);
60 
61  FarmManagementCategory catlist[elements] =
62  {
63  fmc_Others, // zero element unused but must be here
64  fmc_Others,//no_sb_start = 1, // Compulsory, start event must always be 1 (one).
65  fmc_Cultivation,//no_sb_autumn_plough = NO_SBARLEY_BASE,
66  fmc_Cultivation,//no_sb_spring_plough,
67  fmc_Cultivation,//no_sb_spring_harrow,
68  fmc_Others,//no_sb_spring_sow,
69  fmc_Others,//no_sb_spring_roll,
70  fmc_Harvest,//no_sb_harvest,
71  fmc_Others//no_sb_haybailing,
72 
73  // no foobar entry
74 
75  };
76  // Iterate over the catlist elements and copy them to vector
77  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
78 
79  }

References fmc_Cultivation, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, no_sb_foobar, and NO_SBARLEY_BASE.

Referenced by NorwegianSpringBarley().


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
NorwegianSpringBarley::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: NorwegianSpringBarley.h:57
LE::GetMConstants
int GetMConstants(int a)
Definition: Elements.h:407
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
no_sb_spring_plough
Definition: NorwegianSpringBarley.h:37
no_sb_harvest
Definition: NorwegianSpringBarley.h:41
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
no_sb_start
Definition: NorwegianSpringBarley.h:35
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
no_sb_spring_sow
Definition: NorwegianSpringBarley.h:39
NO_SBARLEY_BASE
#define NO_SBARLEY_BASE
Definition: NorwegianSpringBarley.h:31
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_sb_haybailing
Definition: NorwegianSpringBarley.h:42
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
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
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
no_sb_foobar
Definition: NorwegianSpringBarley.h:43
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
no_sb_spring_harrow
Definition: NorwegianSpringBarley.h:38
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
no_sb_spring_roll
Definition: NorwegianSpringBarley.h:40
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
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
no_sb_autumn_plough
Definition: NorwegianSpringBarley.h:36
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
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
NO_SB_DID_AUTUMN_PLOUGH
#define NO_SB_DID_AUTUMN_PLOUGH
Definition: NorwegianSpringBarley.h:32
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