WIP on TLG file parsing
This commit is contained in:
parent
290a5e6b64
commit
5e62523166
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<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);
|
||||
}
|
||||
|
||||
@ -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:
|
22
mfs/tlg_table.cs
Normal file
22
mfs/tlg_table.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user