function f90=interp_llc270_to_llc90(y270,f270,RAC270,y90,fflag)
%-------
% function [f90,f90f]=interp_llc270_to_llc90_aste(y270,f270,RAC270,y90,fflag)
%
% input: y270: llc270 YC (aste270 lat) 
%        f270: llc270 [aste270] 
%        RAC270: llc270 [aste270]
%        y90 : llc90 YC ([aste90] lat)
%        fflag: 0 = just take every 3rd pt, not weight
%               1 = area weighted avg of 3x3 squares
%               2 = sum of 3x3 squares
% output: f90 [aste90]
%----------

%Example inputs:
%dir90='/scratch/atnguyen/llc90_notsqueeze/aste_90x150x60/GRID_noblank/';nx=90;ny=450;nz=50;
%dir270='/scratch/atnguyen/aste_270x450x180/GRID_noblank/';              nx0=270;ny0=1350;
%dirIn='/scratch/atnguyen/aste_270x450x180/run_template/input_binaries/';
%f270=readbin([dirIn 'bathy_fill9iU42Ef_noStLA_v1.bin'],[nx0 ny0]);f270=get_aste_tracer(f270,nfx0,nfy0);
%y90=readbin([dir90 'YC.data'],[nx  ny],1,'real*8');y90=get_aste_tracer(y90,nfx,nfy);
%y270=readbin([dir270 'YC.data'],[nx0 ny0]);y270=get_aste_tracer(y270,nfx0,nfy0);
%RAC270=readbin([dir270 'RAC.data'],[nx0 ny0]);RAC270=get_aste_tracer(RAC270,nfx0,nfy0);

%get size
[nx0 ny0 nz]=size(f270);
[nxp nyp] =size(y270);
[nxq nyq] =size(RAC270);
RAC270=repmat(RAC270,[1 1 nz]);

[nx ny]=size(y90);

%defining field llc90:
f90=nan(nx,ny,nz);

for i=1:nx;
  ix0=(i-1)*3+1:i*3;
  for j=1:ny;
    jy0=(j-1)*3+1:j*3;

    if(fflag==0);%take every 3rd pt
      f90(i,j,:)=f270(ix0(2),jy0(2),:);
    elseif(fflag==1);%take average 3x3 squares
      f90(i,j,:)=sum(sum(f270(ix0,jy0,:).*RAC270(ix0,jy0,:)))./sum(sum(RAC270(ix0,jy0,:)));;
    else;	 %%weighted by total area
      f90(i,j,:)=sum(sum(f270(ix0,jy0,:)));
    end;
  end;
end;

return

