1 |
gforget |
1.13 |
function []=example_interp(); |
2 |
gforget |
1.8 |
%object: a interp2 example within gcmfaces |
3 |
gforget |
1.1 |
|
4 |
|
|
%%%%%%%%%%%%%%%%% |
5 |
gforget |
1.14 |
%load grid: |
6 |
gforget |
1.1 |
%%%%%%%%%%%%%%%%% |
7 |
|
|
|
8 |
gforget |
1.12 |
gcmfaces_global; |
9 |
gforget |
1.13 |
|
10 |
gforget |
1.15 |
if isempty(mygrid); |
11 |
|
|
grid_load; |
12 |
|
|
end; |
13 |
gforget |
1.12 |
|
14 |
gforget |
1.14 |
if myenv.verbose>0; |
15 |
|
|
gcmfaces_msg(['* call example_interp : will define ' ... |
16 |
|
|
'a 2x2 gridded variable (an bathymetry field here), and then ' ... |
17 |
|
|
'use interp2 to map it to the chosen grid. '],''); |
18 |
|
|
end; |
19 |
gforget |
1.1 |
|
20 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
21 |
gforget |
1.12 |
%get sample data: subsampled mygrid.Depth |
22 |
|
|
if myenv.verbose>0; |
23 |
|
|
gcmfaces_msg('* define test case : subsampled bathymetry'); |
24 |
|
|
end; |
25 |
|
|
lon=mygrid.XC; lat=mygrid.YC; |
26 |
|
|
original_Depth=mygrid.Depth; |
27 |
|
|
original_Depth(original_Depth==0)=NaN; |
28 |
|
|
% |
29 |
|
|
[lon,lat,original_Depth]=convert2pcol(lon,lat,original_Depth); |
30 |
|
|
nn=[62:239]; lon=lon(:,nn); lat=lat(:,nn); |
31 |
|
|
original_Depth=original_Depth(:,nn); |
32 |
|
|
[lon,lat]=meshgrid(lon(:,1),lat(1,:)); |
33 |
|
|
original_Depth=original_Depth'; |
34 |
gforget |
1.1 |
|
35 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
36 |
|
|
%do the interpolation: |
37 |
|
|
|
38 |
gforget |
1.12 |
interp2_depth=gcmfaces(5); |
39 |
gforget |
1.8 |
for ii=1:mygrid.nFaces; |
40 |
gforget |
1.12 |
xi=mygrid.XC{ii}; yi=mygrid.YC{ii}; |
41 |
|
|
zi = interp2(lon,lat,original_Depth,xi,yi); |
42 |
|
|
interp2_depth{ii}=zi; |
43 |
gforget |
1.1 |
end; |
44 |
|
|
|
45 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
46 |
|
|
%illustrate the result: |
47 |
|
|
|
48 |
gforget |
1.12 |
figureL; |
49 |
|
|
subplot(2,1,1); set(gca,'FontSize',14); |
50 |
|
|
pcolor(lon,lat,original_Depth); axis([-180 180 -90 90]); shading flat; |
51 |
|
|
title('input to interp2'); |
52 |
|
|
subplot(2,1,2); set(gca,'FontSize',14); |
53 |
|
|
[X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,interp2_depth); |
54 |
|
|
pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat; |
55 |
|
|
title('output of interp2'); |
56 |
gforget |
1.1 |
|
57 |
|
|
|