/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_calc/gcmfaces_interp_1d.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/gcmfaces_interp_1d.m

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


Revision 1.1 - (hide annotations) (download)
Thu Apr 16 17:49:27 2015 UTC (10 years, 3 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
- gcmfaces_interp.m : bilinear interpolation using gcmfaces_interp_coeffs
- gcmfaces_interp_1d.m : linear interpolation along depth or time dimension

1 gforget 1.1 function [Vq]=gcmfaces_interp_1d(xDim,X,V,Xq,varargin);
2     %[val]=gcmfaces_interp_1d(xDim,X,fld,Xq,varargin);
3     %object: linearly interpolate field along xDim dimension
4     % (>3 for gcmfaces objects)
5     %inputs: xDim is the dimension along which to interpolate
6     % X is the original position vector
7     % V is a gcmfaces object with at least
8     % Xq is the target position vector
9     %optional: varargin ...
10     %outputs: Vq is the interpolated field
11    
12     gcmfaces_global;
13    
14     %change format if needed
15     isagcmfaces=isa(V,'gcmfaces');
16     if isagcmfaces; V=convert2gcmfaces(V); end;
17    
18     %move interpolation dimension to first
19     ndim=length(size(V));
20     tmp1=circshift([1:ndim],[0 1-xDim]);
21     V=permute(V,tmp1);
22     if size(X,1)==1; X=X'; end;
23     if size(Xq,1)==1; Xq=Xq'; end;
24    
25     %the interpolation itself
26     Kq=interp1(X,[1:length(X)]',Xq,'linear');
27     Kqne=interp1(X,[1:length(X)]',Xq,'nearest','extrap');
28    
29     %use bilinear; then extrapolate with nearest neighbor
30     Vq=NaN*repmat(V(1,:,:),[length(Xq) 1 1]);
31     for kk=1:length(Xq);
32     if ~isnan(Kq(kk));
33     k0=floor(Kq(kk));
34     k1=min(k0+1,length(X));
35     a0=Kq(kk)-k0;
36     tmp1=(1-a0)*V(k0,:,:)+a0*V(k1,:,:);
37     else;
38     tmp1=NaN*V(1,:,:);
39     end;
40     tmp2=V(Kqne(kk),:,:);
41     tmp1(isnan(tmp1))=tmp2(isnan(tmp1));
42     Vq(kk,:,:)=tmp1;
43     end;
44    
45     %move interpolation dimension to first
46     ndim=length(size(Vq));
47     tmp1=circshift([1:ndim],[0 xDim-1]);
48     Vq=permute(Vq,tmp1);
49    
50     %change format if needed
51     if isagcmfaces; Vq=convert2gcmfaces(Vq); end;
52    

  ViewVC Help
Powered by ViewVC 1.1.22