diff --git a/ext/CommonDataFormatCommonDataModelExt.jl b/ext/CommonDataFormatCommonDataModelExt.jl index dc218d9..3a4deee 100644 --- a/ext/CommonDataFormatCommonDataModelExt.jl +++ b/ext/CommonDataFormatCommonDataModelExt.jl @@ -5,6 +5,8 @@ import CommonDataFormat as CDF import CommonDataModel import CommonDataModel as CDM using CommonDataFormat: CDFDataset, CDFVariable +import CommonDataModel: path, varnames, variable, attribnames, attrib +import CommonDataModel: name, dataset, dimnames const SymbolOrString = Union{Symbol, AbstractString} diff --git a/src/dataset.jl b/src/dataset.jl index 4e344d2..6edb2ad 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -21,7 +21,8 @@ cdf = CDFDataset("data.cdf") ``` """ function CDFDataset(filename) - return open(filename, "r") do io + fname = String(filename) + return open(fname, "r") do io buffer = Mmap.mmap(io) magic_bytes = read_be(buffer, 1, UInt32) @assert validate_cdf_magic(magic_bytes) @@ -34,7 +35,7 @@ function CDFDataset(filename) # Parse CDF header cdr = CDR(buffer, 8, FieldSizeType) gdr = GDR(buffer, Int(cdr.gdr_offset), FieldSizeType) - return CDFDataset{compression, FieldSizeType}(filename, cdr, gdr, buffer) + return CDFDataset{compression, FieldSizeType}(fname, cdr, gdr, buffer) end end diff --git a/src/decompress.jl b/src/decompress.jl index b2d66f7..588a334 100644 --- a/src/decompress.jl +++ b/src/decompress.jl @@ -23,11 +23,11 @@ end function decompress_bytes(data, compression::CompressionType; expected_bytes::Union{Nothing, Int} = nothing) compression == NoCompression && return data @assert compression in (GzipCompression, RLECompression) - if compression == GzipCompression - result = transcode(GzipDecompressor, Vector{UInt8}(data)) - elseif compression == RLECompression + result = if compression == GzipCompression + transcode(GzipDecompressor, Vector{UInt8}(data)) + else isnothing(expected_bytes) && throw(ArgumentError("RLE decompression requires expected size")) - result = _rle_decompress(data, expected_bytes) + _rle_decompress(data, expected_bytes) end if !isnothing(expected_bytes) && length(result) != expected_bytes throw(ArgumentError("Decompressed payload size mismatch (expected $(expected_bytes), got $(length(result)))")) diff --git a/src/epochs.jl b/src/epochs.jl index 24a4bd8..cdd2e07 100644 --- a/src/epochs.jl +++ b/src/epochs.jl @@ -138,7 +138,7 @@ end function Base.show(io::IO, epoch::CDFDateTime) fillval = fillvalue(epoch) - return if fillval == epoch.instant + return if fillval == Dates.value(epoch) print(io, "FILLVAL") else print(io, DateTime(epoch)) diff --git a/src/loading/variable.jl b/src/loading/variable.jl index ecdd2c7..2ae956a 100644 --- a/src/loading/variable.jl +++ b/src/loading/variable.jl @@ -71,8 +71,8 @@ function DiskArrays.readblock!(var::CDFVariable{T, N}, dest::AbstractArray{T}, r first_rec = first(record_range) last_rec = last(record_range) - start_idx = findfirst(entry -> entry.first <= first_rec <= entry.last, entries) - end_idx = findfirst(entry -> entry.first <= last_rec <= entry.last, entries) + start_idx = findfirst(entry -> entry.first <= first_rec <= entry.last, entries)::Int + end_idx = findfirst(entry -> entry.first <= last_rec <= entry.last, entries)::Int record_size = prod(dims_without_record) is_row_major = majority(var) == Row diff --git a/src/records/records.jl b/src/records/records.jl index 3ec7f7d..00336ac 100644 --- a/src/records/records.jl +++ b/src/records/records.jl @@ -11,12 +11,6 @@ struct Header record_type::Int32 end -@inline function Header(io::IO, FieldSizeT) - record_size = Int64(read_be(io, FieldSizeT)) - record_type = read_be(io, Int32) - return Header(record_size, record_type) -end - @inline function Header(buf::Vector{UInt8}, pos, FieldSizeT) record_size = Int64(read_be(buf, pos, FieldSizeT)) record_type = read_be(buf, pos + sizeof(FieldSizeT), Int32) @@ -50,15 +44,6 @@ include("cpr.jl") include("ccr.jl") include("cvvr.jl") -for R in (:ADR, :AEDR, :GDR, :VDR) - @eval begin - @inline function $R(io::IO, offset, RecordSizeType) - seek(io, offset) - return $R(io, RecordSizeType) - end - end -end - # Utility functions to decode CDR flags """ decode_cdr_flags(flags::UInt32) diff --git a/src/records/vdr.jl b/src/records/vdr.jl index 89bd2e9..d38caa8 100644 --- a/src/records/vdr.jl +++ b/src/records/vdr.jl @@ -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)) + dim_varys = collect(read_be(buffer, vdr.pos, gdr.r_num_dims, Int32))::Vector{Int32} return r_dim_sizes(gdr, buffer)[dim_varys .!= 0] end diff --git a/test/Project.toml b/test/Project.toml index a65fe18..6e93707 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,4 +2,5 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" CommonDataModel = "1fbeeb36-5f17-413c-809b-666fb144f157" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 9848995..de0a4d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,6 +13,11 @@ include("CommonDataModelExt_test.jl") Aqua.test_all(CommonDataFormat) end +@testset "JET" begin + using JET + JET.test_package(CommonDataFormat; target_modules = [CommonDataFormat]) +end + @testset "Fill Value" begin for T in (Int8, Int16, Int32, Int64, Float32, Float64, UInt8, UInt16, UInt32) @test CDF.fillvalue(T) isa T