/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_processing/example_interp.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/sample_processing/example_interp.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (hide annotations) (download)
Sun Jan 24 16:25:52 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
Changes since 1.14: +3 -4 lines
- gcmfaces_demo.m: improve help section, add comments wrt gcmfaces_global etc
- example*.m: homogeneize treatment of mygrid (don't reload if not needed)
  and path (use just gcmfaces_global)

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

  ViewVC Help
Powered by ViewVC 1.1.22