@@ -9,8 +9,9 @@ Load all attribute entries for a given attribute from its AEDRs.
99@inline function load_attribute_entries (buffer:: Vector{UInt8} , adr, RecordSizeType, cdf_encoding)
1010 head = max (adr. AgrEDRhead, adr. AzEDRhead)
1111 offsets = get_offsets (buffer, head, RecordSizeType)
12+ needs_byte_swap = is_big_endian_encoding (cdf_encoding)
1213 return map (offsets) do offset
13- load_aedr_data (buffer, offset, RecordSizeType, cdf_encoding )
14+ load_aedr_data (buffer, offset, RecordSizeType, needs_byte_swap )
1415 end
1516end
1617
1920
2021Load all attributes from the CDF file.
2122"""
22- function attrib (cdf:: CDFDataset ; predicate= is_global)
23+ function attrib (cdf:: CDFDataset ; predicate = is_global)
2324 RecordSizeType = recordsize_type (cdf)
2425 buffer = cdf. buffer
2526 cdf_encoding = cdf. cdr. encoding
@@ -59,14 +60,15 @@ function vattrib(cdf::CDFDataset, varnum::Integer)
5960 RecordSizeType = recordsize_type (cdf)
6061 buffer = cdf. buffer
6162 cdf_encoding = cdf. cdr. encoding
62- attributes = Dict {String,Union{String,Vector}} ()
63+ attributes = Dict {String, Union{String, Vector}} ()
6364 offsets = get_offsets_lazy (buffer, cdf. gdr. ADRhead, RecordSizeType)
65+ needs_byte_swap = is_big_endian_encoding (cdf_encoding)
6466 for offset in offsets
6567 is_global (buffer, offset, RecordSizeType) && continue
6668 adr = ADR (buffer, offset, RecordSizeType)
6769 for head in (adr. AgrEDRhead, adr. AzEDRhead)
6870 head == 0 && continue
69- found = _search_aedr_entries (buffer, head, RecordSizeType, cdf_encoding , varnum)
71+ found = _search_aedr_entries (buffer, head, RecordSizeType, needs_byte_swap , varnum)
7072 isnothing (found) && continue
7173 name = String (adr. Name)
7274 attributes[name] = _get_attributes (name, found, cdf)
@@ -99,13 +101,14 @@ function vattrib(cdf, varnum, name)
99101 # Search for the specific attribute by name first
100102 offsets = get_offsets_lazy (buffer, cdf. gdr. ADRhead, RecordSizeType)
101103 name_bytes = codeunits (name)
104+ needs_byte_swap = is_big_endian_encoding (cdf_encoding)
102105 for offset in offsets
103106 is_global (buffer, offset, RecordSizeType) && continue
104107 adr = ADR (buffer, offset, RecordSizeType)
105108 adr. Name != name_bytes && continue
106109 for head in (adr. AgrEDRhead, adr. AzEDRhead)
107110 head == 0 && continue
108- found = _search_aedr_entries (buffer, head, RecordSizeType, cdf_encoding , varnum)
111+ found = _search_aedr_entries (buffer, head, RecordSizeType, needs_byte_swap , varnum)
109112 isnothing (found) && continue
110113 return _get_attributes (name, found, cdf)
111114 end
@@ -114,15 +117,15 @@ function vattrib(cdf, varnum, name)
114117 return nothing
115118end
116119
117- @inline function _search_aedr_entries (source, aedr_head, RecordSizeType, cdf_encoding :: Int32 , target_varnum)
120+ @inline function _search_aedr_entries (source, aedr_head, RecordSizeType, needs_byte_swap , target_varnum)
118121 aedr_head == 0 && return nothing
119122 offset = Int (aedr_head)
120123 _num_offset = 13 + 2 * sizeof (RecordSizeType)
121124 _next_offset = 5 + sizeof (RecordSizeType)
122125 while offset != 0
123126 num = read_be (source, offset + _num_offset, Int32)
124127 if num == target_varnum
125- return load_aedr_data (source, offset, RecordSizeType, cdf_encoding )
128+ return load_aedr_data (source, offset, RecordSizeType, needs_byte_swap )
126129 end
127130 offset = Int (read_be (source, offset + _next_offset, RecordSizeType))
128131 end
134137
135138Return a list of attribute names in the CDF file.
136139"""
137- function attribnames (cdf:: CDFDataset ; predicate= is_global)
140+ function attribnames (cdf:: CDFDataset ; predicate = is_global)
138141 names = String[]
139142 buffer = cdf. buffer
140143 RecordSizeType = recordsize_type (cdf)
0 commit comments