1 function [fxlong,fxlat,fire_area]=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 : coordinate in the wrfout array, that needs to be computed
11 % example FXLAT(:,:,time)
13 % long = FXLONG, longtitude coordinates of the mesh converted to (m)
14 % lat = FXLAT, latitude coordinates of the mesh converted to (m)
15 % fire_area = fire map,[0,1] array, where 0- not
16 % burning area, >0 burning area, 1 - area that was burnt
17 % If input_type=1, then fire_area - set of ordered points
18 % of the boundary 1st=last;
19 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
21 datafile=sprintf('data_%s_%i_%i',wrfout,time,input_type);
22 global saved_data % 0 = read from original files and store in matlab files, 1=read saved data
23 disp(['read_file_perimeter time=',num2str(time),' input_type=',num2str(input_type)]);
30 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT'},{},time);
31 q=nc2struct(wrfout_fire,{'FIRE_AREA'},{},time);
32 save(datafile,'p','q')
34 fire_area=q.fire_area;
35 fxlong=p.fxlong*p.unit_fxlong;
36 fxlat=p.fxlat*p.unit_fxlat;
37 elseif (input_type==1)
42 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT'},{},time);
45 fxlong=p.fxlong*p.unit_fxlong;
46 fxlat=p.fxlat*p.unit_fxlat;
47 fire_area=read_perim_from_file(input_file,fxlong,fxlat,p.unit_fxlong,p.unit_fxlat);
50 fid = fopen('output_fire_area.txt', 'w');
51 dlmwrite('output_fire_area.txt', fire_area, 'delimiter', '\t','precision', '%.4f');
53 elseif (input_type==2)
55 disp(['loading from ',datafile])
59 p=nc2struct(wrfout,{'UNIT_FXLONG','UNIT_FXLAT','FXLONG','FXLAT'},{},time);
60 disp(['storing to ',datafile])
63 disp(['reading fire_area_big from ',input_file])
64 fire_area_big=dlmread(input_file);
65 fxlong=p.fxlong*p.unit_fxlong;
66 fxlat=p.fxlat*p.unit_fxlat;
67 fire_area=zeros(size(fire_area_big(:,1:2)));
68 fire_area(:,1)=fire_area_big(:,1)*p.unit_fxlong;
69 fire_area(:,2)=fire_area_big(:,2)*p.unit_fxlat;
70 %fire_area=fire_area_big(:,1:2);
76 % Input data : String - data, that contains the name of the Text file.
77 % First 2 columns - coordinates of all the
78 % points on the boundary (lon,lat).
79 % 1rt row - time_now (second number is not needed, is set to 0);
80 % 2nd row - size of the mesh;
81 % 3rd row - coordinates of ignition point;
82 % All next rows - coordinates of all the
83 % points on the boundary (lon,lat). %
84 % Output bound - set of ordered points of the boundary 1st=last
85 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
88 function IN=read_perim_from_file(data,long,lat,unit_long,unit_lat)
90 bound = fscanf(fid,'%9g %*1s %8g %*3s',[2 inf]);
91 % bound - set of ordered points of the boundary 1st=last
92 % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
97 bound(:,1)=bound(:,1)*unit_long;
98 bound(:,2)=bound(:,2)*unit_lat;
106 [IN,ON] = inpolygon(long1,lat1,xv,yv);