1 |
function [outq,jj]=interp_scalar(fem_grid_struct,q,x,y,j) |
---|
2 |
%INTERP_SCALAR - interpolate scalar values onto scatter points |
---|
3 |
% INTERP_SCALAR Interpolates a scalar defined at all 2-D grid points |
---|
4 |
% in the fem_grid_struct onto the scattered points (x,y). |
---|
5 |
% |
---|
6 |
% INPUT : fem_grid_struct (from LOADGRID, see FEM_GRID_STRUCT) |
---|
7 |
% q - scalar field to interpolate |
---|
8 |
% x,y - points to interpolate to (optional) |
---|
9 |
% j - elements that contain x,y points (optional) |
---|
10 |
% |
---|
11 |
% If x,y are not passed in, INTERP_SCALAR prompts the user |
---|
12 |
% to specify a location with the mouse. In this case, |
---|
13 |
% the location, element number, and interpolated vaule |
---|
14 |
% are returned through the first output argument, or else |
---|
15 |
% to the screen, as [x y j outq]. |
---|
16 |
% |
---|
17 |
% If j is not passed in, INTERP_SCALAR locates the points |
---|
18 |
% within fem_grid_struct and returns the element list |
---|
19 |
% if two output arguments are provided. |
---|
20 |
% |
---|
21 |
% OUTPUT : outq - interpolated values |
---|
22 |
% j - elements (optional) |
---|
23 |
% x,y - mouse-specified point (optional) |
---|
24 |
% |
---|
25 |
% CALL : outq=interp_scalar(fem_grid_struct,q); (mouse-driven) |
---|
26 |
% [outq,j]=interp_scalar(fem_grid_struct,q,x,y); |
---|
27 |
% outq=interp_scalar(fem_grid_struct,q,x,y,j); |
---|
28 |
% |
---|
29 |
% Written by : Brian O. Blanton |
---|
30 |
% Summer 1998 |
---|
31 |
|
---|
32 |
|
---|
33 |
if nargin <2 | nargin>5 |
---|
34 |
error(' Incorrect number of input arguments to INTERP_SCALAR'); |
---|
35 |
end |
---|
36 |
|
---|
37 |
% VERIFY INCOMING STRUCTURE |
---|
38 |
% |
---|
39 |
if ~is_valid_struct(fem_grid_struct) |
---|
40 |
error(' Argument to INTERP_SCALAR must be a valid fem_grid_struct.') |
---|
41 |
end |
---|
42 |
|
---|
43 |
if ~is_valid_struct2(fem_grid_struct) |
---|
44 |
disp('Adding components') |
---|
45 |
fem_grid_struct=el_areas(fem_grid_struct); |
---|
46 |
fem_grid_struct=belint(fem_grid_struct); |
---|
47 |
end |
---|
48 |
|
---|
49 |
if nargin==2 |
---|
50 |
x=[];y=[];j=[]; |
---|
51 |
elseif nargin==3 |
---|
52 |
error('Must pass in both x AND y to INTERP_SCALAR') |
---|
53 |
elseif nargin==4 |
---|
54 |
if length(y)~=length(x) |
---|
55 |
error('lengths of x and y MUST be equal.') |
---|
56 |
end |
---|
57 |
j=[]; |
---|
58 |
elseif nargin==5 |
---|
59 |
if length(j)~=length(x) |
---|
60 |
error('lengths of element list and x,y must be equal.') |
---|
61 |
end |
---|
62 |
end |
---|
63 |
|
---|
64 |
e=fem_grid_struct.e; |
---|
65 |
AR=fem_grid_struct.ar; |
---|
66 |
A0=fem_grid_struct.A0; |
---|
67 |
A=fem_grid_struct.A; |
---|
68 |
B=fem_grid_struct.B; |
---|
69 |
|
---|
70 |
if isempty(x) |
---|
71 |
disp('Click on a point ...'); |
---|
72 |
waitforbuttonpress; |
---|
73 |
Pt=gcp; |
---|
74 |
x=Pt(2);y=Pt(4); |
---|
75 |
line(x,y,'LineStyle','none','Marker','+') |
---|
76 |
j=[]; |
---|
77 |
end |
---|
78 |
|
---|
79 |
% Need to know which elements the input (x,y) points |
---|
80 |
% live in, if not passed in |
---|
81 |
% |
---|
82 |
if isempty(j) |
---|
83 |
j=findelemex5(x,y,fem_grid_struct.ar,... |
---|
84 |
fem_grid_struct.A,... |
---|
85 |
fem_grid_struct.B,... |
---|
86 |
fem_grid_struct.T); |
---|
87 |
end |
---|
88 |
|
---|
89 |
% Only operate on points within domain. |
---|
90 |
idx=find(~isnan(j)); |
---|
91 |
jdx=j(idx); |
---|
92 |
|
---|
93 |
ARI=.5./AR(jdx); |
---|
94 |
ARI=ARI(:); |
---|
95 |
A03 = AR(jdx)-A0(jdx,1) - A0(jdx,2); |
---|
96 |
|
---|
97 |
q1 = q(e(jdx,1)); |
---|
98 |
q2 = q(e(jdx,2)); |
---|
99 |
q3 = q(e(jdx,3)); |
---|
100 |
|
---|
101 |
e1 = ARI.* (B(jdx,1).*q1+B(jdx,2).*q2+B(jdx,3).*q3); |
---|
102 |
e2 = ARI.* (A(jdx,1).*q1+A(jdx,2).*q2+A(jdx,3).*q3); |
---|
103 |
e3 = 2*ARI.* (A0(jdx,1).*q1+A0(jdx,2).*q2+A03.*q3); |
---|
104 |
|
---|
105 |
x=x(:);y=y(:); |
---|
106 |
|
---|
107 |
outq=NaN*ones(size(x)); |
---|
108 |
outq(idx) = e1.*x(idx) + e2.*y(idx) + e3; |
---|
109 |
|
---|
110 |
if nargin==0 |
---|
111 |
[x y j q] |
---|
112 |
elseif nargin==2 |
---|
113 |
if nargout==1 |
---|
114 |
outq=[x y j outq]; |
---|
115 |
else |
---|
116 |
jj=j; |
---|
117 |
end |
---|
118 |
elseif nargin==4 |
---|
119 |
if nargout==2 |
---|
120 |
jj=j; |
---|
121 |
end |
---|
122 |
end |
---|
123 |
|
---|
124 |
% |
---|
125 |
% Brian O. Blanton |
---|
126 |
% Department of Marine Sciences |
---|
127 |
% 15-1A Venable Hall |
---|
128 |
% CB# 3300 |
---|
129 |
% Uni. of North Carolina |
---|
130 |
% Chapel Hill, NC |
---|
131 |
% 27599-3300 |
---|
132 |
% |
---|
133 |
% 919-962-4466 |
---|
134 |
% blanton@marine.unc.edu |
---|
135 |
% |
---|
136 |
% Summer 1998 |
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|