/// <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(); }
static INetworkParametersCollection FromText(string text) { StringReader reader = new StringReader(text); using (TouchstoneReader tsReader = TouchstoneReader.Create(reader)) { return(tsReader.ReadToEnd()); } }
/// <summary> /// Reads all frequency-dependent network parameter data of type <typeparamref name="T"/> from the specified <see cref="TextReader"/>. A <see cref="InvalidCastException"/> will be /// thrown if the Touchstone options line indicates a different type of data in the file than the requested type. /// </summary> /// <param name="reader">The <see cref="TextReader"/> to read network data from.</param> /// <remarks>Unlike <see cref="ReadData(TextReader)"/>, this method returns a <see cref="NetworkParametersCollection{TMatrix}"/> with all of the /// network data loaded into memory.</remarks> /// <exception cref="ArgumentNullException"><paramref name="reader"/> is null.</exception> /// <exception cref="InvalidDataException">Invalid data or format in <paramref name="reader"/>.</exception> /// <exception cref="InvalidCastException">Data in file is not <typeparamref name="T"/></exception> public static NetworkParametersCollection <T> ReadAllData <T>(TextReader reader) where T : NetworkParametersMatrix { using TouchstoneReader tsReader = TouchstoneReader.Create(reader); Type fileParamType = tsReader.Options.Parameter.ToNetworkParameterMatrixType(); if (fileParamType != typeof(T)) { throw new InvalidCastException($"The specified Touchstone file contains parameter data of type {fileParamType.Name} which does not match the expected type " + $"{typeof(T).Name}"); } else { return((NetworkParametersCollection <T>)tsReader.ReadToEnd()); } }
/// <summary> /// Reads all frequency-dependent network parameter data from the specified <see cref="TextReader"/>. /// </summary> /// <param name="reader">The <see cref="TextReader"/> to read network data from.</param> /// <remarks>Unlike <see cref="ReadData(TextReader)"/>, this method returns a <see cref="INetworkParametersCollection"/> with all of the /// network data loaded into memory.</remarks> /// <exception cref="ArgumentNullException"><paramref name="reader"/> is null.</exception> /// <exception cref="InvalidDataException">Invalid data or format in <paramref name="reader"/>.</exception> public static INetworkParametersCollection ReadAllData(TextReader reader) { using TouchstoneReader tsReader = TouchstoneReader.Create(reader); return(tsReader.ReadToEnd()); }
/// <summary> /// Reads all frequency-dependent network parameter data from the specified file. /// </summary> /// <param name="filePath">The Touchstone file to read data from.</param> /// <returns>All the network data loaded from the file.</returns> /// <remarks>Unlike <see cref="ReadData(string)"/>, this method returns a <see cref="INetworkParametersCollection"/> with all of the /// network data loaded into memory.</remarks> /// <exception cref="ArgumentNullException"><paramref name="filePath"/> is null.</exception> /// <exception cref="FileNotFoundException"><paramref name="filePath"/> is not found.</exception> /// <exception cref="InvalidDataException">Invalid data or format in <paramref name="filePath"/>.</exception> public static INetworkParametersCollection ReadAllData(string filePath) { using TouchstoneReader tsReader = TouchstoneReader.Create(filePath); return(tsReader.ReadToEnd()); }