28 #define _CRT_SECURE_NO_DEPRECATE 151 for (
int y=a_miny; y<=a_maxy; y++ )
154 for (
int x=a_minx; x<=a_maxx; x++ )
183 double l_fractional_amount = a_amount *
m_prop;
184 int l_large_map_index = a_element_sprayed->
GetMapIndex();
191 for (
int y=a_miny; y<=a_maxy; y++ ) {
192 for (
int x=a_minx; x<=a_maxx; x++ ) {
193 if (
m_land->
Get( x, y ) == l_large_map_index )
252 for (
int y=a_miny; y<a_maxy; y++ )
255 for (
int x=a_minx; x<a_maxx; x++ )
282 if (a_x < 0 || a_x >= a_limit_x || a_y < 0 || a_y >= a_limit_y)
return;
284 int l_coord = a_y * a_limit_x + a_x;
285 #ifdef __DETAILED_PESTICIDE_FATE 287 m_pest_map_vegcanopy[l_coord] += a_amount * a_cover;
288 m_pest_map_soil[l_coord] += a_amount - m_pest_map_vegcanopy[l_coord];
305 const int l_side_length = l_grid * 2 + 1;
307 l_diff =
new double[l_side_length];
311 for (
int l=1; l<l_side_length; l++)
316 for (
int l=0; l<l_side_length; l++)
323 for (
int wind=0; wind < 4; wind ++)
326 for (
int x = 0; x< l_side_length; x++ )
328 for (
int y= 0; y< l_side_length; y++ )
338 for (
int step = 0; step <= l_grid; step++)
340 for (
int cc=0; cc<fin; cc++)
342 m_diffusion_mask[0][ strtx + (cc-step) + ((strty-step)*l_side_length)]->SetFraction(l_diff[step]);
348 for (
int step = 0; step <= l_grid; step++)
350 for (
int cc=0; cc<fin; cc++)
352 m_diffusion_mask[2][ strtx + (cc-step) + ((strty+step)*l_side_length)]->SetFraction(l_diff[step]);
358 for (
int step = 0; step <= l_grid; step++)
360 for (
int cc=0; cc<fin; cc++)
362 m_diffusion_mask[3][ (strtx + step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
368 for (
int step = 0; step <= l_grid; step++)
370 for (
int cc=0; cc<fin; cc++)
372 m_diffusion_mask[1][ (strtx - step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
420 #ifdef __WithinOrchardPesticideSim__ 421 if (a_dist_meters==0) pp=0.7784;
445 #ifdef __DETAILED_PESTICIDE_FATE 446 if ((m_pest_map_vegcanopy[i] > l_zero) )
452 unsigned cov = 100 * cover;
455 m_pest_map_vegcanopy[i] -= Rwp;
461 if (m_pest_map_soil[i] > l_zero)
468 m_pest_map_vegcanopy[i] = 0.0;
469 m_pest_map_soil[i] = 0.0;
522 #ifdef __DETAILED_PESTICIDE_FATE 523 m_pest_map_vegcanopy = (
double*)malloc(
sizeof(
double)*
m_pest_map_size);
539 #ifdef __DETAILED_PESTICIDE_FATE 540 m_pest_map_vegcanopy[i] = 0.0;
541 m_pest_map_soil[i] = 0.0;;
570 double rainsteps = 0.1;
571 double coversteps = 1.0;
572 for (
int i = 0; i < 100; i++)
574 double SC = i * coversteps;
575 double LAI = log(0 - (1 - SC))*1.666666667;
576 for (
int r = 0; r < 100; r++)
578 double P = r * rainsteps;
579 double Pi = LAI*(1 - (1 / ((1 + SC * P) / LAI)));
580 double Rw = 0.25*(SC * P - Pi);
589 #ifdef __DETAILED_PESTICIDE_FATE 591 free( m_pest_map_soil );
592 free(m_pest_map_vegcanopy);
604 for (
int w=0; w<4; w++)
621 const int l_side_length = l_grid * 2 + 1;
624 ofstream ofile(
"diffusionmask.txt",ios::out);
625 for (
int i=0; i<4; i++)
627 for (
int x = 0; x< l_side_length; x++ )
629 for (
int y= 0; y< l_side_length; y++ )
643 #define CFG_CHANNEL_BITS 8 644 #define CFG_CHANNEL_MAXVAL (2^CFG_CHANNEL_BITS-1) 646 #define SV_UINT32 unsigned int 648 #define SV_UINT8 unsigned char 652 int a_beginx,
int a_width,
653 int a_beginy,
int a_height,
664 if ( linebuffer == NULL ) {
666 "Pesticide::SavePPM(): Out of memory!",
"" );
671 l_file=fopen(a_filename,
"w" );
673 printf(
"PesticideTest::SavePPM(): " 674 "Unable to open file for writing: %s\n",
679 fprintf( l_file,
"P6\n%d %d %d\n",
684 for (
int line=a_beginy; line< a_beginy + a_height; line++ ) {
686 for (
int column=a_beginx; column < a_beginx + a_width; column++ ) {
689 if ( localcolor <= 255 ) {
690 linebuffer [ i++ ] = char (localcolor & 0xff);
691 linebuffer [ i++ ] = 0;
692 linebuffer [ i++ ] = 0;
694 linebuffer [ i++ ] = 255;
696 if ( localcolor <= 255 ) {
697 linebuffer [ i++ ] = char (localcolor);
698 linebuffer [ i++ ] = 0;
700 linebuffer [ i++ ] = 255;
702 if ( localcolor <= 255 ) {
703 linebuffer [ i++ ] = char (localcolor);
705 linebuffer [ i++ ] = 255;
710 fwrite( linebuffer,
sizeof(
SV_UINT8), linesize, l_file );
static CfgFloat l_pest_ai_half_life_Soil("PEST_AI_HALF_LIFE_SOIL", CFG_CUSTOM, 10.0)
void TwinMapClear(int a_minx, int a_miny, int a_maxx, int a_maxy)
CfgBool cfg_pest_winterwheat_on("PEST_WINTERWHEAT_ON", CFG_CUSTOM, false)
CfgBool l_pest_enable_pesticide_engine("PEST_ENABLE_PESTICIDE_ENGINE", CFG_CUSTOM, false)
The landscape class containing all environmental and topographical data.
void DailyQueueClear(void)
unsigned int m_pest_map_width
CfgFloat l_pest_daily_mort2("PEST_DAILY_MORTALITY_TWO", CFG_CUSTOM, 0.25)
double m_pest_daily_decay_frac_Soil
void TwinMapDiffusion(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover)
double m_RainWashoffFactor[10000]
a structure to hold pre-calculated pesticide rain wash off factor (Rw)
void DiffusionMaskInit(void)
int SupplyWindDirection(void)
Integer configurator entry class.
void DailyQueueAdd(LE *a_element_sprayed, double a_amount)
CfgBool cfg_pest_residue_or_rate("PEST_RESIDUE_OR_RATE", CFG_CUSTOM, true)
#define PEST_GRIDSIZE_POW2
Turns on code for detailed pesticide fate handling.
static CfgFloat l_pest_ai_half_life("PEST_AI_HALF_LIFE", CFG_CUSTOM, 10.0)
int Get(int a_x, int a_y)
void CalcRainWashOffFactors()
Pre-calculates the constants required for rain wash off with increasing rainfall and stores this in m...
double m_pest_daily_decay_frac_Veg
Diffusion_mask m_diffusion_mask[4]
Pre-calculated square diffusion map, assuming wind directions (4) Used after spraying an element in...
CfgFloat l_pest_daily_mort("PEST_DAILY_MORTALITY", CFG_CUSTOM, 0.25)
void TwinMapSprayCorrectBorders(void)
class MapErrorMsg * g_msg
CfgFloat l_pest_insecticide_amount("PEST_INSECTICIDE_AMOUNT", CFG_CUSTOM, 0.00)
vector< PesticideEvent * > m_daily_spray_queue
unsigned m_rainfallcategory
Daily rainfall saved here * 100 to use as an indext to the Pesticide::m_RainWashoffFactor array - an ...
static CfgFloat l_pest_diffusion_slope("PEST_DRIFT_SLOPE", CFG_CUSTOM,-0.6122)
CfgInt cfg_pest_productapplic_startdate2("PEST_PRODUCTAPPLIC_STARTDATE_TWO", CFG_CUSTOM,-1)
double DiffusionFunction(double a_dist_meters)
void DiffusionMaskInitTest(void)
void DailyQueueProcess(void)
Pesticide(RasterMap *a_land, Landscape *a_map)
Bool configurator entry class.
CfgFloat l_pest_product_0_amount("PEST_PRODUCT_ZERO_AMOUNT", CFG_CUSTOM, 0.004145)
static CfgFloat l_pest_ai_half_life_Veg("PEST_AI_HALF_LIFE_VEG", CFG_CUSTOM, 10.0)
void TwinMapSprayPixel(int a_large_map_x, int a_large_map_y, double a_fractional_amount)
double SupplyVegCover(int a_polyref)
void TwinMapSpray(LE *a_element_spryaed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy)
unsigned int m_pest_map_size
bool SavePPM(double *a_map, int a_beginx, int a_width, int a_beginy, int a_height, char *a_filename)
bool m_something_to_decay
CfgFloat l_pest_product_1_amount("PEST_PRODUCT_ONE_AMOUNT", CFG_CUSTOM, 0.004145)
CfgBool l_pest_use_application_rate("PEST_USE_APPLICATIONRATE", CFG_CUSTOM, false)
unsigned int m_pest_map_height
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
CfgFloat l_pest_trigger_threshold2("PEST_TRIGGER_THRESHOLD_TWO", CFG_CUSTOM, 1.0)
CfgBool cfg_pest_winterrape_on("PEST_WINTERRAPE_ON", CFG_CUSTOM, false)
double m_pest_daily_decay_frac
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...
static CfgInt l_pest_diffusion_grid_count("PEST_DIFFUSION_GRID_COUNT", CFG_CUSTOM, 1)
CfgBool cfg_pest_SBS_ERA("PEST_SBS_ERA", CFG_CUSTOM, false)
Double configurator entry class.
CfgInt cfg_pest_productapplic_period("PEST_PRODUCTAPPLIC_PERIOD", CFG_CUSTOM, 1)
static CfgFloat l_pest_zero_threshold("PEST_ZERO_THRESHOLD", CFG_CUSTOM, 0.00001)
CfgInt cfg_pest_productapplic_startdate("PEST_PRODUCTAPPLIC_STARTDATE", CFG_CUSTOM,-1)
CfgBool cfg_pest_springbarley_on("PEST_SPRINGBARLEY_ON", CFG_CUSTOM, false)
class Landscape * g_landscape_p
void DiffusionSprayPixel(int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double a_cover)
CfgInt cfg_pest_productapplic_startdate3("PEST_PRODUCTAPPLIC_STARTDATE_THREE", CFG_CUSTOM,-1)