Reference

Supported API

Touchstone.TouchstoneFile — Type
TouchstoneFile{F<:AbstractVector{Float64}, A<:AbstractArray{ComplexF64,3}}
TouchstoneFile(f::F, N::A, frequencyunit::String, parameter::String,
    format::String, R::Float64, version::Float64, numberofports::Int,
    twoportdataorder::String, numberoffrequencies::Int,
    numberofnoisefrequencies::Int, reference::Vector{Float64},
    information::Vector{String}, matrixformat::String,
    mixedmodeorder::Vector{Tuple{Char, Vector{Int}}},
    comments::Vector{String}, noisedata::Vector{Float64})

Store network parameters and Touchstone metadata. The type parameters F and A are the storage types of f and N, respectively. Use touchstone_load, touchstone_parse, or touchstone_file to construct a validated object; the positional constructor stores its arguments without validation or copying.

The fields, in constructor order, are:

  • f: network frequencies in Hz, regardless of frequencyunit.
  • N: complex network parameters with size (numberofports, numberofports, numberoffrequencies). S parameters are dimensionless, Z parameters are in ohms, and Y parameters are in siemens. For H parameters, N[1,1,:] is in ohms and N[2,2,:] in siemens; for G parameters these units are reversed. Off-diagonal H/G entries are dimensionless. Version 1 normalization is removed when reading.
  • frequencyunit: the file unit, "Hz", "kHz", "MHz", or "GHz". This also specifies the units of frequencies in noisedata; f remains in Hz.
  • parameter: the parameter family, "S", "Y", "Z", "H", or "G". H and G require two ports. Parameter, frequency-unit, and format names are case insensitive.
  • format: the file representation, "RI" (real/imaginary), "MA" (magnitude/angle), or "DB" (20 log10 magnitude/angle). Angles are in degrees.
  • R: the positive option-line reference resistance in ohms. For version 1.1, this is the reference resistance of port 1.
  • version: 1.0, 1.1, 2.0, or 2.1. Multiple option-line resistances identify version 1.1 on reading. A single resistance is indistinguishable from version 1.0, including for one-port files, and is reported as 1.0.
  • numberofports: the number of rows and columns of each network matrix.
  • twoportdataorder: "12_21" or "21_12", specifying the order of the off-diagonal entries in two-port data. Version 1 uses "21_12" for two ports; other port counts use "12_21".
  • numberoffrequencies: the number of network frequency records, length(f).
  • numberofnoisefrequencies: the number of noise records, length(noisedata) ÷ 5.
  • reference: one positive reference impedance in ohms per physical port. Version 1.0 requires every value to equal R. Version 1.1 stores these values on the option line and uses them for normalization; version 2 stores them under [Reference] and uses them only for port references.
  • information: lines in the version 2 information section, with their case preserved and comments stored separately.
  • matrixformat: "Full", "Upper", or "Lower". Triangular file formats represent transpose-symmetric matrices; N always contains the full matrix. Version 1 requires "Full".
  • mixedmodeorder: version 2 descriptors (mode, ports) in matrix order. Mode 'S' has one physical port; modes 'D' and 'C' have an ordered pair of physical ports. An empty vector denotes single-ended data. The array N is already in the specified basis; no basis conversion is made.
  • comments: comment text without the leading !, with its case preserved.
  • noisedata: flat five-value records: frequency in frequencyunit, minimum noise figure in dB, optimum source reflection-coefficient magnitude, its angle in degrees, and effective noise resistance in ohms. Noise data require two ports. Version 1 noise resistance is converted to ohms when reading and normalized by R when writing (port 1 in version 1.1).
Touchstone.touchstone_file — Function
touchstone_file(f::AbstractVector, N::AbstractArray;
    frequencyunit="GHz", parameter="S", format="MA", R=50.0,
    version=2.0, twoportdataorder="", reference=Float64[],
    information=String[], matrixformat="Full",
    mixedmodeorder=Tuple{Char, Vector{Int}}[], comments=String[],
    noisedata=Float64[])

Construct a TouchstoneFile from network frequencies f in Hz and physical network parameters N. The array has size (nports, nports, length(f)); see TouchstoneFile for parameter units and metadata fields.

