Mercurial > forge
comparison extra/ncArray/inst/@ncArray/load.m @ 12663:7c7960da6a76 octave-forge
convert time to datenum
author | abarth93 |
---|---|
date | Wed, 08 Jul 2015 08:06:05 +0000 |
parents | de10a10ef6bf |
children |
comparison
equal
deleted
inserted
replaced
12662:2a027badd794 | 12663:7c7960da6a76 |
---|---|
1 % [val,coord1,coord2,...] = load(self,'coord_name1',range1,'coord_name2',range2,...) | 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. | 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. | 3 % The names of the coordinates (coord_name1, coord_name2,...) coorespond to the standard_name attribute. |
4 % Only 1-dimensional coordinates are currently supported. | 4 % Only 1-dimensional coordinates are currently supported. |
5 % Time units are converted to "datenum". | |
5 % | 6 % |
6 % | 7 % |
7 % Example | 8 % Example |
8 % [temp,lon,lat,depth,time] = load(self,'longitude',[0 10],'latitude',[0 10]) | 9 % [temp,lon,lat,depth,time] = load(self,'longitude',[0 10],'latitude',[0 10]) |
9 | 10 |
14 for i = 1:length(c) | 15 for i = 1:length(c) |
15 c(i).v = full(c(i).val); | 16 c(i).v = full(c(i).val); |
16 % per default take all data along a dimension | 17 % per default take all data along a dimension |
17 c(i).index = ':'; | 18 c(i).index = ':'; |
18 c(i).sub = c(i).v; | 19 c(i).sub = c(i).v; |
20 | |
21 % convert time units | |
22 if ~isempty(strfind(c(i).units,'since')) | |
23 [t0,f] = nctimeunits(c(i).units); | |
24 c(i).v = f*double(c(i).v) + t0; | |
25 end | |
26 | |
19 end | 27 end |
20 | 28 |
21 % loop over all constraints | 29 % loop over all constraints |
22 for i = 1:2:length(varargin) | 30 for i = 1:2:length(varargin) |
23 name = varargin{i}; | 31 name = varargin{i}; |
36 range = varargin{i+1}; | 44 range = varargin{i+1}; |
37 | 45 |
38 if numel(range) == 1 | 46 if numel(range) == 1 |
39 dist = abs(c(j).v - range); | 47 dist = abs(c(j).v - range); |
40 [mindist,i] = min(dist); | 48 [mindist,i] = min(dist); |
49 | |
50 %i | |
41 %mindist | 51 %mindist |
52 %c(j).v(i) | |
53 %datevec(c(j).v(i)) | |
42 else | 54 else |
43 i = find(range(1) < c(j).v & c(j).v < range(end)); | 55 i = find(range(1) < c(j).v & c(j).v < range(end)); |
44 i = min(i):max(i); | 56 i = min(i):max(i); |
45 end | 57 end |
46 | 58 |
47 c(j).index = i; | 59 c(j).index = i; |
48 c(j).sub = c(j).v(i); | 60 c(j).sub = c(j).v(i); |
49 end | 61 end |
50 | 62 |
51 idx = substruct('()',{c.index}); | 63 idx = substruct('()',{c.index}); |
64 %idx | |
52 data = subsref (self,idx); | 65 data = subsref (self,idx); |
53 | 66 |
54 varargout = {data,c.sub}; | 67 varargout = {data,c.sub}; |
55 | 68 |
56 | 69 |