touchstone
Touchstone (SNP) parser for RF Engineering - Full N-Port Support
Parse, analyze, and manipulate Touchstone files with any number of ports (1-port, 2-port, 3-port, 4-port, and beyond).
Installation
This installs an executable in your .cargo/bin directory (.cargo/bin/touchstone).
Features
Full N-Port Support
- Parse any N-port file: .s1p, .s2p, .s3p, .s4p, and beyond (tested up to 32-port)
- Auto-format detection: Automatically handles single-line (1-2 port) and multi-line (3+ port) formats
- Save N-port files: Write networks back to disk with automatic format selection
- All data formats: RI (Real-Imaginary), MA (Magnitude-Angle), DB (Decibel-Angle)
- All frequency units: Hz, kHz, MHz, GHz, THz
- Any reference impedance: 50Ω, 75Ω, or custom values
Network Operations
- Cascade 2-port networks: Combine networks with ABCD parameter method
- Access S-parameters: Extract any Sij parameter in any format
- Interactive plotting: Generate standalone HTML plots for visualization
- Batch processing: Process entire directories of Touchstone files
Production Ready
- 94 comprehensive tests with 100% pass rate
- Zero regressions - All original functionality preserved
- Well-documented - Extensive inline documentation and examples
- Robust error handling - Clear, actionable error messages
Usage
The touchstone executable can be run with a file path as an argument or a directory path as an argument.
Help
Outputs:
)
)
) )
)
# Single file - 2-port (Relative path)
# Single file - 3-port
# Single file - 4-port
# Directory (Plot all files in folder)
# Cascade two 2-port networks
# Cascade with custom output name
# Bare filename
# Windows absolute path
# Windows UNC path (network path)
# Unix absolute path
File Path
which outputs:
============================
)
This works on Windows, MacOS, and Linux file systems!
- MacOS:
file:///Users/iancleary/touchstone/files/ntwk3.s2p.html - Windows:
file:///C:/Users/iancleary/touchstone/files/ntwk3.s2p.html - Linux:
file:///home/iancleary/touchstone/files/ntwk3.s2p.html
This command created an html file that is interactive, and designed to not have any network dependence.
You can view the HTML source file itself here directly: examples/ntwk3.s2p.html.
Note that the crate's execution templates in the data parsed from the touchstone file's network object. So this example will only match for the files/ntwk3.s2p data.
Directory Path
which outputs:
============================
This command created an html file that is interactive, and designed to not have any network dependence.
You can view the HTML source file itself here directly: examples/combined_plot.html.
Note that the crate's execution templates in the data parsed from the touchstone file's network object. So this example will only match for the files/ntwk1.s2p, files/ntwk2.s2p, and files/ntwk3.s2p data.
Library Usage
The touchstone crate can also be used as a library in your Rust projects:
use Network;
// Load any N-port network
let network = new;
// Access metadata
println!;
println!;
println!;
// Access S-parameters (1-indexed)
let s11_db = network.s_db; // S11 in dB format
let s21_ri = network.s_ri; // S21 in Real-Imaginary format
let s32_ma = network.s_ma; // S32 in Magnitude-Angle format
// Save network (auto-selects single-line or multi-line format)
network.save.unwrap;
// Cascade 2-port networks
let net1 = new;
let net2 = new;
// Standard cascade (port 2 → port 1)
let cascaded = net1.cascade;
// Cascade with port specification
let cascaded = net1.cascade_ports;
Supported File Types
.s1p- 1-port networks (e.g., terminations, loads).s2p- 2-port networks (e.g., amplifiers, filters, cables).s3p- 3-port networks (e.g., power dividers, circulators).s4p- 4-port networks (e.g., differential pairs, couplers).sNp- Any N-port network (tested up to 32-port)
Data Formats
All three Touchstone data formats are fully supported:
- RI (Real-Imaginary) - Cartesian coordinates
- MA (Magnitude-Angle) - Polar coordinates with angle in degrees
- DB (Decibel-Angle) - Magnitude in dB, angle in degrees
Frequency Units
All Touchstone frequency units are supported with automatic conversion:
- Hz - Hertz
- kHz - Kilohertz
- MHz - Megahertz
- GHz - Gigahertz
- THz - Terahertz
Recent Updates
Full N-Port Support (v0.10.4)
The library has been completely refactored to support N-port networks:
What's New:
- ✅ Parse any N-port Touchstone file (1 to 32+ ports tested)
- ✅ Auto-detect single-line vs multi-line format
- ✅ Save N-port networks with automatic format selection
- ✅ Access any S-parameter for any port combination
- ✅ 94 comprehensive tests with 100% pass rate
- ✅ Zero regressions - all original 2-port functionality preserved
Technical Improvements:
- Refactored matrix structures from hardcoded 2×2 to dynamic N×N
- Value-based multi-line segment detection
- Robust error handling with helpful messages
- Comprehensive test coverage for 1, 2, 3, 4, and higher-port files
Backwards Compatibility:
- All existing 2-port APIs remain unchanged
- Existing code will continue to work without modifications
- Enhanced with new capabilities for N-port support
- Plotting for 1-port and 2-port networks only
- Plotting a directory of networks is supported, but only currently if the networks are all 2-port networks (haven't tested mixed rank in a directory).