Inputs must use one-based indexing. Views and ranges are accepted. Arrays with element types Float64 for f and ComplexF64 for N are retained; other real frequency and numeric parameter arrays are converted to those types. Reject negative frequencies, nonfinite values, and nonzero values or components that become zero during conversion. Frequencies must increase strictly, including after conversion to the file unit. Numeric keywords R and version accept real values; reference and noisedata accept one-based real vectors. These values use Float64 storage and the same checked conversion. Float16 and Float32 version selectors match supported versions in their input precision before conversion; adjacent values in those types are rejected. Canonical Vector{Float64} metadata vectors are retained.

The keywords select the file representation. References describe the supplied N; changing R or reference does not renormalize S parameters. mixedmodeorder describes the supplied data without transforming its basis. An empty reference uses R for every port. In version 1.1, reference supplies the option-line values and its first value sets R, including for noise normalization. An empty twoportdataorder selects "12_21"; version 1 always uses "21_12" for two ports and "12_21" otherwise. "Upper" and "Lower" require exact transpose symmetry. Use "RI" or "MA" for exact zeros, which have no finite "DB" representation. Information and mixed-mode metadata require version 2. Noise frequencies use frequencyunit, and noise resistance is supplied in ohms. Each comment or information entry must be a single line; information entries cannot contain ! or the section terminator.

Validate the selected file representation one record at a time. The result stores physical arrays and metadata; writing uses their current values.

Examples

julia> f = [1.0e9, 2.0e9]; N = fill(0.5 + 0.0im, 1, 1, 2);

julia> ts = Touchstone.touchstone_file(f, N; frequencyunit="GHz", format="RI");

julia> ts.f === f, ts.N === N
(true, true)

julia> ts.f, ts.frequencyunit
([1.0e9, 2.0e9], "GHz")
Touchstone.touchstone_load — Function
touchstone_load(filename)

Read a Touchstone 1.0, 1.1, 2.0, or 2.1 file and return a TouchstoneFile. Network frequencies f are in Hz and network parameters N use physical units. Noise frequencies retain the file unit; noise resistance is in ohms.

The number of ports is determined from the file contents. No particular filename extension is required. See touchstone_parse to read from IO.

Touchstone.touchstone_parse — Function
touchstone_parse(io::IO)

Read Touchstone data from a seekable stream io at its current position and return a TouchstoneFile. The stream remains open, and an existing stream mark is preserved. Decode complete network records incrementally; malformed input may be rejected before later records are read. Network frequencies are in Hz and network parameters use physical units, as for touchstone_load.

Accept LF, CRLF, or CR line endings and an optional leading UTF-8 byte order mark. Text is decoded as UTF-8 when valid, or as Latin-1 otherwise.

Examples

julia> io = IOBuffer("# MHz S RI R 50\n2.0 0.5 -0.25");

julia> ts = Touchstone.touchstone_parse(io);

julia> ts.f, ts.N[1, 1, 1]
([2.0e6], 0.5 - 0.25im)

julia> ts.frequencyunit
"mhz"
Touchstone.touchstone_save — Function
touchstone_save(filename::String, frequencies::AbstractVector,
    N::AbstractArray; version=1.0, reference=Float64[], R=50.0,
    format="RI", parameter="S", comments=[""], twoportdataorder="12_21",
    matrixformat="Full", frequencyunit="Hz",
    mixedmodeorder=Tuple{Char, Vector{Int}}[], information=String[],
    noisedata=Float64[])

Write network frequencies frequencies in Hz and physical parameters N to filename. See touchstone_file for array dimensions, keyword meanings, and validation. The defaults here select version 1, RI format, and Hz.

Preserve an explicit filename extension. When no extension is supplied, append .sNp for versions 1.0 and 1.1, and .ts for versions 2.0 and 2.1, where N is the number of ports. These defaults follow common naming conventions; the Touchstone 2.1 specification permits .ts for all versions and allows other extensions. Warn when an .sNp extension does not match the port count.

Validate metadata, then encode and validate records while writing a temporary file in the same directory. Replace the destination after successful writing and close using Base.rename. Failures before replacement leave the destination unchanged. Julia versions before 1.12 may fall back to copying if renaming fails. Remove the temporary file on failure. Do not mutate the inputs during a write. An existing regular file retains its read/write/execute permission bits. Replacement does not preserve hard-link identity or follow an existing destination symlink, and it does not guarantee persistence across a system crash. Return nothing.

