% find all wet points adjacent to at least one dry point
nx=8640;
ny=4320;
suf=['_' int2str(nx) 'x' int2str(ny)];
pin='/data1/llc/llc_2160/regions/latlon/';
hFacC=zeros(nx+2,ny+2);
hFacC(2:end-1,2:end-1)=readbin([pin 'grid/hFacC' suf],[nx ny]);
hFacC(1,:)=hFacC(end-1,:);
hFacC(end,:)=hFacC(2,:);
hFacC(:,1)=hFacC(:,end-1);
hFacC(:,end)=hFacC(:,2);
coastline=zeros(nx,ny,'int8');
for i=2:(nx+1), mydisp(i)
  ix=(i-1):(i+1);
  for j=2:(ny+1)
    if hFacC(i,j)>0
      jx=(j-1):(j+1);
      tmp=hFacC(ix,jx);
      if any(tmp(:)==0)
        coastline(i-1,j-1)=1;
      end
    end
  end
end
eval(['save ' pin 'grid/coastline coastline'])
