%
%  This script plots data from files created by skillcalc.m
%
%  Copyright WindRiskTech, L.L.C., 2010
%  K. Emanuel, July, 2010
%  Modified for use at AER, October 2010
%
%-----------------------------------------------------------
%
recalc='n';   % If recalc = 'y', skill is recalculated
%
%-----------------------------------------------------------
%
file=['fields'];
load(file)
%
if recalc == 'y'
    [ni nj]=size(bestwind);
    serr=zeros(ni,nj);
    for i=1:ni,
        for j=1:nj,
            for k=1:max(size(xhist));
            if bestwind(i,j) >= xhist(k)
                kbest=k;
            end
        end    
        if kbest > 0
           serr(i,j)=-sum(vhist(i,j,:).^2)+2.*vhist(i,j,kbest)-1;
        end     
        end
    end
end
%
i=1;
%
%  Specify map projection (see m_map documentation)
%
m_proj('gall-peters','long',[xmin xmax], ...
    'lat',[ymin ymax]);
%
while i < 6
    i=menu('Variable to contour','80 knot probability','Best track peak wind',...
        'Ensemble mean peak wind','Ensemble mean minus best track peak wind',...
        'Skill metric','Exit');
if i == 1
clf
%  Low resolution coastline (faster)
%
%m_coast('patch',[.45 .6 .45],'edgecolor','none');
%
%  Higher resolution coastlines:
%
m_gshhs_l('patch',[.45 .6 .45],'edgecolor','none');
%
set(gca,'color',[.95 .95 1])
%
hold on
m_contour([xmin:xres:xmax],[ymin:yres:ymax],transpose(cumhist(:,:,9)),15)
jj=colorbar;
set(jj,'fontweight','bold')
hold off
m_gridm('fontname','arial','fontsize',11,'fontweight','bold','linestyle','none')
tit1=[storm(1:2) ' ' storm(3:4) ' ' datea(1:4) ' ' datea(5:6) ' ' datea(7:8)...
    ' ' datea(9:10) ' GMT'];
tit2='Probability of peak wind exceeding 80 knots';
title({tit1;tit2},'fontsize',12,'fontweight','bold')
%
elseif i == 2
%
clf
m_gshhs_l('patch',[.45 .6 .45],'edgecolor','none');
%
set(gca,'color',[.95 .95 1])
%
hold on
m_contour([xmin:xres:xmax],[ymin:yres:ymax],transpose(bestwind(:,:)),15)
jj=colorbar;
set(jj,'fontweight','bold')
hold off
m_gridm('fontname','arial','fontsize',11,'fontweight','bold','linestyle','none')
tit1=[storm(1:2) ' ' storm(3:4) ' ' datea(1:4) ' ' datea(5:6) ' ' datea(7:8)...
    ' ' datea(9:10) ' GMT'];
tit2='Best track peak wind (knots)';
title({tit1;tit2},'fontsize',12,'fontweight','bold')
%
elseif i == 3
%    
clf
m_gshhs_l('patch',[.45 .6 .45],'edgecolor','none');
%
set(gca,'color',[.95 .95 1])
%
hold on
m_contour([xmin:xres:xmax],[ymin:yres:ymax],transpose(vplot(:,:)),15)
jj=colorbar;
set(jj,'fontweight','bold')
hold off
m_gridm('fontname','arial','fontsize',11,'fontweight','bold','linestyle','none')
tit1=[storm(1:2) ' ' storm(3:4) ' ' datea(1:4) ' ' datea(5:6) ' ' datea(7:8)...
    ' ' datea(9:10) ' GMT'];
tit2='Mean ensemble wind (knots)';
title({tit1;tit2},'fontsize',12,'fontweight','bold')
%
elseif i == 4
%
clf
m_gshhs_l('patch',[.45 .6 .45],'edgecolor','none');
%
set(gca,'color',[.95 .95 1])
%
hold on
m_contour([xmin:xres:xmax],[ymin:yres:ymax],transpose(vplot-bestwind),15)
jj=colorbar;
set(jj,'fontweight','bold')
hold off
m_gridm('fontname','arial','fontsize',11,'fontweight','bold','linestyle','none')
tit1=[storm(1:2) ' ' storm(3:4) ' ' datea(1:4) ' ' datea(5:6) ' ' datea(7:8)...
    ' ' datea(9:10) ' GMT'];
tit2='Ensemble mean - best track (knots)';
title({tit1;tit2},'fontsize',12,'fontweight','bold')
%
elseif i == 5
%    
clf
m_gshhs_l('patch',[.45 .6 .45],'edgecolor','none');
%
set(gca,'color',[.95 .95 1])
%
hold on
m_contour([xmin:xres:xmax],[ymin:yres:ymax],transpose(serr(:,:)),15)
jj=colorbar;
set(jj,'fontweight','bold')
hold off
m_gridm('fontname','arial','fontsize',11,'fontweight','bold','linestyle','none')
tit1=[storm(1:2) ' ' storm(3:4) ' ' datea(1:4) ' ' datea(5:6) ' ' datea(7:8)...
    ' ' datea(9:10) ' GMT'];
tit2='Error Distribution';
title({tit1;tit2},'fontsize',12,'fontweight','bold')
elseif i == 6
    break
end
end
