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

#include <OrchardCrop.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ OrchardCrop()

OrchardCrop::OrchardCrop ( )
inline
52  {
53  m_first_date=g_date->DayInYear(1,7);
54  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

44 {
45  m_farm = a_farm;
46  m_field = a_field;
47  m_ev = a_ev;
48  bool done = false;
49  int d1;
50  int today = g_date->Date();
51  int noDates= 1;
52  int sprayday=cfg_pest_productapplic_startdate.value();
53 
54  switch ( m_ev->m_todo ) {
55  case orch_start:
56  // Set up the date management stuff
57  m_last_date=g_date->DayInYear(1,9);
58  // Start and stop dates for all events after harvest
59  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
60  // Determined by harvest date - used to see if at all possible
61  m_field->SetMDates(1,0,g_date->DayInYear(1,9));
62  // Check the next crop for early start, unless it is a spring crop
63  // in which case we ASSUME that no checking is necessary!!!!
64  // So DO NOT implement a crop that runs over the year boundary
65 
66  //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)
67  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
68 
69  if (m_ev->m_startday>g_date->DayInYear(1,7))
70  {
71  if (m_field->GetMDates(0,0) >=m_ev->m_startday){
72  g_msg->Warn( WARN_BUG, "OrchardCrop::Do(): Harvest too late for the next crop to start!!!", "" );
73  exit( 1 );
74  }
75  // Now fix any late finishing problems
76  for (int i=0; i<noDates; i++) {
77  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
78  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
79  }
80  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
81  m_field->SetMConstants(i,0);
82  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
83  }
84  }
85  }
86  // Now no operations can be timed after the start of the next crop.
87 
88  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
89  if (today > d1) {
90  // Yes too late - should not happen - raise an error
91  g_msg->Warn( WARN_BUG, " OrchardCrop::Do(): Crop start attempt after last possible start date", "" );
92  exit( 1 );
93  }
94  }//if
95  // Reinit d1 to first possible starting date.
96  d1 = g_date->OldDays()+m_first_date;;
97  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
98  if ( g_date->Date() > d1 ){
99  d1 = g_date->Date();
100  }
101  // OK, let's go.
102 
103  SimpleEvent( d1, orch_cut, false ); //call cutting orchard
104  SimpleEvent( d1, orch_insecticide1, false ); //call insecticide - so there are two threds
105  break;
106 
107 
108  case orch_cut:
109 
110  switch ( cfg_OrchardNoCutsDay.value() ) {
111  case 99:
112  if ( today == ( sprayday - 7 ) ) m_farm->CutOrch( m_field, 0.0, -1); //so cut no matter what. ok?
113  break;
114  case 4:
115  if ( ( today == 259 ) || ( today == 122 ) || ( today == 92 ) || ( today == 196 ) )
116  m_farm->CutOrch( m_field, 0.0, -1);
117  break;
118  case 3:
119  if ( ( today == 259 ) || ( today == 122 ) || ( today == 92 ) ) m_farm->CutOrch( m_field, 0.0, -1);
120  break;
121  case 2:
122  if ( ( today == 259 ) || ( today == 122 ) ) m_farm->CutOrch( m_field, 0.0, -1);
123  break;
124  case 1:
125  if ( ( today == 259 ) ) m_farm->CutOrch( m_field, 0.0, -1);
126  break;
127  default: // No cut
128  break;
129  }
130 
131  /* if (!m_farm->CutOrch( m_field, 0.0, g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
132  SimpleEvent( g_date->Date() + 1, psa_cut_to_hay, false );
133  break;
134  }*/
135  SimpleEvent( g_date->Date(), orch_do_nothing_start, false );
136  break;
137 
139  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ), orch_do_nothing_stop, false );
140  break;
141 
143  done = true;
144  break;
145 
146  case orch_insecticide1:
147  // This will prevent product usage outside the test period
150  if ( m_ev->m_lock || m_farm->DoIt( (int) (100*cfg_ins_app_prop1.value() ))) {
151  if (!m_farm->ProductApplication( m_field, 0.0, cfg_pest_productapplic_startdate.value() - g_date->DayInYear(), cfg_pest_product_1_amount.value(), ppp_1)) {
152  SimpleEvent( g_date->Date() + 1, orch_insecticide1, true );
153  break;
154  }
155  else {
156  if ((cfg_pest_productapplic_startdate.value()<366) && ( cfg_pest_productapplic_startdate.value() <-1))
157  SimpleEvent( g_date->OldDays() + cfg_pest_productapplic_startdate2.value(), orch_insecticide2, false );
158  break;
159  }
160  }
161  break;
162 
163  case orch_insecticide2:
164  if ( m_ev->m_lock || m_farm->DoIt( (int)( 50*cfg_ins_app_prop1.value() ))) {
165  if (!m_farm->ProductApplication( m_field, 0.0, cfg_pest_productapplic_startdate2.value() - g_date->DayInYear(), cfg_pest_product_1_amount.value(), ppp_1)) {
166  SimpleEvent( g_date->Date() + 1, orch_insecticide2, true );
167  break;
168  }
169  }
170  // End of thread
171 
172  ChooseNextCrop (1);
173 
174 
175  break;
176 
177 
178 
179  default:
180  g_msg->Warn( WARN_BUG, "OrchardCrop::Do(): Unknown event type! ", "" );
181  exit( 1 );
182  }
183 
184  return done;
185 }

References cfg_ins_app_prop1, cfg_OrchardNoCutsDay, cfg_pest_product_1_amount, cfg_pest_productapplic_startdate, cfg_pest_productapplic_startdate2, cfg_productapplicendyear, cfg_productapplicstartyear, Crop::ChooseNextCrop(), Farm::CutOrch(), Farm::DoIt(), g_landscape_p, Farm::GetType(), 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, orch_cut, orch_do_nothing_start, orch_do_nothing_stop, orch_insecticide1, orch_insecticide2, orch_start, ppp_1, Farm::ProductApplication(), Crop::SimpleEvent(), Landscape::SupplyYearNumber(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Farm::ProductApplication
virtual bool ProductApplication(LE *a_field, double a_user, int a_days, double a_applicationrate, PlantProtectionProducts a_ppp)
Apply test pesticide to a_field.
Definition: farmfuncs.cpp:1445
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
orch_insecticide2
Definition: OrchardCrop.h:41
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
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
orch_do_nothing_stop
Definition: OrchardCrop.h:39
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount
orch_cut
Definition: OrchardCrop.h:42
orch_insecticide1
Definition: OrchardCrop.h:40
Farm::CutOrch
virtual bool CutOrch(LE *a_field, double a_user, int a_days)
Cut vegetation on orchard crop. //based on cut to silage - values from cutting function of orchard.
Definition: farmfuncs.cpp:2362
Landscape::SupplyYearNumber
int SupplyYearNumber(void)
Definition: Landscape.h:1616
cfg_productapplicstartyear
CfgInt cfg_productapplicstartyear
orch_do_nothing_start
Definition: OrchardCrop.h:38
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
ppp_1
Definition: farm.h:422
Crop::m_last_date
int m_last_date
Definition: farm.h:542
cfg_productapplicendyear
CfgInt cfg_productapplicendyear
orch_start
Definition: OrchardCrop.h:37
cfg_OrchardNoCutsDay
CfgInt cfg_OrchardNoCutsDay
cfg_pest_productapplic_startdate2
CfgInt cfg_pest_productapplic_startdate2
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
g_landscape_p
Landscape * g_landscape_p
Definition: Landscape.cpp:258
cfg_pest_productapplic_startdate
CfgInt cfg_pest_productapplic_startdate