From: <aba...@us...> - 2012-06-11 13:34:37
|
Revision: 10614 http://octave.svn.sourceforge.net/octave/?rev=10614&view=rev Author: abarth93 Date: 2012-06-11 13:34:31 +0000 (Mon, 11 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncread.m Added Paths: ----------- trunk/octave-forge/main/octcdf/inst/ncinfo.m Added: trunk/octave-forge/main/octcdf/inst/ncinfo.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncinfo.m (rev 0) +++ trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-06-11 13:34:31 UTC (rev 10614) @@ -0,0 +1,57 @@ +% finfo = ncinfo(filename) +% vinfo = ncinfo(filename,varname) +% return information about variable varname in netCDF +% file filename + +function info = ncinfo(filename,varname) + +nc = netcdf(filename,'r'); +if nargin == 1 + info.Filename = filename; + + variables = var(nc); + for i=1:length(variables) + info.Variables(i) = ncinfo_var(nc,filename,name(variables{i})); + end +elseif nargin == 2 + info = ncinfo_var(nc,filename,varname); +end + +close(nc); +end + +function vinfo = ncinfo_var(nc,filename,varname) + + +nv = nc{varname}; + +vinfo.Size = fliplr(size(nv)); +vinfo.Filename = filename; +vinfo.Dimensions = {}; +vinfo.Name = varname; + +dims = fliplr(dim(nv)); + +for i=1:length(dims) + vinfo.Dimensions{i} = name(dims{i}); +end + + +na = att(nv); + +%vinfo.Attributes = []; + +for j=1:length(na) + tmp = struct(); + nm = name(na{j}); + + tmp.Name = nm; + tmp.Value = na{j}(:); + vinfo.Attributes(j) = tmp; +end + +vinfo.FillValue = fillval(nv); + + +end + Modified: trunk/octave-forge/main/octcdf/inst/ncread.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-11 10:31:23 UTC (rev 10613) +++ trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-11 13:34:31 UTC (rev 10614) @@ -7,8 +7,11 @@ nc = netcdf(filename,'r'); nv = nc{varname}; sz = size(nv); sz = sz(end:-1:1); -nd = ndims(nv); +% number of dimenions +%nd = length(sz); +nd = length(dim(nv)); + if nargin == 2 start = ones(1,nd); count = inf*ones(1,nd); @@ -36,7 +39,7 @@ for i=1:nd subsr.subs{nd-i+1} = start(i):stride(i):endi(i); end -start,endi +%start,endi x = subsref(nv,subsr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-13 11:40:29
|
Revision: 10629 http://octave.svn.sourceforge.net/octave/?rev=10629&view=rev Author: abarth93 Date: 2012-06-13 11:40:23 +0000 (Wed, 13 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncread.m Added Paths: ----------- trunk/octave-forge/main/octcdf/inst/ncwrite.m Modified: trunk/octave-forge/main/octcdf/inst/ncread.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-13 08:28:08 UTC (rev 10628) +++ trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-13 11:40:23 UTC (rev 10629) @@ -69,3 +69,4 @@ x = permute(x,[ndims(x):-1:1]); +close(nc) Added: trunk/octave-forge/main/octcdf/inst/ncwrite.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncwrite.m (rev 0) +++ trunk/octave-forge/main/octcdf/inst/ncwrite.m 2012-06-13 11:40:23 UTC (rev 10629) @@ -0,0 +1,70 @@ +% ncwrite(filename,varname,x) +% ncwrite(filename,varname,x,start,stride) +% write the variable varname to file filename. + +function ncwrite(filename,varname,x,start,stride) + +nc = netcdf(filename,'w'); +nv = nc{varname}; + +% number of dimenions +nd = length(dim(nv)); + +% sz size (padded with ones) +sz = ones(1,nd); +tmp = size(x); +sz(1:length(tmp)) = tmp; + +if nargin == 3 + start = ones(1,nd); +end + +if nargin < 5 + stride = ones(1,nd); +end + +% end index + +endi = start + (sz-1).*stride; + + +% save data + +% subsref structure +subsr.type = '()'; +subsr.subs = cell(1,nd); +for i=1:nd + subsr.subs{nd-i+1} = start(i):stride(i):endi(i); +end +%start,endi + + +% apply attributes + +factor = nv.scale_factor(:); +offset = nv.add_offset(:); +fv = nv.FillValue_(:); + +if ~isempty(offset) + x = x - offset; +end + +if ~isempty(factor) + x = x / factor; +end + +if ~isempty(fv) + x(isnan(x)) = fv; +else + fv = nv.missing_value; + + if ~isempty(fv) + x(isnan(x)) = fv; + end +end + +x = permute(x,[ndims(x):-1:1]); + +nv = subsasgn(nv,subsr,x); +close(nc) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-07-03 12:55:53
|
Revision: 10718 http://octave.svn.sourceforge.net/octave/?rev=10718&view=rev Author: abarth93 Date: 2012-07-03 12:55:44 +0000 (Tue, 03 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncinfo.m trunk/octave-forge/main/octcdf/inst/ncread.m trunk/octave-forge/main/octcdf/inst/ncwrite.m Modified: trunk/octave-forge/main/octcdf/inst/ncinfo.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-03 12:45:00 UTC (rev 10717) +++ trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-03 12:55:44 UTC (rev 10718) @@ -1,7 +1,7 @@ % finfo = ncinfo(filename) % vinfo = ncinfo(filename,varname) -% return information about variable varname in netCDF -% file filename +% return information about complete netCDF file (filename) or about +% the specific variable varname. function info = ncinfo(filename,varname) Modified: trunk/octave-forge/main/octcdf/inst/ncread.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncread.m 2012-07-03 12:45:00 UTC (rev 10717) +++ trunk/octave-forge/main/octcdf/inst/ncread.m 2012-07-03 12:55:44 UTC (rev 10718) @@ -1,6 +1,9 @@ % x = ncread(filename,varname) % x = ncread(filename,varname,start,count,stride) % read the variable varname from file filename. +% The parameter start contains the starting indices, count +% is the number of elements and stride the increment between +% two successive elements (default 1). function x = ncread(filename,varname,start,count,stride) @@ -74,3 +77,19 @@ x = permute(x,[ndims(x):-1:1]); x = reshape(x,count); close(nc) + + +%% Copyright (C) 2012 Alexander Barth +%% +%% 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/main/octcdf/inst/ncwrite.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncwrite.m 2012-07-03 12:45:00 UTC (rev 10717) +++ trunk/octave-forge/main/octcdf/inst/ncwrite.m 2012-07-03 12:55:44 UTC (rev 10718) @@ -1,6 +1,9 @@ % ncwrite(filename,varname,x) % ncwrite(filename,varname,x,start,stride) % write the variable varname to file filename. +% The parameter start contains the starting indices +% and stride the increment between +% two successive elements (default 1). function ncwrite(filename,varname,x,start,stride) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-07-03 13:21:30
|
Revision: 10719 http://octave.svn.sourceforge.net/octave/?rev=10719&view=rev Author: abarth93 Date: 2012-07-03 13:21:20 +0000 (Tue, 03 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncinfo.m trunk/octave-forge/main/octcdf/inst/ncwrite.m Modified: trunk/octave-forge/main/octcdf/inst/ncinfo.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-03 12:55:44 UTC (rev 10718) +++ trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-03 13:21:20 UTC (rev 10719) @@ -55,3 +55,19 @@ end + + +%% Copyright (C) 2012 Alexander Barth +%% +%% 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/main/octcdf/inst/ncwrite.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncwrite.m 2012-07-03 12:55:44 UTC (rev 10718) +++ trunk/octave-forge/main/octcdf/inst/ncwrite.m 2012-07-03 13:21:20 UTC (rev 10719) @@ -71,3 +71,18 @@ nv = subsasgn(nv,subsr,x); close(nc) + +%% Copyright (C) 2012 Alexander Barth +%% +%% 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/>. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-07-31 13:45:25
|
Revision: 10791 http://octave.svn.sourceforge.net/octave/?rev=10791&view=rev Author: abarth93 Date: 2012-07-31 13:45:19 +0000 (Tue, 31 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/@ncdim/isrecord.m trunk/octave-forge/main/octcdf/inst/ncinfo.m Modified: trunk/octave-forge/main/octcdf/inst/@ncdim/isrecord.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/@ncdim/isrecord.m 2012-07-31 11:44:13 UTC (rev 10790) +++ trunk/octave-forge/main/octcdf/inst/@ncdim/isrecord.m 2012-07-31 13:45:19 UTC (rev 10791) @@ -1,3 +1,4 @@ +% depreciated: use isrecdim instead function isr = isrecord(self) isr = ncisrecord(self); end Modified: trunk/octave-forge/main/octcdf/inst/ncinfo.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-31 11:44:13 UTC (rev 10790) +++ trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-31 13:45:19 UTC (rev 10791) @@ -30,7 +30,7 @@ vinfo.Size = fliplr(size(nv)); vinfo.Filename = filename; -vinfo.Dimensions = {}; +vinfo.Dimensions = []; vinfo.Name = varname; dims = fliplr(dim(nv)); @@ -39,8 +39,9 @@ tmp = struct(); tmp.Name = name(dims{i}); tmp.Length = dims{i}(:); - tmp.Unlimited = isrecord(dims{i}); - vinfo.Dimensions(i) = tmp; + % requires octcdf 1.1.6 + %tmp.Unlimited = isrecdim(dims{i}); + vinfo.Dimensions = [vinfo.Dimensions; tmp]; end @@ -54,7 +55,7 @@ tmp.Name = nm; tmp.Value = na{j}(:); - vinfo.Attributes(j) = tmp; + vinfo.Attributes = [vinfo.Attributes; tmp]; end vinfo.FillValue = fillval(nv); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-07-31 14:33:47
|
Revision: 10793 http://octave.svn.sourceforge.net/octave/?rev=10793&view=rev Author: abarth93 Date: 2012-07-31 14:33:36 +0000 (Tue, 31 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncinfo.m trunk/octave-forge/main/octcdf/inst/ncread.m Modified: trunk/octave-forge/main/octcdf/inst/ncinfo.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-31 14:32:53 UTC (rev 10792) +++ trunk/octave-forge/main/octcdf/inst/ncinfo.m 2012-07-31 14:33:36 UTC (rev 10793) @@ -41,7 +41,12 @@ tmp.Length = dims{i}(:); % requires octcdf 1.1.6 %tmp.Unlimited = isrecdim(dims{i}); - vinfo.Dimensions = [vinfo.Dimensions; tmp]; + + if isempty(vinfo.Dimensions) + vinfo.Dimensions = [tmp]; + else + vinfo.Dimensions(i) = tmp; + end end @@ -55,7 +60,12 @@ tmp.Name = nm; tmp.Value = na{j}(:); - vinfo.Attributes = [vinfo.Attributes; tmp]; + + if isempty(vinfo.Attributes) + vinfo.Attributes = [tmp]; + else + vinfo.Attributes(j) = tmp; + end end vinfo.FillValue = fillval(nv); Modified: trunk/octave-forge/main/octcdf/inst/ncread.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncread.m 2012-07-31 14:32:53 UTC (rev 10792) +++ trunk/octave-forge/main/octcdf/inst/ncread.m 2012-07-31 14:33:36 UTC (rev 10793) @@ -77,6 +77,11 @@ end x = permute(x,[ndims(x):-1:1]); + +if length(count) < 2 + count(2) = 1; +end + x = reshape(x,count); close(nc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |