WIP on TLG file parsing

This commit is contained in:
moosecrab 2022-05-29 06:05:22 -07:00
parent 290a5e6b64
commit 5e62523166
3 changed files with 43 additions and 13 deletions

View File

@ -4,7 +4,7 @@ namespace mfs
{ {
internal class Program { internal class Program {
static void Main(string[] args) { 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");
} }
} }
} }

View File

@ -1,17 +1,19 @@
namespace mfs { namespace mfs {
internal class TLGDatabase { internal class tlg_database {
private enum block_types { private enum block_types {
NONE, NONE,
REFERENCE_DATA, REFERENCE_DATA,
BASIC_TABLE, BASIC_TABLE,
INCREMENT_TABLE, INCREMENT_TABLE,
DERIVATIVE_TABLE, DERIVATIVE_TABLE,
} ; };
private block_types currentblock = block_types.NONE; private block_types currentblock = block_types.NONE;
public Dictionary<string, double> reference_values = new Dictionary<string, double>(); public Dictionary<string, double> reference_values = new();
public List<tlg_table> tables = new();
public TLGDatabase(string path) { public tlg_database(string path) {
readfile(path); readfile(path);
} }
@ -21,13 +23,17 @@
while (!fs.EndOfStream) { while (!fs.EndOfStream) {
line = fs.ReadLine(); line = fs.ReadLine();
line = line.Trim();
if (line == null) { if (line == null) {
line = ""; line = "";
} }
if (string.IsNullOrWhiteSpace(line) || (line[0] == '%')) { if (string.IsNullOrWhiteSpace(line) || (line[0] == '%')) {
// lines starting with % are comment lines and ignored // lines starting with % are comment lines and ignored
// blank or whitespace lines also ignored // blank or whitespace lines also ignored
} else if (line == "END BLOCK") { } else if (line == "END BLOCK") {
// end block resets the parser
currentblock = block_types.NONE; currentblock = block_types.NONE;
} else { } else {
@ -35,23 +41,26 @@
case block_types.NONE: case block_types.NONE:
// look for data blocks, or an include line // look for data blocks, or an include line
switch (line) { switch (line.ToUpperInvariant()) {
case "BEGIN REFERENCE DATA BLOCK": case "BEGIN REFERENCE DATA BLOCK":
currentblock = block_types.REFERENCE_DATA; currentblock = block_types.REFERENCE_DATA;
break; break;
case "BEGIN BASIC TABLE BLOCK": case "BEGIN BASIC TABLE BLOCK":
currentblock = block_types.BASIC_TABLE; currentblock = block_types.BASIC_TABLE;
break; break;
case "BEGIN INCREMENT TABLE BLOCK": case "BEGIN INCREMENT TABLE BLOCK":
currentblock = block_types.INCREMENT_TABLE; currentblock = block_types.INCREMENT_TABLE;
break; break;
case "BEGIN DERIVATIVE TABLE BLOCK": case "BEGIN DERIVATIVE TABLE BLOCK":
currentblock = block_types.DERIVATIVE_TABLE; currentblock = block_types.DERIVATIVE_TABLE;
break; break;
} }
if (line.StartsWith("INCLUDE,", StringComparison.InvariantCultureIgnoreCase)) { if (line.StartsWith("INCLUDE,", StringComparison.InvariantCultureIgnoreCase)) {
string includepath = line.Substring(8).Trim(); string includepath = line[8..].Trim();
if (File.Exists(includepath)) { if (File.Exists(includepath)) {
readfile(includepath); readfile(includepath);
} else { } else {
@ -63,7 +72,7 @@
case block_types.REFERENCE_DATA: case block_types.REFERENCE_DATA:
string[] splitline = line.Split(',', StringSplitOptions.TrimEntries & StringSplitOptions.RemoveEmptyEntries); string[] splitline = line.Split(',', StringSplitOptions.TrimEntries & StringSplitOptions.RemoveEmptyEntries);
if (splitline.Length != 2) { if (splitline.Length != 2) {
throw new Exception("Error parsing reference parameter " + splitline[0]); throw new Exception("Syntax error in reference parameter " + splitline[0]);
} else { } else {
double val = double.NaN; double val = double.NaN;
if (double.TryParse(splitline[1], out val)) { if (double.TryParse(splitline[1], out val)) {
@ -76,12 +85,11 @@
break; break;
case block_types.BASIC_TABLE: case block_types.BASIC_TABLE:
break;
case block_types.INCREMENT_TABLE: case block_types.INCREMENT_TABLE:
break;
case block_types.DERIVATIVE_TABLE: 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; break;
default: default:

22
mfs/tlg_table.cs Normal file
View File

@ -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();
}
}
}