using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OTDR
{
    class AscParser
    {
        private string sFilePath { get; set; }
        private List<Tuple<double, double>> lstResult {get;set;}

        public AscParser(string sFileName)
        {
            sFilePath = sFilePath;
        }

        public void parse()
        {
            StreamReader sr = new StreamReader(sFilePath);
            string sLine = sr.ReadLine();
            bool bRead = false;
            string[] arrPoint;
            while (sLine != null)
            {
                // skip empty rows
                if (sLine.Trim().Length == 0)
                {
                    sLine = sr.ReadLine();
                    continue;
                }
                // starting area of points
                if (sLine == "POS(km)  VAL(dB)")
                    bRead = true;
                else
                {
                    if (bRead)
                    {
                        arrPoint = sLine.Split(' ');
                        lstResult.Add(new Tuple<double, double>(double.Parse(arrPoint[0], CultureInfo.InvariantCulture), double.Parse(arrPoint[1], CultureInfo.InvariantCulture)));
                    }
                }
                sLine = sr.ReadLine();
            }
        }

        public List<Tuple<double, double>> getEventLocIndex()
        {
            return lstResult;

        }
    }
}
