Пример #1
0
void	execute_tec(
					struct	tec_object *tecfile ,
					struct command_line_object *command_line,
					struct	world_output_file_object *outfile,
					struct	world_output_file_object *growth_outfile,
					struct world_object *world)
{
	/*--------------------------------------------------------------*/
	/*	Local Function Declarations.								*/
	/*--------------------------------------------------------------*/
	int		cal_date_lt(struct date, struct date );
	
	long	julday( struct date );
	
	struct	date	caldat( long );
	
	struct	tec_entry	*construct_tec_entry( struct date, char * );
	
	void	world_daily_I(
		long,
		struct world_object *,
		struct command_line_object *,
		struct tec_entry *,
		struct date);
	
	void	world_hourly(
		struct world_object *,
		struct command_line_object *,
		struct tec_entry *,
		struct date);
	
	void	world_daily_F(
		long,
		struct world_object *,
		struct command_line_object *,
		struct tec_entry *,
		struct date);
	
	void	handle_event(
		struct	tec_entry	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_object	*);
	
	void	execute_yearly_growth_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);

	void	execute_yearly_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);
	
	void	execute_daily_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);
	
	void	execute_daily_growth_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);

	void	execute_monthly_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);
	
	void	execute_hourly_output_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date,
		struct	world_output_file_object *);

	void	execute_firespread_event(
		struct	world_object	*,
		struct	command_line_object	*,
		struct	date);
	
	void	execute_state_output_event(
		struct world_object *,
		struct date,
		struct date,
		struct command_line_object *);

	/*--------------------------------------------------------------*/
	/*	Local Variable Definition. 									*/
	/*--------------------------------------------------------------*/
	int check;
	long	day;
	long	hour;
	long	month;
	long	year;
	struct	date	current_date;
	struct	date	next_date;
	struct	tec_entry	*event;
	
	/*--------------------------------------------------------------*/
	/*	Initialize the indices into the base station clime sequences*/
	/*--------------------------------------------------------------*/
	year = 0;
	month = 0;
	day = 0;
	hour = 0;
	
	/*--------------------------------------------------------------*/
	/*	Initialize the tec event									*/
	/*--------------------------------------------------------------*/
	
	event =  construct_tec_entry(world[0].end_date,"none");
	
	/*--------------------------------------------------------------*/
	/*	Loop from the start of the world to the end of the world.	*/
	/*--------------------------------------------------------------*/
	current_date = world[0].start_date;
	next_date = current_date;
	while ( cal_date_lt(current_date,world[0].end_date)){
		/*--------------------------------------------------------------*/
		/*		Perform the tec event.									*/
		/*--------------------------------------------------------------*/
		handle_event(event,command_line,current_date,world);
		/*--------------------------------------------------------------*/
		/*		read the next tec file entry.							*/
		/*		if we are not at the end of the tec file.				*/
		/*--------------------------------------------------------------*/
		if ( !(feof(tecfile[0].tfile))){
			/*--------------------------------------------------------------*/
			/*			read in the next tec line.							*/
			/*--------------------------------------------------------------*/
			check = fscanf(tecfile[0].tfile,"%d %d %d %d %s\n",
				&(event[0].cal_date.year),
				&(event[0].cal_date.month),
				&(event[0].cal_date.day),
				&(event[0].cal_date.hour),
				event[0].command);
			/*--------------------------------------------------------------*/
			/*			report an error if for some reason we cant read it	*/
			/*--------------------------------------------------------------*/
			if ( !check ){
				fprintf(stderr,"\nERROR:  the tec file is corrupted.");
				fclose(tecfile[0].tfile);
				exit(EXIT_FAILURE);
			} /*end if*/
		} /*end if*/
		/*--------------------------------------------------------------*/
		/* 	if end of tec file next event is the end of the world		*/
		/*--------------------------------------------------------------*/
		else{
			event =  construct_tec_entry(world[0].end_date, "none");
		} /*end if-else*/
		/*--------------------------------------------------------------*/
		/*		If the next event's date exceeds the end_date then		*/
		/*		set the next event to nothing and at a time at the 		*/
		/*		end of the simulation.									*/
		/*--------------------------------------------------------------*/
		if ( cal_date_lt(event[0].cal_date,	world[0].end_date) == 0  ){
			event =  construct_tec_entry(world[0].end_date,	"none");
		} /*end if*/
		/*--------------------------------------------------------------*/
		/*		Do stuff until the next tec event.						*/
		/*--------------------------------------------------------------*/
		while ( cal_date_lt(current_date, event[0].cal_date)){
			/*--------------------------------------------------------------*/
			/*			Simulate the world for the start of this day e		*/
			/*--------------------------------------------------------------*/
			if ( current_date.hour == 1 ){
				world_daily_I(
					day,
					world,
					command_line,
					event,
					current_date);
			} /*end if*/
			/*--------------------------------------------------------------*/
			/*          Do hourly stuff for the day.                        */
			/*--------------------------------------------------------------*/
			world_hourly( world,
				command_line,
				event,
				current_date);
			
			/*--------------------------------------------------------------*/
			/*			Perform any requested hourly output					*/
			/*--------------------------------------------------------------*/
			if (command_line[0].output_flags.hourly == 1){
				execute_hourly_output_event(
							  world,
							  command_line,
							  current_date,
							  outfile);
			}

			if(command_line[0].output_flags.hourly_growth ==1 &&
					(command_line[0].grow_flag > 0) ){
				  execute_hourly_growth_output_event(
							      world, 
							      command_line, 
							      current_date, 
							      growth_outfile);
				  
				};
			/*--------------------------------------------------------------*/
			/*			Increment to the next hour.							*/
			/*--------------------------------------------------------------*/
			current_date.hour++;
			/*--------------------------------------------------------------*/
			/*			Check if this is a day end.							*/
			/*--------------------------------------------------------------*/
			if ( current_date.hour == 25 ){
				/*--------------------------------------------------------------*/
				/*			Simulate the world for the end of this day e		*/
				/*--------------------------------------------------------------*/
				world_daily_F(
					day,
					world,
					command_line,
					event,
					current_date);
				/*--------------------------------------------------------------*/
				/*			Perform any requested daily output					*/
				/*--------------------------------------------------------------*/
				if ((command_line[0].output_flags.daily_growth == 1) &&
							(command_line[0].grow_flag > 0) ) {
						execute_daily_growth_output_event(
						world,
						command_line,
						current_date,
						growth_outfile);
				}
				if (command_line[0].output_flags.daily == 1) {
						execute_daily_output_event(
						world,
						command_line,
						current_date,
						outfile);
                               }
				/*--------------------------------------------------------------*/
        /*  Output world state in spinup mode if targets met            */
				/*--------------------------------------------------------------*/

				if((command_line[0].vegspinup_flag > 0) && (world[0].target_status > 0)) {
		      execute_state_output_event(world, current_date, world[0].end_date,command_line);
          printf("\nSpinup completed YEAR %d MONTH %d DAY %d \n", current_date.year,current_date.month,current_date.day);
          exit(0);
        } 

				/*--------------------------------------------------------------*/
				/*			Perform any requested yearly output					*/
				/*--------------------------------------------------------------*/
				if ((command_line[0].output_flags.yearly == 1) &&
					(command_line[0].output_yearly_date.month==current_date.month)&&
					(command_line[0].output_yearly_date.day == current_date.day))
							execute_yearly_output_event(
							world,
							command_line,
							current_date,
							outfile);

				if ((command_line[0].output_flags.yearly_growth == 1) &&
					(command_line[0].output_yearly_date.month==current_date.month)&&
					(command_line[0].output_yearly_date.day == current_date.day) &&
					(command_line[0].grow_flag > 0) )
					execute_yearly_growth_output_event(
					world,
					command_line,
					current_date,
					growth_outfile);
				/*--------------------------------------------------------------*/
				/*				Determine the new calendar date if we add 1 day.*/
				/*				Do this by first conversting the current cal	*/
				/* 				endar date into a julian day.  Then adding one	*/
				/*				to the julian day and the converting back to	*/
				/*				get tomorrows calendar date.					*/
				/*				We assume that it starts at hour 1.				*/
				/*--------------------------------------------------------------*/
				day = day + 1;
				next_date = caldat(julday(current_date)+1);
				current_date.day = next_date.day;
				current_date.hour = next_date.hour;
				if (command_line[0].verbose_flag > 0)
					fprintf(stderr,"\n\nYEAR %d MONTH %d DAY %d\n\n",
					current_date.year,current_date.month,current_date.day);
			} /*end if*/
			/*--------------------------------------------------------------*/
			/*			Check if this is a month end.						*/
			/*--------------------------------------------------------------*/
			if ( next_date.month !=	current_date.month ){
				/*--------------------------------------------------------------*/
				/*				Do monthly stuff.								*/
				/*--------------------------------------------------------------*/

				/*--------------------------------------------------------------*/
				/* if fire spread is called - initiate fire spread routine 	*/
				/*--------------------------------------------------------------*/
				if (command_line[0].firespread_flag == 1) {
					execute_firespread_event(
						world,
						command_line,
						current_date);
				}	
				
				/*--------------------------------------------------------------*/
				/*			Perform any requested monthly output				*/
				/*--------------------------------------------------------------*/
				if (command_line[0].output_flags.monthly == 1)
						execute_monthly_output_event(
						world,
						command_line,
						current_date,
						outfile);
				/*--------------------------------------------------------------*/
				/*				increment month 								*/
				/*--------------------------------------------------------------*/
				month = month + 1;
				current_date.month = next_date.month;
			} /* end if */
			/*--------------------------------------------------------------*/
			/*			Check if this is a year end.						*/
			/*--------------------------------------------------------------*/
			if ( next_date.year != current_date.year ){
				/*--------------------------------------------------------------*/
				/*				Do yearly stuff.								*/
				/*--------------------------------------------------------------*/
				
				/*--------------------------------------------------------------*/
				/*				increment year  								*/
				/*-------------------------------------------------------------*/
				printf("Year %d\n", current_date.year);
				year = year + 1;
				current_date.year= next_date.year;
			}  /*end if*/
			} /*end while*/
		} /*end while*/
		return;
} /*end execute_tec.c*/
Пример #2
0
void	handle_event(
					 struct	tec_entry	*event,
					 struct command_line_object *command_line,
					 struct	date	current_date,
					 struct world_object *world)
{
	/*--------------------------------------------------------------*/
	/*	Local Function Declarations.								*/
	/*--------------------------------------------------------------*/
	void	execute_redefine_strata_event(
		struct world_object *,
		struct command_line_object *,
		struct	date);
	void	execute_redefine_world_event(
		struct world_object *,
		struct command_line_object *,
		struct	date);
	void	execute_redefine_world_mult_event(
		struct world_object *,
		struct command_line_object *,
		struct	date);
	void	execute_redefine_world_thin_event(
		struct world_object *,
		struct command_line_object *,
		struct	date,
		int);
	void	execute_road_construction_event(
		struct world_object *,
		struct command_line_object *,
		struct	date);
	void	execute_state_output_event(
		struct world_object *,
		struct date,
		struct date,
		struct command_line_object *);
	/*--------------------------------------------------------------*/
	/*	Local variable definition.									*/
	/*--------------------------------------------------------------*/
	/*--------------------------------------------------------------*/
	/*	Below is a list of events which are caught if present.		*/
	/*	OTHERWISE a fatal error ensues.								*/
	/*--------------------------------------------------------------*/

