/[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.19 - (hide annotations) (download)
Thu Mar 3 17:04:35 2016 UTC (9 years, 4 months ago) by gforget
Branch: MAIN
Changes since 1.18: +14 -0 lines
- gcmfaces_interp_coeffs.m: add sparse matrix output (for interpolation using convert2vector.m).
- example_interp.m: add sparse matrix method exmaple (inactive).
- convert2vector.m: revised method ('new') that uses gcmfaces (old method remains the default).
- gcmfaces_interp_2d.m: remove extra ';'

1 gforget 1.13 function []=example_interp();
2 gforget 1.16 % EXAMPLE_INTERP illustrates interpolation capabilities
3     % by going back and forth between gcmfaces grid and
4     % longitude-latitude arrays
5    
6     gcmfaces_global;
7    
8     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9     if myenv.verbose>0;
10     gcmfaces_msg('===============================================');
11     gcmfaces_msg(['*** entering example_interp: illustrate ' ...
12     'interpolation capabilities to get in and out of gcmfaces'],'');
13     end;
14 gforget 1.1
15     %%%%%%%%%%%%%%%%%
16 gforget 1.16 %load grid and setup test case:
17 gforget 1.1 %%%%%%%%%%%%%%%%%
18    
19 gforget 1.15 if isempty(mygrid);
20     grid_load;
21     end;
22 gforget 1.12
23 gforget 1.16 %target locations:
24     lon=[-179.75:0.5:179.75]; lat=[-89.75:0.5:89.75];
25     [lat,lon] = meshgrid(lat,lon);
26    
27     %original field:
28     m=mygrid.mskC(:,:,1);
29     fld=m.*mygrid.Depth;
30 gforget 1.1
31     %%%%%%%%%%%%%%%%%%%%%%%
32 gforget 1.16 %interpolate mygrid.Depth to lon-lat grid:
33    
34 gforget 1.12 if myenv.verbose>0;
35 gforget 1.16 gcmfaces_msg('* interpolate mygrid.Depth to lon-lat grid');
36 gforget 1.12 end;
37 gforget 1.16
38     fld_interp=gcmfaces_interp_2d(fld,lon,lat);
39 gforget 1.1
40 gforget 1.19 if 0;
41     %use sparse matrix method:
42     interp=gcmfaces_interp_coeffs(lon(:),lat(:));
43     %
44     tmp1=convert2vector(fld,'new');
45     tmp0=1*~isnan(tmp1);
46     tmp1(isnan(tmp1))=0;
47     %
48     tmp0=interp.SPM*tmp0;
49     tmp1=interp.SPM*tmp1;
50     %
51     fld_SPM=reshape(tmp1./tmp0,size(lon));
52     end;
53    
54 gforget 1.1 %%%%%%%%%%%%%%%%%%%%%%%
55 gforget 1.17 %interpolate back to mygrid.XC, mygrid.YC:
56 gforget 1.1
57 gforget 1.16 if myenv.verbose>0;
58 gforget 1.17 gcmfaces_msg('* interpolate back to gcmfaces grid');
59     end;
60    
61 gforget 1.18 fld_reinterp=gcmfaces_interp_2d(fld_interp,lon,lat,'linear');
62 gforget 1.17
63     %%%%%%%%%%%%%%%%%%%%%%%
64     %remap to gcmfaces grid using extrapolation:
65    
66     if myenv.verbose>0;
67     gcmfaces_msg('* remap to gcmfaces grid using extrapolation');
68 gforget 1.1 end;
69    
70 gforget 1.16 fld_remap=gcmfaces_remap_2d(lon,lat,fld_interp,0,m);
71    
72 gforget 1.1 %%%%%%%%%%%%%%%%%%%%%%%
73 gforget 1.16 %illustrate results:
74 gforget 1.1
75 gforget 1.12 figureL;
76 gforget 1.17 subplot(2,1,1); set(gca,'FontSize',14);
77 gforget 1.16 [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld);
78     pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat;
79     title('original field');
80 gforget 1.17 subplot(2,1,2); set(gca,'FontSize',14);
81 gforget 1.16 pcolor(lon,lat,fld_interp); axis([-180 180 -90 90]); shading flat;
82     title('interpolated field');
83 gforget 1.17
84     figureL;
85     subplot(2,1,1); set(gca,'FontSize',14);
86     [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld_reinterp);
87     pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat;
88     title('reinterpolated field');
89     subplot(2,1,2); set(gca,'FontSize',14);
90 gforget 1.16 [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld_remap);
91 gforget 1.12 pcolor(X,Y,FLD); axis([-180 180 -90 90]); shading flat;
92 gforget 1.16 title('remapped field');
93    
94    
95     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96     if myenv.verbose>0;
97     gcmfaces_msg('*** leaving example_interp');
98     gcmfaces_msg('===============================================');
99     end;
100 gforget 1.1
101    

  ViewVC Help
Powered by ViewVC 1.1.22