diff --git a/mfs/Program.cs b/mfs/Program.cs index 7bb0bee..01f8d78 100644 --- a/mfs/Program.cs +++ b/mfs/Program.cs @@ -1,7 +1,4 @@ -using System; - -namespace mfs -{ +namespace mfs { internal class Program { static void Main(string[] args) { tlg_database testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat"); diff --git a/mfs/tlg_database.cs b/mfs/tlg_database.cs index e97f086..0b364cf 100644 --- a/mfs/tlg_database.cs +++ b/mfs/tlg_database.cs @@ -12,6 +12,8 @@ public Dictionary reference_values = new(); public List tables = new(); + public List independents = new(); + public List dependents = new(); public tlg_database(string path) { readfile(path); @@ -37,29 +39,31 @@ currentblock = block_types.NONE; } else { + if (currentblock == block_types.NONE) { + // switch modes if we find a data block + switch (line.ToUpperInvariant()) { + case "BEGIN REFERENCE DATA BLOCK": + currentblock = block_types.REFERENCE_DATA; + continue; + + case "BEGIN BASIC TABLE BLOCK": + currentblock = block_types.BASIC_TABLE; + break; + + case "BEGIN INCREMENT TABLE BLOCK": + currentblock = block_types.INCREMENT_TABLE; + break; + + case "BEGIN DERIVATIVE TABLE BLOCK": + currentblock = block_types.DERIVATIVE_TABLE; + break; + } + + } switch (currentblock) { - case block_types.NONE: - // look for data blocks, or an include line - switch (line.ToUpperInvariant()) { - case "BEGIN REFERENCE DATA BLOCK": - currentblock = block_types.REFERENCE_DATA; - break; - - case "BEGIN BASIC TABLE BLOCK": - currentblock = block_types.BASIC_TABLE; - break; - - case "BEGIN INCREMENT TABLE BLOCK": - currentblock = block_types.INCREMENT_TABLE; - break; - - case "BEGIN DERIVATIVE TABLE BLOCK": - currentblock = block_types.DERIVATIVE_TABLE; - break; - } - if (line.StartsWith("INCLUDE,", StringComparison.InvariantCultureIgnoreCase)) { + // recursively call the function to handle include lines string includepath = line[8..].Trim(); if (File.Exists(includepath)) { readfile(includepath); @@ -70,7 +74,8 @@ break; case block_types.REFERENCE_DATA: - string[] splitline = line.Split(',', StringSplitOptions.TrimEntries & StringSplitOptions.RemoveEmptyEntries); + // reference data is assumed to be only 2 parts, name and value + string[] splitline = line.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (splitline.Length != 2) { throw new Exception("Syntax error in reference parameter " + splitline[0]); } else { @@ -80,14 +85,14 @@ } else { throw new Exception("Could not parse reference parameter " + splitline[0]); } - + } break; case block_types.BASIC_TABLE: case block_types.INCREMENT_TABLE: case block_types.DERIVATIVE_TABLE: - // all table types handled the same, per TLG code + // all 3 block types handled the same per TLG's code tables.Add(new tlg_table(fs)); currentblock = block_types.NONE; break; @@ -95,6 +100,7 @@ default: break; } + } } if (currentblock != block_types.NONE) { diff --git a/mfs/tlg_table.cs b/mfs/tlg_table.cs index fb8c210..3e4acca 100644 --- a/mfs/tlg_table.cs +++ b/mfs/tlg_table.cs @@ -7,13 +7,93 @@ } public string name = ""; public extrap_type extrap_method = extrap_type.EXTRAP_LINEAR; - public string[] indeps = { }; - public string[] deps = { }; - public string[] multiply_output_by = { }; + public string[] indeps; + public string[] deps; + public string[] multiply_output_by; + public double[] multiply_output_by_num; + public bool scalar_multiplier; public bool regular; public tlg_table(StreamReader fs) { - string line = fs.ReadLine(); + while (!fs.EndOfStream) { + string line = fs.ReadLine(); + line = line.Trim(); + + if (string.IsNullOrWhiteSpace(line) || (line[0] == '%')) { + // skip blank or whitespace lines + continue; + } + + if (line == "END BLOCK") { + // end block processing on end of block + // turn our data points into a grid first + grid_data(); + return; + } + string[] splitline = line.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + if (splitline.Length < 2) { + throw new Exception("Syntax error at keyword " + splitline[0] + " in file " + fs.ToString()); + } + + switch (splitline[0].ToLowerInvariant()) { + // switch on first keyword of line + case "name": + name = splitline[1]; + break; + + case "extrapolation": + switch (splitline[1].ToLowerInvariant()) { + case "linear": + extrap_method = extrap_type.EXTRAP_LINEAR; + break; + + case "nearest": + extrap_method = extrap_type.EXTRAP_NEAREST; + break; + + case "none": + extrap_method = extrap_type.EXTRAP_NONE; + break; + + default: + throw new Exception("Unknown extrapolation method " + splitline[1]); + } + break; + + case "independents": + indeps = splitline[1..]; + break; + + case "dependents": + deps = splitline[1..]; + break; + + case "multiplyoutputby": + double mult; + multiply_output_by_num = new double[splitline.Length - 1]; + multiply_output_by = new string[splitline.Length - 1]; + + for (int i = 1; i < splitline.Length; i++) { + if (double.TryParse(splitline[i], out mult)) { + // MultiplyOutputBy is a scalar + multiply_output_by_num[i - 1] = mult; + scalar_multiplier = true; + } else { + multiply_output_by[i - 1] = splitline[i]; + scalar_multiplier = false; + } + } + break; + + default: + break; + } + } + + } + + private void grid_data() { } }