function []=example_griddata(); %object: a griddata example within gcmfaces %%%%%%%%%%%%%%%%% %load grid: %%%%%%%%%%%%%%%%% gcmfaces_global; if isempty(mygrid); grid_load; end; if myenv.verbose>0; gcmfaces_msg('==============================================='); gcmfaces_msg(['*** entering example_griddata that will define ' ... 'a 2x2 gridded variable (an bathymetry field here), and then ' ... 'use griddata to map it to the chosen grid. '],''); end; %%%%%%%%%%%%%%%%%%%%%%% %get sample data: subsampled mygrid.Depth if myenv.verbose>0; gcmfaces_msg('* define test case : subsampled bathymetry'); end; original_Depth=mygrid.Depth; original_Depth(original_Depth==0)=NaN; lon=mygrid.XC; lat=mygrid.YC; for ff=1:mygrid.nFaces; lon{ff}(1:2:end,:)=NaN; lat{ff}(1:2:end,:)=NaN; original_Depth{ff}(1:2:end,:)=NaN; lon{ff}(:,1:2:end)=NaN; lat{ff}(:,1:2:end)=NaN; original_Depth{ff}(:,1:2:end)=NaN; end; lon=convert2vector(lon); lat=convert2vector(lat); vec=convert2vector(original_Depth); %%%%%%%%%%%%%%%%%%%%%%% %make sure to accomodate the two longitude conventions: if myenv.verbose>0; gcmfaces_msg('* accomodate both lon. conventions, then convert to data vector'); end; x=[lon-360;lon;lon+360]; y=[lat;lat;lat]; z=[vec;vec;vec]; jj=find(~isnan(z)); x=x(jj); y=y(jj); z=z(jj); %%%%%%%%%%%%%%%%%%%%%%% %do the interpolation: if myenv.verbose>0; gcmfaces_msg('* map/interpolate data using griddata'); end; griddata_Depth=gcmfaces(5); for ii=1:mygrid.nFaces; xi=mygrid.XC{ii}; yi=mygrid.YC{ii}; zi = griddata(x',y',z',xi,yi); griddata_Depth{ii}=zi; end; %msk=mygrid.hFacC(:,:,1); griddata_Depth(find(msk==0))=NaN; %%%%%%%%%%%%%%%%%%%%%%% %illustrate the result: figureL; subplot(2,1,1); set(gca,'FontSize',14); [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,original_Depth); pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat; title('input to griddata'); subplot(2,1,2); set(gca,'FontSize',14); [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,griddata_Depth); pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat; title('output of griddata'); if myenv.verbose>0; gcmfaces_msg('* note of caution : griddata puts values on land. '); gcmfaces_msg('*** leaving example_griddata'); gcmfaces_msg('==============================================='); end;