using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication2;

public class Form1 : Form
{
	private Plot_State_s PlotState;

	public BsvReader BsvReader;

	private Splash_Screen splash_screen;

	private IContainer components;

	private Chart chart1;

	public Form1()
	{
		splash_screen = new Splash_Screen();
		splash_screen.ShowSplash();
		InitializeComponent();
	}

	private void Form1_Load(object sender, EventArgs e)
	{
		try
		{
			if (LoadData())
			{
				InitializeChart();
				PlotChart();
				string outPut_File_Name = PlotState.OutPut_File_Name;
				chart1.SaveImage(outPut_File_Name, ChartImageFormat.Png);
				if (PlotState.Visibility == "-H")
				{
					Application.Exit();
				}
			}
		}
		catch (Exception ex)
		{
			string text = ex.ToString() + "\n\nInput File: " + PlotState.File_Name;
			MessageBox.Show(text);
		}
	}

	private void PlotChart()
	{
		chart1.ChartAreas[0].AxisX.Title = PlotState.Plot_X_Label;
		chart1.ChartAreas[0].AxisY.Title = PlotState.Plot_Y_Label;
		string text = "";
		if (PlotState.Plot_Constellation != "")
		{
			char[] separator = new char[1] { ' ' };
			string[] array = PlotState.Plot_Constellation.Split(separator);
			text = array[1] + " ";
		}
		text += PlotState.Plot_Title;
		chart1.Titles.Add(text);
		chart1.Size = new Size(1024, 768);
		chart1.RenderingDpiX = 1200.0;
		chart1.RenderingDpiY = 1200.0;
		Add_Chart_Elements(PlotState);
		chart1.Invalidate();
	}

