Skip to content

Commit 2cede74

Browse files
committed
read into non-contig memory
1 parent 9663704 commit 2cede74

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/datasets/netcdf.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ for m in [:haschunks, :eachchunk]
3030
end
3131
))
3232
end
33+
function check_contig(x)
34+
isa(x,Array) || (isa(x,SubArray) && Base.iscontiguous(x))
35+
end
3336
writeblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->writeblock!(a,aout,r...), v.filename, v.varname, mode=NC_WRITE)
34-
readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->readblock!(a,aout,r...), v.filename, v.varname)
37+
function readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...)
38+
if check_contig
39+
NetCDF.open(a->readblock!(a,aout,r...), v.filename, v.varname)
40+
else
41+
aouttemp = Array(aout)
42+
NetCDF.open(a->readblock!(a,aouttemp,r...), v.filename, v.varname)
43+
aout .= aouttemp
44+
end
45+
end
3546
iscompressed(v::NetCDFVariable) = NetCDF.open(v->v.compress > 0, v.filename, v.varname)
3647

3748
Base.size(v::NetCDFVariable) = v.size

0 commit comments

Comments
 (0)