function [up,vp]=llc_uv_addpadding(u,v,nfx,nfy)
%function [up,vp]=llc_uv_addpadding(u,v,nfx,nfy)
%
%input: [u,v]: compact format
%       [nfx,nfy]: sizes of the faces, same as mygrid.facesSize
%output:
%       [up,vp]: padded, 5 faces, cell format {1}-{5}

sz=size(u);%compact format
if(length(sz)==2);sz=[sz 1];end;
nx=sz(1);ny=sz(2);nz=sz(3);	%270 1350 50 or 270 270*13 50 or 90 90*13 13
%if(nx==270&ny==1350);
%  nfx=[nx 0 nx 180 450];nfy=[450 0 nx nx nx];
%elseif(ny==(nx*13));
%  nfx=[nx nx nx 3*nx 3*nx];nfy=[3*nx 3*nx nx nx nx];
%end;

uf{1}=u(:,              1:    nfy(1)   ,1:nz);
uf{2}=u(:,    nfy(1)   +1:sum(nfy(1:2)),1:nz);
uf{3}=u(:,sum(nfy(1:2))+1:sum(nfy(1:3)),1:nz);
uf{4}=reshape(u(:,sum(nfy(1:3))       +1:sum(nfy(1:3))+    nfx(4)   ,1:nz),nfx(4),nfy(4),nz);
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);

vf{1}=v(:,              1:    nfy(1)   ,1:nz);
vf{2}=v(:,    nfy(1)+   1:sum(nfy(1:2)),1:nz);
vf{3}=v(:,sum(nfy(1:2))+1:sum(nfy(1:3)),1:nz);
vf{4}=reshape(v(:,sum(nfy(1:3))+       1:sum(nfy(1:3))+    nfx(4)   ,1:nz),nfx(4),nfy(4),nz);
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);


clear u v
for iface=1:5
  sz=size(uf{iface});if(length(sz)==2);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));
    u{iface}(1:sz(1),1:sz(2),1:sz(3))=uf{iface};
  end;
  sz=size(vf{iface});if(length(sz)==2);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));
    v{iface}(1:sz(1),1:sz(2),1:sz(3))=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)=ut;			%1&2 length must match
  end;
  clear ut;ut=sym_g_mod(v{4}(1:nfx(4),1,1:nz),7,0);
   if(nfx(2)>0&nfy(2)>0);
         if(nfx(4)>nfy(2));
           utp=zeros(1,nfy(2),nz);utp(1,:,:)=ut(nfx(4)-nfy(2)+1:nfx(4),1:n);
     elseif(nfx(4)<nfy(2));
           utp=zeros(1,nfy(2),nz);utp(1,nfy(2)-nfx(4)+1:nfy(2),1:nz)=ut;
     else;
           utp=ut;
     end;
     u{2}(nfx(2)+1,1:nfy(2),1:nz)=utp;
   end;
  clear ut;ut=u{4}(1,1:nfy(4),1:nz);u{3}(nfx(3)+1,1:nfy(3),1:nz)=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),5,0);v{1}(1:nfx(1),nfy(1)+1,1:nz)=vt;
  if(nfx(2)>0&nfy(2)>0);
    clear vt;vt=v{3}(1:nfx(3),1,1:nz);v{2}(1:nfx(2),nfy(2)+1,1:nz)=vt;
  end;
  clear vt;vt=sym_g_mod(u{5}(1,1:nfy(5),1:nz),5,0);v{3}(1:nfx(3),nfy(3)+1,1:nz)=vt;
  clear vt;vt=v{5}(1:nfx(5),1,1:nz);
  if(nfx(5)>=nfx(4))
    v{4}(1:nfx(4),nfy(4)+1,1:nz)=vt(1:nfx(4),1,1:nz);
  elseif(nfx(5)<nfx(4));
    v{4}(1:nfx(5),nfy(4)+1,1:nz)=vt(1:nfx(5),1,1:nz);
  end;
  clear vt;vt=sym_g_mod(u{1}(1,1:nfy(1),1:nz),5,0);v{5}(1:nfx(5),nfy(5)+1,1:nz)=vt;

vp=v;
up=u;

return