touchstone_save(filename::String, ts::TouchstoneFile)

Write the current frequencies ts.f, physical parameters ts.N, and metadata of ts to filename. Preserve the selected version, units, representation, references, mixed-mode order, information, comments, and noise data. Recompute port and frequency counts from the arrays.

Validation, filename handling, and file replacement are the same as for the array form of touchstone_save. Return nothing.

Examples

julia> ts = Touchstone.touchstone_file([1.0e9], fill(0.5+0.0im, 1, 1, 1);
           version=2.1, format="RI");

julia> mktempdir() do directory
           filename = joinpath(directory, "network.ts")
           touchstone_save(filename, ts)
           saved = touchstone_load(filename)
           (saved.version, saved.f, saved.N == ts.N)
       end
(2.1, [1.0e9], true)
Touchstone.touchstone_write — Function
touchstone_write(io::IO, f::AbstractVector, N::AbstractArray; kwargs...)

Write network frequencies f in Hz and physical parameters N to io, leaving the stream open. Accept the same keywords and defaults as touchstone_file: version 2, MA format, and GHz file frequencies.

Validate all metadata and encoded records before writing any bytes. Invalid inputs leave io untouched; an IO failure during writing can leave partial output. Do not mutate the inputs during a write. Use touchstone_save for file replacement. Return nothing.

Examples

julia> io = IOBuffer();

julia> Touchstone.touchstone_write(io, [2.0e6], fill(0.5 - 0.25im, 1, 1, 1);
           version=1.0, format="RI", frequencyunit="MHz");

julia> print(String(take!(io)))
# MHz S RI R 50.0
! freq ReS11 ImS11
2.0 0.5 -0.25
touchstone_write(io::IO, ts::TouchstoneFile)

Write the current frequencies ts.f, physical parameters ts.N, and metadata to io. Recompute port and frequency counts from the arrays. Validation and IO behavior are the same as for the array form of touchstone_write. Return nothing.

Internal reference

These helpers describe implementation details and are not a stable interface.

Touchstone.TouchstoneOptionLine — Type
TouchstoneOptionLine(frequencyunit::String, parameter::String,
    format::String, R::Float64, reference::Vector{Float64}=Float64[])

Store option-line values: the file frequency unit, network parameter family, numeric representation, and reference resistance R in ohms. reference holds version 1.1 per-port values, with R equal to the first value, or is empty for a scalar option-line resistance. Use parseoptionline to parse and validate text.

Touchstone.arraytonetworkdata — Method
arraytonetworkdata(frequencies, N, numberofports, numberoffrequencies,
    matrixformat, twoportdataorder, parameter, frequencyunit, format, R,
    version; reference=Float64[])

Encode physical parameters N and frequencies in Hz as a flat Float64 vector. Each record contains a frequency in frequencyunit, then pairs of numbers in format, ordered by matrixindices.

Apply the inverse of the physical-unit normalization described in networkdatatoarray. DB values are 20 log10 of the normalized magnitude; MA and DB angles are in degrees. For version 1.1, reference supplies one resistance per port; an empty vector uses R for all ports. This low-level helper expects consistent dimensions and metadata. Use touchstone_file for complete input validation.

Examples

julia> N = fill(100.0 + 0.0im, 1, 1, 1);

julia> Touchstone.arraytonetworkdata([2.0e9], N, 1, 1, "Full", "12_21",
           "Z", "GHz", "RI", 50.0, 1.0)
3-element Vector{Float64}:
 2.0
 2.0
 0.0

julia> Touchstone.arraytonetworkdata([2.0e9], N, 1, 1, "Full", "12_21",
           "Z", "GHz", "RI", 50.0, 2.0)
3-element Vector{Float64}:
   2.0
 100.0
   0.0
Touchstone.encodedline — Method
encodedline(line::AbstractString)

Encode a text line as bytes using the reader's Latin-1/UTF-8 convention. Use Latin-1 when every character fits in one byte and those bytes are not also valid UTF-8; use UTF-8 otherwise. Non-ASCII text is a compatibility extension. The caller validates the text and adds any line ending.

Examples

