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: 2 additions & 0 deletions ext/CommonDataFormatCommonDataModelExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
5 changes: 3 additions & 2 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/decompress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))"))
Expand Down
2 changes: 1 addition & 1 deletion src/epochs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/loading/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions src/records/records.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
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))
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

Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down