function [asteCS,asteSN]=get_aste_angleCSSN(acs,asn,yc,nfx,nfy)
%=========================================
% function [asteCS,asteSN]=get_aste_angleCSSN(acs,asn,nfx,nfy)
% ATN 18-Nov-2012
% function to get 1 big ASTE domain for AngleSN + AngleCS
% need function rotate_CSSNface
% Input:
% 	acs: compact form, obtained from acs=readbin('AngleCS.data',[nx ny],1,'real*4');
% 	asn: compact form, obtained from asn=readbin('AngleSN.data',[nx ny],1,'real*4');
%       yc : lat                         yc =readbin('YC.data',[nx ny],1,'real*4');
%        A) If already in aste compact size, for llc270 it's [270 1350 50]
%              e.g., for aste_270x450x180, [nx,ny,nz]=[270 1350 50]
%        B) If in global size, it's [270 270*13 50]
%              e.g., for global, [nx,ny,nz]=[270 3510 50]
%
%    nfx:	actual x-size of aste faces: [270 0 270 180 450]
%    nfy:	actual y-size of aste faces: [450 0 270 270 270]
%    
% [acsaste,asnaste]: size [2*270 450+270+180]
%===========================================================

[nx,ny,nz]=size(acs);
fac=15/18;%fac=7/9;%fac=2/3;

%-------- order stored in compact format ---------------
nfx1=[nfx(1) nfx(2) nfx(3) nfy(4) nfy(5)];
nfy1=[nfy(1) nfy(2) nfy(3) nfx(4) nfx(5)];

%-------- put compact form into faces: -----------------
if(sum(nfy1)==ny);                 %already in aste geometry
  [temp,ffu]=get_aste_tracer(acs,nfx,nfy);
  [temp,ffv]=get_aste_tracer(asn,nfx,nfy);
  [temp,ycf]=get_aste_tracer(yc,nfx,nfy);
elseif(ny/nx==13);                      %from global llc
  ffu{1}=acs( :,3*nx-nfy1(1)+1:3*nx,: );
  ffu{3}=acs( :,6*nx+1:7*nx,: );
  ffu{4}=reshape( acs( :, 7*nx+1:10*nx,: ) ,3*nx,nx,nz );ffu{4}=ffu{4}(1:nfy1(4),:,:);
  ffu{5}=reshape( acs( :,10*nx+1:13*nx,: ) ,3*nx,nx,nz );ffu{5}=ffu{5}(1:nfy1(5),:,:);

  ffv{1}=asn( :,3*nx-nfy1(1)+1:3*nx,: );
  ffv{3}=asn( :,6*nx+1:7*nx,: );
  ffv{4}=reshape( asn( :, 7*nx+1:10*nx,: ) ,3*nx,nx,nz );ffv{4}=ffv{4}(1:nfy1(4),:,:);
  ffv{5}=reshape( asn( :,10*nx+1:13*nx,: ) ,3*nx,nx,nz );ffv{5}=ffv{5}(1:nfy1(5),:,:);

  ycf{1}=yc(  :,3*nx-nfy1(1)+1:3*nx,: );
  ycf{3}=yc(  :,6*nx+1:7*nx,: );
  ycf{4}=reshape( yc( :, 7*nx+1:10*nx,: ) ,3*nx,nx,nz );ycf{4}=ycf{4}(1:nfy1(4),:,:);
  ycf{5}=reshape( yc( :,10*nx+1:13*nx,: ) ,3*nx,nx,nz );ycf{5}=ycf{5}(1:nfy1(5),:,:);
else
  fprintf('Wrong size for acs: [nx ny nz]=[%i %i %i]\n',[nx ny nz]);
  fprintf('Need acs [%i %i %i](aste) or [%i %i %i](global)\n',...
          [nfx(1) sum(nfy1) nz nfx(1) 13*nfx(1) nz]);
  error('wrong size for acs');
end;

%================================================================ 
%================================================================ 
%================================================================ 
%================== putting all on 1 big matrix =================

