Beispiel #1
0
        /// <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();
        }
Beispiel #2
0
 /// <summary>
 /// Enumerates the 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>
 /// <returns>All the network data loaded from the reader.</returns>
 /// <remarks>Unlike <see cref="ReadAllData(TextReader)"/>, this method returns an enumerable sequence of <see cref="FrequencyParametersPair"/> objects which are
 /// loaded into memory one at a time. This is useful when using LINQ queries (such as limiting the number of frequencies to load) or passing the sequence
 /// to a collection to initialize. This avoids creating the whole collection in 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 IEnumerable <FrequencyParametersPair> ReadData(TextReader reader)
 {
     using TouchstoneReader tsReader = TouchstoneReader.Create(reader);
     while (tsReader.Read() is FrequencyParametersPair pair)
     {
         yield return(pair);
     }
 }
        static INetworkParametersCollection FromText(string text)
        {
            StringReader reader = new StringReader(text);

            using (TouchstoneReader tsReader = TouchstoneReader.Create(reader))
            {
                return(tsReader.ReadToEnd());
            }
        }
Beispiel #4
0
        /// <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());
            }
        }
        static TouchstoneReader OpenReaderFromText(string text)
        {
            StringReader reader = new StringReader(text);

            return(TouchstoneReader.Create(reader));
        }
Beispiel #6
0
 /// <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());
 }
Beispiel #7
0
 /// <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());
 }