Exemple #1
0
        /// <summary>
        /// Return the sample value of the channel given as argument at the sample index given as argument
        /// </summary>
        /// <param name="ChannelName">Name of the channel to search</param>
        /// <param name="SampleIndex">Index of sample</param>
        /// <returns>Channel value at the sample index</returns>
        /// <remarks>Return NaN if the channel is not found or if the sample index doesn't exist</remarks>
        public double Get_ChannelValueAtIndex(string ChannelName, int SampleIndex)
        {
            GW_DataChannel oChan = Get_DataChannel(ChannelName);

            if (!(oChan == null))
            {
                switch (DataSamplingMode)
                {
                case SamplingMode.SingleRate:

                    if (SampleIndex >= 0 && SampleIndex < oChan.Values.Count)
                    {
                        return(oChan.Values[SampleIndex]);
                    }

                    break;

                case SamplingMode.MultipleRates:

                    if (SampleIndex >= 0 && SampleIndex < oChan.Samples.Count)
                    {
                        return(oChan.Samples[SampleIndex].SampleValue);
                    }

                    break;
                }
            }

            return(double.NaN);
        }
Exemple #2
0
        /// <summary>
        /// Return the sample value of the channel given as argument at the time value given as argument
        /// </summary>
        /// <param name="ChannelName">Name of the channel to search</param>
        /// <param name="TimeValue">Time value to search</param>
        /// <returns>Channel value at the time</returns>
        /// <remarks>Return NaN if the channel is not found or if the time value doesn't exist</remarks>
        public double Get_ChannelValueAtTime(string ChannelName, double TimeValue)
        {
            GW_DataChannel oChan = Get_DataChannel(ChannelName);

            if (!(oChan == null))
            {
                switch (DataSamplingMode)
                {
                case SamplingMode.SingleRate:

                {
                    int TimeIndex = Get_SampleIndexAtTime(TimeValue);

                    if (TimeIndex >= 0 && TimeIndex < oChan.Values.Count)
                    {
                        return(oChan.Values[TimeIndex]);
                    }
                }

                break;

                case SamplingMode.MultipleRates:

                {
                    for (int iTime = 0; iTime < oChan.Samples.Count; iTime++)
                    {
                        if (oChan.Samples[iTime].SampleTime > TimeValue)
                        {
                            if (!(iTime == 0))
                            {
                                return(oChan.Samples[iTime - 1].SampleValue);
                            }
                        }
                    }
                }

                break;
                }
            }

            return(double.NaN);
        }
Exemple #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public GW_DataFile()
        {
            DataSamplingMode = SamplingMode.SingleRate;

            Time = new GW_DataChannel("Time");
            Time.ParentDataFile = this;

            Channels       = new GW_DataChannelList(this);
            TimeBufferSize = -1;

            StepTimeMin = 0;
            StepTimeMax = 0;

            CoordConversionUpdateRequested = false;

            //XML Data file default properties
            DataStartTime = DateTime.Now;
            UserComment   = "";
            XmlDataFileCustomProperties = new List <GW_XmlDataFileCustomProperty>();
        }
