| 1 |
function [To]=xyexpand(Tin,niter) |
| 2 |
% Tout=xyexpand(Tin,3); |
| 3 |
% |
| 4 |
% This function takes 2D input and replaces any NaN |
| 5 |
% neighbouring any real numbers with the average of |
| 6 |
% those numbers. This procedure is repeated niter |
| 7 |
% times. Note that the ocean/land volume ratio expands |
| 8 |
% rapidly with each iteration. |
| 9 |
% |
| 10 |
% In short, this is a gap-filler and extrapolator of |
| 11 |
% rudimentary order applied to horizontal slices. |
| 12 |
% |
| 13 |
% Created 08/15/99 by adcroft@mit.edu |
| 14 |
% Modified 11/11/99 by adcroft@mit.edu |
| 15 |
% Maintained by adcroft@mit.edu, abiastoch@ucsd.edu |
| 16 |
|
| 17 |
[nx,ny]=size(Tin); |
| 18 |
ip=[2:nx 1]; |
| 19 |
im=[nx 1:nx-1]; |
| 20 |
jp=[2:ny ny]; |
| 21 |
jm=[1 1:ny-1]; |
| 22 |
|
| 23 |
T=Tin; |
| 24 |
for iter=1:niter, |
| 25 |
|
| 26 |
msk=ones(nx,ny); |
| 27 |
L=isnan(T); |
| 28 |
msk( L )=0; |
| 29 |
|
| 30 |
To=T; |
| 31 |
To( L )=0; |
| 32 |
|
| 33 |
cnt=msk(im,:)+msk(ip,:)+msk(:,jm)+msk(:,jp); |
| 34 |
cnt( find(cnt==0) )=1; |
| 35 |
Tbr=(To(im,:)+To(ip,:)+To(:,jm)+To(:,jp))./cnt; |
| 36 |
|
| 37 |
To( L )=Tbr( L ); |
| 38 |
|
| 39 |
To( find(To==0) )=NaN; |
| 40 |
|
| 41 |
T=To; |
| 42 |
end |