%
% [vmid,wv]=vel2w(xmid,zmid,ip,kp,xn,zn,v);
%
% I don't have a clue what this function does or what the variables are.
%
%
function [vmid,wv]=vel2w(xmid,zmid,ip,kp,xn,zn,v);


ip1=ip+1;
kp1=kp+1;

for k=1:length(xmid)

xf=(xmid(k)-xn(ip(k)))/(xn(ip1(k))-xn(ip(k)));
zf=(zmid(k)-zn(kp(k)))/(zn(kp1(k))-zn(kp(k)));
xf1=1.0-xf;
zf1=1.0-zf;

wv(k,1)=xf1*zf1;
wv(k,2)=xf*zf1;
wv(k,3)=xf1*zf;
wv(k,4)=xf*zf;

%  calculate velocity
vmid(k,1)=wv(k,1)*v(ip(k),kp(k))+wv(k,2)*v(ip1(k),kp(k))+wv(k,3)*v(ip(k),kp1(k))+wv(k,4)*v(ip1(k),kp1(k));

end
