main()¶
This function is the backbone of the whole program. It first initialize all the data structures need.
/**** In Defaults.h ****/
struct global_t global;
struct const_t constant;
struct stats_t stats;
struct display_t dpy;
/***********************/
Then it will initialize the runtime environment by calling init() function.
/***************** In Initialize.h *****************/
init(&global, &constant, &stats, &dpy, &argc, &argv);
/***************************************************/
Then we start the simulation. A for loop wraps around most of the functions, where the each iteration of the loop represents a day passing.
for(global.current_day = 0; global.current_day <= constant.total_number_of_days;
global.current_day++)
{
}
Inside the for loop, we first find all data related to the infection.
/****** In Infection.h ******/
find_infected(&global);
/****************************/
Then, if display is enabled, we display the infection status. In other words, we display everyone’s location and their states of infection.
/**************** In Display.h *****************/
#if defined(X_DISPLAY) || defined(TEXT_DISPLAY)
do_display(&global, &constant, &dpy);
throttle(&constant);
#endif
/***********************************************/
After display, we can call four core functions in Core.h* code file.
/************** In Core.h *************/
move(&global, &constant);
susceptible(&global, &constant, &stats);
infected(&global, &constant, &stats);
update_days_infected(&global, &constant);
/**************************************/
This is the end of the loop.
Finally, after the loop, we can display the results and finalize the runtime environment.
/******** In Finialize.h ********/
show_results(&global, &stats);
cleanup(&global, &constant, &dpy);
/********************************/