matlab
[wrffire.git] / other / Matlab / impact / add_tign_col.m
blob48e66faf67b85e86478a1fb472320cbde3cb9f49
1 function out=add_tign_col(raw,t)
2 % out=add_tign_col(raw,t)
3 % Input:
4 %    raw    spreadsheed loaded by [num,txt,raw]=xlsread('filename.xls')
5 %           row 1 are headings
6 %           column 1 is latitude
7 %           column 2 is longitude
8 %    t      structure created from wrfout as follows:
9 %           t=read_wrfout_tign('wrfout...')
10 %           save t, copy t.mat to another computer if needed, load t
11 % Output:
12 %    out    cell array ready to be written to csh file by
13 %           cell2csv(out,'filename.csv')
14 %           One column is added with the fire arrival time.
15 %           Load the csv file into excel and change the format of the
16 %           column to "Time"
17 %           Copy the other columns from the original file if needed.
19 % Usage:
20 %    load t
21 %    [num,txt,raw]=xlsread('AssetsDB-20170216.xls');
22 %    out=add_tign_col(raw,t);
23 %    cell2csv(out,'AssetsDB.csv')
25 graphics=0;
27 insert_col_pos=3; % number of the column to add 
28 end_times=t.times(end,:);
29 end_datenum = datenum(end_times); % in days from some instant in the past
30 end_minutes=t.xtime(end); % from simulation start
31 start_datenum=end_datenum-end_minutes/(24*60);
32 fprintf('Simulation start %s UTC\n',datestr(start_datenum,0));
33 fprintf('Simulation end   %s UTC\n',datestr(end_datenum,0));
34 [m,n]=size(raw);
35 out=cell(m,n+1);
36 out(:,1:insert_col_pos-1)=raw(:,1:insert_col_pos-1);
37 out(:,insert_col_pos+1:end)=raw(:,insert_col_pos:end);
38 out(1,insert_col_pos)={'Time burned'};
39 lats=cell2mat(raw(2:end,1));
40 lons=cell2mat(raw(2:end,2));
41 tign=gridinterp(t.fxlat,t.fxlong,t.tign_g,lats,lons);
43 if (graphics),
44 disp('drawing')
45 clf
46 %h=mesh(t.fxlat,t.fxlong,t.tign_g);
47 %alpha=0.1;set(h,'EdgeAlpha',alpha,'FaceAlpha',alpha)
48 hold off
49 h=contour3(t.fxlat,t.fxlong,t.tign_g,[0:4*3600:max(tign)],'b');
50 hold on 
51 plot3(lats,lons,tign,'k*')
52 hold off
53 grid on
54 drawnow
55 end
57 burn_datenum = start_datenum + tign/(24*60*60);
58 for i=1:length(lats)
59     fprintf('lat=%8.4f long=%8.4f tign=%g',lats(i),lons(i),tign(i))
60     %plot(lats(i),lons(i),'k*'),drawnow
61     if isnan(burn_datenum(i)) | burn_datenum(i) >= end_datenum-1/100,
62         burn_datestr{i}='';
63     else
64         burn_datestr{i} = datestr(burn_datenum(i),'yyyy-mm-dd HH:MM:SS');
65     end
66     fprintf(' %s\n',burn_datestr{i})
67 end
68 out(2:end,insert_col_pos)=burn_datestr;
69     % disp(out(i+1,:))
70 end