julia> Touchstone.encodedline(" 25 °C"), Touchstone.encodedline(" 50 Ω")
(UInt8[0x20, 0x32, 0x35, 0x20, 0xb0, 0x43], UInt8[0x20, 0x35, 0x30, 0x20, 0xce, 0xa9])
Touchstone.frequencyscale — Method
frequencyscale(frequencyunit::String)

Return the multiplier that converts frequencyunit to Hz. Accept "Hz", "kHz", "MHz", and "GHz", without regard to case.

Examples

julia> Touchstone.frequencyscale("MHz")
1.0e6
Touchstone.isbegininformation — Method
isbegininformation(line::String)

Return true if line starts with [begin information] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isbegininformation("[begin information]")
true

julia> Touchstone.isbegininformation("[version] 1.0")
false
Touchstone.isdecimal — Method
isdecimal(token::AbstractString)

Return true if token has decimal syntax: an optional sign, digits with an optional decimal point, and an optional e or E exponent. Reject whitespace, hexadecimal numbers, Inf, and NaN. This checks syntax only; use parsedecimal to check the representable range.

Examples

julia> Touchstone.isdecimal.(["50", "-.5", "1.5e9", "0x1p-1", "inf", "nan"])
6-element BitVector:
 1
 1
 1
 0
 0
 0
Touchstone.isend — Method
isend(line::String)

Return true if line is [end], allowing trailing whitespace. The caller must lowercase line and strip comments.

Examples

julia> Touchstone.isend("[end]")
true

julia> Touchstone.isend("[version] 1.0")
false
Touchstone.isendinformation — Method
isendinformation(line::String)

Return true if line is [end information], allowing trailing whitespace. The caller must lowercase line and strip comments.

Examples

julia> Touchstone.isendinformation("[end information]")
true

julia> Touchstone.isendinformation("[version] 1.0")
false
Touchstone.ismatrixformat — Method
ismatrixformat(line::String)

Return true if line starts with [matrix format] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.ismatrixformat("[matrix format] full")
true

julia> Touchstone.ismatrixformat("[version] 1.0")
false
Touchstone.ismixedmodeorder — Method
ismixedmodeorder(line::String)

Return true if line starts with [mixed-mode order] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.ismixedmodeorder("[mixed-mode order] d1,2 c1,2")
true

julia> Touchstone.ismixedmodeorder("[version] 1.0")
false
Touchstone.isnoisedata — Method
isnoisedata(line::String)

Return true if line is [noise data], allowing trailing whitespace. The caller must lowercase line and strip comments.

Examples

julia> Touchstone.isnoisedata("[noise data]")
true

julia> Touchstone.isnoisedata("[version] 1.0")
false
Touchstone.isnumberoffrequencies — Method
isnumberoffrequencies(line::String)

Return true if line starts with [number of frequencies] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isnumberoffrequencies("[number of frequencies]")
true

julia> Touchstone.isnumberoffrequencies("[version] 1.0")
false
Touchstone.isnumberofnoisefrequencies — Method
isnumberofnoisefrequencies(line::String)

Return true if line starts with [number of noise frequencies] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isnumberofnoisefrequencies("[number of noise frequencies]")
true

julia> Touchstone.isnumberofnoisefrequencies("[version] 1.0")
false
Touchstone.isnumberofports — Method
isnumberofports(line::String)

Return true if line starts with [number of ports] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isnumberofports("[number of ports] 1")
true

julia> Touchstone.isnumberofports("[version] 1.0")
false
Touchstone.isoptionline — Method
isoptionline(line::String)

Return true if the line starts with # in column one. This recognizes the prefix only; it does not validate the rest of the line.

Examples

julia> Touchstone.isoptionline("# MHz Z MA R 75")
true

julia> Touchstone.isoptionline("[number of ports] 1")
false
Touchstone.isreference — Method
isreference(line::String)

Return true if line starts with [reference] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isreference("[reference]")
true

julia> Touchstone.isreference("[version] 1.0")
false
Touchstone.istwoportdataorder — Method
istwoportdataorder(line::String)

Return true if line starts with [two-port data order] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.istwoportdataorder("[two-port data order] 12_21")
true

julia> Touchstone.istwoportdataorder("[version] 1.0")
false
Touchstone.isversion — Method
isversion(line::String)

