1 function A=ignition7(data,wrf_out)
3 % The function Ignition plots and showes how the fire was propagating,
4 % given ignition point, boundary region and time_now
5 % Input: String - data, that contains the name of the Text file.
6 % First 2 columns - coordinates of all the
7 % points on the boundary (lon,lat).
8 % 1rt row - time_now (second number is not needed, is set to 0);
9 % 2nd row - size of the mesh;
10 % 3rd row - coordinates of ignition point;
11 % All next rows - coordinates of all the
12 % points on the boundary (lon,lat).
14 % Output: Matrix of time of ignition
17 % Volodymyr Kondratenko February 17 2011
18 %--------------------------------------
19 % Command line: what to do to call the function
20 %--------------------------------------
22 % This code is done for the real case for the witch_fire
23 % put the file and data.txt in the run folder
25 % addpath ../../other/Matlab/util1_jan
26 % addpath ../../other/Matlab/netcdf
27 addpath('../../other/Matlab/util1_jan');
28 addpath('../../other/Matlab/netcdf');
30 % wrf_out='wrfout_d01_2007-10-21_12:00:00_real'; // or if you use another wrf_out, that you have
31 % B=ignition6(data,wrf_out);
36 % 1st row - # of latitude rows
37 % 2nd row - # of longtitude
38 % Rest coordinates of the grid points
41 unit_long=ncread(wrf_out,'UNIT_FXLONG');
42 unit_lat=ncread(wrf_out,'UNIT_FXLAT');
43 unit_long=unit_long(1);
45 long=ncread(wrf_out,'FXLONG');
46 lat=ncread(wrf_out,'FXLAT');
55 data = fscanf(fid,'%g %g',[2 inf]); % It has two rows now.
60 time_now=data(1,1); % time of ignition on the boundary
61 mesh_size=data(2,:); % size of the matrix
62 ign_pnt=data(3,:); % coordinates of the ignition point
63 ign_pnt(1)=ign_pnt(1)*unit_long;
64 ign_pnt(2)=ign_pnt(2)*unit_lat;
65 bound=data(4:data_size(1),:);
66 bound(:,1)=bound(:,1)*unit_long;
67 bound(:,2)=bound(:,2)*unit_lat;
69 % bound - set of ordered points of the boundary 1st=last
70 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
73 B=zeros(mesh_size); % "time of ignition matrix" of the nodes
74 % Ignition point corresponds to B()=0
75 C=zeros(mesh_size); % Matrix of distances from ignition point to all points
78 % IN - matrix that shows, whether the point is inside (IN(x,y)>0) the burning region
79 % or outside (IN(x,y)<0)
80 % ON - matrix that, shows whether the point is on the boundary or not
81 % Both matrices evaluated using "polygon"
88 [IN,ON] = inpolygon(long1,lat1,xv,yv);
95 % Calculation of the matrix of distances
96 % || ( (coord_xf(i,j) - x)*unit_xf , (coord_yf(i,j) - y)*unit_yf ) ||
97 % unit_fxlat=pi2/(360.*reradius)
98 % unit_fxlong=cos(lat_ctr*pi2/360.)*unit_fxlat
99 % lat_ctr=config_flags%cen_lat
100 %reradius, & ! 1/earth radiusw
105 % C(i,j)=sqrt((unit_long(1,1,1)*(long(i)-ign_pnt(1)))^2+(unit_lat(1,1,1)*(lat(i)-ign_pnt(2)))^2);
109 %--------------------------------------------------------------------%
111 %--------------------------------------------------------------------%
113 % For each point in the burning area, we
114 % a) Build a line through this point and ignition point
115 % b) Find two(or one) points between which, line intersects boundary area,
116 % should be 2 variants
117 % This is done by checking the F(x,y)=(y-y1)*(x2-x1)-(x-x1)*(y2-y1)
118 % Needed points are that satisfy 2 conditions:
119 % 1) they are sequential;
120 % 2) F(x1,y1)*F(x2,y2)<0
121 % (In ase with one point, F(x,y)=0)
122 % c) Find out which side is right (from 2 possible choices of points)
124 % d) Compute tign of the point by using Thales's theorem
125 % (it is not the same as on Wikipedia, see the link below, page 4)
126 % http://legacy.lclark.edu/~istavrov/geo-minithales-07.pdf
133 if (ON(i,j)>0) % The point we check is on the boundary
136 elseif IN(i,j)>0 % The point is inside the burning region
137 a_old=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(1,1),bound(1,2));
139 while (k>0)&&(k<=bnd_size(1))
144 a_new=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(k,1),bound(k,2));
147 % Check if the point is on the line between
148 % the ignition point and 2 boundary points
149 a1=line_sign(long(i,j,1),lat(i,j,1),bound(k,1),bound(k,2),ign_pnt(1),ign_pnt(2));
150 a2=line_sign(long(i,j,1),lat(i,j,1),bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2));
153 dist1=line_dist(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),ign_pnt(1),ign_pnt(2));
154 dist2=line_dist(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),long(i,j,1),lat(i,j,1));
155 B(i,j)=time_now*(dist1-dist2)/dist1;
159 % Case if the line goes exactly through the boundary point
160 % Check if the point lies between ignition point and boundary point
161 b1=sqrt((long(i,j,1)-ign_pnt(1))^2+(lat(i,j,1)-ign_pnt(2))^2);
162 b2=sqrt((long(i,j,1)-bound(k,1))^2+(lat(i,j,1)-bound(k,2))^2);
163 b3=sqrt((bound(k,1)-ign_pnt(1))^2+(bound(k,2)-ign_pnt(2))^2);
164 if (b1+b2<b3+eps)&&(b1+b2>b3-eps)
165 B(i,j)=time_now*b1/b3;
168 a_new=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(k+1,1),bound(k+1,2));
177 % point is outside the burning region
179 a_old=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(1,1),bound(1,2));
181 while (k>0)&&(k<=bnd_size(1))
186 a_new=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(k,1),bound(k,2));
189 % The point and second boundary point should be on the
190 % same side from the line going between ignition point
191 % and first boundary point
192 a1=line_sign(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),ign_pnt(1),ign_pnt(2));
193 a2=line_sign(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),long(i,j,1),lat(i,j,1));
195 dist1=line_dist(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),ign_pnt(1),ign_pnt(2));
196 b1=sqrt((long(i,j,1)-ign_pnt(1))^2+(lat(i,j,1)-ign_pnt(2))^2);
197 % dist2=line_dist(bound(k,1),bound(k,2),bound(k-1,1),bound(k-1,2),long(i,j,1),lat(i,j,1));
198 B(i,j)=time_now*b1/dist1;
203 % Case if the line goes exactly through the boundary point
204 % Check if the boundary point lies between ignition point and the point
205 b1=sqrt((long(i,j,1)-ign_pnt(1))^2+(lat(i,j,1)-ign_pnt(2))^2);
206 b2=sqrt((long(i,j,1)-bound(k,1))^2+(lat(i,j,1)-bound(k,2))^2);
207 b3=sqrt((bound(k,1)-ign_pnt(1))^2+(bound(k,2)-ign_pnt(2))^2);
208 if (b2+b3<b1+eps)&&(b2+b3>b1-eps)
209 B(i,j)=time_now*b1/b3;
212 a_new=line_sign(ign_pnt(1),ign_pnt(2),long(i,j,1),lat(i,j,1),bound(k+1,1),bound(k+1,2));
224 % check if ign_pnt(1), ign_pnt(2) - integers,
225 % than set B(ignition point)=0
226 if (rem(ign_pnt(1),1)==0) && (rem(ign_pnt(2),1)==0)
227 B(ign_pnt(1),ign_pnt(1))=0;
230 % Writing the data to the file data_out.txt
231 fid = fopen('data_out.txt', 'w');
232 dlmwrite('data_out.txt', B, 'delimiter', '\t','precision', '%.4f');
235 write_array_2d('data_out1.txt',B)
240 % questio: if ignition point coordinates are real and not on the mesh, than
241 % plot will not print them