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