Exemple #4
0
        /// <summary>
        /// Read a data file
        /// </summary>
        /// <param name="fPath">Path of the file to read</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        /// <remarks>
        /// CSV file type: comma separtor ';'
        /// </remarks>
        public bool Load_DataFile(string fPath)
        {
            if (fPath == null)
            {
                return(false);
            }

            bool         bFirstLine = true;
            StreamReader SR         = new StreamReader(fPath);

            while (!SR.EndOfStream)
            {
                string   Line      = SR.ReadLine();
                string[] Data      = Line.Split(';');
                bool     bFirstVal = true;

                if (bFirstLine)
                {
                    bFirstLine = false;

                    for (int i = 0; i < Data.Length; i++)
                    {
                        if (!(Data[i].Equals("")))
                        {
                            if (!bFirstVal)
                            {
                                GW_DataChannel oChan = new GW_DataChannel(Data[i]);
                                Channels.Add(oChan);
                            }
                            else
                            {
                                bFirstVal = false; //First value is time
                            }
                        }
                    }
                }
                else
                {
                    int ValCnt = 0;

                    for (int i = 0; i < Data.Length; i++)
                    {
                        if (!(Data[i].Equals("")))
                        {
                            double Val = 0;
                            if (double.TryParse(Data[i], out Val))
                            {
                                if (!bFirstVal) //Data value
                                {
                                    Channels[i - 1].Add_ChannelValue(Val);
                                    ValCnt++;
                                }
                                else //Time value
                                {
                                    Time.Add_ChannelValue(Val);
                                    bFirstVal = false;

                                    if (Time.Values.Count > 1)
                                    {
                                        double StepTime = Val - Time.Values[Time.Values.Count - 2];

                                        if (Time.Values.Count == 2)
                                        {
                                            StepTimeMin = StepTime;
                                            StepTimeMax = StepTime;
                                        }
                                        else
                                        {
                                            if (StepTime < StepTimeMin)
                                            {
                                                StepTimeMin = StepTime;
                                            }
                                            if (StepTime > StepTimeMax)
                                            {
                                                StepTimeMax = StepTime;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                return(false);  //Not a number
                            }
                        }
                    }

                    //Missing data ?
                    if (!(ValCnt == Channels.Count))
                    {
                        return(false);  //Missing value
                    }
                }
            }

            SR.Close();
            SR = null;
            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Read a XML data file
        /// </summary>
        /// <param name="fPath">Path of the XML file to read</param>
        /// <param name="HeaderOnly">Read only data file header flag</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        public bool Load_XmlDataFile(string fPath, bool HeaderOnly)
        {
            XmlNode xDataFile, xHeader, xChannels, xSamples;
            XmlNode xElemParent, xElemChild;

            this.DataSamplingMode = SamplingMode.MultipleRates;

            try
            {
                XmlDocument oXDoc = new XmlDocument();
                oXDoc.Load(fPath);

                xDataFile = oXDoc.SelectSingleNode("XmlGraphDataFile");

                #region XML Data file header

                //Header reading
                xHeader = xDataFile.SelectSingleNode("DataFileHeader");

                //Data file start time
                xElemChild         = xHeader.SelectSingleNode("DataStartTime");
                this.DataStartTime = DateTime.FromBinary(long.Parse(xElemChild.InnerText));

                //User comment
                xElemChild       = xHeader.SelectSingleNode("DataUserComment");
                this.UserComment = xElemChild.InnerText;

                //Data file user properties
                xElemParent = xHeader.SelectSingleNode("DataCustomProperties");

                foreach (XmlNode xProp in xElemParent.ChildNodes)
                {
                    GW_XmlDataFileCustomProperty oProp = new GW_XmlDataFileCustomProperty();

                    oProp.Name = xProp.Attributes["CustomPropertyName"].Value;

                    string PropType = xProp.Attributes["CustomPropertyType"].Value;
                    oProp.ParsePropertyStringValue(xProp.InnerText, PropType);

                    this.XmlDataFileCustomProperties.Add(oProp);
                }

                #endregion

                #region XML Data files channels

                //Data reading
                if (!HeaderOnly)
                {
                    xChannels = xDataFile.SelectSingleNode("DataFileChannels");

                    foreach (XmlNode xChan in xChannels.ChildNodes)
                    {
                        GW_DataChannel oChan = new GW_DataChannel(SamplingMode.MultipleRates);

                        //Read channel properties
                        oChan.KeyId = int.Parse(xChan.Attributes["ChanId"].Value);

                        xElemChild = xChan.SelectSingleNode("ChannelName");
                        oChan.Name = xElemChild.InnerText;

                        xElemChild        = xChan.SelectSingleNode("ChannelDescription");
                        oChan.Description = xElemChild.InnerText;

                        xElemChild = xChan.SelectSingleNode("ChannelUnit");
                        oChan.Unit = xElemChild.InnerText;

                        xElemChild = xChan.SelectSingleNode("ValueFormat");
                        oChan.GraphicFormat.SetSerieValueFormatFromXmlNode(xElemChild);

                        xElemParent = xChan.SelectSingleNode("ChannelReferenceLines");

                        if (!(xElemParent == null))
                        {
                            foreach (XmlNode xRefLine in xElemParent.ChildNodes)
                            {
                                GraphReferenceLine oLine = new GraphReferenceLine();

                                if (oLine.Read_GraphLineXmlNode(xRefLine))
                                {
                                    oChan.ChannelReferenceLines.Add(oLine);
                                }
                            }
                        }

                        //Read channel samples
                        xSamples = xChan.SelectSingleNode("ChannelSamples");

                        foreach (XmlNode xSerieSample in xSamples.ChildNodes)
                        {
                            SerieSample sSample = new SerieSample();

                            sSample.SampleTime  = double.Parse(xSerieSample.Attributes["ST"].Value);
                            sSample.SampleValue = double.Parse(xSerieSample.InnerText);

                            oChan.Samples.Add(sSample);

                            if (oChan.Samples.Count == 1)
                            {
                                oChan.Min = sSample.SampleValue;
                                oChan.Max = sSample.SampleValue;
                            }
                            else
                            {
                                if (sSample.SampleValue < oChan.Min)
                                {
                                    oChan.Min = sSample.SampleValue;
                                }
                                if (sSample.SampleValue > oChan.Max)
                                {
                                    oChan.Max = sSample.SampleValue;
                                }
                            }
                        }

                        this.Channels.Add(oChan);
                    }
                }

                #endregion
            }
            catch
            {
                return(false);
            }

            return(true);
        }