diff --git a/mfs/Program.cs b/mfs/Program.cs index c5e2e2b..7bb0bee 100644 --- a/mfs/Program.cs +++ b/mfs/Program.cs @@ -4,7 +4,7 @@ namespace mfs { internal class Program { static void Main(string[] args) { - TLGDatabase testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat"); + tlg_database testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat"); } } } \ No newline at end of file diff --git a/mfs/TLGDatabase.cs b/mfs/tlg_database.cs similarity index 83% rename from mfs/TLGDatabase.cs rename to mfs/tlg_database.cs index 1b2808f..e97f086 100644 --- a/mfs/TLGDatabase.cs +++ b/mfs/tlg_database.cs @@ -1,17 +1,19 @@ namespace mfs { - internal class TLGDatabase { + internal class tlg_database { + private enum block_types { NONE, REFERENCE_DATA, BASIC_TABLE, INCREMENT_TABLE, DERIVATIVE_TABLE, - } ; + }; private block_types currentblock = block_types.NONE; - public Dictionary reference_values = new Dictionary(); + public Dictionary reference_values = new(); + public List tables = new(); - public TLGDatabase(string path) { + public tlg_database(string path) { readfile(path); } @@ -21,13 +23,17 @@ while (!fs.EndOfStream) { line = fs.ReadLine(); + line = line.Trim(); + if (line == null) { line = ""; } if (string.IsNullOrWhiteSpace(line) || (line[0] == '%')) { // lines starting with % are comment lines and ignored // blank or whitespace lines also ignored + } else if (line == "END BLOCK") { + // end block resets the parser currentblock = block_types.NONE; } else { @@ -35,23 +41,26 @@ case block_types.NONE: // look for data blocks, or an include line - switch (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)) { - string includepath = line.Substring(8).Trim(); + string includepath = line[8..].Trim(); if (File.Exists(includepath)) { readfile(includepath); } else { @@ -63,7 +72,7 @@ case block_types.REFERENCE_DATA: string[] splitline = line.Split(',', StringSplitOptions.TrimEntries & StringSplitOptions.RemoveEmptyEntries); if (splitline.Length != 2) { - throw new Exception("Error parsing reference parameter " + splitline[0]); + throw new Exception("Syntax error in reference parameter " + splitline[0]); } else { double val = double.NaN; if (double.TryParse(splitline[1], out val)) { @@ -71,17 +80,16 @@ } else { throw new Exception("Could not parse reference parameter " + splitline[0]); } - + } break; case block_types.BASIC_TABLE: - break; - case block_types.INCREMENT_TABLE: - break; - case block_types.DERIVATIVE_TABLE: + // all table types handled the same, per TLG code + tables.Add(new tlg_table(fs)); + currentblock = block_types.NONE; break; default: diff --git a/mfs/tlg_table.cs b/mfs/tlg_table.cs new file mode 100644 index 0000000..fb8c210 --- /dev/null +++ b/mfs/tlg_table.cs @@ -0,0 +1,22 @@ +namespace mfs { + internal class tlg_table { + public enum extrap_type { + EXTRAP_LINEAR, + EXTRAP_NONE, + EXTRAP_NEAREST + } + public string name = ""; + public extrap_type extrap_method = extrap_type.EXTRAP_LINEAR; + public string[] indeps = { }; + public string[] deps = { }; + public string[] multiply_output_by = { }; + public bool regular; + + public tlg_table(StreamReader fs) { + string line = fs.ReadLine(); + + } + } +} + +