1 function cycles(varargin)
3 base_datestr='2013-08-11 00:00:00';
4 base=datenum(base_datestr);
6 spinup_time=ones(1,num_cycles);
7 cycle_length=ones(1,num_cycles);
8 cycle_start =[0,2,3,4,5,6]
9 spinup_time =[2,1,1,1,1,1]
10 times_format='yyyy-mm-dd_HH:MM:SS';
12 t(i).forecast_time=cycle_start(i+1)+1;
13 t(i).obs_start=cycle_start(i);
14 t(i).obs_end=cycle_start(i+1)-1e-6;
15 t(i).replay_start=cycle_start(i);
16 t(i).replay_end=cycle_start(i+1);
17 t(i).run_end=cycle_start(i+1)+2;
18 t(i).perimeter_time=t(i).replay_end*24*3600;
19 forecast_times{i}=datestr(base+t(i).forecast_time,times_format);
28 i=input_num('cycle number',1);
32 link_namelist_command=sprintf('rm -f namelist.input; ln -s namelist.input_%i namelist.input',i);
34 fprintf('Initial simulation from %s to at least %s\n',base_datestr,forecast_times{1})
35 fprintf('Execute %s now?\n',link_namelist_command);
36 if input_num('0/1',1,force)
37 if system(link_namelist_command),
41 disp('Run WRF-SFIRE and continue when done\n')
45 system('ls -l wrfout*')
46 wrfout_time = base+t(i).forecast_time;
47 wrfout{i}=['wrfout_d01_',datestr(wrfout_time,times_format)];
48 if ~exist(wrfout{i},'file')
49 fprintf('file %s does not exist\n',wrfout{i})
50 wrfout_time = wrfout_time - 23.5/24; % no wrfout produced on restart => written 30 min later
51 wrfout{i}=['wrfout_d01_',datestr(wrfout_time,times_format)];
53 wrfrst{i}=['wrfrst_d01_',datestr(base+t(i).replay_start,times_format)];
54 fprintf('%s %s %s %s\n','Reading fire arrival time at',forecast_times{i},' from ',wrfout{i})
55 if t(i).replay_start==0;
56 rewrite='wrfinput_d01';
62 fprintf('%s %s\n','Will write modified time into ',rewrite)
63 rewrite_bak=[rewrite,'.bak'];
64 q=input_num(['1 to copy ',rewrite,' to ',rewrite_bak],1,force);
66 if system(['cp ',rewrite,' ',rewrite_bak]),
67 warning('copy failed')
70 w=read_wrfout_tign(wrfout{i},forecast_times{i});
71 wrfout_bak=[wrfout{i},'.bak'];
72 q=input_num(['1 to move ',wrfout{i},' to ',wrfout_bak],1,force);
74 movefile(wrfout{i},wrfout_bak);
76 time_bounds=[t(i).obs_start,t(i).obs_end,t(i).replay_start,t(i).replay_end]+base;
77 savew=sprintf('w_%i',i);
78 fprintf('saving to %s\n',savew)
80 save(savew,'w','cycle','time_bounds','t')
81 p=detect_fit_level2(cycle,time_bounds,[],w,force)
82 fprintf('Saving p\n');
83 pstr = sprintf('p_%i.mat',i);
86 fprintf('perimeter_time=%10.3f\nrestart=%s\n',t(i).perimeter_time,restart)
87 q=sprintf('replace TIGN_G in %s and run\n %s\n [0/1]',rewrite,link_namelist_command);
88 if input_num(q,1,force)
89 use_analysis = input_num('Use analyis for restart? [0]',0,1)
91 p.analysis= max(p.forecast,p.analysis);
92 p.spinup = p.analysis;
94 ncreplace(rewrite,'TIGN_G',p.spinup)
95 if system(link_namelist_command),
99 %compute ros adjustment factor
100 %ra = ros_adjust(p.forecast,p.analysis,p.observations_end_time,w.nfuel_cat);
101 %fprintf('Recomended ROS adjust factor: %f \n',r disp('Run WRF-SFIRE and continue when done\n')
104 function print_times(ii)
105 ptime(ii,'Forecast used ',t(ii).forecast_time)
106 ptime(ii,'Observations start',t(ii).obs_start)
107 ptime(ii,'Observations end ',t(ii).obs_end)
108 ptime(ii,'Replay start ',t(ii).replay_start)
109 ptime(ii,'Replay end ',t(ii).replay_end)
110 ptime(ii,'Run end ',t(ii).run_end)
111 fprintf('perimeter_time=%10.3f\n',t(ii).perimeter_time)
114 function print_times_table
115 fmt=' %g %g %g %g %g\n';
116 fprintf(['Cycle ',fmt],1:length(t))
117 fprintf(['Forecast used ',fmt],t(:).forecast_time)
118 fprintf(['Observations start',fmt],t(:).obs_start)
119 fprintf(['Observations end ',fmt],t(:).obs_end)
120 fprintf(['Replay start ',fmt],t(:).replay_start)
121 fprintf(['Replay end ',fmt],t(:).replay_end)
122 fprintf(['Run end ',fmt],t(:).run_end)
125 function ptime(ii,s,t)
126 fprintf('Cycle %i %s%7.3f days %s\n',ii,s,t,datestr(t+base,'dd-mmm-yyyy HH:MM:SS'))