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