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

#include <PermanentSetAside.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 PermanentSetAside ()
 
- 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 42 of file PermanentSetAside.h.

Constructor & Destructor Documentation

◆ PermanentSetAside()

PermanentSetAside::PermanentSetAside ( )
inline

Definition at line 46 of file PermanentSetAside.h.

47  {
48  m_first_date=g_date->DayInYear(1,7);
49  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 32 of file PermanentSetAside.cpp.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37  bool done = false;
38  int d1;
39  int today=g_date->Date();
40  int noDates= 1;
41  switch ( m_ev->m_todo ) {
42  case psa_start:
43 
44  // Set up the date management stuff
45  m_last_date=g_date->DayInYear(1,9);
46  // Start and stop dates for all events after harvest
47  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
48  // Determined by harvest date - used to see if at all possible
49  m_field->SetMDates(1,0,g_date->DayInYear(1,9));
50  // Check the next crop for early start, unless it is a spring crop
51  // in which case we ASSUME that no checking is necessary!!!!
52  // So DO NOT implement a crop that runs over the year boundary
53 
54  //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)
55  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
56 
57  if (m_ev->m_startday>g_date->DayInYear(1,7))
58  {
59  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
60  {
61  g_msg->Warn( WARN_BUG, "PermanentSetAside::Do(): "
62  "Harvest too late for the next crop to start!!!", "" );
63  exit( 1 );
64  }
65  // Now fix any late finishing problems
66  for (int i=0; i<noDates; i++) {
67  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
68  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
69  }
70  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
71  m_field->SetMConstants(i,0);
72  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
73  }
74  }
75  }
76  // Now no operations can be timed after the start of the next crop.
77 
78  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
79  if (today > d1)
80  {
81  // Yes too late - should not happen - raise an error
82  g_msg->Warn( WARN_BUG, " PermanentSetAside::Do(): "
83  "Crop start attempt after last possible start date", "" );
84  exit( 1 );
85  }
86  }//if
87 
88  // Reinit d1 to first possible starting date.
89  d1 = g_date->OldDays()+m_first_date;;
90  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
91  if ( g_date->Date() > d1 )
92  {
93  d1 = g_date->Date();
94  }
95  // OK, let's go.
96  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
97 
98  // SimpleEvent( d1, psa_do_nothing_start, false );
99 
100  // ***CJT*** altered 16 August 2004 to be more similar to non-managed set-aside
101  // SimpleEvent( d1, sa_wait, false );
102  // break;
103 
104  SimpleEvent( d1, psa_cut_to_hay, false );
105  break;
106 
107  case psa_cut_to_hay:
108  if (!m_farm->CutToHay( m_field, 0.0,
109  g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
110  SimpleEvent( g_date->Date() + 1, psa_cut_to_hay, false );
111  break;
112  }
113 
114  ChooseNextCrop (1);
115 
116  SimpleEvent( g_date->Date(), psa_do_nothing_start, false );
117  break;
118 
120  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ),
121  psa_do_nothing_stop, false );
122  break;
123 
124  case psa_do_nothing_stop:
125  done = true;
126  break;
127 
128  default:
129  g_msg->Warn( WARN_BUG, "PermanentSetAside::Do(): "
130  "Unknown event type! ", "" );
131  exit( 1 );
132  }
133 
134  return done;
135 }

References Crop::ChooseNextCrop(), Farm::CutToHay(), 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_startday, FarmEvent::m_todo, psa_cut_to_hay, psa_do_nothing_start, psa_do_nothing_stop, psa_start, Crop::SimpleEvent(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
psa_do_nothing_stop
Definition: PermanentSetAside.h:36
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
Farm::CutToHay
virtual bool CutToHay(LE *a_field, double a_user, int a_days)
Carry out hay cutting on a_field.
Definition: farmfuncs.cpp:2269
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
psa_do_nothing_start
Definition: PermanentSetAside.h:35
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
Crop::m_last_date
int m_last_date
Definition: farm.h:542
psa_start
Definition: PermanentSetAside.h:34
psa_cut_to_hay
Definition: PermanentSetAside.h:37
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