Represents a timestamp in the COMTRADE file standard format, IEEE Std C37.111-1999..
Ejemplo n.º 1
0
Archivo: Schema.cs Proyecto: rmc00/gsf
        /// <summary>
        /// Creates a new instance of the <see cref="Schema"/> from an existing configuration file name.
        /// </summary>
        /// <param name="fileName">File name of configuration file to parse.</param>
        public Schema(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);
            string[] parts;
            int lineNumber = 0;

            // Parse version line
            parts = lines[lineNumber++].Split(',');

            if (parts.Length != 2 && parts.Length != 3)
                throw new InvalidOperationException(string.Format("Unexpected number of line image elements for first configuration file line: {0} - expected 2 or 3\r\nImage = {1}", parts.Length, lines[0]));

            StationName = parts[0].Trim();
            DeviceID = parts[1].Trim();

            if (parts.Length == 3 && !string.IsNullOrWhiteSpace(parts[2]))
                m_version = int.Parse(parts[2].Trim());
            else
                m_version = 1991;

            // Parse totals line
            parts = lines[lineNumber++].Split(',');

            if (parts.Length != 3)
                throw new InvalidOperationException(string.Format("Unexpected number of line image elements for second configuration file line: {0} - expected 3\r\nImage = {1}", parts.Length, lines[1]));

            int totalChannels = int.Parse(parts[0].Trim());
            int totalAnalogChannels = int.Parse(parts[1].Trim().Split('A')[0]);
            int totalDigitalChannels = int.Parse(parts[2].Trim().Split('D')[0]);

            if (totalChannels != totalAnalogChannels + totalDigitalChannels)
                throw new InvalidOperationException(string.Format("Total defined channels must equal the sum of the total number of analog and digital channel definitions.\r\nImage = {1}", parts.Length, lines[1]));

            // Parse analog definitions
            List<AnalogChannel> analogChannels = new List<AnalogChannel>();

            for (int i = 0; i < totalAnalogChannels; i++)
            {
                analogChannels.Add(new AnalogChannel(lines[lineNumber++]));
            }

            AnalogChannels = analogChannels.ToArray();

            // Parse digital definitions
            List<DigitalChannel> digitalChannels = new List<DigitalChannel>();

            for (int i = 0; i < totalDigitalChannels; i++)
            {
                digitalChannels.Add(new DigitalChannel(lines[lineNumber++]));
            }

            DigitalChannels = digitalChannels.ToArray();

            // Parse line frequency
            NominalFrequency = double.Parse(lines[lineNumber++]);

            // Parse total number of sample rates
            int totalSampleRates = int.Parse(lines[lineNumber++]);

            if (totalSampleRates == 0)
                totalSampleRates = 1;

            // Parse each sample rate
            List<SampleRate> sampleRates = new List<SampleRate>();

            for (int i = 0; i < totalSampleRates; i++)
                sampleRates.Add(new SampleRate(lines[lineNumber++]));

            SampleRates = sampleRates.ToArray();

            // Parse timestamps
            StartTime = new Timestamp(lines[lineNumber++]);
            TriggerTime = new Timestamp(lines[lineNumber++]);

            // Parse file type
            FileType = (FileType)Enum.Parse(typeof(FileType), lines[lineNumber++], true);

            // Parse time factor
            TimeFactor = double.Parse(lines[lineNumber++]);
        }
Ejemplo n.º 2
0
Archivo: Schema.cs Proyecto: xj0229/gsf
        /// <summary>
        /// Creates a new instance of the <see cref="Schema"/> from an existing configuration file name.
        /// </summary>
        /// <param name="fileName">File name of configuration file to parse.</param>
        public Schema(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);
            string[] parts;
            int      lineNumber = 0;

            // Parse version line
            parts = lines[lineNumber++].Split(',');

            if (parts.Length != 2 && parts.Length != 3)
            {
                throw new InvalidOperationException(string.Format("Unexpected number of line image elements for first configuration file line: {0} - expected 2 or 3\r\nImage = {1}", parts.Length, lines[0]));
            }

            StationName = parts[0].Trim();
            DeviceID    = parts[1].Trim();

            if (parts.Length == 3 && !string.IsNullOrWhiteSpace(parts[2]))
            {
                m_version = int.Parse(parts[2].Trim());
            }
            else
            {
                m_version = 1991;
            }

            // Parse totals line
            parts = lines[lineNumber++].Split(',');

            if (parts.Length != 3)
            {
                throw new InvalidOperationException(string.Format("Unexpected number of line image elements for second configuration file line: {0} - expected 3\r\nImage = {1}", parts.Length, lines[1]));
            }

            int totalChannels        = int.Parse(parts[0].Trim());
            int totalAnalogChannels  = int.Parse(parts[1].Trim().Split('A')[0]);
            int totalDigitalChannels = int.Parse(parts[2].Trim().Split('D')[0]);

            if (totalChannels != totalAnalogChannels + totalDigitalChannels)
            {
                throw new InvalidOperationException(string.Format("Total defined channels must equal the sum of the total number of analog and digital channel definitions.\r\nImage = {0}", lines[1]));
            }

            // Parse analog definitions
            List <AnalogChannel> analogChannels = new List <AnalogChannel>();

            for (int i = 0; i < totalAnalogChannels; i++)
            {
                analogChannels.Add(new AnalogChannel(lines[lineNumber++]));
            }

            AnalogChannels = analogChannels.ToArray();

            // Parse digital definitions
            List <DigitalChannel> digitalChannels = new List <DigitalChannel>();

            for (int i = 0; i < totalDigitalChannels; i++)
            {
                digitalChannels.Add(new DigitalChannel(lines[lineNumber++]));
            }

            DigitalChannels = digitalChannels.ToArray();

            // Parse line frequency
            NominalFrequency = double.Parse(lines[lineNumber++]);

            // Parse total number of sample rates
            int totalSampleRates = int.Parse(lines[lineNumber++]);

            if (totalSampleRates == 0)
            {
                totalSampleRates = 1;
            }

            // Parse each sample rate
            List <SampleRate> sampleRates = new List <SampleRate>();

            for (int i = 0; i < totalSampleRates; i++)
            {
                sampleRates.Add(new SampleRate(lines[lineNumber++]));
            }

            SampleRates = sampleRates.ToArray();

            // Parse timestamps
            StartTime   = new Timestamp(lines[lineNumber++]);
            TriggerTime = new Timestamp(lines[lineNumber++]);

            // Parse file type
            FileType = (FileType)Enum.Parse(typeof(FileType), lines[lineNumber++], true);

            // Parse time factor
            TimeFactor = (lines.Length < lineNumber ? double.Parse(lines[lineNumber]) : 1);
        }