Return true if line starts with [version] in column one. The caller must lowercase line. This checks only the prefix, not its arguments.

Examples

julia> Touchstone.isversion("[version] 2.0")
true

julia> Touchstone.isversion("[number of ports] 1")
false
Touchstone.matrixindices — Method
matrixindices(nports, format, twoportdataorder; printflag=false)

Return network-matrix Cartesian indices for nports, matrix format, and twoportdataorder. Matrix formats are "Full", "Upper", and "Lower" (case insensitive). The order is "12_21" or "21_12" for two ports and must be "12_21" for other port counts. With printflag=true, also print the index layout to standard output.

Examples

julia> Touchstone.matrixindices(2,"Full","12_21")
4-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 1)
 CartesianIndex(1, 2)
 CartesianIndex(2, 1)
 CartesianIndex(2, 2)

julia> Touchstone.matrixindices(2,"Full","21_12")
4-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 1)
 CartesianIndex(2, 1)
 CartesianIndex(1, 2)
 CartesianIndex(2, 2)
Touchstone.matrixindices — Method
matrixindices(nports, format; printflag=false)

Return network-matrix Cartesian indices in file order for nports and matrix format "Full", "Upper", or "Lower" (case insensitive). Use "12_21" ordering. With printflag=true, also print the index layout to standard output.

Examples

julia> Touchstone.matrixindices(2,"Full",printflag=true)
11 12
21 22
4-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 1)
 CartesianIndex(1, 2)
 CartesianIndex(2, 1)
 CartesianIndex(2, 2)

julia> Touchstone.matrixindices(2,"Upper",printflag=true)
11 12
   22
      3-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 1)
 CartesianIndex(1, 2)
 CartesianIndex(2, 2)

julia> Touchstone.matrixindices(2,"Lower",printflag=true)
11
21 22
3-element Vector{CartesianIndex{2}}:
 CartesianIndex(1, 1)
 CartesianIndex(2, 1)
 CartesianIndex(2, 2)
Touchstone.networkdatatoarray — Method
networkdatatoarray(networkdata, numberofports, numberoffrequencies,
    matrixformat, twoportdataorder, parameter, frequencyunit, format, R,
    version; reference=Float64[])

Decode flat file records into (frequencies, N), with frequencies in Hz and physical network parameters in a ComplexF64 array of size (numberofports, numberofports, numberoffrequencies).

For version 1.0, convert file values with Z = z R, Y = y / R, H11 = h11 R, H22 = h22 / R, G11 = g11 / R, and G22 = g22 R. Off-diagonal H/G entries and S parameters are unscaled. For version 1.1, reference supplies per-port normalization; an empty vector uses R for all ports. Version 2 non-S parameters already use physical units.

DB values describe the normalized magnitude in dB; MA and DB angles are in degrees. Reconstruct triangular matrices by transpose symmetry, without complex conjugation. Use touchstone_parse for complete file validation.

Examples

julia> f, N = Touchstone.networkdatatoarray([2.0, 2.0, 0.0], 1, 1,
           "Full", "12_21", "Z", "GHz", "RI", 50.0, 1.0);

julia> f, N[1, 1, 1]
([2.0e9], 100.0 + 0.0im)
Touchstone.parsedecimal — Method
parsedecimal(token::AbstractString, line::AbstractString)

Parse token as a finite Float64 with the decimal syntax accepted by isdecimal. Reject overflow and nonzero values that round to zero. Include the source line in syntax errors.

Touchstone.parseinformation! — Method
parseinformation!(information::Vector{String}, comments::Vector{String},
    io::Union{IO,TouchstoneReader})

Append information-section lines from io to information, preserving case. Append comments separately to comments. Start after [Begin Information] and consume the required [End Information] terminator. Return nothing.

Examples

