Skip to content

Commit

Permalink
use chunks for write(fname,dataset)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 5, 2023
1 parent 721ac59 commit 8f85e19
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,6 @@ function Base.write(dest::NCDataset, src::AbstractDataset;
# end
end

function _destindex(ind, dimname, dimlength, unlimdims)
nind = _normalizeindex(dimlength, ind)
if dimname in unlimdims
nind[1]:dimlength
else
nind
end
end
_maxrange(dimname, idimensions, dimlength) = haskey(idimensions, dimname) ? idimensions[dimname][end] : dimlength

# loop over variables
Expand All @@ -512,7 +504,6 @@ function Base.write(dest::NCDataset, src::AbstractDataset;
var = cfvar.var
# indices for subset
index = ntuple(i -> torange(get(idimensions,dimension_names[i],:)),length(dimension_names))
destindex = ntuple(i -> _destindex(index[i], dimension_names[i], _maxrange(dimension_names[i], idimensions, cfsz[i]), unlimited_dims), length(dimension_names))

var_slice = view(var,index...)

Expand All @@ -538,7 +529,9 @@ function Base.write(dest::NCDataset, src::AbstractDataset;
end

# copy data
destvar.var[destindex...] = var_slice[index...]
for indices = eachchunk(var_slice)
destvar.var[indices...] = var_slice[indices...]
end
end

# loop over all global attributes
Expand Down

0 comments on commit 8f85e19

Please sign in to comment.