10542
|
1 % Create an array representing a NetCDF variable. |
|
2 % |
|
3 % V = ncArray(filename,varname) |
|
4 % V = ncArray(filename,varname,'property',value,...) |
|
5 % create a ncArray that can be accessed as a normal array. |
10486
|
6 % |
|
7 % For read access filename can be compressed if it has the extensions |
|
8 % ".gz" or ".bz2". It use the function cache_decompress to cache to |
|
9 % decompressed files. |
|
10 % |
|
11 % Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue |
|
12 % are thus replaced by NaN and the scaling (add_offset and |
|
13 % scale_factor) is applied during loading and saving. |
|
14 % |
|
15 % |
|
16 % Example: |
|
17 % |
|
18 % Loading the variable (assuming V is 3 dimensional): |
|
19 % |
|
20 % x = V(1,1,1); % load element 1,1,1 |
|
21 % x = V(:,:,:); % load the complete array |
|
22 % x = V(); x = full(V) % loads also the complete array |
|
23 % |
|
24 % Saving data in the netcdf file: |
|
25 % V(1,1,1) = x; % save x in element 1,1,1 |
|
26 % V(:,:,:) = x; |
|
27 % |
|
28 % Attributes |
|
29 % units = V.units; % get attribute called "units" |
|
30 % V.units = 'degree C'; % set attributes; |
|
31 % |
|
32 % Note: use the '.()' notation if the attribute has a leading underscore |
|
33 % (due to a limitation in the matlab parser): |
|
34 % |
|
35 % V.('_someStrangeAttribute') = 123; |
|
36 % |
10542
|
37 % see also cache_decompress, ncCatArray |
|
38 % Web: http://modb.oce.ulg.ac.be/mediawiki/index.php/ncArray |
10486
|
39 |
|
40 % hidded constructor signature: |
12680
|
41 % data = ncArray(var,dims,coord); |
10486
|
42 % is used to create data with coordinate values by ncCatArray |
10482
|
43 |
10483
|
44 function retval = ncArray(varargin) |
10482
|
45 |
|
46 if ischar(varargin{1}) |
|
47 filename = varargin{1}; |
|
48 varname = varargin{2}; |
|
49 var = ncBaseArray(filename,varname); |
|
50 [dims,coord] = nccoord(cached_decompress(filename),varname); |
|
51 |
|
52 for i=1:length(coord) |
|
53 coord(i).val = ncBaseArray(filename,coord(i).name); |
|
54 end |
|
55 else |
|
56 var = varargin{1}; |
|
57 dims = varargin{2}; |
|
58 coord = varargin{3}; |
|
59 end |
|
60 |
|
61 self.var = var; |
|
62 self.dims = dims; |
|
63 self.nd = length(self.dims); |
|
64 self.coord = coord; |
|
65 |
10483
|
66 retval = class(self,'ncArray',BaseArray(size(self.var))); |
10482
|
67 |
|
68 |
|
69 |
10535
|
70 |
|
71 |
|
72 |
|
73 % Copyright (C) 2012 Alexander Barth <barth.alexander@gmail.com> |
|
74 % |
|
75 % This program is free software; you can redistribute it and/or modify |
|
76 % it under the terms of the GNU General Public License as published by |
|
77 % the Free Software Foundation; either version 2 of the License, or |
|
78 % (at your option) any later version. |
|
79 % |
|
80 % This program is distributed in the hope that it will be useful, |
|
81 % but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
82 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
83 % GNU General Public License for more details. |
|
84 % |
|
85 % You should have received a copy of the GNU General Public License |
|
86 % along with this program; If not, see <http://www.gnu.org/licenses/>. |
|
87 |