/[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.3 - (hide annotations) (download)
Fri Jan 29 15:19:48 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.2: +1 -2 lines
- gcmfaces_interp_1d.m: bug fix
- gcmfaces_interp_2d.m: treat case of a single data point

1 gforget 1.2 function [Vq]=gcmfaces_interp_1d(xDim,X,V,Xq);
2     %[Vq]=GCMFACES_INTERP_1D(xDim,X,V,Xq);
3     % Linearly interpolates a field (V; array or gcmfaces) along a
4     % selected dimension (xDim) from locations specified in
5     % vector X to locations specified in vector Xq
6 gforget 1.1
7     gcmfaces_global;
8    
9     %change format if needed
10     isagcmfaces=isa(V,'gcmfaces');
11     if isagcmfaces; V=convert2gcmfaces(V); end;
12    
13     %move interpolation dimension to first
14     ndim=length(size(V));
15     tmp1=circshift([1:ndim],[0 1-xDim]);
16     V=permute(V,tmp1);
17     if size(X,1)==1; X=X'; end;
18     if size(Xq,1)==1; Xq=Xq'; end;
19    
20     %the interpolation itself
21     Kq=interp1(X,[1:length(X)]',Xq,'linear');
22     Kqne=interp1(X,[1:length(X)]',Xq,'nearest','extrap');
23    
24     %use bilinear; then extrapolate with nearest neighbor
25     Vq=NaN*repmat(V(1,:,:),[length(Xq) 1 1]);
26     for kk=1:length(Xq);
27     if ~isnan(Kq(kk));
28     k0=floor(Kq(kk));
29     k1=min(k0+1,length(X));
30     a0=Kq(kk)-k0;
31     tmp1=(1-a0)*V(k0,:,:)+a0*V(k1,:,:);
32     else;
33     tmp1=NaN*V(1,:,:);
34     end;
35     tmp2=V(Kqne(kk),:,:);
36     tmp1(isnan(tmp1))=tmp2(isnan(tmp1));
37     Vq(kk,:,:)=tmp1;
38     end;
39 gforget 1.3
40 gforget 1.1 %move interpolation dimension to first
41     tmp1=circshift([1:ndim],[0 xDim-1]);
42     Vq=permute(Vq,tmp1);
43    
44     %change format if needed
45     if isagcmfaces; Vq=convert2gcmfaces(Vq); end;
46    

  ViewVC Help
Powered by ViewVC 1.1.22