function [fcompactU,fcompactV]=aste_vector2compact(asteU,asteV,nfx,nfy,flagUV);
%------------
%function [fcompactU,fcompactV]=aste_vector2compact(asteU,asteV,nfx,nfy,flagUV);
% In:
% nfx: [270 0 270 180 450]
% nfy: [450 0 270 270 270]
% asteU: aste domain size [nx*2+1 nfy(1)+nfy(3)+nfx(4)+nfx(5)+1,nz]
% asteV: aste domain size [nx*2+1 nfy(1)+nfy(3)+nfx(4)+nfx(5)+1,nz]
%
% Out:
% compact format [270 1350 nz]
% ATN 16-Jan-2015 ------------

nx=nfx(3);
[tempx tempy nz]=size(asteU);
if((nfy(1)+nfy(3)+nfx(4)+1)~=tempy);
  error('inconsistent nfx or nfy versus size asteUV');
  return
else;

if(flagUV==1);ssU=[1,0,1,1,-1];ssV=[1,0,-1,-1,1];
else;         ssU=[1,1,1,1,1];ssV=ssU;end;

%initialize:
  fV{1}=nan(nfx(1),nfy(1),nz);fV{2}=[];fV{3}=nan(nx,nx,nz);
  fV{4}=nan(nfx(4),nfy(4),nz);fV{5}=nan(nfx(5),nfy(5),nz);
  fU{1}=nan(nfx(1),nfy(1),nz);fU{2}=[];fU{3}=nan(nx,nx,nz);
  fU{4}=nan(nfx(4),nfy(4),nz);fU{5}=nan(nfx(5),nfy(5),nz);

%filling
%untangling U into faces: face1 remains fU, faces 3:5 becomes V; sign changes for face3:4
  fU{1}=ssU(1).*asteU(nx+1:2*nx,1:nfy(1),:);%remains unchanged for both U and V
  for k=1:nz;
    clear temp;temp=sym_g_mod(asteU(nx+1+1:2*nx+1,nfy(1)+1:nfy(1)+nfx(3)+nfx(4),k),7,0);
    fV{3}(:,:,k)=ssV(3).*temp(1:nfx(3),1:nfy(3));
    fV{4}(:,:,k)=ssV(4).*temp(nx+1:nx+nfx(4),1:nfy(4));
    clear temp;temp=sym_g_mod(asteU(1:nx,1:nfx(5),k),5,0);fV{5}(:,:,k)=ssV(5).*temp;
  end;

%untangling V into faces: faces1 remains fV, faces 3:5 becomes U; sign changes for face5
  fV{1}=ssV(1).*asteV(nx+1:2*nx,1:nfy(1),:);%remains unchanged for both U and V
  for k=1:nz;
    clear temp;temp=sym_g_mod(asteV(nx+1:2*nx,nfy(1)+1:nfy(1)+nfx(3)+nfx(4),k),7,0);
    fU{3}(:,:,k)=ssU(3).*temp(1:nfx(3),1:nfy(3));
    fU{4}(:,:,k)=ssU(4).*temp(nx+1:nx+nfx(4),1:nfy(4));
    clear temp;temp=sym_g_mod(asteV(1:nx,2:nfx(5)+1,k),5,0);fU{5}(:,:,k)=ssU(5).*temp;
  end;

  fcompactU=[fU{1},fU{3},reshape(fU{4},nfy(4),nfx(4),nz),reshape(fU{5},nfy(5),nfx(5),nz)];
  fcompactV=[fV{1},fV{3},reshape(fV{4},nfy(4),nfx(4),nz),reshape(fV{5},nfy(5),nfx(5),nz)];
  %facesU=fU;
  %facesV=fV;
  
end;

return

