function [xx,yy,uu,vv]=octavec(lon,lat,u,v,iskip,amp);
% function [xx,yy,uu,vv]=octavec(lon,lat,u,v,iskip,amp);
% b klinger, 5/8/16
% Create vector field for octaglobe.
% iskip=optional param for # of longitudes to skip in polar regions
% amp=length of test vectors for sector edges.

%---------------------------------------------------------------------
% convert 1D coord vectors to 2D if necessary
%---------------------------------------------------------------------

if min(size(lon))==1 & min(size(lat))==1
   [Lon,Lat]=meshgrid(lon,lat);
else
   Lon=lon;
   Lat=lat;
end
nn=size(Lat);

%---------------------------------------------------------------------
% zero out vectors that are miscalculated due to proximity to border
%---------------------------------------------------------------------

uv=sqrt(u.^2+v.^2);
uvmin=.01*std(uv(:));
if ~exist('amp')
   amp=.01;
end
sc=amp./(uvmin+uv);
isecH=floor(Lon/45);
isecT=floor((Lon+sc.*u)/45);
ux=u;
vx=v;
ibord=find(isecH~=isecT &  abs(Lat)<=67.5);
ux(ibord)=0*u(ibord);
vx(ibord)=0*v(ibord);
jarct=find((67.5-abs(Lat)).*(67.5-abs(Lat+sc.*v))<0);
ux(jarct)=0*u(jarct);
vx(jarct)=0*v(jarct);

%---------------------------------------------------------------------
% do projection for tails, heads, and vectors
%---------------------------------------------------------------------

[xx,yy]=projocta(Lon,Lat);
[xxH,yyH]=projocta(Lon+sc.*ux,Lat+sc.*vx);
uu=(xxH-xx).*(uvmin+uv);
vv=(yyH-yy).*(uvmin+uv);

if exist('iskip') & iskip>1
   jp=find(abs(lat)>67.5);
   ii=iskip:iskip:nn(2);
   for i=1:iskip-1
      xx(jp,ii-i)=xx(jp,ii);
      yy(jp,ii-i)=yy(jp,ii);
      uu(jp,ii-i)=uu(jp,ii);
      vv(jp,ii-i)=vv(jp,ii);
   end
end