	private Point_Series_State Get_Point_Series_Data(BsvReader BsvReader)
	{
		char[] separator = new char[1] { ' ' };
		Point_List point_List = default(Point_List);
		point_List.xVals = new List<double>();
		point_List.yVals = new List<double>();
		point_List.Add_Marker = true;
		point_List.Y_Min = 99999.9;
		point_List.Y_Max = -99999.9;
		point_List.X_Min = 99999.9;
		point_List.X_Max = -99999.9;
		string text = BsvReader.ReadLine();
		string[] array;
		while (text != null && text != "4444 4444" && !text.StartsWith("***"))
		{
			array = text.Split(separator);
			double.TryParse(array[0], out var result);
			double.TryParse(array[1], out var result2);
			point_List.xVals.Add(result);
			point_List.yVals.Add(result2);
			if (result2 < point_List.Y_Min)
			{
				point_List.Y_Min = result2;
			}
			if (result2 > point_List.Y_Max)
			{
				point_List.Y_Max = result2;
			}
			if (result < point_List.X_Min)
			{
				point_List.X_Min = result;
			}
			if (result > point_List.X_Max)
			{
				point_List.X_Max = result;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		Point_Series_State result3 = default(Point_Series_State);
		result3.Point_List = point_List;
		array = text.Split(separator);
		result3.Last_Delimiter = array[0];
		return result3;
	}

	private Point_List_Series_State Get_WBIQ_Jammer_Power_Data(BsvReader BsvReader)
	{
		char[] separator = new char[1] { ' ' };
		Point_List item = default(Point_List);
		item.PointList_Name = "Jammer: BW <= 50Hz";
		item.xVals = new List<double>();
		item.yVals = new List<double>();
		item.Add_Marker = true;
		item.Y_Min = 99999.9;
		item.Y_Max = -99999.9;
		item.X_Min = 99999.9;
		item.X_Max = -99999.9;
		item.Add_Marker = true;
		item.Marker = MarkerStyle.Cross;
		Point_List item2 = default(Point_List);
		item2.PointList_Name = "Jammer: 50Hz < BW <= 1kHz";
		item2.xVals = new List<double>();
		item2.yVals = new List<double>();
		item2.Y_Min = 99999.9;
		item2.Y_Max = -99999.9;
		item2.X_Min = 99999.9;
		item2.X_Max = -99999.9;
		item2.Add_Marker = true;
		item2.Marker = MarkerStyle.Star10;
		Point_List item3 = default(Point_List);
		item3.PointList_Name = "GSM Blanking Jammer";
		item3.xVals = new List<double>();
		item3.yVals = new List<double>();
		item3.Y_Min = 99999.9;
		item3.Y_Max = -99999.9;
		item3.X_Min = 99999.9;
		item3.X_Max = -99999.9;
		item3.Add_Marker = true;
		item3.Marker = MarkerStyle.Square;
		Point_List item4 = default(Point_List);
		item4.PointList_Name = "Jammer: 1kHz < BW <= 10kHz";
		item4.xVals = new List<double>();
		item4.yVals = new List<double>();
		item4.Y_Min = 99999.9;
		item4.Y_Max = -99999.9;
		item4.X_Min = 99999.9;
		item4.X_Max = -99999.9;
		item4.Add_Marker = true;
		item4.Marker = MarkerStyle.Star4;
		Point_List item5 = default(Point_List);
		item5.PointList_Name = "Jammer: BW > 10kHz";
		item5.xVals = new List<double>();
		item5.yVals = new List<double>();
		item5.Y_Min = 99999.9;
		item5.Y_Max = -99999.9;
		item5.X_Min = 99999.9;
		item5.X_Max = -99999.9;
		item5.Add_Marker = true;
		item5.Marker = MarkerStyle.Triangle;
		string text = BsvReader.ReadLine();
		string[] array;
		while (text != null && text != "6666 6666")
		{
			array = text.Split(separator);
			double.TryParse(array[0], out var result);
			double.TryParse(array[1], out var result2);
			int.TryParse(array[2], out var result3);
			switch ((Jammer_Types)result3)
			{
			case Jammer_Types.GSM:
				item3.xVals.Add(result);
				item3.yVals.Add(result2);
				if (result2 < item3.Y_Min)
				{
					item3.Y_Min = result2;
				}
				if (result2 > item3.Y_Max)
				{
					item3.Y_Max = result2;
				}
				if (result < item3.X_Min)
				{
					item3.X_Min = result;
				}
				if (result > item3.X_Max)
				{
					item3.X_Max = result;
				}
				break;
			case Jammer_Types.Bandwidth_lt_50:
				item.xVals.Add(result);
				item.yVals.Add(result2);
				if (result2 < item.Y_Min)
				{
					item.Y_Min = result2;
				}
				if (result2 > item.Y_Max)
				{
					item.Y_Max = result2;
				}
				if (result < item.X_Min)
				{
					item.X_Min = result;
				}
				if (result > item.X_Max)
				{
					item.X_Max = result;
				}
				break;
			case Jammer_Types.Bandwidth_btw_50_1k:
				item2.xVals.Add(result);
				item2.yVals.Add(result2);
				if (result2 < item2.Y_Min)
				{
					item2.Y_Min = result2;
				}
				if (result2 > item2.Y_Max)
				{
					item2.Y_Max = result2;
				}
				if (result < item2.X_Min)
				{
					item2.X_Min = result;
				}
				if (result > item2.X_Max)
				{
					item2.X_Max = result;
				}
				break;
			case Jammer_Types.Bandwidth_btw_1k_10k:
				item4.xVals.Add(result);
				item4.yVals.Add(result2);
				if (result2 < item4.Y_Min)
				{
					item4.Y_Min = result2;
				}
				if (result2 > item4.Y_Max)
				{
					item4.Y_Max = result2;
				}
				if (result < item4.X_Min)
				{
					item4.X_Min = result;
				}
				if (result > item4.X_Max)
				{
					item4.X_Max = result;
				}
				break;
			case Jammer_Types.Bandwidth_gt_10k:
				item5.xVals.Add(result);
				item5.yVals.Add(result2);
				if (result2 < item5.Y_Min)
				{
					item5.Y_Min = result2;
				}
				if (result2 > item5.Y_Max)
				{
					item5.Y_Max = result2;
				}
				if (result < item5.X_Min)
				{
					item5.X_Min = result;
				}
				if (result > item5.X_Max)
				{
					item5.X_Max = result;
				}
				break;
			default:
				if (!BsvReader.ReachedEndOfFile())
				{
					text = BsvReader.ReadLine();
					continue;
				}
				break;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		Point_List_Series_State result4 = default(Point_List_Series_State);
		result4.Point_List = new List<Point_List>();
		if (item.xVals.Count > 0)
		{
			result4.Point_List.Add(item);
		}
		if (item2.xVals.Count > 0)
		{
			result4.Point_List.Add(item2);
		}
		if (item3.xVals.Count > 0)
		{
			result4.Point_List.Add(item3);
		}
		if (item4.xVals.Count > 0)
		{
			result4.Point_List.Add(item4);
		}
		if (item5.xVals.Count > 0)
		{
			result4.Point_List.Add(item5);
		}
		array = text.Split(separator);
		result4.Last_Delimiter = array[0];
		return result4;
	}

	private Point_List_Series_State Get_WBIQ_Multitone_Jammer_Power_Data(BsvReader BsvReader)
	{
		char[] separator = new char[1] { ' ' };
		Point_List item = default(Point_List);
		item.PointList_Name = "Multi-Tone Jammer";
		item.xVals = new List<double>();
		item.yVals = new List<double>();
		item.Add_Marker = true;
		item.Y_Min = 99999.9;
		item.Y_Max = -99999.9;
		item.X_Min = 99999.9;
		item.X_Max = -99999.9;
		item.Add_Marker = true;
		item.Marker = MarkerStyle.Cross;
		string text = BsvReader.ReadLine();
		string[] array;
		while (text != null && text != "3333 3333" && text != "******Start")
		{
			if (text != "2222 2222")
			{
				array = text.Split(separator);
				double.TryParse(array[0], out var result);
				double.TryParse(array[1], out var result2);
				item.xVals.Add(result);
				item.yVals.Add(result2);
				if (result2 < item.Y_Min)
				{
					item.Y_Min = result2;
				}
				if (result2 > item.Y_Max)
				{
					item.Y_Max = result2;
				}
				if (result < item.X_Min)
				{
					item.X_Min = result;
				}
				if (result > item.X_Max)
				{
					item.X_Max = result;
				}
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		Point_List_Series_State result3 = default(Point_List_Series_State);
		result3.Point_List = new List<Point_List>();
		if (item.xVals.Count > 0)
		{
			result3.Point_List.Add(item);
		}
		array = text.Split(separator);
		result3.Last_Delimiter = array[0];
		return result3;
	}

	private Jammer_Series_State Get_WBIQ_Jammer_Spectrum_Data(BsvReader BsvReader)
	{
		char[] separator = new char[1] { ' ' };
		List<Line> list = new List<Line>();
		Line item = default(Line);
		int num = 0;
		item.xVals = new List<double>();
		item.yVals = new List<double>();
		item.Y_Min = 99999.9;
		item.Y_Max = -99999.9;
		item.X_Min = 99999.9;
		item.X_Max = -99999.9;
		string text = BsvReader.ReadLine();
		string[] array;
		while (text != null && text != "7777 7777")
		{
			if (text != "8888 8888")
			{
				array = text.Split(separator);
				double.TryParse(array[0], out var result);
				double.TryParse(array[1], out var result2);
				item.xVals.Add(result);
				item.yVals.Add(result2);
				if (result2 < item.Y_Min)
				{
					item.Y_Min = result2;
				}
				if (result2 > item.Y_Max)
				{
					item.Y_Max = result2;
				}
				if (result < item.X_Min)
				{
					item.X_Min = result;
				}
				if (result > item.X_Max)
				{
					item.X_Max = result;
				}
			}
			else
			{
				list.Add(item);
				item = default(Line);
				num++;
				item.xVals = new List<double>();
				item.yVals = new List<double>();
				item.Y_Min = 99999.9;
				item.Y_Max = -99999.9;
				item.X_Min = 99999.9;
				item.X_Max = -99999.9;
				item.Insert_Null_Point = true;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		Jammer_Series_State result3 = default(Jammer_Series_State);
		result3.Polyline = list;
		array = text.Split(separator);
		result3.Last_Delimiter = array[0];
		return result3;
	}

	private Jammer_Series_State Get_WBIQ_Multitone_Jammer_Spectrum_Data(BsvReader BsvReader)
	{
		char[] separator = new char[1] { ' ' };
		List<Line> list = new List<Line>();
		Line item = default(Line);
		int num = 0;
		item.xVals = new List<double>();
		item.yVals = new List<double>();
		item.Y_Min = 99999.9;
		item.Y_Max = -99999.9;
		item.X_Min = 99999.9;
		item.X_Max = -99999.9;
		string text = BsvReader.ReadLine();
		string[] array;
		while (text != null && text != "3333 3333" && text != "2222 2222")
		{
			if (text != "4444 4444")
			{
				array = text.Split(separator);
				double.TryParse(array[0], out var result);
				double.TryParse(array[1], out var result2);
				item.xVals.Add(result);
				item.yVals.Add(result2);
				if (result2 < item.Y_Min)
				{
					item.Y_Min = result2;
				}
				if (result2 > item.Y_Max)
				{
					item.Y_Max = result2;
				}
				if (result < item.X_Min)
				{
					item.X_Min = result;
				}
				if (result > item.X_Max)
				{
					item.X_Max = result;
				}
			}
			else
			{
				list.Add(item);
				item = default(Line);
				num++;
				item.xVals = new List<double>();
				item.yVals = new List<double>();
				item.Y_Min = 99999.9;
				item.Y_Max = -99999.9;
				item.X_Min = 99999.9;
				item.X_Max = -99999.9;
				item.Insert_Null_Point = true;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		Jammer_Series_State result3 = default(Jammer_Series_State);
		result3.Polyline = list;
		array = text.Split(separator);
		result3.Last_Delimiter = array[0];
		return result3;
	}

	private Double_Series_State GetDoubleSeries(BsvReader BsvReader)
	{
		List<Line> list = new List<Line>();
		Line item = default(Line);
		item.xVals = new List<double>();
		item.yVals = new List<double>();
		item.Y_Min = 99999.9;
		item.Y_Max = -99999.9;
		item.X_Min = 99999.9;
		item.X_Max = -99999.9;
		Line item2 = default(Line);
		item2.xVals = new List<double>();
		item2.yVals = new List<double>();
		item2.Y_Min = 99999.9;
		item2.Y_Max = -99999.9;
		item2.X_Min = 99999.9;
		item2.X_Max = -99999.9;
		List<string> list2 = BsvReader.ReadNextLine();
		while (list2 != null && list2[0] != "8888")
		{
			double result = 0.0;
			double result2 = 0.0;
			if (list2.Count != 3)
			{
				break;
			}
			double.TryParse(list2[0], out var result3);
			double.TryParse(list2[1], out result);
			double.TryParse(list2[2], out result2);
			item.xVals.Add(result3);
			item.yVals.Add(result);
			if (result < item.Y_Min)
			{
				item.Y_Min = result;
			}
			if (result > item.Y_Max)
			{
				item.Y_Max = result;
			}
			if (result3 < item.X_Min)
			{
				item.X_Min = result3;
			}
			if (result3 > item.X_Max)
			{
				item.X_Max = result3;
			}
			item2.xVals.Add(result3);
			item2.yVals.Add(result2);
			if (result2 < item2.Y_Min)
			{
				item2.Y_Min = result2;
			}
			if (result2 > item2.Y_Max)
			{
				item2.Y_Max = result2;
			}
			if (result3 < item2.X_Min)
			{
				item2.X_Min = result3;
			}
			if (result3 > item2.X_Max)
			{
				item2.X_Max = result3;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			list2 = BsvReader.ReadNextLine();
		}
		list.Add(item);
		list.Add(item2);
		Double_Series_State result4 = default(Double_Series_State);
		result4.Polyline = list;
		result4.Last_Delimiter = list2[0];
		return result4;
	}

	private Single_Series_State GetSingleSeries(BsvReader BsvReader)
	{
		double num = -1E+20;
		double num2 = -1E+20;
		Line polyline = default(Line);
		polyline.xVals = new List<double>();
		polyline.yVals = new List<double>();
		polyline.Y_Min = 1E+20;
		polyline.Y_Max = -1E+20;
		polyline.X_Min = 1E+20;
		polyline.X_Max = -1E+20;
		List<string> list = BsvReader.ReadNextLine();
		while (list != null && list[0] != "***" && list[0] != "******Start")
		{
			double result;
			double result2;
			if (list.Count == 2)
			{
				double.TryParse(list[0], out result);
				double.TryParse(list[1], out result2);
			}
			else if (list.Count == 3)
			{
				if (list[0] != "")
				{
					double.TryParse(list[0], out result);
					double.TryParse(list[2], out result2);
				}
				else
				{
					double.TryParse(list[1], out result);
					double.TryParse(list[2], out result2);
				}
			}
			else
			{
				if (list.Count != 4)
				{
					break;
				}
				double.TryParse(list[1], out result);
				double.TryParse(list[3], out result2);
			}
			if (result != num || result2 != num2)
			{
				polyline.xVals.Add(result);
				polyline.yVals.Add(result2);
			}
			num = result;
			num2 = result2;
			if (result2 < polyline.Y_Min)
			{
				polyline.Y_Min = result2;
			}
			if (result2 > polyline.Y_Max)
			{
				polyline.Y_Max = result2;
			}
			if (result < polyline.X_Min)
			{
				polyline.X_Min = result;
			}
			if (result > polyline.X_Max)
			{
				polyline.X_Max = result;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			list = BsvReader.ReadNextLine();
		}
		Single_Series_State result3 = default(Single_Series_State);
		result3.Polyline = polyline;
		result3.Last_Delimiter = list[0];
		return result3;
	}

	private Single_Series_State Get_WBIQ_SingleSeries_Data(BsvReader BsvReader)
	{
		double num = -1E+20;
		double num2 = -1E+20;
		Line polyline = default(Line);
		polyline.xVals = new List<double>();
		polyline.yVals = new List<double>();
		polyline.Jammer_Type = new List<int>();
		polyline.Y_Min = 1E+20;
		polyline.Y_Max = -1E+20;
		polyline.X_Min = 1E+20;
		polyline.X_Max = -1E+20;
		List<string> list = BsvReader.ReadNextLine();
		while (list != null && list[0] != "8888" && list[0] != "7777" && list[0] != "6666" && list[0] != "5555" && list[0] != "4444" && list[0] != "3333" && list[0] != "2222")
		{
			double result;
			double result2;
			if (list.Count == 2)
			{
				double.TryParse(list[0], out result);
				double.TryParse(list[1], out result2);
			}
			else if (list.Count == 3)
			{
				if (list[0] != "")
				{
					double.TryParse(list[0], out result);
					double.TryParse(list[2], out result2);
				}
				else
				{
					double.TryParse(list[1], out result);
					double.TryParse(list[2], out result2);
				}
			}
			else
			{
				if (list.Count != 4)
				{
					break;
				}
				double.TryParse(list[1], out result);
				double.TryParse(list[3], out result2);
			}
			if (result != num || result2 != num2)
			{
				polyline.xVals.Add(result);
				polyline.yVals.Add(result2);
			}
			num = result;
			num2 = result2;
			if (result2 < polyline.Y_Min)
			{
				polyline.Y_Min = result2;
			}
			if (result2 > polyline.Y_Max)
			{
				polyline.Y_Max = result2;
			}
			if (result < polyline.X_Min)
			{
				polyline.X_Min = result;
			}
			if (result > polyline.X_Max)
			{
				polyline.X_Max = result;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			list = BsvReader.ReadNextLine();
		}
		Single_Series_State result3 = default(Single_Series_State);
		result3.Polyline = polyline;
		if (list[0] == "8888" && !BsvReader.ReachedEndOfFile())
		{
			list = BsvReader.ReadNextLine();
		}
		result3.Last_Delimiter = list[0];
		return result3;
	}

	private HilightBox_Series_State GetHilightBox(BsvReader BsvReader)
	{
		HilightBox hilightBox_Data = default(HilightBox);
		hilightBox_Data.HilightBox_Valid = true;
		hilightBox_Data.Y_Min = 1E+20;
		hilightBox_Data.Y_Max = -1E+20;
		hilightBox_Data.X_Min = 1E+20;
		hilightBox_Data.X_Max = -1E+20;
		List<string> list = null;
		for (int i = 0; i < 4; i++)
		{
			if (BsvReader.ReachedEndOfFile())
			{
				hilightBox_Data.HilightBox_Valid = false;
				break;
			}
			list = BsvReader.ReadNextLine();
			if (list == null || list[0] == "8888" || list[0] == "7777" || list[0] == "6666" || list[0] == "5555" || list[0] == "4444" || list[0] == "3333" || list[0] == "2222")
			{
				hilightBox_Data.HilightBox_Valid = false;
				break;
			}
			double result;
			double result2;
			if (list.Count == 2)
			{
				double.TryParse(list[0], out result);
				double.TryParse(list[1], out result2);
			}
			else if (list.Count == 3)
			{
				if (list[0] != "")
				{
					double.TryParse(list[0], out result);
					double.TryParse(list[2], out result2);
				}
				else
				{
					double.TryParse(list[1], out result);
					double.TryParse(list[2], out result2);
				}
			}
			else
			{
				if (list.Count != 4)
				{
					hilightBox_Data.HilightBox_Valid = false;
					break;
				}
				double.TryParse(list[1], out result);
				double.TryParse(list[3], out result2);
			}
			if (result2 < hilightBox_Data.Y_Min)
			{
				hilightBox_Data.Y_Min = result2;
			}
			if (result2 > hilightBox_Data.Y_Max)
			{
				hilightBox_Data.Y_Max = result2;
			}
			if (result < hilightBox_Data.X_Min)
			{
				hilightBox_Data.X_Min = result;
			}
			if (result > hilightBox_Data.X_Max)
			{
				hilightBox_Data.X_Max = result;
			}
		}
		HilightBox_Series_State result3 = default(HilightBox_Series_State);
		result3.HilightBox_Data = hilightBox_Data;
		if (list != null)
		{
			result3.Last_Delimiter = list[0];
		}
		else
		{
			result3.Last_Delimiter = "";
		}
		return result3;
	}

	private Histogram_Series_State GetHistogramSeries(BsvReader BsvReader)
	{
		Histogram histogram_Data = default(Histogram);
		histogram_Data.xVals = new List<double>();
		histogram_Data.yVals = new List<double>();
		histogram_Data.Y_Min = 1E+20;
		histogram_Data.Y_Max = -1E+20;
		histogram_Data.X_Min = 1E+20;
		histogram_Data.X_Max = -1E+20;
		List<string> list = BsvReader.ReadNextLine();
		while (list != null && !list[0].StartsWith("***"))
		{
			double result;
			double result2;
			if (list.Count == 2)
			{
				double.TryParse(list[0], out result);
				double.TryParse(list[1], out result2);
			}
			else if (list.Count == 3)
			{
				if (list[0] != "")
				{
					double.TryParse(list[0], out result);
					double.TryParse(list[2], out result2);
				}
				else
				{
					double.TryParse(list[1], out result);
					double.TryParse(list[2], out result2);
				}
			}
			else
			{
				if (list.Count != 4)
				{
					break;
				}
				double.TryParse(list[1], out result);
				double.TryParse(list[3], out result2);
			}
			histogram_Data.xVals.Add(result);
			histogram_Data.yVals.Add(result2);
			if (result2 < histogram_Data.Y_Min)
			{
				histogram_Data.Y_Min = result2;
			}
			if (result2 > histogram_Data.Y_Max)
			{
				histogram_Data.Y_Max = result2;
			}
			if (result < histogram_Data.X_Min)
			{
				histogram_Data.X_Min = result;
			}
			if (result > histogram_Data.X_Max)
			{
				histogram_Data.X_Max = result;
			}
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			list = BsvReader.ReadNextLine();
		}
		Histogram_Series_State result3 = default(Histogram_Series_State);
		result3.Histogram_Data = histogram_Data;
		result3.Last_Delimiter = list[0];
		return result3;
	}

	private Annotation_State GetAnnotation(BsvReader BsvReader)
	{
		Annotation annotation = default(Annotation);
		annotation.Annotation_strings = new List<string>();
		string text = BsvReader.ReadLine();
		while (text != null && text != "******End")
		{
			annotation.Annotation_strings.Add(text);
			if (BsvReader.ReachedEndOfFile())
			{
				break;
			}
			text = BsvReader.ReadLine();
		}
		if (text == "******End" && !BsvReader.ReachedEndOfFile())
		{
			text = BsvReader.ReadLine();
		}
		Annotation_State result = default(Annotation_State);
		result.Annotation = annotation;
		result.Last_Delimiter = text;
		return result;
	}

	private bool Process_Gen8_FoldedSpec_Plot(BsvReader BsvReader)
	{
		List<string> list = BsvReader.ReadNextLine();
		if (list[0] == "ffff" || list[0] == "FFFF")
		{
			PlotState.Plot_X_Label = "Frequency (Hz, mod 1kHz)";
			PlotState.Plot_Y_Label = "Power Level (dBm)";
			PlotState.Plot_Constellation = "";
			PlotState.HilightBoxList = new List<HilightBox>();
			PlotState.PolyLine = new List<Line>();
			PlotState.Annotations = new List<Annotation>();
			PlotState.PointList = new List<Point_List>();
			PlotState.HistogramList = new List<Histogram>();
			PlotState.Jammer_PolyLines = new List<Line>();
			Double_Series_State doubleSeries = GetDoubleSeries(BsvReader);
			List<Line> polyline = doubleSeries.Polyline;
			Line item = polyline[0];
			item.PolyLine_Name = "Combined mod-1kHz Signal Energy";
			item.PolyLine_Color_Index = 0;
			if (item.xVals.Count > 0)
			{
				if (item.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item.X_Min;
				}
				if (item.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = 1000.0;
				}
				if (item.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item.Y_Min;
				}
				if (item.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item.Y_Max;
				}
			}
			Line item2 = polyline[1];
			if (item2.xVals.Count > 0)
			{
				item2.PolyLine_Name = "Detection Threshold";
				item2.PolyLine_Color_Index = 1;
				item2.DashStyle = true;
				if (item2.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item2.X_Min;
				}
				if (item2.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = 1000.0;
				}
				if (item2.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item2.Y_Min;
				}
				if (item2.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item2.Y_Max;
				}
			}
			if (item.xVals.Count > 0 && item2.xVals.Count > 0)
			{
				PlotState.PolyLine.Add(item);
				PlotState.PolyLine.Add(item2);
			}
			string last_Delimiter = doubleSeries.Last_Delimiter;
			if (last_Delimiter == "******Start")
			{
				Annotation_State annotation = GetAnnotation(BsvReader);
				if (annotation.Annotation.Annotation_strings.Count > 0)
				{
					PlotState.Annotations.Add(annotation.Annotation);
				}
			}
		}
		return true;
	}

	private bool Process_Gen8_WBIQ_Plot(BsvReader BsvReader, bool plotMTJ)
	{
		List<string> list = BsvReader.ReadNextLine();
		if (list[0] == "9999")
		{
			PlotState.Plot_X_Label = "Frequency [KHz]";
			PlotState.Plot_Y_Label = "Power Level [dBm]";
			PlotState.Plot_Constellation = "";
			PlotState.HilightBoxList = new List<HilightBox>();
			PlotState.PolyLine = new List<Line>();
			PlotState.Annotations = new List<Annotation>();
			PlotState.PointList = new List<Point_List>();
			PlotState.HistogramList = new List<Histogram>();
			PlotState.Jammer_PolyLines = new List<Line>();
			Double_Series_State doubleSeries = GetDoubleSeries(BsvReader);
			List<Line> polyline = doubleSeries.Polyline;
			Line item = polyline[0];
			item.PolyLine_Name = "Spectrum";
			item.PolyLine_Color_Index = 0;
			if (item.xVals.Count > 0)
			{
				if (item.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item.X_Min;
				}
				if (item.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = item.X_Max;
				}
				if (item.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item.Y_Min;
				}
				if (item.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item.Y_Max;
				}
			}
			Line item2 = polyline[1];
			if (item2.xVals.Count > 0)
			{
				item2.PolyLine_Name = "Noise Floor";
				item2.PolyLine_Color_Index = 2;
				if (item2.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item2.X_Min;
				}
				if (item2.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = item2.X_Max;
				}
				if (item2.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item2.Y_Min;
				}
				if (item2.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item2.Y_Max;
				}
			}
			if (item.xVals.Count > 0 && item2.xVals.Count > 0)
			{
				PlotState.PolyLine.Add(item);
				PlotState.PolyLine.Add(item2);
			}
			string text = doubleSeries.Last_Delimiter;
			if (text == "8888")
			{
				Jammer_Series_State jammer_Series_State = Get_WBIQ_Jammer_Spectrum_Data(BsvReader);
				text = jammer_Series_State.Last_Delimiter;
				if (jammer_Series_State.Polyline.Count > 0)
				{
					int count = jammer_Series_State.Polyline.Count;
					for (int i = 0; i < count; i++)
					{
						Line item3 = jammer_Series_State.Polyline[i];
						item3.PolyLine_Name = "Jammer Spectrum";
						item3.PolyLine_Color_Index = 1;
						if (item3.X_Min < PlotState.X_Min)
						{
							PlotState.X_Min = item3.X_Min;
						}
						if (item3.X_Max > PlotState.X_Max)
						{
							PlotState.X_Max = item3.X_Max;
						}
						if (item3.Y_Min < PlotState.Y_Min)
						{
							PlotState.Y_Min = item3.Y_Min;
						}
						if (item3.Y_Max > PlotState.Y_Max)
						{
							PlotState.Y_Max = item3.Y_Max;
						}
						PlotState.Jammer_PolyLines.Add(item3);
					}
				}
			}
			if (text == "7777")
			{
				Point_List_Series_State point_List_Series_State = Get_WBIQ_Jammer_Power_Data(BsvReader);
				text = point_List_Series_State.Last_Delimiter;
				if (point_List_Series_State.Point_List.Count > 0)
				{
					int num = 0;
					while (num < point_List_Series_State.Point_List.Count)
					{
						Point_List item4 = point_List_Series_State.Point_List[num];
						if (item4.xVals.Count > 0)
						{
							item4.PointList_Color_Index = 1;
							if (item4.X_Min < PlotState.X_Min)
							{
								PlotState.X_Min = item4.X_Min;
							}
							if (item4.X_Max > PlotState.X_Max)
							{
								PlotState.X_Max = item4.X_Max;
							}
							if (item4.Y_Min < PlotState.Y_Min)
							{
								PlotState.Y_Min = item4.Y_Min;
							}
							if (item4.Y_Max > PlotState.Y_Max)
							{
								PlotState.Y_Max = item4.Y_Max;
							}
							PlotState.PointList.Add(item4);
							num++;
						}
					}
				}
			}
			if (text == "6666")
			{
				Single_Series_State single_Series_State = Get_WBIQ_SingleSeries_Data(BsvReader);
				Line polyline2 = single_Series_State.Polyline;
				text = single_Series_State.Last_Delimiter;
				if (polyline2.xVals.Count > 0)
				{
					polyline2.PolyLine_Name = "Input Tone";
					polyline2.PolyLine_Color_Index = 4;
					if (polyline2.X_Min < PlotState.X_Min)
					{
						PlotState.X_Min = polyline2.X_Min;
					}
					if (polyline2.X_Max > PlotState.X_Max)
					{
						PlotState.X_Max = polyline2.X_Max;
					}
					if (polyline2.Y_Min < PlotState.Y_Min)
					{
						PlotState.Y_Min = polyline2.Y_Min;
					}
					if (polyline2.Y_Max > PlotState.Y_Max)
					{
						PlotState.Y_Max = polyline2.Y_Max;
					}
					PlotState.PolyLine.Add(polyline2);
				}
			}
			if (text == "5555")
			{
				Point_Series_State point_Series_State = Get_Point_Series_Data(BsvReader);
				Point_List point_List = point_Series_State.Point_List;
				text = point_Series_State.Last_Delimiter;
				point_List.PointList_Name = "Signal";
				if (point_List.xVals.Count > 0)
				{
					point_List.Add_Marker = true;
					point_List.Marker = MarkerStyle.Diamond;
					point_List.PointList_Color_Index = 4;
					if (point_List.X_Min < PlotState.X_Min)
					{
						PlotState.X_Min = point_List.X_Min;
					}
					if (point_List.X_Max > PlotState.X_Max)
					{
						PlotState.X_Max = point_List.X_Max;
					}
					if (point_List.Y_Min < PlotState.Y_Min)
					{
						PlotState.Y_Min = point_List.Y_Min;
					}
					if (point_List.Y_Max > PlotState.Y_Max)
					{
						PlotState.Y_Max = point_List.Y_Max;
					}
					PlotState.PointList.Add(point_List);
				}
			}
			if (text == "4444")
			{
				Jammer_Series_State jammer_Series_State2 = Get_WBIQ_Multitone_Jammer_Spectrum_Data(BsvReader);
				text = jammer_Series_State2.Last_Delimiter;
				if (plotMTJ)
				{
					int count2 = jammer_Series_State2.Polyline.Count;
					for (int j = 0; j < count2; j++)
					{
						Line item5 = jammer_Series_State2.Polyline[j];
						item5.PolyLine_Name = "Multitone Jammer Spectrum";
						item5.PolyLine_Color_Index = 3;
						if (item5.X_Min < PlotState.X_Min)
						{
							PlotState.X_Min = item5.X_Min;
						}
						if (item5.X_Max > PlotState.X_Max)
						{
							PlotState.X_Max = item5.X_Max;
						}
						if (item5.Y_Min < PlotState.Y_Min)
						{
							PlotState.Y_Min = item5.Y_Min;
						}
						if (item5.Y_Max > PlotState.Y_Max)
						{
							PlotState.Y_Max = item5.Y_Max;
						}
						PlotState.Jammer_PolyLines.Add(item5);
					}
				}
			}
			if (text == "2222")
			{
				Point_List_Series_State point_List_Series_State2 = Get_WBIQ_Multitone_Jammer_Power_Data(BsvReader);
				text = point_List_Series_State2.Last_Delimiter;
				if (point_List_Series_State2.Point_List.Count > 0 && plotMTJ)
				{
					int num2 = 0;
					while (num2 < point_List_Series_State2.Point_List.Count)
					{
						Point_List item6 = point_List_Series_State2.Point_List[num2];
						if (item6.xVals.Count > 0)
						{
							item6.PointList_Color_Index = 3;
							if (item6.X_Min < PlotState.X_Min)
							{
								PlotState.X_Min = item6.X_Min;
							}
							if (item6.X_Max > PlotState.X_Max)
							{
								PlotState.X_Max = item6.X_Max;
							}
							if (item6.Y_Min < PlotState.Y_Min)
							{
								PlotState.Y_Min = item6.Y_Min;
							}
							if (item6.Y_Max > PlotState.Y_Max)
							{
								PlotState.Y_Max = item6.Y_Max;
							}
							PlotState.PointList.Add(item6);
							num2++;
						}
					}
				}
			}
			if (text == "3333")
			{
				HilightBox_Series_State hilightBox = GetHilightBox(BsvReader);
				hilightBox.HilightBox_Data.HilightBox_Name = "Wide Band Jammer";
				hilightBox.HilightBox_Data.HilightBox_Color = Color.FromArgb(128, 255, 128, 0);
				PlotState.HilightBoxList.Add(hilightBox.HilightBox_Data);
				text = BsvReader.ReadLine();
			}
			if (text == "******Start")
			{
				Annotation_State annotation = GetAnnotation(BsvReader);
				if (annotation.Annotation.Annotation_strings.Count > 0)
				{
					PlotState.Annotations.Add(annotation.Annotation);
				}
				text = annotation.Last_Delimiter;
			}
			if (text == "UUUU UUUU")
			{
				if (!BsvReader.ReachedEndOfFile())
				{
					text = BsvReader.ReadLine();
				}
				PlotState.Plot_X_Label = "Frequency [MHz]";
			}
		}
		return true;
	}

	private bool Process_Gen8_ADCIQ_Plot(BsvReader BsvReader)
	{
		List<string> list = BsvReader.ReadNextLine();
		bool flag = false;
		if (list[0] == "CW_ACTIVE")
		{
			flag = true;
		}
		else
		{
			if (!(list[0] == "CW_NOT_ACTIVE"))
			{
				return false;
			}
			flag = false;
		}
		list = BsvReader.ReadNextLine();
		if (list[0] == "9999")
		{
			PlotState.Plot_X_Label = "Frequency [KHz]";
			if (flag)
			{
				PlotState.Plot_Y_Label = "Power Level [dBm]";
			}
			else
			{
				PlotState.Plot_Y_Label = "Voltage level (dBv)";
			}
			PlotState.Plot_Constellation = "";
			PlotState.HilightBoxList = new List<HilightBox>();
			PlotState.PolyLine = new List<Line>();
			PlotState.Annotations = new List<Annotation>();
			PlotState.PointList = new List<Point_List>();
			PlotState.HistogramList = new List<Histogram>();
			PlotState.Jammer_PolyLines = new List<Line>();
			Double_Series_State doubleSeries = GetDoubleSeries(BsvReader);
			List<Line> polyline = doubleSeries.Polyline;
			Line item = polyline[0];
			item.PolyLine_Name = "Spectrum";
			item.PolyLine_Color_Index = 0;
			if (item.xVals.Count > 0)
			{
				if (item.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item.X_Min;
				}
				if (item.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = item.X_Max;
				}
				if (item.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item.Y_Min;
				}
				if (item.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item.Y_Max;
				}
			}
			Line item2 = polyline[1];
			if (item2.xVals.Count > 0)
			{
				item2.PolyLine_Name = "Noise Floor";
				item2.PolyLine_Color_Index = 2;
				if (item2.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = item2.X_Min;
				}
				if (item2.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = item2.X_Max;
				}
				if (item2.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = item2.Y_Min;
				}
				if (item2.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = item2.Y_Max;
				}
			}
			if (item.xVals.Count > 0 && item2.xVals.Count > 0)
			{
				PlotState.PolyLine.Add(item);
				PlotState.PolyLine.Add(item2);
			}
			string text = doubleSeries.Last_Delimiter;
			if (text == "8888")
			{
				Jammer_Series_State jammer_Series_State = Get_WBIQ_Jammer_Spectrum_Data(BsvReader);
				text = jammer_Series_State.Last_Delimiter;
				if (jammer_Series_State.Polyline.Count > 0)
				{
					int count = jammer_Series_State.Polyline.Count;
					for (int i = 0; i < count; i++)
					{
						Line item3 = jammer_Series_State.Polyline[i];
						item3.PolyLine_Name = "Jammer Spectrum";
						item3.PolyLine_Color_Index = 1;
						if (item3.X_Min < PlotState.X_Min)
						{
							PlotState.X_Min = item3.X_Min;
						}
						if (item3.X_Max > PlotState.X_Max)
						{
							PlotState.X_Max = item3.X_Max;
						}
						if (item3.Y_Min < PlotState.Y_Min)
						{
							PlotState.Y_Min = item3.Y_Min;
						}
						if (item3.Y_Max > PlotState.Y_Max)
						{
							PlotState.Y_Max = item3.Y_Max;
						}
						PlotState.Jammer_PolyLines.Add(item3);
					}
				}
			}
			if (text == "7777")
			{
				Point_List_Series_State point_List_Series_State = Get_WBIQ_Jammer_Power_Data(BsvReader);
				text = point_List_Series_State.Last_Delimiter;
				if (point_List_Series_State.Point_List.Count > 0)
				{
					int num = 0;
					while (num < point_List_Series_State.Point_List.Count)
					{
						Point_List item4 = point_List_Series_State.Point_List[num];
						if (item4.xVals.Count > 0)
						{
							item4.PointList_Color_Index = 1;
							if (item4.X_Min < PlotState.X_Min)
							{
								PlotState.X_Min = item4.X_Min;
							}
							if (item4.X_Max > PlotState.X_Max)
							{
								PlotState.X_Max = item4.X_Max;
							}
							if (item4.Y_Min < PlotState.Y_Min)
							{
								PlotState.Y_Min = item4.Y_Min;
							}
							if (item4.Y_Max > PlotState.Y_Max)
							{
								PlotState.Y_Max = item4.Y_Max;
							}
							PlotState.PointList.Add(item4);
							num++;
						}
					}
				}
			}
			if (text == "6666")
			{
				Single_Series_State single_Series_State = Get_WBIQ_SingleSeries_Data(BsvReader);
				Line polyline2 = single_Series_State.Polyline;
				text = single_Series_State.Last_Delimiter;
				if (polyline2.xVals.Count > 0)
				{
					polyline2.PolyLine_Name = "Input Tone";
					polyline2.PolyLine_Color_Index = 4;
					if (polyline2.X_Min < PlotState.X_Min)
					{
						PlotState.X_Min = polyline2.X_Min;
					}
					if (polyline2.X_Max > PlotState.X_Max)
					{
						PlotState.X_Max = polyline2.X_Max;
					}
					if (polyline2.Y_Min < PlotState.Y_Min)
					{
						PlotState.Y_Min = polyline2.Y_Min;
					}
					if (polyline2.Y_Max > PlotState.Y_Max)
					{
						PlotState.Y_Max = polyline2.Y_Max;
					}
					PlotState.PolyLine.Add(polyline2);
				}
			}
			if (text == "5555")
			{
				Point_Series_State point_Series_State = Get_Point_Series_Data(BsvReader);
				Point_List point_List = point_Series_State.Point_List;
				text = point_Series_State.Last_Delimiter;
				point_List.PointList_Name = "Signal";
				if (point_List.xVals.Count > 0)
				{
					point_List.Add_Marker = true;
					point_List.Marker = MarkerStyle.Diamond;
					point_List.PointList_Color_Index = 4;
					if (point_List.X_Min < PlotState.X_Min)
					{
						PlotState.X_Min = point_List.X_Min;
					}
					if (point_List.X_Max > PlotState.X_Max)
					{
						PlotState.X_Max = point_List.X_Max;
					}
					if (point_List.Y_Min < PlotState.Y_Min)
					{
						PlotState.Y_Min = point_List.Y_Min;
					}
					if (point_List.Y_Max > PlotState.Y_Max)
					{
						PlotState.Y_Max = point_List.Y_Max;
					}
					PlotState.PointList.Add(point_List);
				}
			}
			if (text == "4444")
			{
				HilightBox_Series_State hilightBox = GetHilightBox(BsvReader);
				HilightBox_Series_State hilightBox2 = GetHilightBox(BsvReader);
				HilightBox_Series_State hilightBox_Series_State = default(HilightBox_Series_State);
				HilightBox_Series_State hilightBox_Series_State2 = default(HilightBox_Series_State);
				string text2 = BsvReader.PeekLine();
				if (!text2.StartsWith("3333") && !text2.StartsWith("****"))
				{
					hilightBox_Series_State = GetHilightBox(BsvReader);
					hilightBox_Series_State2 = GetHilightBox(BsvReader);
				}
				else
				{
					hilightBox_Series_State.HilightBox_Data.HilightBox_Valid = false;
					hilightBox_Series_State2.HilightBox_Data.HilightBox_Valid = false;
				}
				if ((hilightBox2.HilightBox_Data.X_Min != 0.0 || hilightBox2.HilightBox_Data.X_Max != 0.0) && hilightBox2.HilightBox_Data.HilightBox_Valid)
				{
					hilightBox2.HilightBox_Data.HilightBox_Name = "GLO Band";
					hilightBox2.HilightBox_Data.HilightBox_Color = Color.FromArgb(128, 128, 255, 255);
					PlotState.HilightBoxList.Add(hilightBox2.HilightBox_Data);
				}
				if ((hilightBox_Series_State.HilightBox_Data.X_Min != 0.0 || hilightBox_Series_State.HilightBox_Data.X_Max != 0.0) && hilightBox_Series_State.HilightBox_Data.HilightBox_Valid)
				{
					hilightBox_Series_State.HilightBox_Data.HilightBox_Name = "BDS Band";
					hilightBox_Series_State.HilightBox_Data.HilightBox_Color = Color.FromArgb(128, 255, 0, 255);
					PlotState.HilightBoxList.Add(hilightBox_Series_State.HilightBox_Data);
				}
				if ((hilightBox_Series_State2.HilightBox_Data.X_Min != 0.0 || hilightBox_Series_State2.HilightBox_Data.X_Max != 0.0) && hilightBox_Series_State2.HilightBox_Data.HilightBox_Valid)
				{
					hilightBox_Series_State2.HilightBox_Data.HilightBox_Name = "GAL Band";
					hilightBox_Series_State2.HilightBox_Data.HilightBox_Color = Color.FromArgb(128, 0, 255, 0);
					PlotState.HilightBoxList.Add(hilightBox_Series_State2.HilightBox_Data);
				}
				if (hilightBox.HilightBox_Data.HilightBox_Valid)
				{
					hilightBox.HilightBox_Data.HilightBox_Name = "GPS Band";
					hilightBox.HilightBox_Data.HilightBox_Color = Color.FromArgb(255, 255, 255, 0);
					PlotState.HilightBoxList.Add(hilightBox.HilightBox_Data);
				}
				if (hilightBox.HilightBox_Data.HilightBox_Valid && hilightBox2.HilightBox_Data.HilightBox_Valid && hilightBox_Series_State.HilightBox_Data.HilightBox_Valid && hilightBox_Series_State2.HilightBox_Data.HilightBox_Valid)
				{
					list = BsvReader.ReadNextLine();
					text = list[0];
				}
				else
				{
					text = text2;
				}
			}
			if (text == "3333")
			{
				HilightBox_Series_State hilightBox3 = GetHilightBox(BsvReader);
				hilightBox3.HilightBox_Data.HilightBox_Name = "Wide Band Jammer";
				hilightBox3.HilightBox_Data.HilightBox_Color = Color.FromArgb(128, 255, 128, 0);
				PlotState.HilightBoxList.Add(hilightBox3.HilightBox_Data);
			}
			if (text == "******Start")
			{
				Annotation_State annotation = GetAnnotation(BsvReader);
				if (annotation.Annotation.Annotation_strings.Count > 0)
				{
					PlotState.Annotations.Add(annotation.Annotation);
				}
			}
		}
		return true;
	}

	private bool Process_Basic_Plot(BsvReader BsvReader, string Last_Delimiter)
	{
		int num = 0;
		int num2 = 0;
		string pattern = "\\*\\*\\*\\s+\\d+";
		Regex regex = new Regex(pattern);
		PlotState.PolyLine = new List<Line>();
		PlotState.Annotations = new List<Annotation>();
		PlotState.PointList = new List<Point_List>();
		PlotState.HilightBoxList = new List<HilightBox>();
		PlotState.HistogramList = new List<Histogram>();
		PlotState.Jammer_PolyLines = new List<Line>();
		while (!BsvReader.ReachedEndOfFile())
		{
			if (Last_Delimiter == "***" && !regex.IsMatch(BsvReader.LastLineRead()))
			{
				Single_Series_State singleSeries = GetSingleSeries(BsvReader);
				Line polyline = singleSeries.Polyline;
				polyline.PolyLine_Name = BsvReader.GetPlot_Series_Title(num);
				Last_Delimiter = singleSeries.Last_Delimiter;
				polyline.PolyLine_Color_Index = num2++;
				if (polyline.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = polyline.X_Min;
				}
				if (polyline.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = polyline.X_Max;
				}
				if (polyline.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = polyline.Y_Min;
				}
				if (polyline.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = polyline.Y_Max;
				}
				if (PlotState.Y_Min == PlotState.Y_Max)
				{
					PlotState.Y_Min -= 1.0;
					PlotState.Y_Max += 1.0;
				}
				PlotState.PolyLine.Add(polyline);
				if (num2 == 6)
				{
					num2 = 0;
				}
				num++;
			}
			else if (regex.IsMatch(BsvReader.LastLineRead()))
			{
				Point_Series_State point_Series_State = Get_Point_Series_Data(BsvReader);
				Point_List point_List = point_Series_State.Point_List;
				point_List.PointList_Name = BsvReader.GetPlot_Series_Title(num);
				Last_Delimiter = point_Series_State.Last_Delimiter;
				point_List.PointList_Color_Index = num2++;
				if (point_List.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = point_List.X_Min;
				}
				if (point_List.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = point_List.X_Max;
				}
				if (point_List.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = point_List.Y_Min;
				}
				if (point_List.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = point_List.Y_Max;
				}
				PlotState.PointList.Add(point_List);
				if (num2 == 6)
				{
					num2 = 0;
				}
				num++;
			}
			else if (Last_Delimiter == "******Hist")
			{
				Histogram_Series_State histogramSeries = GetHistogramSeries(BsvReader);
				Histogram histogram_Data = histogramSeries.Histogram_Data;
				histogram_Data.Histogram_Name = BsvReader.GetPlot_Series_Title(num);
				Last_Delimiter = histogramSeries.Last_Delimiter;
				histogram_Data.Histogram_Color_Index = num2++;
				if (histogram_Data.X_Min < PlotState.X_Min)
				{
					PlotState.X_Min = histogram_Data.X_Min;
				}
				if (histogram_Data.X_Max > PlotState.X_Max)
				{
					PlotState.X_Max = histogram_Data.X_Max;
				}
				if (histogram_Data.Y_Min < PlotState.Y_Min)
				{
					PlotState.Y_Min = histogram_Data.Y_Min;
				}
				if (histogram_Data.Y_Max > PlotState.Y_Max)
				{
					PlotState.Y_Max = histogram_Data.Y_Max;
				}
				PlotState.HistogramList.Add(histogram_Data);
				if (num2 == 6)
				{
					num2 = 0;
				}
				num++;
			}
			else if (Last_Delimiter == "******Start")
			{
				Annotation_State annotation = GetAnnotation(BsvReader);
				if (annotation.Annotation.Annotation_strings.Count > 0)
				{
					PlotState.Annotations.Add(annotation.Annotation);
				}
			}
		}
		return true;
	}

	private bool LoadData()
	{
		string[] commandLineArgs = Environment.GetCommandLineArgs();
		bool result = false;
		try
		{
			PlotState.Test_Type = commandLineArgs[1];
			PlotState.Visibility = commandLineArgs[2];
			PlotState.File_Name = commandLineArgs[3];
			PlotState.OutPut_File_Name = commandLineArgs[4];
		}
		catch
		{
			Console.WriteLine("GNSS_Plot: Invalid Command Line.");
		}
		if (File.Exists(PlotState.File_Name))
		{
			using StreamReader streamReader = new StreamReader(PlotState.File_Name);
			PlotState.X_Min = 1E+20;
			PlotState.X_Max = -1E+20;
			PlotState.Y_Min = 1E+20;
			PlotState.Y_Max = -1E+20;
			BsvReader = new BsvReader(streamReader, hasHeaders: true);
			if (PlotState.Test_Type == "-B" || PlotState.Test_Type == "-b" || PlotState.Test_Type == "-C" || PlotState.Test_Type == "-c")
			{
				string last_Delimiter = BsvReader.Get_Basic_Plot_Headers(streamReader);
				PlotState.Plot_Title = BsvReader.GetPlotTitle();
				PlotState.Plot_X_Label = BsvReader.GetPlot_X_Label();
				PlotState.Plot_Y_Label = BsvReader.GetPlot_Y_Label();
				PlotState.Plot_Constellation = BsvReader.GetPlot_Constellation();
				result = Process_Basic_Plot(BsvReader, last_Delimiter);
			}
			else if (PlotState.Test_Type == "-W" || PlotState.Test_Type == "-w")
			{
				List<string> list = BsvReader.ReadNextLine();
				if (list.Count >= 1)
				{
					PlotState.Engine = list[0];
					if (list[0] == "Gen7")
					{
						PlotState.Engine = list[0];
					}
					else if (list[0] == "Gen8_ADCIQ")
					{
						PlotState.OutPut_File_Name += ".png";
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_ADCIQ_Plot(BsvReader);
					}
					else if (list[0] == "Gen8")
					{
						PlotState.OutPut_File_Name += ".png";
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_WBIQ_Plot(BsvReader, plotMTJ: false);
					}
					else if (list[0] == "9999 9999")
					{
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_WBIQ_Plot(BsvReader, plotMTJ: false);
					}
				}
				else
				{
					Console.WriteLine("GNSS_Plot: Invalid WBIQ Plot File.");
				}
			}
			else if (PlotState.Test_Type == "-WM" || PlotState.Test_Type == "-wm")
			{
				List<string> list2 = BsvReader.ReadNextLine();
				if (list2.Count >= 1)
				{
					PlotState.Engine = list2[0];
					if (list2[0] == "Gen7")
					{
						PlotState.Engine = list2[0];
					}
					else if (list2[0] == "Gen8_ADCIQ")
					{
						PlotState.OutPut_File_Name += ".png";
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_ADCIQ_Plot(BsvReader);
					}
					else if (list2[0] == "Gen8")
					{
						PlotState.OutPut_File_Name += ".png";
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_WBIQ_Plot(BsvReader, plotMTJ: true);
					}
					else if (list2[0] == "9999 9999")
					{
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_WBIQ_Plot(BsvReader, plotMTJ: true);
					}
				}
				else
				{
					Console.WriteLine("GNSS_Plot: Invalid WBIQ Plot File.");
				}
			}
			else if (PlotState.Test_Type == "-N" || PlotState.Test_Type == "-n")
			{
				result = false;
			}
			else if (PlotState.Test_Type == "-F" || PlotState.Test_Type == "-f")
			{
				List<string> list3 = BsvReader.ReadNextLine();
				if (list3.Count >= 1)
				{
					PlotState.Engine = list3[0];
					if (list3[0] == "Gen8")
					{
						PlotState.OutPut_File_Name += ".png";
						PlotState.Plot_Title = PlotState.File_Name;
						result = Process_Gen8_FoldedSpec_Plot(BsvReader);
					}
				}
			}
			else
			{
				result = false;
				Console.WriteLine("GNSS_Plot: Unknown Plot Type.");
			}
		}
		else
		{
			result = false;
			Console.WriteLine("GNSS_Plot: Couldn't Open Data File.");
		}
		return result;
	}

	private void InitializeChart()
	{
		ChartArea chartArea = new ChartArea();
		chartArea.AxisX.MajorGrid.LineColor = Color.LightGray;
		chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
		chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 8f);
		chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 8f);
		if (PlotState.X_Min == PlotState.X_Max)
		{
			PlotState.X_Min -= PlotState.X_Min * 0.1 * (double)Math.Sign(PlotState.X_Min);
			PlotState.X_Max += PlotState.X_Max * 0.1 * (double)Math.Sign(PlotState.X_Max);
		}
		if (PlotState.Y_Min == PlotState.Y_Max)
		{
			PlotState.Y_Min -= PlotState.Y_Min * 0.1 * (double)Math.Sign(PlotState.Y_Min);
			PlotState.Y_Max += PlotState.Y_Max * 0.1 * (double)Math.Sign(PlotState.Y_Max);
		}
		if (PlotState.X_Min >= 1.0 || PlotState.X_Min <= -1.0)
		{
			long num = (long)(PlotState.X_Min * 100.0);
			chartArea.AxisX.Minimum = (double)num / 100.0;
		}
		else
		{
			chartArea.AxisX.Minimum = PlotState.X_Min;
		}
		if (PlotState.X_Max >= 1.0 || PlotState.X_Max <= -1.0)
		{
			long num2 = (long)(PlotState.X_Max * 100.0);
			chartArea.AxisX.Maximum = (double)num2 / 100.0;
		}
		else
		{
			chartArea.AxisX.Maximum = PlotState.X_Max;
		}
		if (PlotState.Y_Min >= 1.0 || PlotState.Y_Min <= -1.0)
		{
			long num3 = (long)(PlotState.Y_Min * 100.0);
			chartArea.AxisY.Minimum = (double)num3 / 100.0;
		}
		else
		{
			chartArea.AxisY.Minimum = PlotState.Y_Min;
		}
		if (PlotState.Annotations.Count > 0)
		{
			double num4 = (PlotState.Y_Max - PlotState.Y_Min) / 10.0;
			if (PlotState.Y_Max >= 1.0 || PlotState.Y_Max <= -1.0)
			{
				long num5 = (long)((PlotState.Y_Max + num4) * 100.0 + 1.0);
				chartArea.AxisY.Maximum = (double)num5 / 100.0;
			}
			else
			{
				chartArea.AxisY.Maximum = PlotState.Y_Max + num4;
			}
		}
		else if (PlotState.Y_Max >= 1.0 || PlotState.Y_Max <= -1.0)
		{
			long num6 = (long)(PlotState.Y_Max * 100.0);
			chartArea.AxisY.Maximum = (double)num6 / 100.0;
		}
		else
		{
			chartArea.AxisY.Maximum = PlotState.Y_Max;
		}
		chartArea.BackColor = Color.FromArgb(125, 128, 128);
		chart1.ChartAreas.Add(chartArea);
	}

	private void AddPolyLine(int PolyLineIndex)
	{
		string polyLine_Name = PlotState.PolyLine[PolyLineIndex].PolyLine_Name;
		Series series = new Series();
		series.Name = polyLine_Name;
		series.LegendText = "";
		series.ChartType = SeriesChartType.Line;
		series.XValueType = ChartValueType.Double;
		series.YAxisType = AxisType.Primary;
		series.YValueType = ChartValueType.Double;
		chart1.Series.Add(series);
		int polyLine_Color_Index = PlotState.PolyLine[PolyLineIndex].PolyLine_Color_Index;
		List<int> list = Get_Color(polyLine_Color_Index);
		int red = list[0];
		int green = list[1];
		int blue = list[2];
		chart1.Series[polyLine_Name].Color = Color.FromArgb(red, green, blue);
		if (PlotState.PolyLine[PolyLineIndex].DashStyle)
		{
			chart1.Series[polyLine_Name].BorderDashStyle = ChartDashStyle.Dash;
		}
		List<double> xVals = PlotState.PolyLine[PolyLineIndex].xVals;
		List<double> yVals = PlotState.PolyLine[PolyLineIndex].yVals;
		chart1.Series[polyLine_Name].Points.DataBindXY(xVals, yVals);
		if (PlotState.PolyLine[PolyLineIndex].Insert_Null_Point)
		{
			chart1.Series[polyLine_Name].Points[0].IsEmpty = true;
		}
	}

	private void AddHistogram(int HistogramIndex)
	{
		string histogram_Name = PlotState.HistogramList[HistogramIndex].Histogram_Name;
		Series series = new Series();
		series.Name = histogram_Name;
		series.LegendText = "";
		series.ChartType = SeriesChartType.Area;
		series.XValueType = ChartValueType.Double;
		series.YAxisType = AxisType.Primary;
		series.YValueType = ChartValueType.Double;
		chart1.Series.Add(series);
		int histogram_Color_Index = PlotState.HistogramList[HistogramIndex].Histogram_Color_Index;
		List<int> list = Get_Color(histogram_Color_Index);
		int red = list[0];
		int green = list[1];
		int blue = list[2];
		chart1.Series[histogram_Name].Color = Color.FromArgb(red, green, blue);
		List<double> xVals = PlotState.HistogramList[HistogramIndex].xVals;
		List<double> yVals = PlotState.HistogramList[HistogramIndex].yVals;
		chart1.Series[histogram_Name].Points.DataBindXY(xVals, yVals);
	}

	private void Add_Annotation(Plot_State_s Plot_State, int Annotation_Index)
	{
		if (Plot_State.Annotations.Count > Annotation_Index)
		{
			Annotation annotation = Plot_State.Annotations[Annotation_Index];
			int num = 0;
			string name = "Annotation";
			Series series = new Series();
			series.Name = name;
			series.ChartType = SeriesChartType.Point;
			series.XValueType = ChartValueType.Double;
			series.YAxisType = AxisType.Primary;
			series.YValueType = ChartValueType.Double;
			chart1.Series.Add(series);
			List<double> list = new List<double>();
			List<double> list2 = new List<double>();
			double item = Plot_State.X_Min + (Plot_State.X_Max - Plot_State.X_Min) / 4.0;
			double item2 = Plot_State.Y_Max + (Plot_State.Y_Max - Plot_State.Y_Min) / 10.0;
			list.Add(item);
			list2.Add(item2);
			chart1.Series[name].Points.DataBindXY(list, list2);
			string text = annotation.Annotation_strings[0];
			num = 1;
			for (int count = annotation.Annotation_strings.Count; num < count; num++)
			{
				text = text + "\n" + annotation.Annotation_strings[num];
			}
			text += "\n";
			RectangleAnnotation rectangleAnnotation = new RectangleAnnotation();
			rectangleAnnotation.Text = text;
			rectangleAnnotation.IsMultiline = true;
			rectangleAnnotation.AnchorDataPoint = chart1.Series[name].Points[0];
			rectangleAnnotation.Visible = true;
			chart1.Annotations.Add(rectangleAnnotation);
		}
	}

	private void Add_Jammers()
	{
		if (PlotState.Jammer_PolyLines.Count <= 0)
		{
			return;
		}
		string polyLine_Name = PlotState.Jammer_PolyLines[0].PolyLine_Name;
		Series series = new Series();
		series.Name = polyLine_Name;
		series.LegendText = "";
		series.ChartType = SeriesChartType.Line;
		series.XValueType = ChartValueType.Double;
		series.YAxisType = AxisType.Primary;
		series.YValueType = ChartValueType.Double;
		chart1.Series.Add(series);
		int polyLine_Color_Index = PlotState.Jammer_PolyLines[0].PolyLine_Color_Index;
		List<int> list = Get_Color(polyLine_Color_Index);
		int red = list[0];
		int green = list[1];
		int blue = list[2];
		chart1.Series[polyLine_Name].Color = Color.FromArgb(red, green, blue);
		int count = PlotState.Jammer_PolyLines.Count;
		int i = 0;
		List<double> list2 = new List<double>();
		List<double> list3 = new List<double>();
		Point point = default(Point);
		point.X = 0;
		point.Y = 0;
		List<int> list4 = new List<int>();
		int num = 0;
		for (; i < count; i++)
		{
			list2.Add(0.0);
			list3.Add(0.0);
			list4.Add(num);
			num++;
			for (int j = 0; j < PlotState.Jammer_PolyLines[i].xVals.Count; j++)
			{
				list2.Add(PlotState.Jammer_PolyLines[i].xVals[j]);
				list3.Add(PlotState.Jammer_PolyLines[i].yVals[j]);
				num++;
			}
		}
		chart1.Series[polyLine_Name].Points.DataBindXY(list2, list3);
		int count2 = list4.Count;
		for (num = 0; num < count2; num++)
		{
			int index = list4[num];
			chart1.Series[polyLine_Name].Points[index].IsEmpty = true;
		}
	}

	private void AddPointList(int PointList_Index)
	{
		string pointList_Name = PlotState.PointList[PointList_Index].PointList_Name;
		Series series = new Series();
		series.Name = pointList_Name;
		series.LegendText = "";
		series.ChartType = SeriesChartType.Point;
		series.XValueType = ChartValueType.Double;
		series.YAxisType = AxisType.Primary;
		series.YValueType = ChartValueType.Double;
		chart1.Series.Add(series);
		int pointList_Color_Index = PlotState.PointList[PointList_Index].PointList_Color_Index;
		List<int> list = Get_Color(pointList_Color_Index);
		int red = list[0];
		int green = list[1];
		int blue = list[2];
		chart1.Series[pointList_Name].Color = Color.FromArgb(red, green, blue);
		chart1.Series[pointList_Name].MarkerStyle = PlotState.PointList[PointList_Index].Marker;
		chart1.Series[pointList_Name].MarkerSize = 10;
		List<double> xVals = PlotState.PointList[PointList_Index].xVals;
		List<double> yVals = PlotState.PointList[PointList_Index].yVals;
		chart1.Series[pointList_Name].Points.DataBindXY(xVals, yVals);
	}

	private void AddHilightBox(int HilightBoxIndex)
	{
		string hilightBox_Name = PlotState.HilightBoxList[HilightBoxIndex].HilightBox_Name;
		Series series = new Series();
		series.Name = hilightBox_Name;
		series.LegendText = "";
		series.ChartType = SeriesChartType.Area;
		series.XValueType = ChartValueType.Double;
		series.YAxisType = AxisType.Primary;
		series.YValueType = ChartValueType.Double;
		chart1.Series.Add(series);
		chart1.Series[hilightBox_Name].Color = PlotState.HilightBoxList[HilightBoxIndex].HilightBox_Color;
		List<double> list = new List<double>();
		list.Add(PlotState.X_Min);
		list.Add(PlotState.HilightBoxList[HilightBoxIndex].X_Min);
		list.Add(PlotState.HilightBoxList[HilightBoxIndex].X_Min);
		list.Add(PlotState.HilightBoxList[HilightBoxIndex].X_Max);
		list.Add(PlotState.HilightBoxList[HilightBoxIndex].X_Max);
		list.Add(PlotState.X_Max);
		double item = PlotState.Y_Max + (PlotState.Y_Max - PlotState.Y_Min) / 10.0;
		List<double> list2 = new List<double>();
		list2.Add(item);
		list2.Add(item);
		list2.Add(PlotState.Y_Min);
		list2.Add(PlotState.Y_Min);
		list2.Add(item);
		list2.Add(item);
		chart1.Series[hilightBox_Name].Points.DataBindXY(list, list2);
	}

	private void Add_Chart_Elements(Plot_State_s Plot_State)
	{
		int count = PlotState.HilightBoxList.Count;
		for (int i = 0; i < count; i++)
		{
			AddHilightBox(i);
		}
		int count2 = PlotState.PolyLine.Count;
		for (int j = 0; j < count2; j++)
		{
			AddPolyLine(j);
		}
		int count3 = PlotState.PointList.Count;
		for (int k = 0; k < count3; k++)
		{
			AddPointList(k);
		}
		int count4 = PlotState.Jammer_PolyLines.Count;
		if (count4 > 0)
		{
			Add_Jammers();
		}
		int count5 = PlotState.HistogramList.Count;
		for (int l = 0; l < count5; l++)
		{
			AddHistogram(l);
		}
		int count6 = PlotState.Annotations.Count;
		for (int m = 0; m < count6; m++)
		{
			Add_Annotation(Plot_State, m);
		}
	}

	private List<int> Get_Color(int Color_Index)
	{
		int[,] array = new int[7, 3]
		{
			{ 0, 0, 255 },
			{ 255, 0, 0 },
			{ 0, 255, 0 },
			{ 255, 0, 255 },
			{ 0, 0, 0 },
			{ 0, 255, 255 },
			{ 255, 255, 255 }
		};
		List<int> list = new List<int>();
		list.Add(array[Color_Index, 0]);
		list.Add(array[Color_Index, 1]);
		list.Add(array[Color_Index, 2]);
		return list;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		System.Windows.Forms.DataVisualization.Charting.Legend legend = new System.Windows.Forms.DataVisualization.Charting.Legend();
		System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WindowsFormsApplication2.Form1));
		this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
		((System.ComponentModel.ISupportInitialize)this.chart1).BeginInit();
		base.SuspendLayout();
		this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
		legend.Name = "Legend1";
		this.chart1.Legends.Add(legend);
		this.chart1.Location = new System.Drawing.Point(0, 0);
		this.chart1.Name = "chart1";
		this.chart1.Size = new System.Drawing.Size(1008, 730);
		this.chart1.TabIndex = 0;
		this.chart1.Text = "chart1";
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(1008, 730);
		base.Controls.Add(this.chart1);
		base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
		base.Name = "Form1";
		this.Text = "GNSS_Plot";
		base.Load += new System.EventHandler(Form1_Load);
		((System.ComponentModel.ISupportInitialize)this.chart1).EndInit();
		base.ResumeLayout(false);
	}
}
