function [fld_out,index]=get_aste_tracer(fld_in,XC,YC)
%=========================================
% function [fld_out,index]=get_aste_tracer(fld_in,XC,YC)
% ATN 01-Dec-2011
% function to get ASTE domain for tracers
% Input:
% 	fld_in: gcmfaces f1-f5 or f{1}-{5}
%	XC   : f1-f5, longitude, for upper domain range
%	YC   : f1-f5, latitude, for upper domain range
%    
% fld_out: a matrix of size [64+90 97+90+44]*N
%          N=1 for llc_90, N=6 for llc_540

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

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

if(strcmp(temp.class,'gcmfaces'));
  [nx ny nz] = size(fld_in.f1);
elseif(strcmp(temp.class,'cell'));
  [nx ny nz] = size(fld_in{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
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;
fld_out=nan(NXnew,NYnew,nz);

for k=1:nz
  if(strcmp(temp.class,'gcmfaces'));
    h1 =fld_in.f1(:,:,k);             
    h2 =sym_g(fld_in.f2(:,:,k),5,0);
    h3 =sym_g(fld_in.f3(:,:,k),5,0);  
    h4 =sym_g(fld_in.f4(:,:,k),5,0); 
    h5 =sym_g(fld_in.f5(:,:,k),6,0);  
    h5p=sym_g(fld_in.f5(:,:,k),7,0);  
  elseif(strcmp(temp.class,'cell'));
    h1 =fld_in{1}(:,:,k);             
    h2 =sym_g(fld_in{2}(:,:,k),5,0);
    h3 =sym_g(fld_in{3}(:,:,k),5,0);  
    h4 =sym_g(fld_in{4}(:,:,k),5,0); 
    h5 =sym_g(fld_in{5}(:,:,k),6,0);  
    h5p=sym_g(fld_in{5}(:,:,k),7,0);  
  end;

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

  temph1=nan(Nx2,NYnew);
  temph1(:,Ny5p+1:Ny5p+Ny5)=h2(ix2,iy2);

  fld_out(:,:,k)=[temph;h1(ix1,iy1),h3,h4(ix4,iy4);temph1];
end;
index=[Nx5,nx,Nx2;Ny1,nx,Ny4];

return

