/[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.5 - (hide annotations) (download)
Fri Mar 20 15:41:43 2015 UTC (11 years, 7 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.4: +5 -20 lines
- remove deprecated choiceGrid (or choiceV3orV4) switches and arguments

1 gforget 1.5 function []=example_faces2latlon2faces();
2 gforget 1.1 %object: interpolate back and forth between gcmfaces and lat-lon grid
3    
4     gcmfaces_global; global mytri;
5    
6     if myenv.verbose>0;
7     gcmfaces_msg('===============================================');
8     gcmfaces_msg(['*** entering example_faces2latlon2faces that will ' ...
9     'interpolate a field on the chosen to a lat-lon grid and back' ...
10     'to the original grid'],'');
11     end;
12    
13     %%%%%%%%%%%%%%%%%
14     %load parameters:
15     %%%%%%%%%%%%%%%%%
16    
17 gforget 1.4 gcmfaces_global;
18 gforget 1.5
19     nF=5;
20     fileFormat='compact';
21     dirGrid=fullfile(myenv.gcmfaces_dir,'..',filesep,'GRID',filesep);
22 gforget 1.4
23     mygrid=[]; grid_load(dirGrid,nF,fileFormat,1);
24 gforget 1.1
25     %store reference grid
26     mygrid_refgrid=mygrid;
27    
28     %%%%%%%%%%%%%%%%%%%
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