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.9 |
dir0=[myenv.gcmfaces_dir '/sample_input/']; |
17 |
gforget |
1.8 |
dirGrid=[dir0 '/GRID' choiceV3orV4 '/']; |
18 |
|
|
dirIn=[dir0 '/SAMPLE' choiceV3orV4 '/']; |
19 |
|
|
if strcmp(choiceV3orV4,'v4'); nF=5; fileFormat='compact'; else; nF=1; fileFormat='straight'; end; |
20 |
gforget |
1.10 |
grid_load(dirGrid,nF,fileFormat); |
21 |
gforget |
1.1 |
|
22 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
23 |
gforget |
1.2 |
%get sample data: V3 SSH |
24 |
gforget |
1.9 |
dirV3=[myenv.gcmfaces_dir '/sample_input/SAMPLEv3/']; |
25 |
gforget |
1.2 |
etan=rdmds([dirV3 'DDetan'],0); etan(etan==0)=NaN; |
26 |
gforget |
1.9 |
dirV3=[myenv.gcmfaces_dir '/sample_input/GRIDv3/']; |
27 |
gforget |
1.2 |
lon=rdmds([dirV3 'XC']); lat=rdmds([dirV3 'YC']); |
28 |
gforget |
1.11 |
lon=lon(1:2:end,21:2:140); |
29 |
|
|
lat=lat(1:2:end,21:2:140); |
30 |
|
|
etan=etan(1:2:end,21:2:140); |
31 |
gforget |
1.1 |
|
32 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
33 |
|
|
%do the interpolation: |
34 |
gforget |
1.11 |
x=[lon-360;lon;lon+360]; y=[lat;lat;lat]; z=[etan;etan;etan]; |
35 |
gforget |
1.1 |
|
36 |
|
|
z_interp=gcmfaces(5); |
37 |
gforget |
1.8 |
for ii=1:mygrid.nFaces; |
38 |
gforget |
1.1 |
xi=mygrid.XC{ii}; yi=mygrid.YC{ii}; |
39 |
|
|
zi = interp2(x',y',z',xi,yi); |
40 |
|
|
z_interp{ii}=zi; |
41 |
|
|
end; |
42 |
|
|
|
43 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
44 |
|
|
%illustrate the result: |
45 |
|
|
|
46 |
gforget |
1.11 |
figure; x=[lon-360;lon]; y=[lat;lat]; z=[etan;etan]; |
47 |
gforget |
1.1 |
pcolor(x,y,z); axis([-180 180 -90 90]); shading flat; caxis([-2 1]); colorbar; |
48 |
|
|
|
49 |
gforget |
1.11 |
figure; [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,z_interp); |
50 |
gforget |
1.1 |
pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat; caxis([-2 1]); colorbar; |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|