11980
|
1 % [val,coord1,coord2,...] = load(self,'coord_name1',range1,'coord_name2',range2,...) |
|
2 % Load a subset of a variable based on range of coordiante variables. |
|
3 % The names of the coordinates (coord_name1, coord_name2,...) coorespond to the standard_name attribute. |
|
4 % Only 1-dimensional coordinates are currently supported. |
|
5 % |
|
6 % |
|
7 % Example |
|
8 % [temp,lon,lat,depth,time] = load(self,'longitude',[0 10],'latitude',[0 10]) |
|
9 |
|
10 function varargout = load(self,varargin) |
|
11 |
|
12 c = coord(self); |
|
13 |
|
14 for i = 1:length(c) |
|
15 c(i).v = full(c(i).val); |
|
16 % per default take all data along a dimension |
|
17 c(i).index = ':'; |
|
18 c(i).sub = c(i).v; |
|
19 end |
|
20 |
|
21 % loop over all constraints |
|
22 for i = 1:2:length(varargin) |
|
23 name = varargin{i}; |
|
24 |
|
25 j = find(strcmp(name,{c.standard_name})); |
|
26 if isempty(j) |
|
27 warning(['no coordinate has the standard_name ' name ... |
|
28 '. Try to use variable names.']); |
|
29 |
|
30 j = find(strcmp(name,{c.name})); |
|
31 if isempty(j) |
|
32 error(['no coordinate has the name ' name '.']); |
|
33 end |
|
34 end |
|
35 |
|
36 range = varargin{i+1}; |
|
37 |
|
38 if numel(range) == 1 |
|
39 dist = abs(c(j).v - range); |
|
40 [mindist,i] = min(dist); |
|
41 %mindist |
|
42 else |
|
43 i = find(range(1) < c(j).v & c(j).v < range(end)); |
|
44 i = min(i):max(i); |
|
45 end |
|
46 |
|
47 c(j).index = i; |
|
48 c(j).sub = c(j).v(i); |
|
49 end |
|
50 |
|
51 idx = substruct('()',{c.index}); |
|
52 data = subsref (self,idx); |
|
53 |
|
54 varargout = {data,c.sub}; |
|
55 |
|
56 |
|
57 % i = 1; |
|
58 |
|
59 % mask = xr(1) <= x & x <= xr(2); |
|
60 % l = find(mask); |
|
61 |
|
62 % [ij{:}] = ind2sub(size(mask),l); |
|
63 |
|
64 % for j=1:len |
|
65 % mins(j) = min(ij{j}); |
|
66 % maxs(j) = max(ij{j}); |
|
67 |