	if ( !strcmp(event[0].command,"none") ){
		/* nothing here */
	}
	else if ( !strcmp(event[0].command,"print_yearly_on") ){
		command_line[0].output_flags.yearly= 1;
		command_line[0].output_yearly_date.month = current_date.month;
		command_line[0].output_yearly_date.day = current_date.day;
	}
	else if ( !strcmp(event[0].command,"print_yearly_off") ){
		command_line[0].output_flags.yearly= 0;
	}
	else if ( !strcmp(event[0].command,"print_yearly_growth_on")){
		command_line[0].output_flags.yearly_growth = 1;
		command_line[0].output_yearly_date.month = current_date.month;
		command_line[0].output_yearly_date.day = current_date.day;
	}
	else if (  !strcmp(event[0].command,"print_yearly_growth_off")){
		command_line[0].output_flags.yearly_growth = 0;
	}
	else if ( !strcmp(event[0].command,"print_monthly_on") ){
		command_line[0].output_flags.monthly= 1;
	}
	else if ( !strcmp(event[0].command,"print_monthly_off") ){
		command_line[0].output_flags.monthly= 0;
	}
	else if ( !strcmp(event[0].command,"print_daily_on") ){
		command_line[0].output_flags.daily= 1;
	}
	else if ( !strcmp(event[0].command,"print_daily_off") ){
		command_line[0].output_flags.daily= 0;
	}
	else if ( !strcmp(event[0].command,"print_daily_growth_on")){
		command_line[0].output_flags.daily_growth = 1;
	}
	else if ( !strcmp(event[0].command,"print_daily_csv_growth_on")){
		command_line[0].output_flags.daily_growth = 1;
	}
	else if ( !strcmp(event[0].command,"print_daily_csv_on") ){
		command_line[0].output_flags.daily = 1;
	}
	else if ( !strcmp(event[0].command,"print_yearly_csv_on") ){
		command_line[0].output_flags.yearly = 1;
		command_line[0].output_yearly_date.month = current_date.month;
		command_line[0].output_yearly_date.day = current_date.day;
	}
	else if ( !strcmp(event[0].command,"print_monthly_csv_on") ){
		command_line[0].output_flags.monthly = 1;
	}
	else if ( !strcmp(event[0].command,"print_daily_growth_off")){
		command_line[0].output_flags.daily_growth = 0;
	}
	else if ( !strcmp(event[0].command,"print_daily_csv_growth_off")){
		command_line[0].output_flags.daily_growth = 0;
	}
	else if ( !strcmp(event[0].command,"print_daily_csv_off") ){
		command_line[0].output_flags.daily = 0;
	}
	else if ( !strcmp(event[0].command,"print_yearly_csv_off") ){
		command_line[0].output_flags.yearly = 0;
	}
	else if ( !strcmp(event[0].command,"print_monthly_csv_off") ){
		command_line[0].output_flags.monthly = 0;
	}
	else if ( !strcmp(event[0].command,"print_hourly_on") ){
		command_line[0].output_flags.hourly= 1;
	}
	else if ( !strcmp(event[0].command,"print_hourly_off") ){
		command_line[0].output_flags.hourly= 0;
	}
	else if ( !strcmp(event[0].command,"output_current_state") ){
		execute_state_output_event(world, current_date,
			world[0].end_date,command_line);
	}
	else if ( !strcmp(event[0].command,"redefine_strata") ){
		execute_redefine_strata_event(world, command_line, current_date);
	}
	else if ( !strcmp(event[0].command,"redefine_world") ){
		execute_redefine_world_event(world, command_line, current_date);
	}
	else if ( !strcmp(event[0].command,"redefine_world_multiplier") ){
		execute_redefine_world_mult_event(world, command_line, current_date);
	}	
	else if ( !strcmp(event[0].command,"redefine_world_thin_remain") ){
		execute_redefine_world_thin_event(world, command_line, current_date, 1);
	}		
	else if ( !strcmp(event[0].command,"redefine_world_thin_harvest") ){
		execute_redefine_world_thin_event(world, command_line, current_date, 2);
	}		
	else if ( !strcmp(event[0].command,"roads_on") ){
		command_line[0].road_flag = 1;
		execute_road_construction_event(world, command_line, current_date);
	}
	else if ( !strcmp(event[0].command,"roads_off") ){
		command_line[0].road_flag = 0;
	}
	else{
		fprintf(stderr,"FATAL ERROR: in handle event - event %s not recognized.\n",
			event[0].command);
		exit(EXIT_FAILURE);
	}
} /*end handle_event*/