%
% Overlays evolution of a-deck maximum wind speed on WRT-AER event set wind
% speeds. "intensity.m" must be run first. 
%
%  Copyright WindRiskTech, L.L.C., October 2010
%
%--------------------------------------------------------------------------
adeck=input('Use real-time .fst file (1) or adeck file (2)');
if storm(1:2) == 'AL'
    stormlc='al';
elseif storm(1:2) == 'EP'
    stormlc='ep';
elseif storm(1:2) == 'WP'
    stormlc='wp';
elseif storm(1:2) == 'IO'
    stormlc='io';
elseif storm(1:2) == 'SH'
    stormlc='sh';
end
stormnew=storm;
stormnew(1:2)=stormlc;
if adeck == 1
    file=strcat(stormnew,datea(1:4),'.fst');
else
    file=strcat('decks/a',stormnew,datea(1:4),'.dat');
end    
fid=fopen(file,'r');
C=textscan(fid,'%s %f %d %*s %s %d %s %s %f %*[^\n]','delimiter',',');
st=fclose(fid);
bas=C{1};
dates=C{3};
model=C{4};
lead=C{5};
ws=C{8};
nend=max(size(ws));
jbeg=nend;
jend=1;
for j=1:nend,
    TF1=strcmp(model(j,1),'OFCL');
    TF2=strcmp(model(j,1),'JTWC');
    if dates(j,1) == str2num(datea) & (TF1 == 1 | TF2 == 1)
        jbeg=min(j,jbeg);
        jend=max(j,jend);
    end
end  
jsize=jend-jbeg+1;
if jsize < 1
    disp(' ')
    disp('.fst deck for appropriate forecast time not found')
    return
end  
wind=ws(jbeg:jend);
leadtime=lead(jbeg:jend);
year=floor(dates(jbeg:jend)./1e6);
month=floor((dates(jbeg:jend)-1e6.*year)./1e4);
day=floor((dates(jbeg:jend)-1e6.*year-1e4.*month)/1e2);
hour=floor((dates(jbeg:jend)-1e6.*year-1e4.*month-1e2.*day));
%
byear=floor(str2num(datea)./1e6);
bmonth=floor((str2num(datea)-1e6.*byear)./1e4);
bday=floor((str2num(datea)-1e6.*byear-1e4.*bmonth)/1e2);
bhour=floor((str2num(datea)-1e6.*byear-1e4.*bmonth-1e2.*bday));
%
q=max(size(year));
ndate=zeros(1,q);
for i=1:q,
    ndate(i)=datenum(double(year(i)),double(month(i)),double(day(i)),double(hour(i)),0,0);
    ndate(i)=double(ndate(i))+double(leadtime(i))./24.0;
end    
bndate=double(datenum(byear,bmonth,bday,bhour,0,0));
btime=ndate-bndate;
hold on
   k=plot(btime,transpose(wind),'r','linewidth',2);
hold off   
