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
2 changes: 1 addition & 1 deletion src/records/gdr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ end
function r_dim_sizes(gdr::GDR, buffer::Vector{UInt8})
pos = gdr.pos + sizeof(Int64) + sizeof(Int32) + sizeof(Int32) + sizeof(Int32)
r_num_dims = gdr.r_num_dims
@assert r_num_dims > 0
@assert r_num_dims >= 0
return read_be(buffer, pos, r_num_dims, Int32)
end
2 changes: 1 addition & 1 deletion src/records/vdr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end
@inline function record_sizes(vdr::rVDR)
gdr = vdr.gdr
buffer = vdr.buffer
dim_varys = collect(read_be(buffer, vdr.pos, gdr.r_num_dims, Int32))::Vector{Int32}
dim_varys = collect(read_be(buffer, vdr.pos, gdr.r_num_dims, Int32))
return r_dim_sizes(gdr, buffer)[dim_varys .!= 0]
end

Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CommonDataModel = "1fbeeb36-5f17-413c-809b-666fb144f157"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17 changes: 12 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ end
@test ntoh(hton(ds["Epoch"][1])) == DateTime(2024, 9, 1, 0, 0)

@test @allocations(ds["BR"]) <= 50
@info @allocated(ds.attrib)
if VERSION >= v"1.12"
@test @allocated(ds.attrib) <= 30000
else
@test @allocated(ds.attrib) <= 70000
allocations = @allocated(ds.attrib)
threshold = VERSION >= v"1.12" ? 30000 : 70000
if allocations > threshold
@info "ds.attrib allocated $allocations bytes (threshold: $threshold)"
end
end

Expand All @@ -105,3 +104,11 @@ end
@test var.vdr isa CommonDataFormat.rVDR
@test size(var) == (3, 5400)
end

@testset "r-variables 2" begin
file = download_test_data("https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/releases/download/v0.1.8/omni2_h0_mrg1hr_20150101_v01.cdf")
ds = CDFDataset(file)
var = ds["Epoch"]
@test var.vdr isa CommonDataFormat.rVDR
@test size(var) == (4344,)
end
16 changes: 15 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Downloads

function data_path(name)
for dir in [
joinpath(@__DIR__, "..", "ref", "CDFpp", "tests", "resources"),
Expand All @@ -8,4 +10,16 @@ function data_path(name)
isfile(path) && return path
end
error("Data file not found: $name")
end
end

# Download test data from URL and cache locally
function download_test_data(url, filename = basename(url))
cache_dir = joinpath(pkgdir(CommonDataFormat), "data")
mkpath(cache_dir)
filepath = joinpath(cache_dir, filename)
if !isfile(filepath)
@info "Downloading test data: $filename"
Downloads.download(url, filepath)
end
return filepath
end
Loading