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. |