asteCS=zeros(nfy(5)+nfx(1),nfy(1)+nfx(3)+nfx(4),nz);
asteSN=zeros(nfy(5)+nfx(1),nfy(1)+nfx(3)+nfx(4),nz);

%lower right corner: face 1
asteCS(nfy(5)+1:nfy(5)+nfx(1),1:nfy(1),1:nz) = ffu{1};
asteSN(nfy(5)+1:nfy(5)+nfx(1),1:nfy(1),1:nz) = ffv{1};

% lower left corner, face 5, rotated 90deg clockwise (use Gael's sym_g(input,7,0))
  clear iRot face oldCS oldSN newCS newSN
  iRot=7;face=5;
  oldCS=ffu{face};oldSN=ffv{face};
  [newCS,newSN]=rotate_CSSNface(oldCS,oldSN,ycf{face},iRot);
  asteCS(1:nfy(5),1:nfx(5))= newCS;
  asteSN(1:nfy(5),1:nfx(5))= newSN;

% mid left: face 3, rot 180deg
%    nfx:	actual x-size of aste faces: [270 0 270 180 450]
%    nfy:	actual y-size of aste faces: [450 0 270 270 270]
  clear iRot face oldCS oldSN newCS newSN
  iRot=6;face=3;
  oldCS=ffu{face};oldSN=ffv{face};
  [newCS,newSN]=rotate_CSSNface(oldCS,oldSN,ycf{face},iRot);
  asteCS(1:nfx(3),nfx(5)+1:nfx(5)+nfy(3))=newCS;
  asteSN(1:nfx(3),nfx(5)+1:nfx(5)+nfy(3))=newSN;

  clear iRot face oldCS oldSN newCS newSN iaste jaste iface jface
  iRot=6;face=5;
  oldCS=ffu{face};oldSN=ffv{face};
  [newCS,newSN]=rotate_CSSNface(oldCS,oldSN,ycf{face},iRot);

  iaste=round([nfy(5)*fac+1,nfy(5)]);jaste=round([nfx(5)+(1-fac)*nfy(5)-4,nfx(5)+nfy(5)]);
  iface=round([nfx(5)-nfy(5)*(1-fac)+1,nfx(5)]);jface=round([(1-fac)*nfy(5)-4,nfy(5)]);

  asteCS(iaste(1):iaste(2),jaste(1):jaste(2))=...
	newCS(iface(1):iface(2),jface(1):jface(2));
  asteSN(iaste(1):iaste(2),jaste(1):jaste(2))=...
	newSN(iface(1):iface(2),jface(1):jface(2));

% mid right: face 3, rot 90deg ccw, sym_t(input,5,0);
  clear iRot face oldCS oldSN newCS newSN
  iRot=5;face=3;
  oldCS=ffu{face};oldSN=ffv{face};
  [newCS,newSN]=rotate_CSSNface(oldCS,oldSN,ycf{face},iRot);
  asteCS(nfy(5)+1:nfy(5)+nfx(1),nfy(1)+1:nfy(1)+nfx(3))=newCS;
  asteSN(nfy(5)+1:nfy(5)+nfx(1),nfy(1)+1:nfy(1)+nfx(3))=newSN;

% upper right corner, face 4 (Bering Strait), rot 90deg ccw: sym_g(input,5,0)
  clear iRot face oldCS oldSN newCS newSN
  iRot=5;face=4;
  oldCS=ffu{face};oldSN=ffv{face};
  [newCS,newSN]=rotate_CSSNface(oldCS,oldSN,ycf{face},iRot);
  asteCS(nfy(5)+1:nfy(5)+nfx(1),nfy(1)+nfx(3)+1:nfy(1)+nfx(3)+nfx(4))=newCS;
  asteSN(nfy(5)+1:nfy(5)+nfx(1),nfy(1)+nfx(3)+1:nfy(1)+nfx(3)+nfx(4))=newSN;

return
