rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
velocity_matrixfile_extract.m
1 function [Vx, Vy, lambda] = velocity_matrixfile_extract(fullfn,X,Y)
2 %function [Vx, Vy, lambda] = velocity_matrixfile_extract(fullfn,X,Y)
3 %
4 % function extracting the velocities from the given file in the
5 % points X and Y. A search is performed in case of partial access.
6 % So this function is expensive.
7 
8 %V = load(fullfn);
9 V = cache('load',fullfn);
10 
11 % find integer indices such that V.X(j)==X(i) and V.Y(j) = Y(i)
12 % if whole flux-matrix is requested
13 
14 if ~isempty(X) % otherwise size 0/0 => 0/1 !!!
15  X = X(:); Y = Y(:);
16 end;
17 
18 if isequal(X,V.X(:)) && isequal(Y,V.Y(:))
19  i = 1:length(X);
20  j = 1:length(X);
21 elseif isempty(X)
22  i = [];
23  j = [];
24 else
25  % otherwise search corresponding matrix entries
26  %% the following gives memory problem in 'large point set' requests
27  % keyboard;
28  % VXX = repmat(V.X(:)',length(X),1);
29  % VYY = repmat(V.Y(:)',length(X),1);
30  % XX = repmat(X(:),1,length(V.X));
31  % YY = repmat(Y(:),1,length(V.X));
32  % [i,j] = find(VXX==XX & VYY==YY);
33  % should give one entry for each i!!
34  % if ~isequal(sort(i),(1:length(X))')
35  % error('requested points not or multiple times in matrix!');
36  % end;
37 
38  % so mixture: blockwise approach as above
39  % i = [];j = [];
40  % % compute optimal cut-size if required
41  % n1 = length(X(:));
42  % cutsize = ceil(5000000/length(V.X));
43  % ncuts = ceil(n1/cutsize)
44  % for c = 1:ncuts
45  % ind1 = (1+(c-1)*cutsize):min(n1, c*cutsize);
46  % ind1 = ind1';
47  % VXX = repmat(V.X(:)',length(ind1),1);
48  % VYY = repmat(V.Y(:)',length(ind1),1);
49  % XX = repmat(X(ind1),1,length(V.X));
50  % YY = repmat(Y(ind1),1,length(V.X));
51  % [ipart,jpart] = find(VXX==XX & VYY==YY);
52  % j = [j; jpart(:)];
53  % i = [i; ipart(:)+(c-1)*cutsize];
54  % end;
55 
56  [i,j] = find_corresp([X(:)';Y(:)'],[V.X(:)';V.Y(:)']);
57  % remove occasional double find-results (inner edges)
58  [si, sind] = sort(i);
59  sj = j(sind);
60  % forward-difference
61  diff = si(2:end)-si(1:end-1);
62  k = find(diff~=0); % => si(k+1)~=si(k)
63  i = [si(1);si(k+1)];
64  j = [sj(1);sj(k+1)];
65  %should give one entry for each i!!
66  if ~isequal(sort(i),(1:length(X))')
67  error('requested points not or multiple times in matrix!');
68  end;
69 end;
70 % i(k) is the linear index of the point k in the list X / Y
71 % j(k) is the linear index of the point k in the list V.X / V.Y
72 Vx = NaN*ones(size(X));
73 Vy = NaN*ones(size(X));
74 if ~isempty(i)
75  Vx(i) = V.Vx(j);
76  Vy(i) = V.Vy(j);
77 end;
78 lambda = V.lambda;
79 
80 %| \docupdate