1 function [fxlong,fxlat,fire_perimeter,timestep_end]=read_file_perimeter(wrfout,wrfout_fire,time,input_type,input_file)
2 % Volodymyr Kondratenko April 3 2012
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % Input: wrfout : String with the name of the wrfout file,
7 % It is needed for reading the latitude and longtitude
8 % coordinates of the mesh and also UNIT_FXLONG and
10 % time : time step index in the wrfout (last index)
11 % example FXLAT(:,:,time)
13 % p structure with various fiels
14 % long = FXLONG, longtitude coordinates of the mesh converted to (m)
15 % lat = FXLAT, latitude coordinates of the mesh converted to (m)
16 % fire_area = fire map,[0,1] array, where 0- not
17 % burning area, >0 burning area, 1 - area that was burnt
18 % If input_type=1, then fire_area - set of ordered points
19 % of the boundary 1st=last;
20 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
22 datafile=sprintf('data_%s_%i_%i',wrfout,time,input_type);
23 global saved_data % 0 = read from original files and store in matlab files, 1=read saved data
24 disp(['read_file_perimeter time=',num2str(time),' input_type=',num2str(input_type)]);
27 error('not supported')
32 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT','Times','ITIMESTEP'},{'DT'},time);
33 q=nc2struct(wrfout_fire,{'FIRE_AREA'},{},time);
34 save(datafile,'p','q')
36 fire_area=q.fire_area;
37 fxlong=p.fxlong*p.unit_fxlong;
38 fxlat=p.fxlat*p.unit_fxlat;
39 elseif (input_type==1)
40 error('not supported')
45 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT'},{},time);
48 fxlong=p.fxlong*p.unit_fxlong;
49 fxlat=p.fxlat*p.unit_fxlat;
50 fire_area=read_perim_from_file(input_file,fxlong,fxlat,p.unit_fxlong,p.unit_fxlat);
53 fid = fopen('output_fire_area.txt', 'w');
54 dlmwrite('output_fire_area.txt', fire_area, 'delimiter', '\t','precision', '%.4f');
56 elseif (input_type==2)
58 disp(['loading from ',datafile])
62 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT','ITIMESTEP'},{'DT','DX','DY'},time);
63 disp(['storing to ',datafile])
66 disp(['reading fire_perimeter_big from ',input_file,' frame ',num2str(time)])
67 fire_perimeter_big=dlmread(input_file);
68 fxlong=p.fxlong*p.unit_fxlong;
69 fxlat=p.fxlat*p.unit_fxlat;
70 fire_area=zeros(size(fire_perimeter_big(:,1:2)));
71 fire_perimeter(:,1)=fire_perimeter_big(:,1)*p.unit_fxlong;
72 fire_perimeter(:,2)=fire_perimeter_big(:,2)*p.unit_fxlat;
73 timestep_end=p.itimestep*p.dt;
74 %fire_area=fire_area_big(:,1:2);
80 % Input data : String - data, that contains the name of the Text file.
81 % First 2 columns - coordinates of all the
82 % points on the boundary (lon,lat).
83 % 1rt row - time_now (second number is not needed, is set to 0);
84 % 2nd row - size of the mesh;
85 % 3rd row - coordinates of ignition point;
86 % All next rows - coordinates of all the
87 % points on the boundary (lon,lat). %
88 % Output bound - set of ordered points of the boundary 1st=last
89 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
92 function IN=read_perim_from_file(data,long,lat,unit_long,unit_lat)
94 bound = fscanf(fid,'%9g %*1s %8g %*3s',[2 inf]);
95 % bound - set of ordered points of the boundary 1st=last
96 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
101 bound(:,1)=bound(:,1)*unit_long;
102 bound(:,2)=bound(:,2)*unit_lat;
110 [IN,ON] = inpolygon(long1,lat1,xv,yv);