Skip to content

Commit d446f9b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into stringTests
* upstream/main: Add Autoformatting with Blue style (#12)
2 parents 981cc50 + e65dc0e commit d446f9b

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue"

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
## [UNRELEASED] - 2025-01-08
1+
## [UNRELEASED] · YYYY-MM-DD
2+
### 🌀 Changed
3+
- Reformat sources with [Blue](https://github.com/JuliaDiff/BlueStyle) ([#12](https://github.com/cbrnr/XDF.jl/pull/12) by [Alberto Barradas](https://github.com/abcsds))
24
### ✨ Added
35
- Add tests for string markers from issue xdf-modules/libxdf#19 (([#13](https://github.com/cbrnr/XDF.jl/pull/13) by [Alberto Barradas](https://github.com/abcsds)))
4-
5-
## [0.2.0] - 2022-02-23
6+
7+
## [0.2.0] · 2022-02-23
8+
### ✨ Added
69
- Add support for string markers and string streams ([#2](https://github.com/cbrnr/XDF.jl/pull/2) by [Alberto Barradas](https://github.com/abcsds) and [Clemens Brunner](https://github.com/cbrnr))
710
- Make header and footer XML available in "xml" key ([#4](https://github.com/cbrnr/XDF.jl/pull/4) by [Alberto Barradas](https://github.com/abcsds))
811

9-
## [0.1.0] - 2020-09-25
10-
### Added
12+
## [0.1.0] · 2020-09-25
13+
### Added
1114
- Initial release (by [Clemens Brunner](https://github.com/cbrnr))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
![License](https://img.shields.io/github/license/cbrnr/XDF.jl)
2+
[![Code Style Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
23

34
XDF.jl
45
======

src/XDF.jl

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@ export read_xdf
77

88
using Logging: @info, @debug
99

10-
11-
CHUNK_TYPE = Dict(1=>"FileHeader",
12-
2=>"StreamHeader",
13-
3=>"Samples",
14-
4=>"ClockOffset",
15-
5=>"Boundary",
16-
6=>"StreamFooter")
17-
18-
DATA_TYPE = Dict("int8"=>Int8,
19-
"int16"=>Int16,
20-
"int32"=>Int32,
21-
"int64"=>Int64,
22-
"float32"=>Float32,
23-
"double64"=>Float64,
24-
"string"=>String)
25-
10+
CHUNK_TYPE = Dict(
11+
1 => "FileHeader",
12+
2 => "StreamHeader",
13+
3 => "Samples",
14+
4 => "ClockOffset",
15+
5 => "Boundary",
16+
6 => "StreamFooter",
17+
)
18+
19+
DATA_TYPE = Dict(
20+
"int8" => Int8,
21+
"int16" => Int16,
22+
"int32" => Int32,
23+
"int64" => Int64,
24+
"float32" => Float32,
25+
"double64" => Float64,
26+
"string" => String,
27+
)
2628

2729
"""
2830
read_xdf(filename::AbstractString, sync::Bool=true)
2931
3032
Read XDF file and optionally sync streams (default true).
3133
"""
3234
function read_xdf(filename::AbstractString, sync::Bool=true)
33-
streams = Dict{Int, Any}()
35+
streams = Dict{Int,Any}()
3436
counter = Dict(zip(keys(CHUNK_TYPE), zeros(Int, length(CHUNK_TYPE)))) # count chunks
3537

3638
open(filename) do io
@@ -127,7 +129,9 @@ function read_xdf(filename::AbstractString, sync::Bool=true)
127129
streams[id]["data"][index[id], j] = String(read(io, read_varlen_int(io)))
128130
end
129131
else
130-
streams[id]["data"][index[id], :] = reinterpret(dtype, read(io, sizeof(dtype) * nchannels))
132+
streams[id]["data"][index[id], :] = reinterpret(
133+
dtype, read(io, sizeof(dtype) * nchannels)
134+
)
131135
end
132136
index[id] += 1
133137
end
@@ -154,7 +158,6 @@ function read_xdf(filename::AbstractString, sync::Bool=true)
154158
return streams
155159
end
156160

157-
158161
"Read variable-length integer."
159162
function read_varlen_int(io::IO)
160163
nbytes = read(io, Int8)
@@ -167,15 +170,13 @@ function read_varlen_int(io::IO)
167170
end
168171
end
169172

170-
171173
"Find XML tag and return its content (optionally converted to specified type)."
172174
function findtag(xml::AbstractString, tag::AbstractString, type=String::DataType)
173175
m = match(Regex("<$tag>(.*)</$tag>"), xml)
174176
content = isnothing(m) ? nothing : m[1]
175177
return isnothing(content) || type == String ? content : parse(type, content)
176178
end
177179

178-
179180
"Synchronize clock values by their given offsets."
180181
function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2})
181182
x = hcat(ones(size(offsets, 1), 1), offsets[:, 1])
@@ -184,4 +185,4 @@ function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2})
184185
return time .+ (coefs[1] .+ coefs[2] .* time)
185186
end
186187

187-
end
188+
end

test/runtests.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ using XDF, Downloads, Test, SHA
1414
@test endswith(streams[0]["header"], "</uid></info>")
1515
@test startswith(streams[0]["footer"], "<?xml version=\"1.0\"?>")
1616
@test endswith(streams[0]["footer"], "</clock_offsets></info>")
17-
@test streams[0]["data"] == [192 255 238
18-
12 22 32
19-
13 23 33
20-
14 24 34
21-
15 25 35
22-
12 22 32
23-
13 23 33
24-
14 24 34
25-
15 25 35]
17+
@test streams[0]["data"] == [
18+
192 255 238
19+
12 22 32
20+
13 23 33
21+
14 24 34
22+
15 25 35
23+
12 22 32
24+
13 23 33
25+
14 24 34
26+
15 25 35
27+
]
2628

2729
@test 46202862 in keys(streams)
2830
@test streams[46202862]["name"] == "SendDataString"
@@ -37,8 +39,8 @@ using XDF, Downloads, Test, SHA
3739
@test size(streams[46202862]["data"]) == (9, 1)
3840
@test startswith(streams[46202862]["data"][1, 1], "<?xml version")
3941
@test endswith(streams[46202862]["data"][1, 1], "</info>")
40-
@test streams[46202862]["data"][2:end, 1] == ["Hello", "World", "from", "LSL", "Hello",
41-
"World", "from", "LSL"]
42+
@test streams[46202862]["data"][2:end, 1] ==
43+
["Hello", "World", "from", "LSL", "Hello", "World", "from", "LSL"]
4244
end
4345

4446
@testset "XDF file with clock resets" begin

0 commit comments

Comments
 (0)