function [icoast]=locate_aste_coast(hf,num_grid)
% ----- a quick way to locate coast: ------------------------------------
% function [icoast]=locate_aste_coast(hf,num_grid)
%
% Input: hf [nx ny nz] or [nxp nyp nz] (270x1350xnz or 540x900xnz)
%        num_grid: number of grid points next to coast
%
% Output: icoast: index [1:num_grid=coast,0=otherwise] in ASTE geometry
%                 can use aste_tracer2compact to get back to compact
%                 if desired
%         icoast [nxp nyp nz]
% ATN 07-Oct-2013
%------------------------------------------------------------------------

nfx=[270 0 270 180 450];nfy=[450 0 270 270 270];nx=270;ny=1350;nxp=540;nyp=900;

%dirGrid='/net/nares/raid8/ecco-shared/llc270/aste_270x450x180/output/obcsERAdlwsub5pdrag1a/GRID/';
%hf=readbin([dirGrid 'hFacC.data'],[nx ny]);hf=get_aste_tracer(hf,nfx,nfy);

%check size, put in ASTE format if needed:
sz=size(hf);if(length(sz)==2);sz=[sz 1];end;
if(sz(1)==nx & sz(2)==ny);
  hf=get_aste_tracer(hf,nfx,nfy);
elseif(~(sz(1)==nxp & sz(2)==nyp));
  fprintf('%wrong size of hf %i %i %\n',[sz]);
end;

iland=find(hf==0);hf(find(hf>0))=1;

%Pacific and Atlantic: <-- specific to ASTE domain
ix=310;iy=830:nyp;j=find(squeeze(hf(ix,iy,1))==0);if(length(j)>0);hf(nx+1:nxp,iy(j(1)):nyp,:)=nan;end;
ix=310;iy=1:60;j=find(squeeze(hf(ix,iy,1))==0);if(length(j)>0);hf(1:nxp,1:iy(j(end)),:)=nan;end;

msk=1-hf;%msk(find(msk<1))=0;
icoast=nan(size(msk));

%say want first 6 grid points next to coast ~50km in llc270 horizontal res
%num_grid=6;	
for k=1:sz(3);
  mska=msk(:,:,k);
  temp=zeros(size(mska));
  for j=1:num_grid;
    mskb=smooth2a(mska,1);ii=find((mskb-mska)>0);temp(ii)=j;mskb(ii)=1;
    mska=mskb;mska(find(mska>0))=1;
  end;
  msk(:,:,k)=mska;
  icoast(:,:,k)=temp;
end;
msk(iland)=0;
icoast(iland)=0;

%icoast=find(mskb(:)==1);

return
