Class TouchstoneParser
- Namespace
- Touchstone.Parser.Parsing
- Assembly
- Touchstone.Parser.dll
Parses Touchstone (.sNp) files into strongly typed TouchstoneData objects. Supports Touchstone v1.0/v1.1 format for 1-port through N-port networks.
public static class TouchstoneParser
- Inheritance
-
TouchstoneParser
- Inherited Members
Remarks
The parser handles all three data formats (RI, MA, DB), all frequency units (Hz, kHz, MHz, GHz), and all parameter types (S, Y, Z, H, G).
All frequency values are normalized to Hertz and all parameter values are normalized to real/imaginary representation internally.
Methods
DetectPortCount(string)
Detects the number of ports from the file extension.
public static int DetectPortCount(string fileName)
Parameters
fileNamestringThe file name (e.g., "filter.s2p").
Returns
- int
The number of ports, or 0 if it cannot be determined.
Parse(Stream, string?)
Parses a Touchstone file from a stream.
public static TouchstoneData Parse(Stream stream, string? fileName = null)
Parameters
streamStreamThe stream containing the Touchstone data.
fileNamestringOptional file name for port count detection and metadata.
Returns
- TouchstoneData
A TouchstoneData instance containing the parsed data.
Exceptions
- TouchstoneParserException
Thrown when the content is invalid.
Parse(TextReader, string?)
Parses Touchstone data from a TextReader.
public static TouchstoneData Parse(TextReader reader, string? fileName = null)
Parameters
readerTextReaderThe text reader providing the Touchstone data.
fileNamestringOptional file name for port count detection and metadata.
Returns
- TouchstoneData
A TouchstoneData instance containing the parsed data.
Exceptions
- TouchstoneParserException
Thrown when the content is invalid.
Parse(string)
Parses a Touchstone file from the specified file path.
public static TouchstoneData Parse(string filePath)
Parameters
filePathstringThe path to the .sNp file.
Returns
- TouchstoneData
A TouchstoneData instance containing the parsed data.
Exceptions
- FileNotFoundException
Thrown when the file does not exist.
- TouchstoneParserException
Thrown when the file content is invalid.
ParseAsync(string, CancellationToken)
Asynchronously parses a Touchstone file from the specified file path.
public static Task<TouchstoneData> ParseAsync(string filePath, CancellationToken cancellationToken = default)
Parameters
filePathstringThe path to the .sNp file.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<TouchstoneData>
A TouchstoneData instance containing the parsed data.
ParseString(string, string?)
Parses Touchstone data from a raw string.
public static TouchstoneData ParseString(string content, string? fileName = null)
Parameters
contentstringThe Touchstone file content as a string.
fileNamestringOptional file name for port count detection and metadata.
Returns
- TouchstoneData
A TouchstoneData instance containing the parsed data.