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

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

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


Revision 1.6 - (hide annotations) (download)
Mon Jan 11 17:30:11 2016 UTC (10 years, 9 months ago) by gforget
Branch: MAIN
Changes since 1.5: +13 -13 lines
- revise handing of path, grid and input files, warnings and messages:

1 gforget 1.5 function []=example_faces2latlon2faces();
2 gforget 1.1 %object: interpolate back and forth between gcmfaces and lat-lon grid
3    
4 gforget 1.6 %%%%%%%%%%%%%%%%%
5     %load grid:
6     %%%%%%%%%%%%%%%%%
7    
8     p = genpath('gcmfaces/'); addpath(p);
9     p = genpath('MITprof/'); addpath(p);
10    
11     gcmfaces_global;
12    
13     mygrid=[]; grid_load;
14 gforget 1.1
15     if myenv.verbose>0;
16     gcmfaces_msg('===============================================');
17     gcmfaces_msg(['*** entering example_faces2latlon2faces that will ' ...
18     'interpolate a field on the chosen to a lat-lon grid and back' ...
19     'to the original grid'],'');
20     end;
21    
22     %store reference grid
23     mygrid_refgrid=mygrid;
24    
25 gforget 1.6 %triangulation variable generated by gcmfaces_bindata
26     global mytri;
27    
28 gforget 1.1 %%%%%%%%%%%%%%%%%%%
29     %field for testing:
30     %%%%%%%%%%%%%%%%%%%
31    
32     if myenv.verbose>0;
33     gcmfaces_msg('* define a sinusoidal field for testing');
34     end;
35     fld=sin(2*pi/180*mygrid.XC).*sin(2*pi/180*mygrid.YC);
36    
37     %%%%%%%%%%%%%%%%%%%%%%%%%%
38     %lat-lon grid for testing:
39     %%%%%%%%%%%%%%%%%%%%%%%%%%
40    
41     if myenv.verbose>0;
42     gcmfaces_msg('* define 2x2 lat-lon grid for testing');
43     end;
44     %define lat-lon grid
45     lon=[-179:2:179]; lat=[-89:2:89]; aa=[-180 180 -90 90];
46     if max(mygrid_refgrid.XC)>180;
47     lon=[1:2:359]; aa=[0 360 -90 90];
48     end;
49     % lon=[-179:2:179]; lat=[-30:2:30];
50     [lat,lon] = meshgrid(lat,lon);
51     %prepare mygrid for lat-lon with no mask
52     mygrid_latlon.nFaces=1;
53     mygrid_latlon.XC=gcmfaces({lon}); mygrid_latlon.YC=gcmfaces({lat});
54 gforget 1.3 mygrid_latlon.dirGrid='none';
55     mygrid_latlon.fileFormat='straight';
56     mygrid_latlon.ioSize=size(lon);
57 gforget 1.1
58     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59     %interpolate to lat-lon grid:
60     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61    
62     if myenv.verbose>0;
63     gcmfaces_msg('* interpolate test field to lat-lon grid');
64     end;
65     mygrid=mygrid_latlon; gcmfaces_bindata;
66     veclon=convert2array(mygrid.XC); veclon=veclon(mytri.kk);
67     veclat=convert2array(mygrid.YC); veclat=veclat(mytri.kk);
68    
69     mygrid=mygrid_refgrid; gcmfaces_bindata;
70     vecfld=gcmfaces_interp_2d(fld,veclon,veclat);%go from gcmfaces grid to lat-lon grid
71    
72     mygrid=mygrid_latlon; gcmfaces_bindata;
73     fld_latlon=NaN*convert2array(mygrid.XC);
74     fld_latlon(mytri.kk)=vecfld;
75     fld_latlon=convert2array(fld_latlon);
76    
77     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78     %interpolate back to ref grid:
79     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80    
81     if myenv.verbose>0;
82     gcmfaces_msg('* interpolate back to original grid');
83     end;
84     mygrid=mygrid_refgrid; gcmfaces_bindata;
85     veclon=convert2array(mygrid.XC); veclon=veclon(mytri.kk);
86     veclat=convert2array(mygrid.YC); veclat=veclat(mytri.kk);
87    
88     mygrid=mygrid_latlon; gcmfaces_bindata;
89     vecfld=gcmfaces_interp_2d(fld_latlon,veclon,veclat);%go from gcmfaces grid to lat-lon grid
90    
91     mygrid=mygrid_refgrid; gcmfaces_bindata;
92     fld_refgrid=NaN*convert2array(mygrid.XC);
93     fld_refgrid(mytri.kk)=vecfld;
94     fld_refgrid=convert2array(fld_refgrid);
95    
96     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97     %get and plot the lat-lon array:
98     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99    
100     if myenv.verbose>0;
101     gcmfaces_msg('* plot lat-lon grid interpolated field');
102     end;
103     FLD=fld_latlon{1};
104 gforget 1.4 figureL;
105     subplot(2,1,1); set(gca,'FontSize',14);
106     pcolor(lon,lat,FLD); axis([-270 270 -100 100]);
107     shading flat; colorbar; title('interpolated lat-lon map');
108 gforget 1.1
109     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110     %plot difference due to interpolation
111     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112    
113     if myenv.verbose>0;
114     gcmfaces_msg('* plot error due to back and forth interpolation');
115     end;
116     mygrid=mygrid_refgrid;
117 gforget 1.4 subplot(2,1,2); set(gca,'FontSize',14);
118     [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld_refgrid-fld);
119     pcolor(X,Y,log10(abs(FLD))); axis([-270 270 -100 100]);
120     shading flat; caxis([-5 -2]); colorbar;
121     title('log10(error) due to back and forth interpolation');
122 gforget 1.1
123     if myenv.verbose>0;
124     gcmfaces_msg('*** leaving example_faces2latlon2faces');
125     gcmfaces_msg('===============================================');
126     end;

  ViewVC Help
Powered by ViewVC 1.1.22