2 % runs new cycling routine as much a spossible, run from within direcory
3 % with wrfout file and restart file. Requires fuels.m file
5 % f - string with path to wrfout file
7 % written into restart files
9 cycle = input_num('Which cycle? ',1);
11 if strcmp('t',f(end)) %read saved .mat file
12 w = read_wrfout_tign(f)
13 else %read wrfoutfile directly
14 ts = choose_time_step(f);
15 w = read_wrfout_tign(f,ts);
18 gs = input_num('What grid spacing?',250)
19 %make the path structure
20 ps1 = cluster_paths(w,1,gs);
21 savestr = sprintf('ps_%d.mat',cycle);
23 %new points interpolated along the paths
24 ps = interp_paths(ps1,0.9);
27 %make analysis fire arrival time
29 %avg ROS in the forecast and data estimate, adjr0 is experimental
30 %adjustment factor for adjr0 in namelist.fire
31 [r1,r2,adjr0,outer] = cone_compare(ps,tn);
32 fprintf('Forecast ROS: %f \n Data ROS: %f \n',r1,r2)
33 %compare forecast fire area with analysis fire area
34 area_diff = outer.a1-outer.a2;
36 %load fuel information from the wrfout
38 %figure,plot(fuel(2).fmc_g,fuel(2).ros_fmc_g);
39 %find most common fuel type in burned area
40 w.nfuel_cat(w.nfuel_cat==14) = NaN;
41 msk = w.tign_g<max(w.tign_g(:));
42 common_fuel = mode(w.nfuel_cat(msk));
43 %find fmc as a function of ROS
44 fitter = fit(fuel(common_fuel).ros_fmc_g',fuel(common_fuel).fmc_g','cubicspline');
45 %how much to adjust the fmc by
46 %need to adjust for slope of terrain, right now just use 1/2 of the
48 fmc_adjust = 1/2*(fitter(r2)-fitter(r1));
50 fprintf('Adjusting fuels by %f percent\n',fmc_adjust);
51 %adjiust fuel gloabally for starters
53 % put analysis fire arrival time struct
54 new_w = insert_analysis(w,ps,tn);
57 %restart with wrfinput file
59 domain = input_num('Which wrfinput_d0x file to write FMC into? x = 1 ',1)
60 rst = [wi,num2str(domain)];
61 rst_bak = [rst,'.bak'];
62 cpy_str = sprintf('cp %s %s',rst,rst_bak);
65 %restart with wrfrst file
68 fprintf('%d : %s\n',i,d(i).name)
70 r = input_num('Which restart file to use?',1)
72 rst_bak = [rst,'.bak'];
73 cpy_str = sprintf('cp %s %s',rst,rst_bak);
75 %copy the file used for the restart
77 %restart from the analysis
78 ncreplace(rst,'TIGN_G',new_w.analysis);
79 %only change fmc content if a bigger fire has a bigger ROS
80 if ros_diff*area_diff>0
81 fmc_change(fmc_adjust,rst);
83 fprintf('Linking new namelist.input file\n')
85 fprintf('All done. Copy files to directories and restart WRF-SFIRE\n');