| 1 |
gforget |
1.8 |
function []=example_griddata(choiceV3orV4); |
| 2 |
|
|
%object: a griddata example within gcmfaces |
| 3 |
|
|
%inputs: choiceV3orV4 ('v3' or 'v4') selects the sample GRID |
| 4 |
gforget |
1.1 |
|
| 5 |
|
|
%%%%%%%%%%%%%%%%% |
| 6 |
|
|
%load parameters: |
| 7 |
|
|
%%%%%%%%%%%%%%%%% |
| 8 |
|
|
|
| 9 |
gforget |
1.9 |
gcmfaces_global; |
| 10 |
|
|
dir0=[myenv.gcmfaces_dir '/sample_input/']; |
| 11 |
gforget |
1.8 |
dirGrid=[dir0 '/GRID' choiceV3orV4 '/']; |
| 12 |
|
|
dirIn=[dir0 '/SAMPLE' choiceV3orV4 '/']; |
| 13 |
|
|
if strcmp(choiceV3orV4,'v4'); nF=5; fileFormat='compact'; else; nF=1; fileFormat='straight'; end; |
| 14 |
|
|
global mygrid; mygrid=[]; grid_load(dirGrid,nF,fileFormat); |
| 15 |
gforget |
1.1 |
|
| 16 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
| 17 |
gforget |
1.2 |
%get sample data: V3 SSH |
| 18 |
gforget |
1.9 |
dirV3=[myenv.gcmfaces_dir '/sample_input/SAMPLEv3/']; |
| 19 |
gforget |
1.2 |
etan=rdmds([dirV3 'DDetan'],0); etan(etan==0)=NaN; |
| 20 |
gforget |
1.9 |
dirV3=[myenv.gcmfaces_dir '/sample_input/GRIDv3/']; |
| 21 |
gforget |
1.2 |
lon=rdmds([dirV3 'XC']); lat=rdmds([dirV3 'YC']); |
| 22 |
gforget |
1.1 |
|
| 23 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
| 24 |
|
|
%do the interpolation: |
| 25 |
|
|
x=[lon-360;lon]; y=[lat;lat]; z=[etan;etan]; |
| 26 |
|
|
jj=find(~isnan(z)); x=x(jj); y=y(jj); z=z(jj); |
| 27 |
|
|
|
| 28 |
|
|
z_interp=gcmfaces(5); |
| 29 |
gforget |
1.8 |
for ii=1:mygrid.nFaces; |
| 30 |
gforget |
1.1 |
xi=mygrid.XC{ii}; yi=mygrid.YC{ii}; |
| 31 |
|
|
zi = griddata(x',y',z',xi,yi); |
| 32 |
|
|
z_interp{ii}=zi; |
| 33 |
|
|
end; |
| 34 |
|
|
|
| 35 |
|
|
%msk=mygrid.hFacC(:,:,1); z_interp(find(msk==0))=NaN; |
| 36 |
|
|
|
| 37 |
|
|
%%%%%%%%%%%%%%%%%%%%%%% |
| 38 |
|
|
%illustrate the result: |
| 39 |
|
|
|
| 40 |
|
|
figure; set(gcf,'Units','Normalized','Position',[0.1 0.1 0.4 0.6]); |
| 41 |
|
|
x=[lon-360;lon]; y=[lat;lat]; z=[etan;etan]; |
| 42 |
|
|
pcolor(x,y,z); axis([-180 180 -90 90]); shading flat; caxis([-2 1]); colorbar; |
| 43 |
|
|
|
| 44 |
|
|
figure; set(gcf,'Units','Normalized','Position',[0.5 0.1 0.4 0.6]); |
| 45 |
|
|
[X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,z_interp); |
| 46 |
|
|
pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat; caxis([-2 1]); colorbar; |
| 47 |
|
|
|
| 48 |
gforget |
1.8 |
fprintf('note that griddata puts values in remote places ... \n'); |
| 49 |
|
|
fprintf('so one should obviously be cautious when using this routine\n'); |
| 50 |
|
|
fprintf('hit return to continue \n'); |
| 51 |
gforget |
1.1 |
pause; |
| 52 |
|
|
|