NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/FCAST_1.2/interprect.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function R=interprect(Q,Z,m,slev)
2
3 % R=interprect(Q,Z,m,slev)
4 %
5 % INPUTS:
6 % Q [nn x nnv]        = Scalar quantity
7 % Z [nn x nnv]        = Vertical locations of nodes
8 %
9 % OUTPUT STRUCTURE:
10 % R.Q                 = interpolated quantity
11 % R.X, R.Y and R.Z    = actual x locations of grid
12 % R.XG, R.YG and R.ZG = integer grid indices
13
14 % OPNML COMPLIANT 3-19-99 CVL
15
16 if nargin<4
17         slev=[10e4 10e4];
18 elseif length(slev)==1
19         slev=slev*[1 1];
20 end
21
22 % Transposing Q and Z; I assume you have more
23 % horizontal than vertical nodes!
24
25 Q=Q';
26 Z=Z';
27 nnv=size(Q,1);
28
29 % DEFINE MESH SPATIAL GRID AND NODAL GRID
30
31 x=slev(1)*(floor(min(m.x(:))/slev(1)):...
32         ceil(max(m.x(:))/slev(1))+1);
33 y=slev(2)*(floor(min(m.y(:))/slev(2)):...
34         ceil(max(m.y(:))/slev(2))+1);
35
36 xg=1:length(x);
37 yg=1:length(y);
38 zg=1:nnv;
39 [x,y,z]=meshgrid(x,y,zg);
40 [rx,ry,rz]=size(x);
41 [xg,yg,zg]=meshgrid(xg,yg,zg);
42
43 % CALCULATE BASIS FUNCTIONS FOR MESH
44
45 m=belint(m);
46 m=el_areas(m);
47
48 % CALCULATE POINTS ON LINE
49
50 xc=x(:,:,1);
51 yc=y(:,:,1);
52
53 xy=[xc(:),yc(:)];
54 [p,l]=basis2d(m,xy);
55
56 ind=find(~isnan(l(:)));
57 l=l(ind);
58 p=p(ind,1:3);
59
60 % INITIALIZE RESULTS FIELD
61
62 r=nan*ones(rx*ry,rz);
63 zo=nan*ones(rx*ry,rz);
64
65 % INTERPOLATE AT EACH SIGMA LEVEL
66
67 for in=1:nnv
68         qs=Q(in,:);
69         zs=Z(in,:);
70         r(ind,in)=sum(p'.*qs(m.e(l,:))')';
71         zo(ind,in)=sum(p'.*zs(m.e(l,:))')';
72 end
73
74 % CORRECT zo FOR NaN'S
75
76 ind=find(isnan(zo(:,1)));
77 inddeep=min(find(Z(1,:)==min(Z(1,:))));
78 zo(ind,:)=ones(length(ind),1)*Z(:,inddeep)';
79
80 % BUILD OUTPUT STRUCTURE
81
82 R.Q=reshape(r,rx,ry,rz);
83 R.X=x;
84 R.Y=y;
85 R.Z=reshape(zo,rx,ry,rz);
86 R.XG=xg;
87 R.YG=yg;
88 R.ZG=zg;
Note: See TracBrowser for help on using the browser.