#include #include #include #include #include #include /*Constants*/ #define MAXLeadTime 2 #define FALSE 0 #define TRUE !FALSE #define OK TRUE #define PI 3.1415926535897932384626433832795028841971693 /*** Assumed: time units = hours, distance units = miles burn line follows perfect circle circle radius grows at constant rate/time period <<< CHANGE THIS water payloads dropped at fixed time intervals and remove some % of current burn circle ***/ // INPUT VALUES: double rzero; //radius of burn circle at time 0 double rgrow; //radius growth rate in miles per hour double dropxlen; //miles of fireline extinguished by one water payload drop double dropdelta; //hours between consecutive payload drops double maxtime; //number of hours to simulate int display_drops; //number of individual payload drops to display // CALCULATED VALUES long drop; // Water drop counter double timeNow; // current simulated time double radiusNow; double burnLen; double pctBurnNow; double newBurnLen; double pctPrevious; double areaPrevious; double areaTotal; double areaDel; double areaBurnPct; double areaBurnDel; double areaCumBurn; /* Functions prototypes */ static set_init(void); static receiving_orders(void); static int get_demand(void); static int get_leadtime(void); static summary_report(void); void calc_drop(void); /* Main program */ int main(int argc, char *argv[]) { int i; char* message; //message to display if order was placed int u_available,u_demanded,u_used; //daily units available, demanded, and used static char help[] = "./firesim R G X D T [S]\n\ R = radius of burn circle at time 0, in miles\n\ G = radius growth rate, in miles per hour point\n\ X = miles of fire extinguished per water payload dropped\n\ D = hours between water payload drops\n\ T = number of hours to simulate\n\ S = number of payload drops to display details for (optional, default = 0)\n"; if (argc < 6 || argc > 7) {printf(help); exit(0);} rzero = atof(argv[1]); rgrow = atof(argv[2]); dropxlen = atof(argv[3]); dropdelta = atof(argv[4]); maxtime = atof(argv[5]); display_drops = 0; if (argc==7) display_drops=atoi(argv[6]); // if ((Q<0)||(R<0)||(N<0)||(display_daily>N)||(display_daily<0)) {printf(help); exit(0);} //* all decision variables are positive printf("WILDFIRE SIMULATION PARAMETERS:\n\n"); printf("%10.3f Initial burn circle radius\n%10.3f Radius growth rate\n%10.3f Miles extinguished per water payload\n%10.3f Hours between payload drops\n%10.3f Hours to simulate\n%10d Payload drops to display\n", rzero,rgrow,dropxlen,dropdelta,maxtime,display_drops); printf("\n\n"); set_init(); /* set initial value */ print_header(); print_line(); display_drop(); while (timeNow <= maxtime && newBurnLen > 0.0) { calc_drop(); if(drop <= display_drops) display_drop(); } print_line(); display_drop(); } print_header() { printf(" Drop Time Radius Circle %% Left Fireline"); printf(" TotArea Spread Burn%% Burned CumBurn\n"); printf(" No. (hrs) (mi) (mi) (pct) (mi)"); printf(" (mi^2) (mi^2) (pct) (mi^2) (mi^2)\n"); } print_line() { printf(" ---- ---- ------ ------ ------ --------"); printf(" ------- ------ ----- ------ -------\n"); } set_init(void) /* set initial values */ { drop = 0; timeNow = 0.0; radiusNow = rzero; burnLen = radiusNow*2.0*PI; pctBurnNow = 1.0; newBurnLen = burnLen; areaTotal = PI*radiusNow*radiusNow; areaDel = areaTotal; areaBurnPct = 1; areaBurnDel = areaDel*areaBurnPct; areaCumBurn = areaBurnDel; /* srand() takes an unsigned int as an argument and sets the seed */ /* used for generating random numbers. If time is used, the results is different */ /* every time program runs */ srand((unsigned)time(NULL)); } display_drop(void) // display data for individual drop { printf("%8i %8.3f %8.3f %8.3f %8.2f %8.3f",drop,timeNow,radiusNow,burnLen,pctBurnNow*100.0, newBurnLen); printf(" %10.2f %8.2f %8.2f %8.2f %10.2f\n",areaTotal,areaDel,areaBurnPct*100,areaBurnDel,areaCumBurn); } void calc_drop() { ++drop; timeNow += dropdelta; radiusNow = rzero + timeNow*rgrow; burnLen = 2.0*PI*radiusNow; pctPrevious = pctBurnNow; pctBurnNow -= dropxlen/burnLen; newBurnLen = burnLen * pctBurnNow; if (newBurnLen <= 0.0){ newBurnLen = pctBurnNow = 0.0;} areaPrevious = areaTotal; areaTotal = PI*radiusNow*radiusNow; areaDel = areaTotal-areaPrevious; areaBurnPct = pctPrevious; areaBurnDel = areaBurnPct*areaDel; areaCumBurn += areaBurnDel; } /* get lead time */ int get_leadtime(void) { } /* simulation summary report */ summary_report(void) { }