% fvelip.m
% routine to find velocities from Georges Bank current meter time series
% for a given time (in decimal year-day).
% this version produces a plot of the velocities on a base map
function fvelip(ydi)
load /home3/ocn/jmanning/gbs95/moor/mfiles/jimc/allvel
%ydi = input(' enter year-day 1995: ');
latst1 = 40 + (51.846/60);
lonst1 = -(67 + (33.525/60));
latst2 = 40.9560;
lonst2 = -67.6264;
latnep = 41.7335;
lonnep = -66.5383;
latnec = 42.2982;
lonnec = -65.8385;

% current parameters

vare = ['st1u05';'st1u62';'st1u68';'st2u15';'st2u35';'st2u62'];
vare = [vare;'nepu23';'nepu37';'nepu59'];
vare = [vare;'ncu023';'ncu048';'ncu099';'ncu149';'ncu191'];

varn = ['st1v05';'st1v62';'st1v68';'st2v15';'st2v35';'st2v62'];
varn = [varn;'nepv23';'nepv37';'nepv59'];
varn = [varn;'ncv023';'ncv048';'ncv099';'ncv149';'ncv191'];


vart = ['st1taa';'st1taa';'st1taa';'st2t15';'st2t35';'st2t62'];
vart = [vart;'neptaa';'neptaa';'neptaa'];
vart = [vart;'nchtaa';'nchtaa';'nchtaa';'nchtaa';'nchtaa'];

lat = [latst1 latst1 latst1 latst2 latst2 latst2];
lat = [lat latnep latnep latnep latnec latnec latnec latnec latnec];

lon = [lonst1 lonst1 lonst1 lonst2 lonst2 lonst2];
lon = [lon lonnep lonnep lonnep lonnec lonnec lonnec lonnec lonnec];
dep = [5 62 68 15 35 62 23 37 59 23 48 99 149 191];

% wind stress parameters

varews = ['st1ews'];
varnws = ['st1nws'];
vartws = ['st1tws'];
latws =  [41.7];
lonws =  [-67.4];

%
% find velocities at specified time
%
numt = length(lat);
for iv = 1:numt
 eval(['tim = ' vart(iv,:) ';']);
 if(ydi>tim(length(tim)))
  ve(iv) = nan;
  vn(iv) = nan;
 else
  str = ['ve(iv) = interp1(tim,' vare(iv,:) ',ydi);'];
  eval(str);
  str = ['vn(iv) = interp1(tim,' varn(iv,:) ',ydi);'];
  eval(str);
 end
end
%
% find wind stress at specified time
%
numtws = length(latws);
for iv = 1:numtws
 eval(['tim = ' vartws(iv,:) ';']);
 if(ydi>tim(length(tim)))
  wse(iv) = nan;
  wsn(iv) = nan;
 else
  str = ['wse(iv) = interp1(tim,' varews(iv,:) ',ydi);'];
  eval(str);
  str = ['wsn(iv) = interp1(tim,' varnws(iv,:) ',ydi);'];
  eval(str);
 end
end

% plot results

aspro = 0.76;
stylev = 1;                            % current arrow style etc.
origin = 1;
latcv = 0.018;
loncv = latcv*aspro;

plot(lon,lat,'+')
for iv = 1:numt;
 arrowm(lon(iv),lat(iv),ve(iv),vn(iv),stylev,origin,loncv,latcv);
end

stylew = -1;                            % wind stress arrow style etc.
latcw = 0.075;
loncw = latcw*aspro;
for iv = 1:numtws
 arrowm(lonws(iv),latws(iv),wse(iv)*10,wsn(iv)*10,stylew,origin,loncw,latcw)

% add text for actual wind level
 ws2=sqrt(wse(iv)^2+wsn(iv)^2);
 ws3=floor(ws2*100)/100.
 sctex = [num2str(ws3) ' dyn'];
 text(-67.4,41.55,sctex,'fontangle','italic','fontsize',12,...
  'horizontalalignment','center','verticalalignment','bottom',...
  'fontweight','demi')
 
end


% plot scale arrows

 alim=axis;
 vesc = 10;
 vnsc = 0;
 xar = alim(2) - 1.85*loncv*vesc;
 yar = alim(3) + 0.18*(alim(4)-alim(3));
% arrowm(xar,yar,vesc,vnsc,stylev,origin,loncv,latcv);
 arrowm(-68,41.7,vesc,vnsc,stylev,origin,loncv,latcv);
 sctex = [int2str(vesc) 'cm/s'];
 xtex = xar + 0.5*loncv*vesc;
 ytex = yar+ 0.025*(alim(4)-alim(3));
% text(xtex,ytex,sctex,'fontangle','italic','fontsize',12,...
 text(-68,41.55,sctex,'fontangle','italic','fontsize',12,...
  'horizontalalignment','center','verticalalignment','bottom',...
  'fontweight','demi')

 wesc = 2;
 wnsc = 0;
 xar = alim(2) - 1.95*loncw*wesc;
 yar = alim(3) + 0.02*(alim(4)-alim(3));
% arrowm(xar,yar,wesc,wnsc,stylew,origin,loncw,latcw);
% arrowm(-68,41.45,wesc,wnsc,stylew,origin,loncw,latcw);
 sctex = [int2str(wesc) 'dy'];
 xtex = xar + 0.5*loncw*wesc;
 ytex = yar+ 0.025*(alim(4)-alim(3));
% text(xtex,ytex,sctex,'fontangle','italic','fontsize',12,...
% text(-68,41.3,sctex,'fontangle','italic','fontsize',12,...
%  'horizontalalignment','center','verticalalignment','bottom',...
%  'fontweight','demi')



 