information = String[]
comments = String[]
io = IOBuffer("This is an information section.
[End Information]")
Touchstone.parseinformation!(information,comments,io)
println(information)

# output
["This is an information section."]
Touchstone.parsematrixformat — Method
parsematrixformat(line::String)

Return "Full", "Lower", or "Upper" from a lowercased [matrix format] line with comments removed.

Examples

julia> Touchstone.parsematrixformat("[matrix format] lower")
"Lower"

julia> Touchstone.parsematrixformat("[matrix format] upper")
"Upper"
Touchstone.parsemixedmodeorder! — Method
parsemixedmodeorder!(mixedmodeorder::Vector{Tuple{Char, Vector{Int}}},
    line::String)
parsemixedmodeorder!(mixedmodeorder, comments, line, numberofports, io)

Append descriptors from a [Mixed-Mode Order] line to mixedmodeorder as (mode, ports) tuples. Convert mode letters to uppercase and port indices to integers. The five-argument form also reads continuation lines from io, collects their comments, and requires numberofports descriptors. Strip comments from the initial line before calling either form.

These helpers parse descriptor syntax; port coverage, pairing, and reference impedances are checked when constructing or parsing the complete file. Return nothing.

Examples

julia> mixedmodeorder = Tuple{Char, Vector{Int}}[];Touchstone.parsemixedmodeorder!(mixedmodeorder,"[Mixed-Mode Order] D2,3 D6,5 C2,3 C6,5 S4 S1");mixedmodeorder
6-element Vector{Tuple{Char, Vector{Int64}}}:
 ('D', [2, 3])
 ('D', [6, 5])
 ('C', [2, 3])
 ('C', [6, 5])
 ('S', [4])
 ('S', [1])
Touchstone.parsenetworkdata! — Function
parsenetworkdata!(networkdata::Vector{Float64}, comments::Vector{String},
    io::Union{IO,TouchstoneReader}, version::Real=1.0; width::Int=0,
    expectedfrequencies::Int=0, expectednoise::Int=-1)

Append encoded network records from io to networkdata, collect comments, and return (numberoffrequencies, recordwidth). Values retain their file units and representation. Frequencies must be finite, nonnegative, and strictly increasing.

A positive width supplies the number of scalar values per record, allowing arbitrary wrapping within a record. In this mode, a positive expectedfrequencies limits the record count and expectednoise=0 rejects [Noise Data]. The complete file parser checks the declared counts. With width=0, infer record boundaries from lines containing a frequency followed by parameter pairs; expectedfrequencies and expectednoise are ignored.

Consume [Noise Data], but leave [End] for parsenoisedata!. In version 1, a five-value line whose frequency does not exceed the preceding network frequency starts the noise section; leave that line unread.

Examples

networkdata = Float64[]
comments = String[]
io = IOBuffer("1.0000 0.3926 -0.1211 -0.0003 -0.0021 -0.0003 -0.0021 0.3926 -0.1211
2.0000 0.3517 -0.3054 -0.0096 -0.0298 -0.0096 -0.0298 0.3517 -0.3054
10.000 0.3419 0.3336 -0.0134 0.0379 -0.0134 0.0379 0.3419 0.3336")
Touchstone.parsenetworkdata!(networkdata,comments,io,1.0)
println(networkdata)

# output
[1.0, 0.3926, -0.1211, -0.0003, -0.0021, -0.0003, -0.0021, 0.3926, -0.1211, 2.0, 0.3517, -0.3054, -0.0096, -0.0298, -0.0096, -0.0298, 0.3517, -0.3054, 10.0, 0.3419, 0.3336, -0.0134, 0.0379, -0.0134, 0.0379, 0.3419, 0.3336]
networkdata = Float64[]
comments = String[]
io = IOBuffer("2 .95 -26 3.57 157 .04 76 .66 -14
22 .60 -144 1.30 40 .14 40 .56 -85
! NOISE PARAMETERS
4 .7 .64 69 .38
18 2.7 .46 -33 .40")
Touchstone.parsenetworkdata!(networkdata,comments,io,1.0)
println(networkdata)

# output
[2.0, 0.95, -26.0, 3.57, 157.0, 0.04, 76.0, 0.66, -14.0, 22.0, 0.6, -144.0, 1.3, 40.0, 0.14, 40.0, 0.56, -85.0]
networkdata = Float64[]
comments = String[]
io = IOBuffer("2 .95 -26 3.57 157 .04 76 .66 -14
22 .60 -144 1.30 40 .14 40 .56 -85
[Noise Data]
4 .7 .64 69 19
18 2.7 .46 -33 20
[End]")
Touchstone.parsenetworkdata!(networkdata,comments,io,2.0)
println(networkdata)

# output
[2.0, 0.95, -26.0, 3.57, 157.0, 0.04, 76.0, 0.66, -14.0, 22.0, 0.6, -144.0, 1.3, 40.0, 0.14, 40.0, 0.56, -85.0]
Touchstone.parsenoisedata! — Method
parsenoisedata!(noisedata, comments, io; requireend=false, allowend=true)

Append five-value noise records from io to noisedata, collect comments, and return the number of noise frequencies. Values retain their file units, including normalized version 1 resistance; the complete file parser converts that resistance to ohms. Frequencies must be finite, nonnegative, and strictly increasing.

Consume [End] when present. Set requireend=true to reject a missing terminator, or allowend=false to reject it in version 1 input. Start at the first noise record, after any [Noise Data] keyword.

Examples

networkdata = Float64[]
noisedata = Float64[]
comments = String[]
io = IOBuffer("1.0000 0.3926 -0.1211 -0.0003 -0.0021 -0.0003 -0.0021 0.3926 -0.1211
2.0000 0.3517 -0.3054 -0.0096 -0.0298 -0.0096 -0.0298 0.3517 -0.3054
10.000 0.3419 0.3336 -0.0134 0.0379 -0.0134 0.0379 0.3419 0.3336")
Touchstone.parsenetworkdata!(networkdata,comments,io,1.0)
Touchstone.parsenoisedata!(noisedata,comments,io)
println(noisedata)

# output
Float64[]
networkdata = Float64[]
noisedata = Float64[]
comments = String[]
io = IOBuffer("2 .95 -26 3.57 157 .04 76 .66 -14
22 .60 -144 1.30 40 .14 40 .56 -85
! NOISE PARAMETERS
4 .7 .64 69 .38
18 2.7 .46 -33 .40")
Touchstone.parsenetworkdata!(networkdata,comments,io,1.0)
Touchstone.parsenoisedata!(noisedata,comments,io)
println(noisedata)

# output
[4.0, 0.7, 0.64, 69.0, 0.38, 18.0, 2.7, 0.46, -33.0, 0.4]
networkdata = Float64[]
noisedata = Float64[]
comments = String[]
io = IOBuffer("2 .95 -26 3.57 157 .04 76 .66 -14
22 .60 -144 1.30 40 .14 40 .56 -85
[Noise Data]
4 .7 .64 69 19
18 2.7 .46 -33 20
[End]")
Touchstone.parsenetworkdata!(networkdata,comments,io,2.0)
Touchstone.parsenoisedata!(noisedata,comments,io)
println(noisedata)

# output
[4.0, 0.7, 0.64, 69.0, 19.0, 18.0, 2.7, 0.46, -33.0, 20.0]
Touchstone.parsenumberoffrequencies — Method
parsenumberoffrequencies(line::String)

Return the positive decimal integer after [number of frequencies] in line. Reject zero or negative counts. Strip comments before calling this helper.

Examples

julia> Touchstone.parsenumberoffrequencies("[number of frequencies] 10")
10
Touchstone.parsenumberofnoisefrequencies — Method
parsenumberofnoisefrequencies(line::String)

Return the positive decimal integer after [number of noise frequencies] in line. Reject zero or negative counts; omit the keyword when no noise data are present. Strip comments before calling this helper.

Examples

julia> Touchstone.parsenumberofnoisefrequencies("[number of noise frequencies] 10")
10
Touchstone.parsenumberofports — Method
parsenumberofports(line::String)

Return the decimal integer after [number of ports] in line. The complete file parser checks that the port count is positive. Strip comments before calling this helper.

Examples

julia> Touchstone.parsenumberofports("[number of ports] 1")
1
Touchstone.parseoptionline — Method
parseoptionline(line::String)

Parse an option line into a TouchstoneOptionLine containing frequencyunit, parameter, format, reference resistance R in ohms, and per-port reference values when present.

Tokens are separated by whitespace and may appear in any order, except that R must be followed by its positive, finite value. Missing parameters default to GHz, S, MA, and R 50. Keep the first occurrence of each parameter and reject unknown tokens. A version 1.1 list after R must finish the option line; its first value supplies R. The complete file parser checks its length against the port count. Strip comments before calling this helper.

Examples

julia> Touchstone.parseoptionline("# MHz Z MA R 75")
Touchstone.TouchstoneOptionLine("MHz", "Z", "MA", 75.0, Float64[])

julia> Touchstone.parseoptionline("# MHz H RI R 75")
Touchstone.TouchstoneOptionLine("MHz", "H", "RI", 75.0, Float64[])

julia> Touchstone.parseoptionline("# R 75 kHz Y")
Touchstone.TouchstoneOptionLine("kHz", "Y", "ma", 75.0, Float64[])
Touchstone.parsereference! — Method
parsereference!(reference::Vector{Float64}, comments::Vector{String},
    line::String, numberofports::Int, io::Union{IO,TouchstoneReader})

Append positive, finite reference impedances in ohms to reference, starting with the lowercased [reference] line line and reading continuation lines from io until there is one value per port. Reject too few or too many values. The caller strips comments from line; comments on continuation lines are appended to comments. Return nothing.

Examples

io = IOBuffer("[Reference] 50.0 60.0 75.0")
numberofports = 3
comments = String[]
reference = Float64[]
line = Touchstone.stripcommentslowercase!(comments,readline(io))
Touchstone.parsereference!(reference, comments, line, numberofports, io)
println(reference)

# output
[50.0, 60.0, 75.0]
io = IOBuffer("[Reference] 50.0 
60.0 75.0")
numberofports = 3
comments = String[]
reference = Float64[]
line = Touchstone.stripcommentslowercase!(comments,readline(io))
Touchstone.parsereference!(reference, comments, line, numberofports, io)
println(reference)

# output
[50.0, 60.0, 75.0]
io = IOBuffer("[Reference] 50.0 
60.0 75.0
[Number of Frequencies] 1")
numberofports = 3
comments = String[]
reference = Float64[]
line = Touchstone.stripcommentslowercase!(comments,readline(io))
Touchstone.parsereference!(reference, comments, line, numberofports, io)
println(reference)

# output
[50.0, 60.0, 75.0]
io = IOBuffer("[Reference] .5 +75")
numberofports = 2
comments = String[]
reference = Float64[]
line = Touchstone.stripcommentslowercase!(comments,readline(io))
Touchstone.parsereference!(reference, comments, line, numberofports, io)
println(reference)

# output
[0.5, 75.0]
Touchstone.parsetwoportdataorder — Method
parsetwoportdataorder(line::String)

Return "12_21" or "21_12" from a [two-port data order] line. Reject other order strings. Strip comments before calling this helper.

Examples

julia> Touchstone.parsetwoportdataorder("[two-port data order] 12_21")
"12_21"

julia> Touchstone.parsetwoportdataorder("[two-port data order] 21_12")
"21_12"
Touchstone.parseversion — Method
parseversion(line::String)

Return the floating-point version value after [version] in line. The complete file parser validates whether the declared version is supported. Strip comments before calling this helper.

Examples

julia> Touchstone.parseversion("[version] 2.0")
2.0
Touchstone.stripcomments! — Method
stripcomments!(comments::Vector{String}, line::String)

Append text after the first ! to comments and return the preceding text, without changing case or stripping whitespace. Decode valid UTF-8 as-is and invalid UTF-8 as Latin-1.

Examples

julia> comments = String[];

julia> Touchstone.stripcomments!(comments, "Model A ! measured at 25 °C")
"Model A "

julia> comments
1-element Vector{String}:
 " measured at 25 °C"
Touchstone.stripcommentslowercase! — Method
stripcommentslowercase!(comments::Vector{String}, line::String)

Append text after the first ! to comments, preserving its case. Return the remaining line in lowercase without stripping whitespace. Decode valid UTF-8 as-is and invalid UTF-8 as Latin-1. See stripcomments! to preserve the case of the returned line.

Examples

julia> comments=String[];println(Touchstone.stripcommentslowercase!(comments,"! This is a comment"));println(comments)

[" This is a comment"]

julia> comments=String[];println(Touchstone.stripcommentslowercase!(comments,"This is a !comment"));println(comments)
this is a
["comment"]

julia> comments=String[];println(Touchstone.stripcommentslowercase!(comments,"! 25 \xb0C"));println(comments)

[" 25 °C"]