diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bf61b8..c63f4d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,19 @@ ### Changed -- **Breaking**: `CDF_CHAR`/`CDF_UCHAR` variables have eltype `String` (trailing null padding stripped); `StaticString` is removed. Avoids a recompile for each new string width ([#79]). +- **Breaking**: variable attributes are returned as stored: `LABL_PTR_i` is the label variable's name, no longer resolved to its labels (ISTP conventions live in CDFDatasets). `fillvalue` moved to CDFDatasets. + +## [0.4.2] - 2026-10-06 ### Fixed -- Sparse and unwritten records read as the pad value, or the previous physical record for previous-record sparse variables, instead of uninitialized memory (e.g. THEMIS `th?_fgm_*_quality`). +- Sparse and unwritten records read as the pad value, or the previous physical record for previous-record sparse variables, instead of uninitialized memory. + +## [0.4.0] - 2026-10-06 + +### Changed + +- **Breaking**: `CDF_CHAR`/`CDF_UCHAR` variables have eltype `String` (trailing null padding stripped); `StaticString` is removed. Avoids a recompile for each new string width ([#79]). ## [0.3.0] - 2026-10-02 @@ -33,7 +41,9 @@ - **Breaking**: Renamed exported enum `DataType` to `CDFDataType` ([#46]) as the old name collided with `Base.DataType`. -[Unreleased]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/compare/v0.3.0...HEAD +[Unreleased]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/compare/v0.4.5...HEAD +[0.4.2]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/compare/v0.4.1...v0.4.2 +[0.4.0]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/compare/v0.3.2...v0.4.0 [0.3.0]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/JuliaSpacePhysics/CommonDataFormat.jl/releases/tag/v0.2.0 diff --git a/data/labl_ptr.cdf b/data/labl_ptr.cdf deleted file mode 100644 index aaf863e..0000000 Binary files a/data/labl_ptr.cdf and /dev/null differ diff --git a/data/make_labl_ptr.py b/data/make_labl_ptr.py deleted file mode 100644 index c5432fe..0000000 --- a/data/make_labl_ptr.py +++ /dev/null @@ -1,13 +0,0 @@ -# LABL_PTR_1 pointing at an existing variable and at a missing one (seen in IM_K0_EUV). -# Run: uv run --with cdflib python data/make_labl_ptr.py data/labl_ptr.cdf -import sys -import numpy as np -from cdflib.cdfwrite import CDF - -c = CDF(sys.argv[1], delete=True) -vec = {"Data_Type": 45, "Num_Elements": 1, "Rec_Vary": True, "Dim_Sizes": [3]} -c.write_var({"Variable": "labels", "Data_Type": 51, "Num_Elements": 2, "Rec_Vary": False, "Dim_Sizes": [3]}, - var_data=np.array(["Bx", "By", "Bz"])) -c.write_var({**vec, "Variable": "ok"}, var_attrs={"LABL_PTR_1": "labels"}, var_data=np.zeros((2, 3))) -c.write_var({**vec, "Variable": "dangling"}, var_attrs={"LABL_PTR_1": "CARTESIAN"}, var_data=np.zeros((2, 3))) -c.close() diff --git a/src/CommonDataFormat.jl b/src/CommonDataFormat.jl index 4130c00..3ebe10a 100644 --- a/src/CommonDataFormat.jl +++ b/src/CommonDataFormat.jl @@ -46,7 +46,6 @@ include("parsing.jl") include("decompress.jl") include("records/records.jl") include("variable.jl") -include("vattribute.jl") include("dataset.jl") include("loading/attribute.jl") include("loading/variable.jl") diff --git a/src/loading/attribute.jl b/src/loading/attribute.jl index 1bbd8ef..38649c1 100644 --- a/src/loading/attribute.jl +++ b/src/loading/attribute.jl @@ -69,8 +69,7 @@ function Base.iterate(la::LazyVAttrib, offset::Int = Int(la.cdf.gdr.ADRhead)) next_offset = Int(adr.ADRnext) found = _search_aedr_entries(buffer, _entry_head(la, adr), RecordSizeType, needs_byte_swap, la.varnum) if !isnothing(found) - name = adr_name(buffer, adr) - return (name => _get_attributes(name, found, la.cdf), next_offset) + return (adr_name(buffer, adr) => found, next_offset) end offset = next_offset end @@ -98,7 +97,7 @@ function Base.get(la::LazyVAttrib, name::AbstractString, default = nothing) name_equals(buffer, _adr_name_pos(offset, RecordSizeType), name_str, RecordSizeType) || continue adr = ADR{RecordSizeType}(buffer, offset) found = _search_aedr_entries(buffer, _entry_head(la, adr), RecordSizeType, needs_byte_swap, varnum) - return isnothing(found) ? default : _get_attributes(name, found, cdf) + return isnothing(found) ? default : found end return default end @@ -108,17 +107,6 @@ Base.get(la::LazyVAttrib, name, default = nothing) = default Base.haskey(la::LazyVAttrib, name::AbstractString) = !isnothing(get(la, name, nothing)) Base.haskey(la::LazyVAttrib, name) = false -# Handle pointers like LABL_PTR_1 -# https://github.com/SciQLop/PyISTP/blob/0a565c39c73dd800934bc379dd7c2e00c28d23d0/pyistp/_impl.py#L16 -function _get_attributes(name, value, cdf) - occursin("LABL_PTR", name) && value isa String || return value - vdr = find_vdr(cdf, value) - # Dangling pointers exist in the wild (e.g. IM_K0_EUV); keep the raw name. - isnothing(vdr) && return value - # `Array` skips DiskArrays indexing - return vec(Array(_variable(cdf, value, vdr))) -end - @inline function _search_aedr_entries(source, aedr_head, ::Type{RecordSizeType}, needs_byte_swap, target_varnum) where {RecordSizeType} aedr_head == 0 && return nothing offset = Int(aedr_head) diff --git a/src/vattribute.jl b/src/vattribute.jl deleted file mode 100644 index d411beb..0000000 --- a/src/vattribute.jl +++ /dev/null @@ -1,14 +0,0 @@ -# https://spdf.gsfc.nasa.gov/istp_guide/vattributes.html -# Variable attributes are linked with each individual variable, and provide additional information about each variable. - -# https://spdf.gsfc.nasa.gov/istp_guide/vattributes.html#FILLVAL -# FILLVAL : the number inserted in the CDF in place of data values that are known to be bad or missing. Fill data are always non-valid data. -fillvalue(::Type{Float32}) = -1.0f31 -fillvalue(::Type{Float64}) = -1.0e31 -fillvalue(::Type{Int8}) = Int8(-128) -fillvalue(::Type{Int16}) = Int16(-32768) -fillvalue(::Type{Int32}) = Int32(-2147483648) -fillvalue(::Type{Int64}) = Int64(-9223372036854775808) -fillvalue(::Type{UInt8}) = UInt8(255) -fillvalue(::Type{UInt16}) = UInt16(65535) -fillvalue(::Type{UInt32}) = UInt32(4294967295) diff --git a/test/runtests.jl b/test/runtests.jl index 475d624..d6ea0fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -155,12 +155,6 @@ end @test ds["CU"][1:3] == Float32[76.23, 78.16, 81.24] end -@testset "LABL_PTR to a missing variable" begin - ds = CDFDataset(data_path("labl_ptr.cdf")) - @test ds["dangling"].attrib["LABL_PTR_1"] == "CARTESIAN" - @test ds["ok"].attrib["LABL_PTR_1"] == ["Bx", "By", "Bz"] -end - @testset "scalar r-variable" begin ds = CDFDataset(data_path("scalar_rvar.cdf")) var = ds["x"]