function [Uout,Vout]=get_aste_vector(Uin,Vin,XC,YC,sign_switch)
%=========================================
% function [Uout,Vout]=get_aste_vector(Uin,Vin,XC,YC,sign_switch)
% ATN 01-Dec-2011
% function to get ASTE domain for vectors
% Input:
% 	Uin: gcmfaces f1-f5 or U{1}-{5}, U
% 	Vin: gcmfaces f1-f5 or V{1}-{5}, V
%	XC   : XC field (longitude)
%	YC   : YC field (latitude)
%    sign_switch: 1 for U/V fields, 0 for DX,DY fields
%    
% fld_out: a matrix of size [64+90 97+90+44]*N where N=1 for llc90 or 6 for llc540
%===========================================================

% check if gcmfaces or patchface3D faces
temp=whos('XC');

lat_Atlantic = 4;
lat_Pacific = 40;
lat_Siberia = 65;

if(strcmp(temp.class,'gcmfaces'));
  [nx ny nz] = size(Uin.f1);
elseif(strcmp(temp.class,'cell'));
  [nx ny nz] = size(Uin{1});
end;

% Determine ASTE domain ---------------

if(strcmp(temp.class,'gcmfaces'));
  i1=find(YC.f1(1,:)>=lat_Atlantic);i1=i1(1)-2;				% >5N in Atlantic Sector
  i2 = find(YC.f2(1,:)>=lat_Siberia); i2=i2(1)-2;                % >64N in Siberia Sector
  i4=find(YC.f4(:,1)>=lat_Pacific);i4 =[i4',i4(end)+1,i4(end)+2];% >50N in Pacific Sector
  i5p= find(XC.f5(1,:)>-100);i5p=i5p(1)-5;					% cut off Pacific Sector (W of 100W) f5
elseif(strcmp(temp.class,'cell'));
  i1=find(YC{1}(1,:)>=lat_Atlantic);i1=i1(1)-2;				% >5N in Atlantic Sector
  i2=find(YC{2}(1,:)>=lat_Siberia); i2=i2(1)-2;                  % >64N in Siberia Sector
  i4=find(YC{4}(:,1)>=lat_Pacific);i4 =[i4',i4(end)+1,i4(end)+2];% >50N in Pacific Sector
  i5p= find(XC{5}(1,:)>-100);i5p=i5p(1)-5;					% cut off Pacific Sector (W of 100W) f5
end;

i5 = max(ny-length(i5p:nx)+1,1);
%i5p= max(nx-length(i1:ny)+1,1);

ix1=1:nx;    iy1=i1:ny;    Nx1=length(ix1);  Ny1=length(iy1);    %[90 97]
ix2=1:ny-i2; iy2=1:nx;     Nx2=length(ix2);  Ny2=length(iy2);    %[11 90]
ix3=1:nx;    iy3=1:nx;     Nx3=length(ix3);  Ny3=length(iy3);    %[90 90]
ix4=1:nx;    iy4=i4;       Nx4=length(ix4);  Ny4=length(iy4);    %[90 44]
ix5=i5:ny;   iy5=1:nx;     Nx5=length(ix5);  Ny5=length(iy5);    %[97 90] or [64 90]
ix5p=i5p:nx; iy5p=iy1;     Nx5p=length(ix5p);Ny5p=length(iy5p);  %[90 97] or [64 97]
%ix5=i1:ny;   iy5=1:nx;     Nx5=length(ix5);  Ny5=length(iy5);    %[97 90]
% ---- done ASTE domain ix,iy --------

NXnew = Nx5 + nx +Nx2;
NYnew = Ny1 + Ny3 + Ny4;
Uout=nan(NXnew,NYnew,nz);
Vout=nan(NXnew,NYnew,nz);

for k=1:nz
  if(strcmp(temp.class,'gcmfaces'));
    u1 =       Uin.f1(:,:,k);         v1 =       Vin.f1(:,:,k);
    u2 =-sym_g(Vin.f2(:,:,k),5,0);    v2 = sym_g(Uin.f2(:,:,k),5,0);
    u3 =-sym_g(Vin.f3(:,:,k),5,0);    v3 = sym_g(Uin.f3(:,:,k),5,0);
    u4 =-sym_g(Vin.f4(:,:,k),5,0);    v4 = sym_g(Uin.f4(:,:,k),5,0);
    u5 =-sym_g(Uin.f5(:,:,k),6,0);    v5 =-sym_g(Vin.f5(:,:,k),6,0);
    u5p= sym_g(Vin.f5(:,:,k),7,0);    v5p=-sym_g(Uin.f5(:,:,k),7,0);
  elseif(strcmp(temp.class,'cell'));
    u1 =       Uin{1}(:,:,k);         v1 =       Vin{1}(:,:,k);
    u2 =-sym_g(Vin{2}(:,:,k),5,0);    v2 = sym_g(Uin{2}(:,:,k),5,0);
    u3 =-sym_g(Vin{3}(:,:,k),5,0);    v3 = sym_g(Uin{3}(:,:,k),5,0);
    u4 =-sym_g(Vin{4}(:,:,k),5,0);    v4 = sym_g(Uin{4}(:,:,k),5,0);
    u5 =-sym_g(Uin{5}(:,:,k),6,0);    v5 =-sym_g(Vin{5}(:,:,k),6,0);
    u5p= sym_g(Vin{5}(:,:,k),7,0);    v5p=-sym_g(Uin{5}(:,:,k),7,0);
  end;

  tempu=nan(Nx5,NYnew);	%[97 97+90+45] = [97 232]
  tempu(1:Nx5,Ny5p+1:Ny5p+Ny5)=u5(ix5,iy5);
  tempu(Nx5-Nx5p+1:Nx5,1:Ny5p)=u5p(ix5p,iy5p);

  tempu1=nan(Nx2,NYnew); tempu1(:,Ny5p+1:Ny5p+Ny5)=u2(ix2,iy2);

  tempv=nan(Nx5,NYnew);	%[97 97+90+45] = [97 232]
  tempv(1:Nx5,Ny5p+1:Ny5p+Ny5)=v5(ix5,iy5);
  tempv(Nx5-Nx5p+1:Nx5,1:Ny5p)=v5p(ix5p,iy5p);

  tempv1=nan(Nx2,NYnew); tempv1(:,Ny5p+1:Ny5p+Ny5)=v2(ix2,iy2);

  Uout(:,:,k)=[tempu;u1(ix1,iy1),u3,u4(ix4,iy4);tempu1];
  Vout(:,:,k)=[tempv;v1(ix1,iy1),v3,v4(ix4,iy4);tempv1];
end;

if(sign_switch==0);	%if no need to flip sign for U/V, as in case of DX,DY
  Uout=abs(Uout);
  Vout=abs(Vout);
end;

return

