ALMaSS Partridge ODdox  1.1
The partridge model description following ODdox protocol
pesticide.cpp
Go to the documentation of this file.
1 //
2 // pesticide.cpp
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2003, Christopher John Topping, EcoSol
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 #define _CRT_SECURE_NO_DEPRECATE
29 //#define __WithinOrchardPesticideSim__
30 
31 #include <iostream> // std::cout
32 #include <algorithm> // std::fill
33 #include <vector> // std::vector
34 #include <cstdio> // Only needed for debugging purposes.
35 #include <math.h>
36 #include <fstream>
37 #include "ls.h"
38 
39 using namespace std;
40 
42 CfgBool l_pest_enable_pesticide_engine("PEST_ENABLE_PESTICIDE_ENGINE", CFG_CUSTOM, false);
44 CfgInt l_pest_NoPPPs("PEST_NO_OF_PPPS", CFG_CUSTOM, 1,1,10);
45 static CfgFloat l_pest_ai_half_life("PEST_AI_HALF_LIFE", CFG_CUSTOM, 10.0);
46 static CfgFloat l_pest_ai_half_life_Soil("PEST_AI_HALF_LIFE_SOIL", CFG_CUSTOM, 10.0);
47 static CfgFloat l_pest_ai_half_life_Veg("PEST_AI_HALF_LIFE_VEG", CFG_CUSTOM, 10.0);
48 static CfgFloat l_pest_diffusion_slope("PEST_DRIFT_SLOPE", CFG_CUSTOM, -0.6122);
49 static CfgInt l_pest_diffusion_grid_count("PEST_DIFFUSION_GRID_COUNT",CFG_CUSTOM, 1 );
50 static CfgFloat l_pest_zero_threshold("PEST_ZERO_THRESHOLD",CFG_CUSTOM, 0.00001 );
51 
52 CfgFloat cfg_pest_product_1_amount("PEST_PRODUCT_ONE_AMOUNT", CFG_CUSTOM, 1.0);
53 CfgFloat cfg_pest_product_2_amount("PEST_PRODUCT_TWO_AMOUNT", CFG_CUSTOM, 1.0);
54 CfgFloat cfg_pest_product_3_amount("PEST_PRODUCT_THREE_AMOUNT", CFG_CUSTOM, 1.0);
55 CfgFloat cfg_pest_product_4_amount("PEST_PRODUCT_FOUR_AMOUNT", CFG_CUSTOM, 1.0);
56 CfgFloat cfg_pest_product_5_amount("PEST_PRODUCT_FIVE_AMOUNT", CFG_CUSTOM, 1.0);
57 CfgFloat cfg_pest_product_6_amount("PEST_PRODUCT_SIX_AMOUNT", CFG_CUSTOM, 1.0);
58 CfgFloat cfg_pest_product_7_amount("PEST_PRODUCT_SEVEN_AMOUNT", CFG_CUSTOM, 1.0);
59 CfgFloat cfg_pest_product_8_amount("PEST_PRODUCT_EIGHT_AMOUNT", CFG_CUSTOM, 1.0);
60 CfgFloat cfg_pest_product_9_amount("PEST_PRODUCT_NINE_AMOUNT", CFG_CUSTOM, 1.0);
61 CfgFloat cfg_pest_product_10_amount("PEST_PRODUCT_TEN_AMOUNT", CFG_CUSTOM, 1.0);
62 
63 CfgBool l_pest_use_application_rate("PEST_USE_APPLICATIONRATE", CFG_CUSTOM, false);
64 CfgFloat l_pest_daily_mort( "PEST_DAILY_MORTALITY", CFG_CUSTOM, 0.25 );
65 CfgFloat l_pest_daily_mort2( "PEST_DAILY_MORTALITY_TWO", CFG_CUSTOM, 0.25 );
68 CfgFloat l_pest_trigger_threshold1( "PEST_TRIGGER_THRESHOLD_ONE", CFG_CUSTOM, 1.0 );
69 CfgFloat l_pest_trigger_threshold2( "PEST_TRIGGER_THRESHOLD_TWO", CFG_CUSTOM, 1.0 );
70 
71 CfgInt cfg_pest_productapplic_startdate("PEST_PRODUCTAPPLIC_STARTDATE", CFG_CUSTOM, -1);
72 CfgInt cfg_pest_productapplic_startdate2("PEST_PRODUCTAPPLIC_STARTDATE_TWO",CFG_CUSTOM,-1);
73 CfgInt cfg_pest_productapplic_startdate3("PEST_PRODUCTAPPLIC_STARTDATE_THREE",CFG_CUSTOM,-1);
74 CfgInt cfg_pest_productapplic_period("PEST_PRODUCTAPPLIC_PERIOD",CFG_CUSTOM,1);
75 
76 CfgBool cfg_pest_residue_or_rate("PEST_RESIDUE_OR_RATE",CFG_CUSTOM,true);
77 
78 CfgBool cfg_pest_springbarley_on("PEST_SPRINGBARLEY_ON", CFG_CUSTOM, false);
79 CfgBool cfg_pest_springwheat_on("PEST_SPRINGWHEAT_ON", CFG_CUSTOM, false);
80 CfgBool cfg_pest_winterwheat_on("PEST_WINTERWHEAT_ON", CFG_CUSTOM, false);
81 CfgBool cfg_pest_winterbarley_on("PEST_WINTERBARLEY_ON", CFG_CUSTOM, false);
82 CfgBool cfg_pest_wintertriticale_on("PEST_WINTERTRITICALE_ON", CFG_CUSTOM, false);
83 CfgBool cfg_pest_winterrye_on("PEST_WINTERRYE_ON", CFG_CUSTOM, false);
84 CfgBool cfg_pest_winterrape_on("PEST_WINTERRAPE_ON", CFG_CUSTOM, false);
85 CfgBool cfg_pest_potatoes_on("PEST_POTATOES_ON", CFG_CUSTOM, false);
86 CfgBool cfg_pest_beet_on("PEST_BEET_ON", CFG_CUSTOM, false);
87 CfgBool cfg_pest_cabbage_on("PEST_CABBAGE_ON", CFG_CUSTOM, false);
88 CfgBool cfg_pest_carrots_on("PEST_CARROTS_ON", CFG_CUSTOM, false);
89 CfgBool cfg_pest_tulips_on("PEST_TULIPS_ON", CFG_CUSTOM, false);
90 CfgBool cfg_pest_SBS_ERA("PEST_SBS_ERA", CFG_CUSTOM, false);
91 
93 extern Landscape *g_land;
94 
95 
96 
97 void Pesticide::Tick(void)
98 {
100  {
101  return;
102  }
103  // Calculate DT50 rates
104  // DT50 will change by the rate of 0.22 extra per degree different from 20
105  double temp = g_weather->GetTemp();
106  double Dt50 = l_pest_ai_half_life.value()* exp(0.094779*(20 - temp));
107 
108  m_pest_daily_decay_frac = pow(10.0, log10(0.5) / Dt50);
109  // Get todays rainfall
110  m_rainfallcategory = (unsigned)floor(g_land->SupplyRain() * 100 + 0.5);
111  if (m_rainfallcategory >= 100) m_rainfallcategory = 99;
112  // Now make it an index to the 100x100 array.
113  m_rainfallcategory *= 100;
115  {
116  for (int ppp = ppp_1; ppp < m_NoPPPs; ppp++)
117  {
119  }
120  return;
121  }
122  for (int ppp = ppp_1; ppp < m_NoPPPs; ppp++)
123  {
127  }
128 }
129 //-----------------------------------------------------------------------------------------------------------------------------
130 
132 {
136  if (! m_daily_spray_queue[a_ppp].empty()) m_daily_spray_queue[a_ppp].resize( 0 );
137 }
138 //-----------------------------------------------------------------------------------------------------------------------------
139 
140 void Pesticide::DailyQueueAdd( LE* a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp )
141 {
142  PesticideEvent *l_event = new PesticideEvent( a_element_sprayed, a_amount, a_ppp );
143  m_daily_spray_queue[a_ppp].push_back(l_event);
144 }
145 //-----------------------------------------------------------------------------------------------------------------------------
146 
148 {
155  if (0 == m_daily_spray_queue[a_ppp].size())
156  // Event queue empty, nobody sprayed anything today.
157  return;
158 
159  // Spraying at least one field. Force the main pesticide map
160  // decay method to run tomorrow.
161  m_something_to_decay[a_ppp] = true;
162 
163  for ( unsigned int i=0; i<m_daily_spray_queue[a_ppp].size(); i++ )
164  {
166  int minx=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMinX();
167  int maxx=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMaxX();
168  int miny=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMinY();
169  int maxy=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMaxY();
170  // For cover we use the crop, and save this for later
171  double cover = m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetVegCover();
172  TwinMapClear(minx, miny, maxx, maxy);
173  // Add the amount in m_amount to the twin map (all squares covered with the polygon get m_amount added.
174  TwinMapSpray( m_daily_spray_queue[a_ppp][i]->m_sprayed_elem, m_daily_spray_queue[a_ppp][i]->m_amount, minx, miny, maxx, maxy);
175  // This adds it to the main map and if necessary sorts out the allocation between veg and soil.
176  TwinMapDiffusion(minx, miny, maxx, maxy, cover, a_ppp);
177  }
178 }
179 //-----------------------------------------------------------------------------------------------------------------------------
180 
181 void Pesticide::TwinMapClear( int a_minx, int a_miny, int a_maxx, int a_maxy )
182 {
183  for ( int y=a_miny; y<=a_maxy; y++ )
184  {
185  int t = y * m_pest_map_width;
186  for ( int x=a_minx; x<=a_maxx; x++ )
187  {
188  m_pest_map_twin[t + x] = 0.0;
189  }
190  }
191 }
192 //-----------------------------------------------------------------------------------------------------------------------------
193 
194 void Pesticide::TwinMapSpray( LE* a_element_sprayed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy )
195 {
205  /* Replaced with more detailed fate code for EFSA June 2014
206  if (l_pest_use_application_rate.value()) {
207  // We are applying a field rate. The actual residue needs to be calculated here
208  double biomass = a_element_sprayed->GetVegBiomass();
209  double cover = a_element_sprayed->GetVegCover();
210  // rate is in mg/m and needs to be converted to mg/kg
211  double residue = (a_amount/(biomass*0.001)) * 0.435855; // g to kg veg // 0.435855 is a specific calculation to obtain the same residue that Joe Crocker used for the scale of use study
212  a_amount = residue * cover;
213  }
214  */
215  double l_fractional_amount = a_amount * m_prop; // m_prop is a constant related to the grid area (i.e. how many squares are in one grid square).
216  int l_large_map_index = a_element_sprayed->GetMapIndex();
217  for ( int y=a_miny; y<=a_maxy; y++ ) {
218  for ( int x=a_minx; x<=a_maxx; x++ ) {
219  if ( m_land->Get( x, y ) == l_large_map_index )
220  {
221  // This adds the l_fractional_amount to the twin map
222  TwinMapSprayPixel( x, y, l_fractional_amount );
223  }
224  }
225  }
227 }
228 //-----------------------------------------------------------------------------------------------------------------------------
229 
231 {
232  if ( m_x_excess ) {
233  for ( unsigned int i=0; i<m_pest_map_width-1; i++ ) {
235  }
236  }
237 
238  if ( m_y_excess ) {
239  unsigned int l_additive = (m_pest_map_height-1)*m_pest_map_width;
240  for ( unsigned int i=0; i<m_pest_map_height-1; i++ ) {
241  m_pest_map_twin[ i + l_additive ] *= m_corr_y;
242  }
243  }
244 
245  if ( m_x_excess && m_y_excess ) {
246  m_pest_map_twin[ m_pest_map_size-1 ] *= (((double)(PEST_GRIDAREA)) / ((double)(m_x_excess*m_y_excess)));
247  }
248 }
249 //-----------------------------------------------------------------------------------------------------------------------------
250 
251 /*
252 void Pesticide::TwinMapCopyToMask( int a_minx, int a_miny, int a_maxx, int a_maxy )
253 {
254  // Copy the newly calculated pesticide amounts over to the mask map
255  for ( int y=a_miny; y<=a_maxy; y++ )
256  {
257  int t = y * m_pest_map_width;
258  for ( int x=a_minx; x<=a_maxx; x++ )
259  {
260  m_pest_map_mask[t + x] = m_pest_map_twin[t + x];
261  }
262  }
263 }
264 */
265 //-----------------------------------------------------------------------------------------------------------------------------
266 
267 /*
268 void Pesticide::TwinMapAddToMain( void )
269 {
270  for ( unsigned int i=0; i<m_pest_map_size; i++ ) {
271  m_pest_map_main[i] += m_pest_map_twin[i];
272  }
273 }
274 //-----------------------------------------------------------------------------------------------------------------------------
275 */
276 void Pesticide::TwinMapDiffusion( int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp )
277 {
278  for ( int y=a_miny; y<a_maxy; y++ )
279  {
280  int t = y*m_pest_map_width;
281  for ( int x=a_minx; x<a_maxx; x++ )
282  {
283  if ( m_pest_map_twin[ t + x ] > 0.0 )
284  {
285  double l_amount = m_pest_map_twin[ t + x ];
286  for ( unsigned int i=0; i<m_diffusion_mask[m_wind].size(); i++ )
287  {
288  // This adds the pesticide to the main map - simply adds the calculated amount.
290  m_pest_map_height,m_diffusion_mask[m_wind][i]->GetFraction() *l_amount, a_cover, a_ppp);
291  }
292  }
293  }
294  }
295 }
296 //-----------------------------------------------------------------------------------------------------------------------------
297 
298 #ifdef __DETAILED_PESTICIDE_FATE
299 inline void Pesticide::DiffusionSprayPixel(int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double a_cover, PlantProtectionProducts a_ppp)
300 #else
301 inline void Pesticide::DiffusionSprayPixel(int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double /* a_cover */, PlantProtectionProducts a_ppp)
302 #endif
303 {
311  // First we have to do the typical out of bounds checks - if these fail do nothing, the pesticide fell off the world
312  if (a_x < 0 || a_x >= a_limit_x || a_y < 0 || a_y >= a_limit_y) return;
313  // Now calculate the coordinate entry in the array and store this as l_coord
314  int l_coord = a_y * a_limit_x + a_x;
315 #ifdef __DETAILED_PESTICIDE_FATE
316  // Here we need to calculate the partition of pesticide into two compartments.
317  m_pest_map_vegcanopy[a_ppp][l_coord] += a_amount * a_cover;
318  m_pest_map_soil[a_ppp][l_coord] += a_amount - m_pest_map_vegcanopy[a_ppp][l_coord];
319 #else
320  m_pest_map_main[a_ppp][l_coord] += a_amount;
321 #endif
322 }
323 //-----------------------------------------------------------------------------------------------------------------------------
324 
326 {
334  int l_grid = l_pest_diffusion_grid_count.value();
335  const int l_side_length = l_grid * 2 + 1;
336  double* l_diff;
337  l_diff = new double[l_side_length];
338  int cells = 1;
339  double sum = 1.0;
340  l_diff[0] = 1.0;
341  for (int l=1; l<l_side_length; l++)
342  {
343  l_diff[l] = DiffusionFunction(l);
344  sum += l_diff[l];
345  }
346  for (int l=0; l<l_side_length; l++)
347  {
348  l_diff[l] /= sum;
349  l_diff[l] /= cells;
350  cells += 2; // 2 more cells per row away from centre square
351  }
352  // Calculated for 4 wind directions
353  for (int wind=0; wind < 4; wind ++)
354  {
355  m_diffusion_mask[wind].resize( l_side_length * l_side_length );
356  for ( int x = 0; x< l_side_length; x++ )
357  {
358  for ( int y= 0; y< l_side_length; y++ )
359  {
360  m_diffusion_mask[wind][x + y * l_side_length] = new Diffusor( x, y, 0); // first zero all values
361  }
362  }
363  }
364  int strtx = l_grid;
365  int strty = l_grid;
366  int fin = 1;
367  // North
368  for (int step = 0; step <= l_grid; step++)
369  {
370  for (int cc=0; cc<fin; cc++)
371  {
372  m_diffusion_mask[0][ strtx + (cc-step) + ((strty-step)*l_side_length)]->SetFraction(l_diff[step]);
373  }
374  fin += 2;
375  }
376  // South
377  fin = 1;
378  for (int step = 0; step <= l_grid; step++)
379  {
380  for (int cc=0; cc<fin; cc++)
381  {
382  m_diffusion_mask[2][ strtx + (cc-step) + ((strty+step)*l_side_length)]->SetFraction(l_diff[step]);
383  }
384  fin += 2;
385  }
386  // East
387  fin = 1;
388  for (int step = 0; step <= l_grid; step++)
389  {
390  for (int cc=0; cc<fin; cc++)
391  {
392  m_diffusion_mask[3][ (strtx + step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
393  }
394  fin += 2;
395  }
396  // West
397  fin = 1;
398  for (int step = 0; step <= l_grid; step++)
399  {
400  for (int cc=0; cc<fin; cc++)
401  {
402  m_diffusion_mask[1][ (strtx - step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
403  }
404  fin += 2;
405  }
406 
407  delete[] l_diff;
408 }
409 //-----------------------------------------------------------------------------------------------------------------------------
410 
411 
412 
413 /*
414 void Pesticide::DiffusionMaskInit( void )
415 {
416  int l_grid = l_pest_diffusion_grid_count.value();
417  int l_side_length = l_grid * 2 + 1;
418 
419  m_diffusion_mask.resize( l_side_length * l_side_length );
420 
421  unsigned int i = 0;
422  //double l_diff_zero = DiffusionFunction( 0.0 );
423  double l_diff_sum = 0.0;
424  for ( int x = -l_grid; x < l_grid + 1; x++ ) {
425  for ( int y = -l_grid; y < l_grid + 1; y++ ) {
426  double l_dist = sqrt( (double) x*x + y*y ); // ***CJT*** added 28/8/2009
427  // m_diffusion_mask has the square to drift spray to with the proportions relative to the amount received in the centre square
428  // but the total may be greater than one, so we need the adjustment provided by the second loop
429  double l_diff = DiffusionFunction(l_dist);
430  l_diff_sum += l_diff;
431  m_diffusion_mask[i] = new Diffusor( x, y, l_diff); // ***CJT*** changed 28/8/2009 l_diff_zero
432  i++;
433  }
434  }
435  for ( unsigned x = 0; x < i; x++) {
436  m_diffusion_mask[x]->m_fraction /= l_diff_sum;
437  }
438 }
439 
440 */
441 
442 double Pesticide::DiffusionFunction( double a_dist_meters )
443 {
444  double pp;
449 // y=(2.753767)*(x+(1.86976))**(-2.121563)
450 #ifdef __WithinOrchardPesticideSim__
451  if (a_dist_meters==0) pp=0.7784;
452  else pp=0.0277;
453 #else
454  //pp = (2.7705 * pow(a_dist_meters, -0.9787)) * 0.01; // german drif equation (reference)
455  pp = (2.7705 * pow(a_dist_meters, -1.7)) * 0.01; // german drif equation - reduction of drift by 50%
456  //pp = (2.7705 * pow(a_dist_meters, -2.5)) * 0.01; // german drif equation - reduction of drift by 75%
457  //pp = (2.7705 * pow(a_dist_meters, -3.5)) * 0.01; // german drif equation - reduction of drift by 90%
458 
459  //pp=2.753767 * pow(( a_dist_meters+1.86976 ), -2.121563); // based on drift data from the spray drift calculator within FOCUS's surface water scenarios SWASH software (FOCUS, 2001)
460  //pp= exp( l_pest_diffusion_slope.value() * a_dist_meters );
461  pp=pow(( a_dist_meters+1 ), l_pest_diffusion_slope.value() );
462  //pp = (2.7593 * pow(a_dist_meters,-0.9778)) * 0.001;
463  if (pp<(l_pest_zero_threshold.value()/10)) pp=0; // Don't bother with the little ones
464 #endif
465  return pp;
466 }
467 //-----------------------------------------------------------------------------------------------------------------------------
468 
470 {
471  if ( ! m_something_to_decay[a_ppp] ) return;
476  double l_zero = l_pest_zero_threshold.value();
477  m_something_to_decay[a_ppp] = false;
478  for ( unsigned int i=0; i<m_pest_map_size; i++ )
479  {
480 #ifdef __DETAILED_PESTICIDE_FATE
481  if ((m_pest_map_vegcanopy[a_ppp][i] > l_zero) )
482  {
483  //Calculate wash-off m_pest_map_width * m_pest_map_height y * m_pest_map_width + x
484  int x = ( i % m_pest_map_width ) << PEST_GRIDSIZE_POW2;
485  int y = ( i / m_pest_map_width ) << PEST_GRIDSIZE_POW2;
486  double cover = g_landscape_p->SupplyVegCover(x,y);
487  unsigned cov = 100 * cover; // Cover is steps of zero to 99, may need to check for bounds here (may get cover of 1.0 ?)
488  double Rwp = m_pest_map_vegcanopy[a_ppp][i] *= m_RainWashoffFactor[m_rainfallcategory+cov]; // m_RainWashoffFactor is the index to the array
489  m_pest_map_soil[a_ppp][i] = (m_pest_map_soil[a_ppp][i] + Rwp) * m_pest_daily_decay_frac_Soil;
490  m_pest_map_vegcanopy[a_ppp][i] -= Rwp;
491  m_pest_map_vegcanopy[a_ppp][i] *= m_pest_daily_decay_frac_Veg;
492  m_something_to_decay[a_ppp] = true;
493  }
494  else
495  {
496  if (m_pest_map_soil[a_ppp][i] > l_zero)
497  {
498  m_pest_map_soil[a_ppp][i] = m_pest_map_soil[a_ppp][i] * m_pest_daily_decay_frac_Soil;
499  m_something_to_decay[a_ppp] = true;
500  }
501  else
502  {
503  m_pest_map_vegcanopy[a_ppp][i] = 0.0;
504  m_pest_map_soil[a_ppp][i] = 0.0;
505  }
506  }
507 #else
508  if (m_pest_map_main[a_ppp][i] > l_zero)
509  {
515  m_something_to_decay[a_ppp] = true;
516  }
517  else
518  {
519  m_pest_map_main[a_ppp][i] = 0.0;
520  }
521 #endif
522  }
523 }
524 //-----------------------------------------------------------------------------------------------------------------------------
525 
527 {
529  {
532  m_map = a_map;
533  m_land = a_land;
534  for (int i=0; i< m_NoPPPs; i++) m_something_to_decay[i] = false;
536 
537  // Figure out critical border coordinates,
538  // proportional fractions etc.
539  m_prop = 1.0 / ((double)(PEST_GRIDAREA));
541  if ( m_x_excess ) {
542  m_corr_x = (double)PEST_GRIDSIZE /(double)m_x_excess;
543  }
545  if ( m_y_excess ) {
546  m_corr_y = (double)PEST_GRIDSIZE / (double)m_y_excess;
547  }
548 
549  m_pest_map_width = m_land->MapWidth() >> PEST_GRIDSIZE_POW2; // landscape width divided by the sqrt(cellsize) e.g. cellsize 4 and landscape width = 10000, result is 10000/(sqrt(4) = 5000
550  if ( m_land->MapWidth() & (PEST_GRIDSIZE-1))
552 
554  if ( m_land->MapHeight() & (PEST_GRIDSIZE-1))
556 
558 
559  m_pest_map_twin = new double[m_pest_map_size];
560 #ifdef __DETAILED_PESTICIDE_FATE
561  m_pest_map_vegcanopy.resize(m_NoPPPs);
562  m_pest_map_soil.resize(m_NoPPPs);
563 #else
564  m_pest_map_main.resize(m_NoPPPs);
565 #endif
566  for (int p = 0; p < m_NoPPPs; p++) {
567 #ifdef __DETAILED_PESTICIDE_FATE
568  m_pest_map_vegcanopy[p].resize(m_pest_map_size);
569  m_pest_map_soil[p].resize(m_pest_map_size);
570  fill(m_pest_map_vegcanopy[p].begin(), m_pest_map_vegcanopy[p].end(), 0.0);
571  fill(m_pest_map_soil[p].begin(), m_pest_map_soil[p].end(), 0.0);
572 #else
573  m_pest_map_main[p].resize(m_pest_map_size);
574  fill(m_pest_map_main[p].begin(), m_pest_map_main[p].end(), 0.0);
575 
576 #endif
577  m_daily_spray_queue[p].resize(0);
578  }
579 
580  for (unsigned int i = 0; i < m_pest_map_size; i++) m_pest_map_twin[i] = 0.0;
581 
582  m_pest_daily_decay_frac = pow(10.0, log10(0.5) / l_pest_ai_half_life.value());
584 #ifdef __BORLANDC__
586 #else
588 #endif
589 
590  m_pest_daily_decay_frac_Soil = pow(10.0, log10(0.5) / l_pest_ai_half_life_Soil.value());
591  // This calculates
595  }
596 }
597 //-----------------------------------------------------------------------------------------------------------------------------
598 
600 {
604  double rainsteps = 0.1; // mm, multiply rainfall by 100 to get this, save result as integer
605  double coversteps = 1.0; // %, multiply cover by 100 to get this, save result as integer
606  for (int i = 0; i < 100; i++)
607  {
608  double SC = i * coversteps;
609  double LAI = log(0 - (1 - SC))*1.666666667; // This is the inverse of Beer's Law
610  for (int r = 0; r < 100; r++)
611  {
612  double P = r * rainsteps;
613  double Pi = LAI*(1 - (1 / ((1 + SC * P) / LAI)));
614  double Rw = 0.25*(SC * P - Pi); // Rw is a proportion of canopy pesticide washed off.
615  m_RainWashoffFactor[r * 100 + i] = Rw;
616  }
617  }
618 }
619 //-----------------------------------------------------------------------------------------------------------------------------
620 
622 {
624  {
625  for (int winddir = 0; winddir < 4; winddir++)
626  {
627  for (unsigned int i = 0; i < m_diffusion_mask[winddir].size(); i++)
628  {
629  delete m_diffusion_mask[winddir][i];
630  }
631  m_diffusion_mask[winddir].resize(0);
632  }
633  delete m_pest_map_twin;
634  }
635 }
636 //-----------------------------------------------------------------------------------------------------------------------------
637 
638 #ifdef PEST_DEBUG
639 
641 {
642  int l_grid = l_pest_diffusion_grid_count.value();
643  const int l_side_length = l_grid * 2 + 1;
644 
645  // Need a debug test, output all diffusion masks to file
646  ofstream ofile("diffusionmask.txt",ios::out);
647  for (int i=0; i<4; i++)
648  {
649  for ( int x = 0; x< l_side_length; x++ )
650  {
651  for ( int y= 0; y< l_side_length; y++ )
652  {
653  ofile << m_diffusion_mask[i][x+(y*l_side_length)]->GetFraction() << '\t';
654  }
655  ofile << endl;
656  }
657  ofile << endl;
658  ofile << endl;
659  }
660  ofile.close();
661  }
662 //-----------------------------------------------------------------------------------------------------------------------------
663 
664 // For file saving and loading.
665 #define CFG_CHANNEL_BITS 8
666 #define CFG_CHANNEL_MAXVAL (2^CFG_CHANNEL_BITS-1)
667 
668 #define SV_UINT32 unsigned int
669 #define SV_INT32 int
670 #define SV_UINT8 unsigned char
671 #define SV_INT8 char
672 
673 bool Pesticide::SavePPM( double *a_map,
674  int a_beginx, int a_width,
675  int a_beginy, int a_height,
676  char* a_filename )
677 {
678  a_beginx = 0;
679  a_width = m_pest_map_width;
680  a_beginy = 0;
681  a_height = m_pest_map_height;
682 
683  SV_UINT32 linesize = a_width*3;
684  SV_UINT8* linebuffer = (SV_UINT8*)malloc(sizeof(SV_UINT8)* linesize);
685 
686  if ( linebuffer == NULL ) {
688  "Pesticide::SavePPM(): Out of memory!", "" );
689  exit(1);
690  }
691 
692  FILE* l_file;
693  l_file=fopen(a_filename, "w" );
694  if ( !l_file ) {
695  printf("PesticideTest::SavePPM(): "
696  "Unable to open file for writing: %s\n",
697  a_filename );
698  exit(1);
699  }
700 
701  fprintf( l_file, "P6\n%d %d %d\n",
702  a_width,
703  a_height,
704  255 );
705 
706  for ( int line=a_beginy; line< a_beginy + a_height; line++ ) {
707  int i = 0;
708  for ( int column=a_beginx; column < a_beginx + a_width; column++ ) {
709  int localcolor = (int)( a_map[ line * m_pest_map_width + column ]
710  * 255.0);
711  if ( localcolor <= 255 ) {
712  linebuffer [ i++ ] = char (localcolor & 0xff);
713  linebuffer [ i++ ] = 0;
714  linebuffer [ i++ ] = 0;
715  } else {
716  linebuffer [ i++ ] = 255;
717  localcolor -= 255;
718  if ( localcolor <= 255 ) {
719  linebuffer [ i++ ] = char (localcolor);
720  linebuffer [ i++ ] = 0;
721  } else {
722  linebuffer [ i++ ] = 255;
723  localcolor -= 255;
724  if ( localcolor <= 255 ) {
725  linebuffer [ i++ ] = char (localcolor);
726  } else {
727  linebuffer [ i++ ] = 255;
728  }
729  }
730  }
731  }
732  fwrite( linebuffer, sizeof(SV_UINT8), linesize, l_file );
733  }
734 
735  fclose( l_file );
736  free( linebuffer );
737  return true;
738 }
739 //-----------------------------------------------------------------------------------------------------------------------------
740 
741 /*
742 void Pesticide::Test( Landscape *a_map )
743 {
744  for ( int i=0; i<730; i++) {
745 
746  if ( random(100) < 10 ) {
747  int l_sprays = random(5)+1;
748  for ( int j=0; j<l_sprays; j++ ) {
749  int l_x = random(1500);
750  int l_y = random(1500);
751  DailyQueueAdd( a_map->
752  SupplyLEPointer( a_map->SupplyPolyRef( l_x, l_y )),
753  1.0 );
754  }
755  char l_filename[20];
756  sprintf( l_filename, "ppms/p%04d.ppm", i );
757  SavePPM( m_pest_map_main,
758  0, 0, 0, 0,
759  l_filename );
760  }
761 
762  Tick();
763  }
764 }
765 //-----------------------------------------------------------------------------------------------------------------------------
766 */
767 #endif // PEST_DEBUG
768 
769 PesticideMap::PesticideMap(int a_startyear, int a_noyears, int a_cellsize, Landscape * a_landscape, RasterMap* a_land, bool a_typeofmap)
770 {
771  m_typeofmap = a_typeofmap;
772  m_startyear = a_startyear;
773  m_endyear = a_startyear + a_noyears;
774  m_cellsize = a_cellsize;
775  m_OurLandscape = a_landscape;
776  m_Rastermap = a_land;
777  m_pmap_width = m_OurLandscape->SupplySimAreaWidth() / m_cellsize;
778  m_pmap_height = m_OurLandscape->SupplySimAreaHeight() / m_cellsize; ;
779 
780  // Need to create the grid to fill. This grid is always used.
781  m_pmap_insecticides = new vector<double>;
782  m_pmap_insecticides->resize(m_pmap_width*m_pmap_height);
783  fill(m_pmap_insecticides->begin(), m_pmap_insecticides->end(), 0);
784  ofstream * m_PMap;
785  m_PMap = new ofstream("ALMaSS_InsecticideMap.txt", ios::out);
786  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
787  m_PMap->close();
788  // These two grids are used only if we want all three types recoreded.
789  if (!m_typeofmap)
790  {
791  // We need all three in this case
792  m_pmap_fungicides = new vector<double>;
793  m_pmap_fungicides->resize(m_pmap_width*m_pmap_height);
794  fill(m_pmap_fungicides->begin(), m_pmap_fungicides->end(), 0);
795  m_PMap = new ofstream("ALMaSS_FungicideMap.txt", ios::out);
796  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
797  m_PMap->close();
798  m_pmap_herbicides = new vector<double>;
799  m_pmap_herbicides->resize(m_pmap_width*m_pmap_height);
800  fill(m_pmap_herbicides->begin(), m_pmap_herbicides->end(), 0);
801  m_PMap = new ofstream("ALMaSS_HerbicideMap.txt", ios::out);
802  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
803  m_PMap->close();
804  }
805  else
806  {
807  m_pmap_fungicides = NULL;
808  m_pmap_herbicides = NULL;
809  }
810 }
811 
813 {
814  delete m_pmap_insecticides;
815  if (!m_typeofmap)
816  {
817  // We need all three in this case
818  delete m_pmap_fungicides;
819  delete m_pmap_herbicides;
820 
821  }
822 }
823 
824 bool PesticideMap::DumpPMap(vector<double>* a_map)
825 {
826  string fname;
827  if (a_map == m_pmap_insecticides) fname = "ALMaSS_InsecticideMap.txt";
828  else if (a_map == m_pmap_fungicides) fname = "ALMaSS_FungicideMap.txt";
829  else fname = "ALMaSS_HerbicideMap.txt";
830  {
831  ofstream* m_PMap = new ofstream(fname.c_str(), ios::app);
832  if (!(*m_PMap).is_open())
833  {
834  g_msg->Warn(WARN_FILE, "PesticideMap::DumpMap Unable to open file for append: ", fname.c_str());
835  exit(1);
836  }
837  // File is OK, save the map
838  (*m_PMap) << "Year " << g_date->GetYear() << "Month " << g_date->GetMonth() << endl;
839  for (int y = 0; y < m_pmap_height; y++)
840  {
841  for (int x = 0; x < m_pmap_width; x++)
842  {
843  (*m_PMap) << (*a_map)[y*m_pmap_width + x] << ' ';
844  }
845  }
846  (*m_PMap) << endl;
847  m_PMap->close();
848  }
849  fill(a_map->begin(), a_map->end(), 0);
850  return true;
851 }
852 
853 
854 void PesticideMap::Spray(LE* a_element_sprayed, TTypesOfPesticideCategory a_type)
855 {
867  vector<double>* ourmap = m_pmap_insecticides; ;
868  if (a_type == fungicide) ourmap = m_pmap_fungicides;
869  else if (a_type == herbicide) ourmap = m_pmap_herbicides;
870  int l_large_map_index = a_element_sprayed->GetMapIndex();
871  int minx = a_element_sprayed->GetMinX();
872  int miny = a_element_sprayed->GetMinY();
873  int maxx = a_element_sprayed->GetMaxX();
874  int maxy = a_element_sprayed->GetMaxY();
875  for (int y = miny; y <= maxy; y++) {
876  for (int x = minx; x <= maxx; x++) {
877  if (m_Rastermap->Get(x, y) == l_large_map_index)
878  {
879  // Add one m spray value of 1.0 per m
880  (*ourmap)[(x/m_cellsize)+(y/m_cellsize)*m_pmap_width]++;
881  }
882  }
883  }
884 }
885 //-----------------------------------------------------------------------------------------------------------------------------
Pesticide::TwinMapSprayPixel
void TwinMapSprayPixel(int a_large_map_x, int a_large_map_y, double a_fractional_amount)
Definition: pesticide.h:357
Pesticide::DailyQueueClear
void DailyQueueClear(PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:131
l_pest_use_application_rate
CfgBool l_pest_use_application_rate("PEST_USE_APPLICATIONRATE", CFG_CUSTOM, false)
LE::GetMinX
int GetMinX(void)
Definition: elements.h:335
Diffusor
Definition: pesticide.h:77
Pesticide::TwinMapDiffusion
void TwinMapDiffusion(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:276
PlantProtectionProducts
PlantProtectionProducts
A list PPP names for tracking by the Pesticide class.
Definition: farm.h:420
Calendar::GetYear
int GetYear(void)
Definition: calendar.h:67
Pesticide::m_rainfallcategory
unsigned m_rainfallcategory
Daily rainfall saved here * 100 to use as an index to the Pesticide::m_RainWashoffFactor array - an o...
Definition: pesticide.h:193
cfg_pest_springbarley_on
CfgBool cfg_pest_springbarley_on("PEST_SPRINGBARLEY_ON", CFG_CUSTOM, false)
l_pest_NoPPPs
CfgInt l_pest_NoPPPs("PEST_NO_OF_PPPS", CFG_CUSTOM, 1, 1, 10)
The number of active Plant Protection Products to be tracked - a performance penalty if enabled with ...
Pesticide::m_x_excess
int m_x_excess
Definition: pesticide.h:154
SV_UINT32
#define SV_UINT32
Definition: pesticide.cpp:668
RasterMap::MapHeight
int MapHeight(void)
Definition: rastermap.h:53
cfg_pest_cabbage_on
CfgBool cfg_pest_cabbage_on("PEST_CABBAGE_ON", CFG_CUSTOM, false)
l_pest_ai_half_life_Soil
static CfgFloat l_pest_ai_half_life_Soil("PEST_AI_HALF_LIFE_SOIL", CFG_CUSTOM, 10.0)
cfg_pest_product_8_amount
CfgFloat cfg_pest_product_8_amount("PEST_PRODUCT_EIGHT_AMOUNT", CFG_CUSTOM, 1.0)
LE::GetMaxX
int GetMaxX(void)
Definition: elements.h:333
Landscape::SupplyWindDirection
int SupplyWindDirection(void)
Definition: landscape.h:1423
Pesticide::m_y_excess
int m_y_excess
Definition: pesticide.h:155
RasterMap::Get
int Get(int a_x, int a_y)
Definition: rastermap.h:81
cfg_pest_product_10_amount
CfgFloat cfg_pest_product_10_amount("PEST_PRODUCT_TEN_AMOUNT", CFG_CUSTOM, 1.0)
Pesticide
Definition: pesticide.h:106
PEST_GRIDSIZE_POW2
#define PEST_GRIDSIZE_POW2
Definition: pesticide.h:39
l_pest_zero_threshold
static CfgFloat l_pest_zero_threshold("PEST_ZERO_THRESHOLD", CFG_CUSTOM, 0.00001)
Pesticide::m_diffusion_mask
Diffusion_mask m_diffusion_mask[4]
Pre-calculated square diffusion map, assuming wind directions (4) Used after spraying an element in...
Definition: pesticide.h:197
ls.h
fungicide
Definition: landscape.h:63
l_pest_diffusion_slope
static CfgFloat l_pest_diffusion_slope("PEST_DRIFT_SLOPE", CFG_CUSTOM, -0.6122)
cfg_pest_beet_on
CfgBool cfg_pest_beet_on("PEST_BEET_ON", CFG_CUSTOM, false)
Calendar::GetMonth
int GetMonth(void)
Definition: calendar.h:69
cfg_pest_product_9_amount
CfgFloat cfg_pest_product_9_amount("PEST_PRODUCT_NINE_AMOUNT", CFG_CUSTOM, 1.0)
Pesticide::m_pest_map_size
unsigned int m_pest_map_size
The total size of one map in cellsize resolution.
Definition: pesticide.h:184
PesticideMap::PesticideMap
PesticideMap(int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land, bool a_typeofmap)
Definition: pesticide.cpp:769
Pesticide::DiffusionSprayPixel
void DiffusionSprayPixel(int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double a_cover, PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:301
Pesticide::~Pesticide
virtual ~Pesticide(void)
Definition: pesticide.cpp:621
l_pest_enable_pesticide_engine
CfgBool l_pest_enable_pesticide_engine("PEST_ENABLE_PESTICIDE_ENGINE", CFG_CUSTOM, false)
Used to turn on or off the PPP functionality of ALMaSS.
LE::GetMinY
int GetMinY(void)
Definition: elements.h:336
cfg_pest_carrots_on
CfgBool cfg_pest_carrots_on("PEST_CARROTS_ON", CFG_CUSTOM, false)
Pesticide::Tick
void Tick(void)
Definition: pesticide.cpp:97
PesticideMap::Spray
void Spray(LE *a_element_sprayed, TTypesOfPesticideCategory a_type)
Definition: pesticide.cpp:854
l_pest_trigger_threshold2
CfgFloat l_pest_trigger_threshold2("PEST_TRIGGER_THRESHOLD_TWO", CFG_CUSTOM, 1.0)
PesticideEvent
Definition: pesticide.h:61
SV_UINT8
#define SV_UINT8
Definition: pesticide.cpp:670
Pesticide::m_daily_spray_queue
vector< vector< PesticideEvent * > > m_daily_spray_queue
List lists of landscape elements, which was sprayed on a given day. One for each PPP we track.
Definition: pesticide.h:200
herbicide
Definition: landscape.h:63
cfg_pest_winterrape_on
CfgBool cfg_pest_winterrape_on("PEST_WINTERRAPE_ON", CFG_CUSTOM, false)
l_pest_daily_mort2
CfgFloat l_pest_daily_mort2("PEST_DAILY_MORTALITY_TWO", CFG_CUSTOM, 0.25)
PesticideMap::~PesticideMap
~PesticideMap()
Definition: pesticide.cpp:812
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
l_pest_ai_half_life_Veg
static CfgFloat l_pest_ai_half_life_Veg("PEST_AI_HALF_LIFE_VEG", CFG_CUSTOM, 10.0)
Pesticide::m_pest_map_main
vector< vector< double > > m_pest_map_main
Definition: pesticide.h:179
Landscape
The landscape class containing all environmental and topographical data.
Definition: landscape.h:112
cfg_pest_potatoes_on
CfgBool cfg_pest_potatoes_on("PEST_POTATOES_ON", CFG_CUSTOM, false)
cfg_pest_springwheat_on
CfgBool cfg_pest_springwheat_on("PEST_SPRINGWHEAT_ON", CFG_CUSTOM, false)
Weather::GetTemp
double GetTemp(long a_date)
Get the temperature on a particular date.
Definition: weather.h:417
Pesticide::m_something_to_decay
bool m_something_to_decay[ppp_foobar]
Speed hack. Only actually run the daily decay routine on the pesticide map if and only if we are sure...
Definition: pesticide.h:146
CfgBool
Bool configurator entry class.
Definition: configurator.h:127
Pesticide::TwinMapClear
void TwinMapClear(int a_minx, int a_miny, int a_maxx, int a_maxy)
Definition: pesticide.cpp:181
cfg_pest_winterwheat_on
CfgBool cfg_pest_winterwheat_on("PEST_WINTERWHEAT_ON", CFG_CUSTOM, false)
g_landscape_p
class Landscape * g_landscape_p
Definition: Landscape.cpp:258
Pesticide::m_NoPPPs
int m_NoPPPs
The number of active PPPs to track.
Definition: pesticide.h:149
cfg_pest_tulips_on
CfgBool cfg_pest_tulips_on("PEST_TULIPS_ON", CFG_CUSTOM, false)
Pesticide::DiffusionMaskInit
void DiffusionMaskInit(void)
Definition: pesticide.cpp:325
l_pest_ai_half_life
static CfgFloat l_pest_ai_half_life("PEST_AI_HALF_LIFE", CFG_CUSTOM, 10.0)
PEST_GRIDAREA
#define PEST_GRIDAREA
Definition: pesticide.h:41
cfg_pest_productapplic_startdate3
CfgInt cfg_pest_productapplic_startdate3("PEST_PRODUCTAPPLIC_STARTDATE_THREE", CFG_CUSTOM,-1)
Pesticide::DailyQueueAdd
void DailyQueueAdd(LE *a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:140
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
cfg_pest_product_4_amount
CfgFloat cfg_pest_product_4_amount("PEST_PRODUCT_FOUR_AMOUNT", CFG_CUSTOM, 1.0)
PEST_GRIDSIZE
#define PEST_GRIDSIZE
Definition: pesticide.h:40
l_pest_diffusion_grid_count
static CfgInt l_pest_diffusion_grid_count("PEST_DIFFUSION_GRID_COUNT", CFG_CUSTOM, 1)
cfg_pest_SBS_ERA
CfgBool cfg_pest_SBS_ERA("PEST_SBS_ERA", CFG_CUSTOM, false)
Pesticide::MainMapDecay
void MainMapDecay(PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:469
TTypesOfPesticideCategory
TTypesOfPesticideCategory
Definition: landscape.h:63
Pesticide::m_pest_daily_decay_frac
double m_pest_daily_decay_frac
Definition: pesticide.h:163
Landscape::SupplyVegCover
double SupplyVegCover(int a_polyref)
Definition: landscape.h:1048
cfg_pest_productapplic_period
CfgInt cfg_pest_productapplic_period("PEST_PRODUCTAPPLIC_PERIOD", CFG_CUSTOM, 1)
Definition: elements.cpp:123
CfgFloat::value
double value(void)
Definition: configurator.h:118
Pesticide::m_land
RasterMap * m_land
Definition: pesticide.h:168
Pesticide::DailyQueueProcess
void DailyQueueProcess(PlantProtectionProducts a_ppp)
Definition: pesticide.cpp:147
g_pest
class Pesticide * g_pest
Definition: pesticide.cpp:92
ppp_1
Definition: farm.h:422
CFG_CUSTOM
Definition: configurator.h:60
Landscape::SupplyRain
double SupplyRain(void)
Definition: landscape.h:1365
cfg_pest_product_3_amount
CfgFloat cfg_pest_product_3_amount("PEST_PRODUCT_THREE_AMOUNT", CFG_CUSTOM, 1.0)
LE
Definition: elements.h:81
Pesticide::DiffusionFunction
double DiffusionFunction(double a_dist_meters)
Definition: pesticide.cpp:442
Pesticide::m_prop
double m_prop
Definition: pesticide.h:156
Pesticide::m_pest_map_width
unsigned int m_pest_map_width
The width of one map in cellsize resolution.
Definition: pesticide.h:186
WARN_FATAL
Definition: maperrormsg.h:35
cfg_pest_productapplic_startdate
CfgInt cfg_pest_productapplic_startdate("PEST_PRODUCTAPPLIC_STARTDATE", CFG_CUSTOM, -1)
Definition: elements.cpp:120
cfg_pest_winterbarley_on
CfgBool cfg_pest_winterbarley_on("PEST_WINTERBARLEY_ON", CFG_CUSTOM, false)
l_pest_daily_mort
CfgFloat l_pest_daily_mort("PEST_DAILY_MORTALITY", CFG_CUSTOM, 0.25)
WARN_FILE
Definition: maperrormsg.h:37
cfg_pest_product_6_amount
CfgFloat cfg_pest_product_6_amount("PEST_PRODUCT_SIX_AMOUNT", CFG_CUSTOM, 1.0)
CfgInt
Integer configurator entry class.
Definition: configurator.h:87
l_pest_trigger_threshold1
CfgFloat l_pest_trigger_threshold1("PEST_TRIGGER_THRESHOLD_ONE", CFG_CUSTOM, 1.0)
This is a trigger values that can be used to trigger pesticides effects. Currently only used by the B...
cfg_pest_product_5_amount
CfgFloat cfg_pest_product_5_amount("PEST_PRODUCT_FIVE_AMOUNT", CFG_CUSTOM, 1.0)
Pesticide::Pesticide
Pesticide(RasterMap *a_land, Landscape *a_map)
Definition: pesticide.cpp:526
Pesticide::m_corr_y
double m_corr_y
Definition: pesticide.h:158
Pesticide::m_RainWashoffFactor
double m_RainWashoffFactor[10000]
a structure to hold pre-calculated pesticide rain wash off factor (Rw)
Definition: pesticide.h:191
CfgFloat
Double configurator entry class.
Definition: configurator.h:106
Pesticide::m_corr_x
double m_corr_x
Definition: pesticide.h:157
Pesticide::m_pest_map_twin
double * m_pest_map_twin
The complete pesticide map.
Definition: pesticide.h:182
CfgInt::value
int value(void)
Definition: configurator.h:98
Pesticide::m_wind
int m_wind
Definition: pesticide.h:159
cfg_pest_wintertriticale_on
CfgBool cfg_pest_wintertriticale_on("PEST_WINTERTRITICALE_ON", CFG_CUSTOM, false)
RasterMap
Definition: rastermap.h:40
Pesticide::m_pest_daily_decay_frac_Soil
double m_pest_daily_decay_frac_Soil
Definition: pesticide.h:165
cfg_pest_productapplic_startdate2
CfgInt cfg_pest_productapplic_startdate2("PEST_PRODUCTAPPLIC_STARTDATE_TWO", CFG_CUSTOM,-1)
cfg_pest_winterrye_on
CfgBool cfg_pest_winterrye_on("PEST_WINTERRYE_ON", CFG_CUSTOM, false)
g_date
class Calendar * g_date
Definition: calendar.cpp:38
Pesticide::TwinMapSprayCorrectBorders
void TwinMapSprayCorrectBorders(void)
Definition: pesticide.cpp:230
Pesticide::m_pest_daily_decay_frac_Veg
double m_pest_daily_decay_frac_Veg
Definition: pesticide.h:164
cfg_pest_product_2_amount
CfgFloat cfg_pest_product_2_amount("PEST_PRODUCT_TWO_AMOUNT", CFG_CUSTOM, 1.0)
g_land
Landscape * g_land
RasterMap::MapWidth
int MapWidth(void)
Definition: rastermap.h:52
PesticideMap::DumpPMap
bool DumpPMap(vector< double > *a_map)
Definition: pesticide.cpp:824
CfgBool::value
bool value(void)
Definition: configurator.h:135
Pesticide::DiffusionMaskInitTest
void DiffusionMaskInitTest(void)
Definition: pesticide.cpp:640
Pesticide::m_map
Landscape * m_map
Definition: pesticide.h:171
LE::GetMaxY
int GetMaxY(void)
Definition: elements.h:334
cfg_pest_product_1_amount
CfgFloat cfg_pest_product_1_amount("PEST_PRODUCT_ONE_AMOUNT", CFG_CUSTOM, 1.0)
cfg_pest_residue_or_rate
CfgBool cfg_pest_residue_or_rate("PEST_RESIDUE_OR_RATE", CFG_CUSTOM, true)
Pesticide::CalcRainWashOffFactors
void CalcRainWashOffFactors()
Pre-calculates the constants required for rain wash off with increasing rainfall and stores this in m...
Definition: pesticide.cpp:599
Pesticide::m_pest_map_height
unsigned int m_pest_map_height
The height of one map in cellsize resolution.
Definition: pesticide.h:188
cfg_pest_product_7_amount
CfgFloat cfg_pest_product_7_amount("PEST_PRODUCT_SEVEN_AMOUNT", CFG_CUSTOM, 1.0)
g_weather
class Weather * g_weather
Definition: weather.cpp:41
Pesticide::TwinMapSpray
void TwinMapSpray(LE *a_element_spryaed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy)
Definition: pesticide.cpp:194
Pesticide::SavePPM
bool SavePPM(double *a_map, int a_beginx, int a_width, int a_beginy, int a_height, char *a_filename)
Definition: pesticide.cpp:673
LE::GetMapIndex
int GetMapIndex(void)
Definition: elements.h:190