1 function [t,d]=propagate(t,d,dir,fire_area,fire_mask,distance,ros,time_end,print)
2 % [t,d]=propagate(t,d,dir,fire_area,fire_mask,distance,ros,time_end,print)
3 % t(i,j,2,2) fire arrival time location (i,j)
4 % t(i,j,a,b) fire arrival time at a point on the line connecting (i,j) and (i+a-1,j+b-1)
5 % t(i,j,:,:) =fire arrival time given at (i,j) at start
6 % d(i,j,a,b) distance remaining to (i+a-1,j+b-1), in proper units
7 % dir - 1 time forward, -1 backward
8 % fire_area - 1 what can burn, 0 what not
9 % fire_mask - 1 can propagate from there, 0 -ignore
10 % distance(m,n,a,b) - distance on (i,j) and (i+a-1,j+b-1)
11 % ros(m,n,a,b) - rate of spread
12 % time_end - the latest time to propagate to (earliest if dir=-1)
13 % print 1 for tracing steps, 2 for detailed
15 if abs(dir) ~= 1, error('dir must be +-1'),end
16 if print>1,,tign=t(:,:,2,2),end
17 m=size(t,1);n=size(t,2);
18 if ~exist('print','var'),
21 active=dir*(time_end-t(:,:,2,2))>0;
22 for step=1:10*max(m,n),
26 if active(i,j) & fire_mask(i,j),
31 fprintf('step %i point %i %i direction %i %i time %g ',step,i,j,a-2,b-2,t(i,j,a,b));
33 dt = max(dir*(time_end-t(i,j,a,b)),0); % time available to time)end
35 dd = dt.*ros(i,j,a,b); % distance to travel until time_end
36 if d(i,j,a,b)> dd, % positive distance remains
37 t(i,j,a,b)=time_end; % the end of the segment traveled is at time_now
38 d(i,j,a,b)= d(i,j,a,b)-dd; % decrease the distances remaining
40 fprintf('distance remaining %g time %g',d(i,j,a,b),t(i,j,a,b));
43 t_end=t(i,j,a,b)+dir*d(i,j,a,b)./ros(i,j,a,b); % time at the segment end if print>1,
45 fprintf('time at end %g ',t_end);
47 ii=i+a-2; % the grid point this end point coincides with
49 if ii>=1 & ii<=m & jj>=1 & jj<=n & fire_area(ii,jj)
51 val=min(t(ii,jj,2,2),t_end);
53 val=max(t(ii,jj,2,2),t_end);
56 fprintf('setting %i %i from %g to %g',ii,jj,t(ii,jj,2,2),val);
58 t(ii,jj,:,:)=val; % reinitialize the point ii, jj
59 d(ii,jj,:,:)=distance(ii,jj,:,:); % no distance traveled
60 active(ii,jj)=true; % can propagate from this
76 change=norm(t(:)-t_old(:),1);
80 fprintf('step %i tign min %g max %g change %g\n',step,mint,maxt,change)
82 if print>1,tign=t(:,:,2,2),end