/// <summary> /// Swaps the indexes of a line parameter set /// </summary> /// <param name="p"></param> /// <param name="i1"></param> /// <param name="i2"></param> /// <returns></returns> private static LineParameters SwapIndexes(LineParameters p, int i1, int i2) { LineParameters p2 = new LineParameters(); p2.Initialize(); p.MutualImpedance.CopyTo(p2.MutualImpedance, 0); p.SelfImpedance.CopyTo(p2.SelfImpedance, 0); p2.SelfImpedance[i1] = p.SelfImpedance[i2]; p2.SelfImpedance[i2] = p.SelfImpedance[i1]; p2.MutualImpedance[i1] = p.MutualImpedance[i2]; p2.MutualImpedance[i2] = p.MutualImpedance[i1]; return(p2); }
/// <summary> /// Looks for a leika file on the path, and tries to extract the impedance data from it /// </summary> /// <param name="fileName"></param> /// <param name="path"></param> /// <returns></returns> private static LineParameters?GetLeikaData(string fileName, string path, int phases) { try { if (phases < 1 || phases > 3) { Console.WriteLine($"Invalid number of phases for file {fileName}"); return(null); } //get all the report files var files = Directory.GetFiles(path, "*.txt"); //what is this? //TODO: just get the file we need for (int i = 0; i < files.Length; i++) { files[i] = Path.GetFileName(files[i]); } if (files.Contains(fileName + ".txt")) { var lines = File.ReadAllLines(Path.Combine(path, fileName) + ".txt"); for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains("IMPEDANCES AFTER ELIMINATION OF EARTHED CONDUCTORS")) { if (i + 18 > lines.Length) { Console.WriteLine("Was expecting more lines in file"); break; } Impedance zero = new Impedance { Reactance = 0, Resistance = 0 }; LineParameters p = new LineParameters(); //TODO: we should be handling the per phase cases here p.Initialize(); p.SelfImpedance[0] = GetImpedance("1L1", lines[i + 9]); if (phases >= 2) { p.SelfImpedance[1] = GetImpedance("1L2", lines[i + 9]); } else { p.SelfImpedance[1] = zero; } if (phases == 3) { p.SelfImpedance[2] = GetImpedance("1L3", lines[i + 9]); } else { p.SelfImpedance[2] = zero; } if (phases >= 2) { p.MutualImpedance[0] = GetImpedance("1L1-1L2", lines[i + 17]); } else { p.MutualImpedance[0] = zero; } if (phases == 3) { p.MutualImpedance[1] = GetImpedance("1L1-1L3", lines[i + 18]); p.MutualImpedance[2] = GetImpedance("1L2-1L3", lines[i + 18]); } else { p.MutualImpedance[1] = zero; p.MutualImpedance[2] = zero; } return(p); } } } else { Console.WriteLine($"File {fileName}.txt was not found on the leika path"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(null); }