/[MITgcm]/MITgcm_contrib/gael/comm/course-idma2016/matlab/idma_interp_2d.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/comm/course-idma2016/matlab/idma_interp_2d.m

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


Revision 1.1 - (hide annotations) (download)
Fri Jan 15 07:18:38 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: HEAD
- IDMA_AREA_MEAN computes area-weighted average
- IDMA_INTERP_2D linearly interpolates gcmfaces field to a set of locations

1 gforget 1.1 function [val]=idma_interp_2d(lon,lat,fld,method);
2     %IDMA_INTERP_2D linearly interpolates gcmfaces field (fld) to
3     % a set of locations (lon, lat) using one of several methods:
4     % 'natural', 'linear', 'nearest', or 'mix' (default).
5     % The 'mix' is `natural' extended with 'nearest' when
6     % the input field has been land-masked with NaNs.
7     %
8     %Example:
9     % lon=[-179.9:0.2:179.9]; lat=[-89.9:0.2:89.9];
10     % [lat,lon] = meshgrid(lat,lon);
11     % fld=mygrid.Depth.*mygrid.mskC(:,:,1);
12     % [val]=idma_interp_2d(lon,lat,fld);
13     % figureL; pcolor(lon,lat,val); shading flat;
14    
15     gcmfaces_global;
16     if isempty(whos('method'));
17     method='mix';
18     end;
19    
20     if isempty(which('DelaunayTri'));
21     error('this code needs DelaunayTri that is not found');
22     end;
23    
24     XC=convert2array(mygrid.XC);
25     YC=convert2array(mygrid.YC);
26     VEC=convert2array(fld);
27     val=NaN*lon;
28     for ii=1:3;
29     if ii==1;
30     myXC=XC; myXC(myXC<0)=myXC(myXC<0)+360;
31     jj=find(lon>90);
32     elseif ii==2;
33     myXC=XC;
34     jj=find(lon>=-90&lon<=90);
35     else;
36     myXC=XC; myXC(myXC>0)=myXC(myXC>0)-360;
37     jj=find(lon<-90);
38     end;
39     kk=find(~isnan(myXC));
40     TRI=DelaunayTri(myXC(kk),YC(kk));
41     if strcmp(method,'mix');
42     F = TriScatteredInterp(TRI, VEC(kk),'natural');
43     tmp1=F(lon(jj),lat(jj));
44     F = TriScatteredInterp(TRI, VEC(kk),'nearest');
45     tmp2=F(lon(jj),lat(jj));
46     tmp1(isnan(tmp1))=tmp2(isnan(tmp1));
47     val(jj)=tmp1;
48     else;
49     F = TriScatteredInterp(TRI, VEC(kk),method);
50     val(jj)=F(lon(jj),lat(jj));
51     end;
52     end;
53    
54    

  ViewVC Help
Powered by ViewVC 1.1.22