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

#include <YoungForest.h>

Public Member Functions

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

Constructor & Destructor Documentation

◆ YoungForestCrop()

YoungForestCrop::YoungForestCrop ( )
inline

Definition at line 54 of file YoungForest.h.

55  {
56  m_first_date=g_date->DayInYear(1,4);
57  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 32 of file YoungForest.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 
40  switch ( m_ev->m_todo ) {
41  case yf_start:
42  {
43  // Set up the date management stuff
44  m_last_date=g_date->DayInYear(1,9);
45  // Start and stop dates for all events after harvest
46  int noDates= 1;
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!!!!F
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, "YoungForestCrop::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  int today=g_date->Date();
79  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
80  if (today > d1)
81  {
82  // Yes too late - should not happen - raise an error
83  g_msg->Warn( WARN_BUG, " YoungForestCrop::Do(): "
84  "Crop start attempt after last possible start date", "" );
85  exit( 1 );
86  }
87  }//if
88 
89  // Reinit d1 to first possible starting date.
90  d1 = g_date->OldDays()+m_first_date;;
91  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
92  if ( g_date->Date() > d1 )
93  {
94  d1 = g_date->Date();
95  }
96  // OK, let's go.
97  SimpleEvent( d1, yf_do_nothing_start, false );
98  }
99  break;
100 
101  case yf_do_nothing_start:
102  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ),
103  yf_do_nothing_stop, false );
104  break;
105 
106  case yf_do_nothing_stop:
107 
108  ChooseNextCrop (1);
109 
110  done = true;
111  break;
112 
113  default:
114  g_msg->Warn( WARN_BUG, "YoungForestCrop::Do(): "
115  "Unknown event type! ", "" );
116  exit( 1 );
117  }
118 
119  return done;
120 }

References Crop::ChooseNextCrop(), 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, Crop::SimpleEvent(), tof_OptimisingFarm, yf_do_nothing_start, yf_do_nothing_stop, and yf_start.


The documentation for this class was generated from the following files:
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
yf_do_nothing_stop
Definition: YoungForest.h:45
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
yf_start
Definition: YoungForest.h:43
yf_do_nothing_start
Definition: YoungForest.h:44
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
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