diff --git a/.gitignore b/.gitignore index 8c960ec..7d1c878 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.jl.cov *.jl.*.cov *.jl.mem + +Manifest.toml \ No newline at end of file diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..2ac6f98 --- /dev/null +++ b/Project.toml @@ -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"] diff --git a/src/Touchstone.jl b/src/Touchstone.jl index e714e8d..81ad7ce 100644 --- a/src/Touchstone.jl +++ b/src/Touchstone.jl @@ -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 """ @@ -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 @@ -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] @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 1e2bdd7..3b46c41 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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