function [up,vp]=llc_uv_addpadding(u,v,nfx,nfy)

sz=size(u);%compact format 270 x 1350 x nz x nt
if(length(sz)==2);sz=[sz 1 1];elseif(length(sz)==3);sz=[sz 1];end;
nx=sz(1);ny=sz(2);nz=sz(3);nt=sz(4);	%270 1350 50 

uf{1}=u(:,              1:    nfy(1)   ,1:nz,1:nt);
uf{2}=u(:,    nfy(1)   +1:sum(nfy(1:2)),1:nz,1:nt);
uf{3}=u(:,sum(nfy(1:2))+1:sum(nfy(1:3)),1:nz,1:nt);
uf{4}=reshape(u(:,sum(nfy(1:3))       +1:sum(nfy(1:3))+    nfx(4)   ,1:nz),nfx(4),nfy(4),nz,nt);
uf{5}=reshape(u(:,sum(nfy(1:3))+nfx(4)+1:sum(nfy(1:3))+sum(nfx(4:5)),1:nz),nfx(5),nfy(5),nz,nt);

vf{1}=v(:,              1:    nfy(1)   ,1:nz,1:nt);
vf{2}=v(:,    nfy(1)+   1:sum(nfy(1:2)),1:nz,1:nt);
vf{3}=v(:,sum(nfy(1:2))+1:sum(nfy(1:3)),1:nz,1:nt);
vf{4}=reshape(v(:,sum(nfy(1:3))+       1:sum(nfy(1:3))+    nfx(4)   ,1:nz),nfx(4),nfy(4),nz,nt);
vf{5}=reshape(v(:,sum(nfy(1:3))+nfx(4)+1:sum(nfy(1:3))+sum(nfx(4:5)),1:nz),nfx(5),nfy(5),nz,nt);


clear u v
for iface=1:5
  sz=size(uf{iface});if(length(sz)==2);sz=[sz 1 1];elseif(length(sz)==3);sz=[sz 1];end;
  clear i0;i0=find(sz==0);
  if(length(i0)>0);
    u{iface}=[];
  else;
    u{iface}=zeros(sz(1)+1,sz(2)  ,sz(3),sz(4));
    u{iface}(1:sz(1),1:sz(2),1:sz(3),1:sz(4))=uf{iface};
  end;
  sz=size(vf{iface});if(length(sz)==2);sz=[sz 1 1];elseif(length(sz)==3);sz=[sz 1];end;
  clear i0;i0=find(sz==0);
  if(length(i0)>0);
    v{iface}=[];
  else;
    v{iface}=zeros(sz(1)  ,sz(2)+1,sz(3),sz(4));
    v{iface}(1:sz(1),1:sz(2),1:sz(3),1:sz(4))=vf{iface};
  end;
end

%now u edge:
  if(nfx(2)>0&nfy(2)>0);
    clear ut;ut=u{2}(1,1:nfy(2),1:nz);u{1}(nfx(1)+1,1:nfy(1),1:nz,1:nt)=ut;			%1&2 length must match
  end;
  clear ut;ut=sym_g_mod(v{4}(1:nfx(4),1,1:nz,1:nt),7,0);
   if(nfx(2)>0&nfy(2)>0);
         if(nfx(4)>nfy(2));
           utp=zeros(1,nfy(2),nz,nt);utp(1,:,:)=ut(nfx(4)-nfy(2)+1:nfx(4),1:nz,1:nt);
     elseif(nfx(4)<nfy(2));
           utp=zeros(1,nfy(2),nz,nt);utp(1,nfy(2)-nfx(4)+1:nfy(2),1:nz,1:nt)=ut;
     else;
           utp=ut;
     end;
     u{2}(nfx(2)+1,1:nfy(2),1:nz,1:nt)=utp;
   end;
  clear ut;ut=u{4}(1,1:nfy(4),1:nz,1:nt);u{3}(nfx(3)+1,1:nfy(3),1:nz,1:nt)=ut;
%will not fill the last cells nx*3+1 for u{4} and u{5} because they're land, so assume zeros

%now v edge: (a bit more complicated that u)
  clear vt;vt=sym_g_mod(u{3}(1,1:nfy(3),1:nz,1:nt),5,0);v{1}(1:nfx(1),nfy(1)+1,1:nz,1:nt)=vt;
  if(nfx(2)>0&nfy(2)>0);
    clear vt;vt=v{3}(1:nfx(3),1,1:nz,1:nt);v{2}(1:nfx(2),nfy(2)+1,1:nz,1:nt)=vt;
  end;
  clear vt;vt=sym_g_mod(u{5}(1,1:nfy(5),1:nz,1:nt),5,0);v{3}(1:nfx(3),nfy(3)+1,1:nz,1:nt)=vt;
  clear vt;vt=v{5}(1:nfx(5),1,1:nz,1:nt);
  if(nfx(5)>=nfx(4))
    v{4}(1:nfx(4),nfy(4)+1,1:nz)=vt(1:nfx(4),1,1:nz,1:nt);
  elseif(nfx(5)<nfx(4));
    v{4}(1:nfx(5),nfy(4)+1,1:nz)=vt(1:nfx(5),1,1:nz,1:nt);
  end;
  clear vt;vt=sym_g_mod(u{1}(1,1:nfy(1),1:nz,1:nt),5,0);v{5}(1:nfx(5),nfy(5)+1,1:nz,1:nt)=vt;

vp=v;
up=u;

return
