1 function [a_bu,a_bv]=interp_w2buv(a)
2 % interpolate horizontally values at w points to bottom of cell
3 % under the u and v points
5 % extend values at at w by 1 on each side by continuation
6 etype='constant'; % extend by constant
8 alt=zeros(s(1)+2,s(2)+2,s(3),s(4)); % extend laterally by 1
9 alt(2:end-1,2:end-1,:,:)=a; % embded original array
10 alt(1,2:end-1,:,:)=extend(a(1,:,:,:),a(2,:,:,:),etype); % extend by reflection
11 alt(end,2:end-1,:,:)=extend(a(end,:,:,:),a(end-1,:,:,:),etype);
12 alt(2:end-1,1,:,:)=extend(a(:,2*1,:,:),a(:,2,:,:),etype); %
13 alt(2:end-1,end,:,:)=extend(a(:,end,:,:),a(:,end-1,:,:),etype);
15 % interpolate to bottom cell locations under u and v
16 a_bu=0.5*(alt(1:end-1,:,:,:)+alt(2:end,:,:,:));
17 a_bv=0.5*(alt(:,1:end-1,:,:)+alt(:,2:end,:,:));
20 function x0=extend(x1,x2,etype)
25 x0=x1+(x1-x2); % reflection
28 error('extend: unknown type')