Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with modern Julia #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.jl.cov
*.jl.*.cov
*.jl.mem

Manifest.toml
17 changes: 17 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name = "Touchstone"
uuid = "958a2305-7e5c-4f48-8401-e0b3f0c58adc"
version = "0.0.1"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[extras]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AxisArrays", "FileIO", "Test"]
29 changes: 16 additions & 13 deletions src/Touchstone.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
__precompile__()
module Touchstone
using FileIO, AxisArrays, Interpolations

using FileIO
using AxisArrays
using Interpolations
using UUIDs

export Linear, Constant, RealImag, MagAngle, dBAngle, reformat, loadset

const tsextensions = [".s1p",".s2p",".s3p",".s4p",".s5p",".s6p",".s7p",".s8p",".ts"]
function __init__()
FileIO.add_format(format"TS", (), tsextensions)
FileIO.add_format(format"TS", (), tsextensions, [:Touchstone => UUID("958a2305-7e5c-4f48-8401-e0b3f0c58adc")])
end

"""
Expand Down Expand Up @@ -60,11 +65,11 @@ function loadset(path::String; interp = Linear())
first = false
newaxarrs = [
AxisArray(zeros(size(a)[1:4]..., length(faxis), size(a)[6:end]...),
axes(a)[1:4]..., Axis{:f}(faxis), axes(a)[6:end]...)
AxisArrays.axes(a)[1:4]..., Axis{:f}(faxis), AxisArrays.axes(a)[6:end]...)
]
else
push!(newaxarrs, AxisArray(zeros(size(a)[1:4]..., length(faxis),
size(a)[6:end]...), axes(a)[1:4]..., Axis{:f}(faxis), axes(a)[6:end]...))
size(a)[6:end]...), AxisArrays.axes(a)[1:4]..., Axis{:f}(faxis), AxisArrays.axes(a)[6:end]...))
end

# This is a little ugly, probably could be better but Interpolations.jl doesn't
Expand All @@ -82,7 +87,7 @@ function loadset(path::String; interp = Linear())
end
end

function FileIO.load(f::File{format"TS"}; kwargs...)
function load(f::File{format"TS"}; kwargs...)
open(f) do s
n = filename(f)
ext = splitext(n)[2]
Expand All @@ -100,7 +105,7 @@ function FileIO.load(f::File{format"TS"}; kwargs...)
end
end

function FileIO.load(s0::Stream{format"TS"};
function load(s0::Stream{format"TS"};
v2::Bool=false, nports::Int=2)
v2 && error("Touchstone v2 not yet implemented.") #TODO
@assert nports > 0
Expand All @@ -123,8 +128,8 @@ function FileIO.load(s0::Stream{format"TS"};
while true
l = readline(s); lct+=1
l == "!< END PARAMS" && break
param = replace(l[4:end], " ", "")
(k,v) = (split(param, "=")...)
param = replace(l[4:end], " "=>"")
(k,v) = split(param, "=")
push!(sweepaxes, AxisArrays.Axis{Symbol(k)}([parse(Float64, v)]))
end
continue
Expand All @@ -134,12 +139,11 @@ function FileIO.load(s0::Stream{format"TS"};
if l[1] == '#' # Parse option line
#TODO: check that the option line precedes all data lines
#TODO: check that there is only one option line per file
#TODO: replace 1 or more whitespace by 1 space
#TODO: more input sanitizing, etc.
optargs = split(lowercase(l),' ')[2:end]
optargs = split(lowercase(l), ' ', keepempty=false)[2:end]

# resistances specified as e.g. "R 50.0"
ridx = findfirst(x->x=="R", optargs)
ridx = findfirst(x->x=="r", optargs)
(ridx > 0) && (opts[:resistance] = optargs[ridx+1])

fs = intersect(["ghz","mhz","khz","hz"], optargs)
Expand All @@ -161,8 +165,7 @@ function FileIO.load(s0::Stream{format"TS"};
i = 0
while true
i += 1
# TODO: Replace multiple spaces by one space.
dataline = split(strip(l), ' ')
dataline = split(strip(l), ' ', keepempty=false)
length(dataline) != expectednum(nports, i) &&
error("unexpected number of values on line $lct.")
if i == 1
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Touchstone
using Base.Test, FileIO, AxisArrays
using Test
using FileIO
using AxisArrays

using Touchstone: nlines, expectednum, format_axis, param_axes

Expand Down Expand Up @@ -76,7 +78,7 @@ end
@test sweep[Axis{:format}].val == [:mag, :angle]
@test sweep[Axis{:from}].val == [1, 2]
@test sweep[Axis{:to}].val == [1, 2]
@test any(ax isa Axis{:BusLengthControl} for ax in axes(sweep))
@test any(ax isa Axis{:BusLengthControl} for ax in AxisArrays.axes(sweep))
end

@testset "> S3P file" begin
Expand Down