Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/loading/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@ end
@inline _construct(cdf, name, vdr, dims::NTuple{N, Int}, ::Type{T}) where {N, T} =
CDFVariable{T, N, typeof(vdr), typeof(cdf)}(name, vdr, cdf, dims)

"""
read!(ds::CDFDataset, name, dest::AbstractArray{T, N}) -> dest

Read the full contents of variable `name` into the preallocated `dest`.
"""
function Base.read!(ds::CDFDataset, name::String, dest::AbstractArray{T, N}) where {T, N}
vdr = find_vdr(ds, name)
isnothing(vdr) && throw(KeyError(name))
return _read_full!(dest, ds, name, vdr)
end

"""
read(ds::CDFDataset, name, ::Type{Array{T, N}}) -> Array{T, N}

Allocating variant of [`read!`](@ref): read the full contents of variable `name` into a
freshly allocated `Array{T, N}`.
"""
function Base.read(ds::CDFDataset, name::String, ::Type{Array{T, N}}) where {T, N}
vdr = find_vdr(ds, name)
isnothing(vdr) && throw(KeyError(name))
dims = (map(Int, record_sizes(vdr, ds, Val(N - 1)))..., Int(vdr.max_rec) + 1)
return _read_full!(Array{T, N}(undef, dims), ds, name, vdr)
end

function _read_full!(dest::AbstractArray{T, N}, ds, name, vdr) where {T, N}
Base.require_one_based_indexing(dest)
Tfile = julia_type(vdr.data_type, vdr.num_elems)
Expand Down
3 changes: 0 additions & 3 deletions src/records/vdr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ Load an r-Variable Descriptor Record from the buffer at the specified offset.
return rVDR{FieldSizeT}(fields..., pos)
end


# Static-arity variants for the typed `read!` path: the caller supplies the dimension
# count via `Val`, so tuple lengths stay inferable under `juliac --trim`.
function record_sizes(vdr::VDR, cdf, ::Val{M}) where {M}
vdr.num_dims == M ||
throw(DimensionMismatch("variable has $(vdr.num_dims) dimensions, expected $M"))
Expand Down
6 changes: 0 additions & 6 deletions test/cdf_trim_probe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@ function (@main)(args::Vector{String})
ds.majority == CDF.Row &&
ds.compression == CDF.NoCompression &&
length(keys(ds)) > 0
# Typed data reads: z-variable (VDR) 1D + 2D with row-major swap.
v = read!(ds, "var", Vector{Float64}(undef, 101))
ok &= v[1] == 1.0
m = read!(ds, "var2d_counter", Matrix{Float64}(undef, 10, 10))
ok &= m[1, 1] == 0.0 && m[2, 1] == 1.0 && m[10, 10] == 99.0
ok &= read(ds, "var2d_counter", Matrix{Float64}) == m
return ok ? 0 : 1
end
24 changes: 0 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@ end
@test occursin("attributes: ", sprint(show, MIME("text/plain"), ds["var"]))
end

@testset "read! typed entry point" begin
ds = CDFDataset(data_path("a_cdf.cdf"))
v = read!(ds, "var", Vector{Float64}(undef, 101))
@test v == ds["var"][:]
m = read!(ds, "var2d_counter", Matrix{Float64}(undef, 10, 10))
@test m == reshape(0.0:99.0, 10, 10)
@test_throws KeyError read!(ds, "nonexistent", zeros(1))
@test_throws ArgumentError read!(ds, "var", zeros(Float32, 101))
@test_throws DimensionMismatch read!(ds, "var", zeros(100))
@test_throws DimensionMismatch read!(ds, "var", zeros(101, 1))

@test read(ds, "var", Vector{Float64}) == v
@test read(ds, "var2d_counter", Matrix{Float64}) == m
@test_throws KeyError read(ds, "nonexistent", Vector{Float64})
@test_throws ArgumentError read(ds, "var", Vector{Float32})
@test_throws DimensionMismatch read(ds, "var", Matrix{Float64})

rds = CDFDataset(data_path("ac_h0_mfi_20230102_v07.cdf"))
rvar = rds["BGSEc"]
b = read!(rds, "BGSEc", Matrix{eltype(rvar)}(undef, size(rvar)))
@test b == rvar[:, :]
@test read(rds, "BGSEc", Matrix{eltype(rvar)}) == b
end

@testset "Compressed cdf file (gzip)" begin
compressed = CDFDataset(data_path("a_compressed_cdf.cdf"))
reference = CDFDataset(data_path("a_cdf.cdf"))
Expand Down
6 changes: 2 additions & 4 deletions test/trim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# stray dynamic dispatch (e.g. a record-size type passed as a value instead of `::Type{T}`,
# or `getproperty` dragging in the heterogeneous attribute machinery) fails the verifier.
#
# Data reading is covered through the typed entry point `read!(ds, name, dest)`, where
# eltype/ndims come from `dest` instead of the file. The generic `ds[name]` path stays
# out of scope: its element type is only known at runtime, so it cannot be statically
# resolved.
# The generic `ds[name]` path stays out of scope: its element type is only known at runtime,
# so it cannot be statically resolved.

using Test

Expand Down
Loading