%
%  This script plots time series of wind speed and direction at a given 
%  point of interest, specified by maximum lifetime wind, by maximum wind at 
%  the point of interest or the intersection points of tracks with a 
%  specified set of line segments, or by track number. The script "Prep" 
%  must be run first.  K. Emanuel, November 2008
%  Copyright 2009 WindRiskTech L.L.C.; Last modified January 2011
%
%-------------------------------------------------------------------------
%
nswitch=input('Order by city maximum (1), storm maximum (2), or track number (3)?');
clear x* y* u* v* date offset pres daym hour
nttemp=input('Input track number');
plat=input('Enter point latitude');
plong=input('Enter point longitude');
if plong < 0
    plong=plong+360;
end    
%
shape='circ';
load('temp.mat')
fs3=['sorted'];
load(fs3)
%
if nswitch == 1
   nt=nsortp(nttemp);
elseif nswitch == 2   
   nt=nsort(nttemp);
else
   nt=nttemp;
end   
%
clear vs dir dayk
[ut,vt,jmax] = utrans(latstore(nt,:),longstore(nt,:));
[vs, dir, dayk] = pointseries(latstore(nt,:),longstore(nt,:),vstore(nt,:),rmstore(nt,:), ...
         monthstore(nt,:),daystore(nt,:),hourstore(nt,:),ut(nt,:),vt(nt,:),jmax,plat,plong);
vloc=max(vs);
%
if sum(vs(nt,:)) == 0
    disp('This storm does not affect point in question')
else
%
[ax,h1,h2]=plotyy(dayk,vs,dayk,dir);
yvmax=10.*ceil(0.1.*max(vs))+10;
set(ax(1),'YLim',[0 yvmax ])
set(ax(1),'Ytick',[0:10:yvmax])
set(ax(2),'YLim',[0 360])
set(ax(2),'Ytick',[0 90 180 270 360])
set(h1,'linewidth',3)
set(h2,'linestyle','none')
set(h2,'marker','.')
set(h2,'markersize',10)
set(ax(1),'fontweight','bold','fontsize',12)
set(ax(2),'fontweight','bold','fontsize',12) 
set(ax(1),'XLim',[dayk(1) dayk(end)])
set(ax(2),'XLim',[dayk(1) dayk(end)])
datetick(ax(1),'x','HH:MM')
datetick(ax(2),'x','HH:MM')
%
month1=datestr(dayk(1),'mmmm');
month2=datestr(dayk(end),'mmmm');
day1=datestr(dayk(1),'dd');
day2=datestr(dayk(end),'dd');
ntstring=num2str(nt);
titstring2=['Track number ' ntstring  ];
titstring3=[month1 ' ' day1 ' - ' month2 ' ' day2];
set(get(ax(1),'Ylabel'),'String','Point wind speed (knots)','fontweight','bold','fontsize',12)
set(get(ax(2),'Ylabel'),'String','Point wind direction','fontweight','bold','fontsize',12)
xlabel(titstring3,'fontsize',12,'fontweight','bold')
title(titstring2,'fontsize',12,'fontweight','bold')
%
end
