ReadNext() 공개 메소드

Reads next EMAX record.
public ReadNext ( ) : bool
리턴 bool
예제 #1
0
        /// <summary>
        /// Reads next EMAX record.
        /// </summary>
        /// <returns><c>true</c> if read succeeded; otherwise <c>false</c> if end of data set was reached.</returns>
        public bool ReadNext()
        {
            double frequency;
            double diff;
            int    halfCycles;

            if (m_parser.ReadNext())
            {
                // Calculate the timestamp
                m_calculatedTimestamp = m_currentSecond.AddTicks(m_subsecondDistribution[m_currentIndex]);

                if (!m_parser.TimeError)
                {
                    // Correct the values
                    frequency  = m_parser.ControlFile.SystemParameters.frequency;
                    diff       = Math.Abs(m_calculatedTimestamp.Subtract(m_parser.Timestamp).TotalSeconds);
                    halfCycles = (int)Math.Round(diff * frequency * 2.0D);

                    if (halfCycles % 2 == 0)
                    {
                        Array.Copy(Values, m_correctedValues, m_correctedValues.Length);
                    }
                    else
                    {
                        Values.Select(v => - v).ToList().CopyTo(m_correctedValues);
                    }
                }
                else
                {
                    // We can't determine whether the values need correction
                    // without a proper timestamp from the underlying parser
                    Array.Copy(Values, m_correctedValues, m_correctedValues.Length);
                }

                // Move to the next subsecond in the distribution
                m_currentIndex++;

                if (m_currentIndex == m_subsecondDistribution.Length)
                {
                    // If we reach the end of the subsecond distribution,
                    // add one to currentSecond and reset the currentIndex to zero
                    m_currentSecond = m_currentSecond.AddSeconds(1.0D);
                    m_currentIndex  = 0;
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Opens all EMAX data file streams.
        /// </summary>
        public void OpenFiles()
        {
            long previousMilliseconds;
            long milliseconds;
            int  count;

            int sampleRate;
            int distributionIndex;

            m_parser.OpenFiles();

            sampleRate = m_parser.ControlFile.SystemParameters.samples_per_second;
            m_subsecondDistribution = Ticks.SubsecondDistribution(sampleRate);

            using (Parser parser = new Parser())
            {
                parser.ControlFile = m_parser.ControlFile;
                parser.FileName    = m_parser.FileName;

                // Open EMAX data file
                parser.OpenFiles();

                m_currentSecond      = DateTime.MinValue;
                previousMilliseconds = -1;
                milliseconds         = 0;
                count = 0;

                while (parser.ReadNext())
                {
                    // Set currentSecond to this frame's timestamp
                    m_currentSecond = parser.Timestamp;

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // If the milliseconds are exactly one millisecond greater than the previous
                    // timestamp's milliseconds, we can accurately find the timestamp of this frame
                    if (previousMilliseconds > 0 && milliseconds - previousMilliseconds == 1)
                    {
                        break;
                    }

                    // Update previousMilliseconds and count
                    previousMilliseconds = milliseconds;
                    count++;
                }

                // Remove subseconds from currentSecond
                m_currentSecond = m_currentSecond.AddTicks(-(m_currentSecond.Ticks % Ticks.PerSecond));

                // Get the milliseconds since the top of the second
                milliseconds %= 1000;

                // This should get very near to the index of the
                // desired value in the subsecond distribution
                distributionIndex = ((int)milliseconds * sampleRate) / 1000;

                // Scan forward in the subsecond distribution until we are sure we've found the correct index
                while ((long)m_subsecondDistribution[distributionIndex].ToMilliseconds() != milliseconds)
                {
                    distributionIndex++;
                }

                // Set currentIndex to the index in the distribution of the first timestamp in this file
                m_currentIndex = distributionIndex - count;

                // Subtract seconds from currentSecond and add the equivalent number of indexes
                // to currentIndex until currentIndex is greater than or equal to zero
                while (m_currentIndex < 0)
                {
                    m_currentSecond = m_currentSecond.AddSeconds(-1.0D);
                    m_currentIndex += sampleRate;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Opens all EMAX data file streams.
        /// </summary>
        public void OpenFiles()
        {
            long previousMilliseconds;
            long milliseconds;
            int count;

            int sampleRate;
            int distributionIndex;

            m_parser.OpenFiles();

            sampleRate = m_parser.ControlFile.SystemParameters.samples_per_second;
            m_subsecondDistribution = Ticks.SubsecondDistribution(sampleRate);

            using (Parser parser = new Parser())
            {
                parser.ControlFile = m_parser.ControlFile;
                parser.FileName = m_parser.FileName;

                // Open EMAX data file
                parser.OpenFiles();

                m_currentSecond = DateTime.MinValue;
                previousMilliseconds = -1;
                milliseconds = 0;
                count = 0;

                while (parser.ReadNext())
                {
                    // Set currentSecond to this frame's timestamp
                    m_currentSecond = parser.Timestamp;

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // If the milliseconds are exactly one millisecond greater than the previous
                    // timestamp's milliseconds, we can accurately find the timestamp of this frame
                    if (previousMilliseconds > 0 && milliseconds - previousMilliseconds == 1)
                        break;

                    // Update previousMilliseconds and count
                    previousMilliseconds = milliseconds;
                    count++;
                }

                // Remove subseconds from currentSecond
                m_currentSecond = m_currentSecond.AddTicks(-(m_currentSecond.Ticks % Ticks.PerSecond));

                // Get the milliseconds since the top of the second
                milliseconds %= 1000;

                // This should get very near to the index of the
                // desired value in the subsecond distribution
                distributionIndex = ((int)milliseconds * sampleRate) / 1000;

                // Scan forward in the subsecond distribution until we are sure we've found the correct index
                while ((long)m_subsecondDistribution[distributionIndex].ToMilliseconds() != milliseconds)
                    distributionIndex++;

                // Set currentIndex to the index in the distribution of the first timestamp in this file
                m_currentIndex = distributionIndex - count;

                // Subtract seconds from currentSecond and add the equivalent number of indexes
                // to currentIndex until currentIndex is greater than or equal to zero
                while (m_currentIndex < 0)
                {
                    m_currentSecond = m_currentSecond.AddSeconds(-1.0D);
                    m_currentIndex += sampleRate;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Opens all EMAX data file streams.
        /// </summary>
        public void OpenFiles()
        {
            long previousMilliseconds;
            long milliseconds;
            int  count;

            int sampleRate;
            int distributionIndex;

            m_parser.OpenFiles();

            sampleRate = m_parser.ControlFile.SystemParameters.samples_per_second;
            m_subsecondDistribution = Ticks.SubsecondDistribution(sampleRate);

            using (Parser parser = new Parser())
            {
                parser.ControlFile = m_parser.ControlFile;
                parser.FileName    = m_parser.FileName;

                // Open EMAX data file
                parser.OpenFiles();

                m_currentSecond      = DateTime.MinValue;
                previousMilliseconds = -1;
                milliseconds         = 0;
                count = 0;

                while (parser.ReadNext())
                {
                    if (parser.TimeError)
                    {
                        continue;
                    }

                    // Set currentSecond to this frame's timestamp
                    m_currentSecond = parser.Timestamp;

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // If the milliseconds are exactly one millisecond greater than the previous
                    // timestamp's milliseconds, we can accurately find the timestamp of this frame
                    if (previousMilliseconds > 0 && milliseconds - previousMilliseconds == 1)
                    {
                        break;
                    }

                    // Update previousMilliseconds and count
                    previousMilliseconds = milliseconds;
                    count++;
                }

                if (m_currentSecond == DateTime.MinValue)
                {
                    // If there was an error reading the timestamps in the parser,
                    // calculate the timestamp from the data in the control file
                    TimeZoneInfo tzInfo             = parser.ControlFile.SystemParameters.GetTimeZoneInfo();
                    DateTime     faultTime          = parser.ControlFile.SystemParameters.FaultTime;
                    string       daylightName       = parser.ControlFile.SystemParameters.time_zone_information.DaylightName;
                    short        faultMilliseconds  = parser.ControlFile.SystemParameters.mS_time;
                    short        prefaultSamples    = parser.ControlFile.SystemParameters.prefault_samples;
                    short        startOffsetSamples = parser.ControlFile.SystemParameters.start_offset_samples;

                    // Set currentSecond to the timestamp of the first frame
                    m_currentSecond = faultTime.AddMilliseconds(faultMilliseconds).AddSeconds(-(prefaultSamples + startOffsetSamples) / (double)sampleRate);

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // Timestamps in the control file are stored in UTC (or close to it),
                    // but it seems that sometimes EMAX adjusts timestamps without applying DST
                    // rules so we use the DaylightName of the time zone info as a sanity check
                    // and fall back on the BaseUtcOffset property in these weird cases
                    if (daylightName == tzInfo.DaylightName || daylightName != tzInfo.Id)
                    {
                        m_currentSecond = TimeZoneInfo.ConvertTimeFromUtc(m_currentSecond, tzInfo);
                    }
                    else
                    {
                        m_currentSecond += tzInfo.BaseUtcOffset;
                    }

                    m_currentSecond = DateTime.SpecifyKind(m_currentSecond, DateTimeKind.Unspecified);
                }

                // Remove subseconds from currentSecond
                m_currentSecond = m_currentSecond.AddTicks(-(m_currentSecond.Ticks % Ticks.PerSecond));

                // Get the milliseconds since the top of the second
                milliseconds %= 1000;

                // This should get very near to the index of the
                // desired value in the subsecond distribution
                distributionIndex = ((int)milliseconds * sampleRate) / 1000;

                // Scan forward in the subsecond distribution until we are sure we've found the correct index
                while ((long)m_subsecondDistribution[distributionIndex].ToMilliseconds() != milliseconds)
                {
                    distributionIndex++;
                }

                // Set currentIndex to the index in the distribution of the first timestamp in this file
                m_currentIndex = distributionIndex - count;

                // Subtract seconds from currentSecond and add the equivalent number of indexes
                // to currentIndex until currentIndex is greater than or equal to zero
                while (m_currentIndex < 0)
                {
                    m_currentSecond = m_currentSecond.AddSeconds(-1.0D);
                    m_currentIndex += sampleRate;
                }
            }
        }
        /// <summary>
        /// Opens all EMAX data file streams.
        /// </summary>
        public void OpenFiles()
        {
            long previousMilliseconds;
            long milliseconds;
            int count;

            int sampleRate;
            int distributionIndex;

            m_parser.OpenFiles();

            sampleRate = m_parser.ControlFile.SystemParameters.samples_per_second;
            m_subsecondDistribution = Ticks.SubsecondDistribution(sampleRate);

            using (Parser parser = new Parser())
            {
                parser.ControlFile = m_parser.ControlFile;
                parser.FileName = m_parser.FileName;

                // Open EMAX data file
                parser.OpenFiles();

                m_currentSecond = DateTime.MinValue;
                previousMilliseconds = -1;
                milliseconds = 0;
                count = 0;

                while (parser.ReadNext())
                {
                    if (parser.TimeError)
                        continue;

                    // Set currentSecond to this frame's timestamp
                    m_currentSecond = parser.Timestamp;

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // If the milliseconds are exactly one millisecond greater than the previous
                    // timestamp's milliseconds, we can accurately find the timestamp of this frame
                    if (previousMilliseconds > 0 && milliseconds - previousMilliseconds == 1)
                        break;

                    // Update previousMilliseconds and count
                    previousMilliseconds = milliseconds;
                    count++;
                }

                if (m_currentSecond == DateTime.MinValue)
                {
                    // If there was an error reading the timestamps in the parser,
                    // calculate the timestamp from the data in the control file
                    TimeZoneInfo tzInfo = parser.ControlFile.SystemParameters.GetTimeZoneInfo();
                    DateTime faultTime = parser.ControlFile.SystemParameters.FaultTime;
                    string daylightName = parser.ControlFile.SystemParameters.time_zone_information.DaylightName;
                    short faultMilliseconds = parser.ControlFile.SystemParameters.mS_time;
                    short prefaultSamples = parser.ControlFile.SystemParameters.prefault_samples;
                    short startOffsetSamples = parser.ControlFile.SystemParameters.start_offset_samples;

                    // Set currentSecond to the timestamp of the first frame
                    m_currentSecond = faultTime.AddMilliseconds(faultMilliseconds).AddSeconds(-(prefaultSamples + startOffsetSamples) / (double)sampleRate);

                    // Get total milliseconds since epoch
                    milliseconds = m_currentSecond.Ticks / Ticks.PerMillisecond;

                    // Timestamps in the control file are stored in UTC (or close to it),
                    // but it seems that sometimes EMAX adjusts timestamps without applying DST
                    // rules so we use the DaylightName of the time zone info as a sanity check
                    // and fall back on the BaseUtcOffset property in these weird cases
                    if (daylightName == tzInfo.DaylightName || daylightName != tzInfo.Id)
                        m_currentSecond = TimeZoneInfo.ConvertTimeFromUtc(m_currentSecond, tzInfo);
                    else
                        m_currentSecond += tzInfo.BaseUtcOffset;

                    m_currentSecond = DateTime.SpecifyKind(m_currentSecond, DateTimeKind.Unspecified);
                }

                // Remove subseconds from currentSecond
                m_currentSecond = m_currentSecond.AddTicks(-(m_currentSecond.Ticks % Ticks.PerSecond));

                // Get the milliseconds since the top of the second
                milliseconds %= 1000;

                // This should get very near to the index of the
                // desired value in the subsecond distribution
                distributionIndex = ((int)milliseconds * sampleRate) / 1000;

                // Scan forward in the subsecond distribution until we are sure we've found the correct index
                while ((long)m_subsecondDistribution[distributionIndex].ToMilliseconds() != milliseconds)
                    distributionIndex++;

                // Set currentIndex to the index in the distribution of the first timestamp in this file
                m_currentIndex = distributionIndex - count;

                // Subtract seconds from currentSecond and add the equivalent number of indexes
                // to currentIndex until currentIndex is greater than or equal to zero
                while (m_currentIndex < 0)
                {
                    m_currentSecond = m_currentSecond.AddSeconds(-1.0D);
                    m_currentIndex += sampleRate;
                }
            }
        }