public void TestReadFourPort() { INetworkParametersCollection coll = default; FluentActions.Invoking(() => coll = FromText(SampleFiles.FourPort_v1)).Should().NotThrow(); coll.NumberOfPorts.Should().Be(4); }
/// <summary> /// Reads all remaining available network data from the Touchstone file from the current point. /// </summary> /// <returns>A <see cref="INetworkParametersCollection"/> containing each pair of frequency and <see cref="NetworkParametersMatrix"/> objects, /// or null if no more data is available.</returns> /// <exception cref="InvalidDataException">Data or format in file is bad.</exception> /// <exception cref="ObjectDisposedException">Reader has been disposed.</exception> public INetworkParametersCollection ReadToEnd() { if (!disposedValue) { INetworkParametersCollection collection = null; // Read returns a nullable FrequencyParametersPair object; in this statement, // we use is to validate that it isn't null and break into its parts in a single step. while (Read() is (double frequency, NetworkParametersMatrix matrix)) { if (collection == null) { int numPorts = matrix.NumPorts; collection = Options.Parameter switch { ParameterType.Scattering => new NetworkParametersCollection <ScatteringParametersMatrix>(numPorts), _ => throw new NotImplementedException(), }; } collection[frequency] = matrix; } return(collection); } else { throw new ObjectDisposedException(nameof(TouchstoneReader)); } }
/// <summary> /// Creates a new <see cref="Touchstone"/> object by parsing the options, keywords, and network data contained within the specified file. /// </summary> /// <param name="filePath">The Touchstone (*.snp) file to be loaded.</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="FileNotFoundException"></exception> /// <exception cref="InvalidDataException"></exception> public Touchstone(string filePath) { using TouchstoneReader reader = TouchstoneReader.Create(filePath); Options = reader.Options; Keywords = reader.Keywords; NetworkParameters = reader.ReadToEnd(); }
/// <summary>Creates a new empty <see cref="Touchstone"/> with a the specified ports and options.</summary> /// <param name="numPorts">The number of ports of the device that the Touchstone file will represent.</param> /// <param name="opts">The <see cref="TouchstoneOptions"/> that will define the format of the resulting file.</param> public Touchstone(int numPorts, TouchstoneOptions opts) { NetworkParameters = opts.Parameter switch { ParameterType.Scattering => new NetworkParametersCollection <ScatteringParametersMatrix>(numPorts), _ => throw new NotImplementedException() }; Options = opts; }
/// <summary> /// Cascades (embeds) the <see cref="NetworkParametersMatrix"/> objects for all common frequencies between subsequently connected ports to render a single composite /// <see cref="NetworkParametersCollection{TMatrix}"/> defining the relationship between the ports of the first device and the ports of the second device. /// </summary> /// <param name="next">The <see cref="NetworkParametersCollection{TMatrix}"/> to cascade with the current collection.</param> /// <returns>A new composite <see cref="NetworkParametersCollection{TMatrix}"/> describing the network from the ports of the first device to the ports of the second device across frequency.</returns> public NetworkParametersCollection <TMatrix> Cascade(INetworkParametersCollection next) { return(Cascade <TMatrix>(this, next)); }
/// <summary>Creates a new Touchstone file from an existing <see cref="INetworkParametersCollection"/> with default settings.</summary> /// <param name="parameters">Specifies the network data that will comprise this Touchstone file.</param> public Touchstone(INetworkParametersCollection parameters) { NetworkParameters = parameters; Keywords.NumberOfPorts = parameters.NumberOfPorts; }