From: <aba...@us...> - 2012-06-22 15:20:44
|
Revision: 10671 http://octave.svn.sourceforge.net/octave/?rev=10671&view=rev Author: abarth93 Date: 2012-06-22 15:20:33 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m trunk/octave-forge/extra/ncArray/inst/ncCatData.m Deleted: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,81 +0,0 @@ -% C = ncCatArray(dim,filenames,varname) -% C = ncCatArray(dim,pattern,varname) -% C = ncCatArray(dim,filenamefun,varname,range) -% -% create a concatenated array from variables (varname) in a list of -% netcdf files along dimension dim.Individual elements can be accessed by -% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded -% -% This list of netcdf files can be specified as a cell array (filenames), -% shell wildcard pattern (e.g. file_*.nc) or a function handle -% filenamefun. In this later case, this i-th filename is -% filenamefun(range(i)). -% -% Example: -% -% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') -% -% data = ncCatArray(3,'file-*.nc','SST') -% -% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... -% datenum(2012,07,08):datenum(2012,07,09)); -% -% Note: in Octave the glob function is used to determine files matching the -% shell wildcard pattern, while in Matlab rdir is used. The function rdir -% is available from Matlab exchange under BSD license -% (http://www.mathworks.com/matlabcentral/fileexchange/19550). - -% Author: Alexander Barth (bar...@gm...) -% -function ncCA = ncCatArray(dim,pattern,varname,range) - -if iscell(pattern) - filenames = pattern; - -elseif ischar(pattern) - try - filenames = glob(pattern); - catch - try - d = rdir(pattern); - filenames = {d(:).name}; - catch - error(['The function rdir or glob (octave) is not available. '... - 'rdir can be installed from '... - 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); - end - end -elseif isa(pattern, 'function_handle') - filenames = cell(1,length(range)); - - for i=1:length(range) - filenames{i} = pattern(range(i)); - end -end - -arrays = cell(1,length(filenames)); - -for i=1:length(filenames) - arrays{i} = ncBaseArray(filenames{i},varname); -end - - -ncCA = CatArray(dim,arrays); - -% Copyright (C) 2012 Alexander Barth <bar...@gm...> -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; If not, see <http://www.gnu.org/licenses/>. - - - Copied: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m (from rev 10669, trunk/octave-forge/extra/ncArray/inst/ncCatData.m) =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -0,0 +1,111 @@ +% C = ncCatArray(dim,filenames,varname) +% C = ncCatArray(dim,pattern,varname) +% C = ncCatArray(dim,filenamefun,varname,range) +% +% create a concatenated array from variables (varname) in a list of +% netcdf files along dimension dim.Individual elements can be accessed by +% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded + +% This list of netcdf files can be specified as a cell array (filenames), +% shell wildcard pattern (e.g. file_*.nc) or a function handle +% filenamefun. In this later case, this i-th filename is +% filenamefun(range(i)). +% +% Example: +% +% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') +% +% data = ncCatArray(3,'file-*.nc','SST') +% +% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... +% datenum(2012,07,08):datenum(2012,07,09)); +% +% Note: in Octave the glob function is used to determine files matching the +% shell wildcard pattern, while in Matlab rdir is used. The function rdir +% is available from Matlab exchange under BSD license +% (http://www.mathworks.com/matlabcentral/fileexchange/19550). + +% Author: Alexander Barth (bar...@gm...) +% +function data = ncCatArray(dim,pattern,varname,range) + +catdimname = '_cat_dim'; + +if iscell(pattern) + filenames = pattern; + +elseif ischar(pattern) + try + filenames = glob(pattern); + catch + try + d = rdir(pattern); + filenames = {d(:).name}; + catch + error(['The function rdir or glob (octave) is not available. '... + 'rdir can be installed from '... + 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); + end + end +elseif isa(pattern, 'function_handle') + filenames = cell(1,length(range)); + + for i=1:length(range) + filenames{i} = pattern(range(i)); + end +end + +if nargin == 3 + range = 1:length(filenames); +end + +var = arr(dim,filenames,varname); + +[dims,coord] = nccoord(cached_decompress(filenames{1}),varname); + +if dim > length(dims) + % concatenate is new dimension + dims{dim} = catdimname; + coord(dim).dims = {catdimname}; + coord(dim).val = range; +end + + +for i=1:length(coord) + % coordinates do also depend on the dimension only which we concatenate + coord(i).val = arr(dim,filenames,coord(i).name); + if dim > length(coord(i).dims) + coord(i).dims{dim} = catdimname; + end +end + +data = ncArray(var,dims,coord); + +end + + +function CA = arr(dim,filenames,varname) +arrays = cell(1,length(filenames)); +for i=1:length(filenames) + arrays{i} = ncBaseArray(filenames{i},varname); +end + +CA = CatArray(dim,arrays); +end +% Copyright (C) 2012 Alexander Barth <bar...@gm...> +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see <http://www.gnu.org/licenses/>. + + + Deleted: trunk/octave-forge/extra/ncArray/inst/ncCatData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,111 +0,0 @@ -% C = ncCatArray(dim,filenames,varname) -% C = ncCatArray(dim,pattern,varname) -% C = ncCatArray(dim,filenamefun,varname,range) -% -% create a concatenated array from variables (varname) in a list of -% netcdf files along dimension dim.Individual elements can be accessed by -% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded - -% This list of netcdf files can be specified as a cell array (filenames), -% shell wildcard pattern (e.g. file_*.nc) or a function handle -% filenamefun. In this later case, this i-th filename is -% filenamefun(range(i)). -% -% Example: -% -% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') -% -% data = ncCatArray(3,'file-*.nc','SST') -% -% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... -% datenum(2012,07,08):datenum(2012,07,09)); -% -% Note: in Octave the glob function is used to determine files matching the -% shell wildcard pattern, while in Matlab rdir is used. The function rdir -% is available from Matlab exchange under BSD license -% (http://www.mathworks.com/matlabcentral/fileexchange/19550). - -% Author: Alexander Barth (bar...@gm...) -% -function data = ncCatData(dim,pattern,varname,range) - -catdimname = '_cat_dim'; - -if iscell(pattern) - filenames = pattern; - -elseif ischar(pattern) - try - filenames = glob(pattern); - catch - try - d = rdir(pattern); - filenames = {d(:).name}; - catch - error(['The function rdir or glob (octave) is not available. '... - 'rdir can be installed from '... - 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); - end - end -elseif isa(pattern, 'function_handle') - filenames = cell(1,length(range)); - - for i=1:length(range) - filenames{i} = pattern(range(i)); - end -end - -if nargin == 3 - range = 1:length(filenames); -end - -var = arr(dim,filenames,varname); - -[dims,coord] = nccoord(cached_decompress(filenames{1}),varname); - -if dim > length(dims) - % concatenate is new dimension - dims{dim} = catdimname; - coord(dim).dims = {catdimname}; - coord(dim).val = range; -end - - -for i=1:length(coord) - % coordinates do also depend on the dimension only which we concatenate - coord(i).val = arr(dim,filenames,coord(i).name); - if dim > length(coord(i).dims) - coord(i).dims{dim} = catdimname; - end -end - -data = ncArray(var,dims,coord); - -end - - -function CA = arr(dim,filenames,varname) -arrays = cell(1,length(filenames)); -for i=1:length(filenames) - arrays{i} = ncBaseArray(filenames{i},varname); -end - -CA = CatArray(dim,arrays); -end -% Copyright (C) 2012 Alexander Barth <bar...@gm...> -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; If not, see <http://www.gnu.org/licenses/>. - - - Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,5 +1,5 @@ function test_ncarray() -% test ncBaseArray, ncCatArray, ncArray and ncCatData +% test ncBaseArray, ncCatArray, ncArray and ncCatArray varname = 'SST'; @@ -224,7 +224,7 @@ -CA2 = ncCatData(3,fullfile(tmpdir,'file*nc'),varname); +CA2 = ncCatArray(3,fullfile(tmpdir,'file*nc'),varname); SST_test = CA2(:,:,2); SST_ref = ncread(files{2},'SST'); assert(isequalwithequalnans(SST_test,SST_ref)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |