1 |
gforget |
1.1 |
function [fldOut]=gcmfaces_map_2d(lon,lat,fldIn,nExtrap,wRepeat); |
2 |
|
|
%object: use bin average to remap ONE lat-lon grid FIELD to a gcmfaces grid |
3 |
|
|
%input: lon,lat are the lat-lon grid, or vectors |
4 |
|
|
% fld is the gcmfaces field to be interpolated to lon,lat |
5 |
|
|
%optional: nExtrap (0 by default) is the number of points to extrapolate ocean field (into |
6 |
|
|
% the land mask before interpolation to the lat-lon grid. |
7 |
|
|
% wRepeat (2 degrees by default) is the width of repeats at |
8 |
|
|
% lat-lon global domain edges (needed to avoid missing values) |
9 |
|
|
%assumption : fld is nan-masked |
10 |
|
|
|
11 |
|
|
gcmfaces_global; |
12 |
|
|
|
13 |
|
|
if isempty(lon); lon=[-180:0.5:180]; lat=[-90:0.5:90]; end; |
14 |
|
|
if size(lon,1)==1|size(lon,2)==1; [lat,lon]=meshgrid(lat,lon); end; |
15 |
|
|
if isempty(whos('nExtrap')); nExtrap=0; end; |
16 |
|
|
if isempty(whos('wRepeat')); wRepeat=2; end; |
17 |
|
|
|
18 |
|
|
%1) extrapolate if needed |
19 |
|
|
if nExtrap>0; |
20 |
|
|
mskExtrap=~isnan(fldIn); |
21 |
|
|
for ii=1:nExtrap; |
22 |
|
|
mskExtrap=exch_T_N(mskExtrap); |
23 |
|
|
for iF=1:mskExtrap.nFaces; |
24 |
|
|
tmp1=mskExtrap{iF}; tmp1(isnan(tmp1))=0; |
25 |
|
|
tmp2=tmp1(2:end-1,2:end-1)+tmp1(1:end-2,2:end-1)+tmp1(3:end,2:end-1)+tmp1(2:end-1,1:end-2)+tmp1(2:end-1,3:end); |
26 |
|
|
tmp2(tmp2~=0)=1; mskExtrap{iF}=tmp2; |
27 |
|
|
end; |
28 |
|
|
end; |
29 |
|
|
mskExtrap(find(mskExtrap==0))=NaN; |
30 |
|
|
% |
31 |
|
|
fldIn=diffsmooth2D_extrap_inv(fldIn,mskExtrap); |
32 |
|
|
end; |
33 |
|
|
|
34 |
|
|
%2) extract vector of ocean points |
35 |
|
|
x=convert2vector(mygrid.XC); |
36 |
|
|
y=convert2vector(mygrid.YC); |
37 |
|
|
v=convert2vector(fldIn); |
38 |
|
|
% ii=find(~isnan(v)); |
39 |
|
|
ii=find(~isnan(x)); |
40 |
|
|
x=x(ii); y=y(ii); v=v(ii); |
41 |
|
|
|
42 |
|
|
%3) add points at lat-lon global domain edges |
43 |
|
|
ii=find(y>90-wRepeat); x=[x;x(ii)]; y=[y;180-y(ii)]; v=[v;v(ii)]; |
44 |
|
|
ii=find(y<-90+wRepeat); x=[x;x(ii)]; y=[y;-180-y(ii)]; v=[v;v(ii)]; |
45 |
|
|
ii=find(x>180-wRepeat&x<180); x=[x;x(ii)-360]; y=[y;y(ii)]; v=[v;v(ii)]; |
46 |
|
|
ii=find(x<-180+wRepeat&x>-180); x=[x;x(ii)+360]; y=[y;y(ii)]; v=[v;v(ii)]; |
47 |
|
|
|
48 |
|
|
%4) generate the interpolant |
49 |
|
|
F = TriScatteredInterp(x,y,v); |
50 |
|
|
|
51 |
|
|
%5) target grid |
52 |
|
|
fldOut = F(lon,lat); |
53 |
|
|
|
54 |
|
|
|