More work on TLG database and table handling.
This commit is contained in:
parent
5e62523166
commit
dd36e804a4
@ -1,7 +1,4 @@
|
|||||||
using System;
|
namespace mfs {
|
||||||
|
|
||||||
namespace mfs
|
|
||||||
{
|
|
||||||
internal class Program {
|
internal class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
tlg_database testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat");
|
tlg_database testdb = new("aero\\Master Files\\Stratolaunch_CA_AllTables_Master_RevL.dat");
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
public Dictionary<string, double> reference_values = new();
|
public Dictionary<string, double> reference_values = new();
|
||||||
public List<tlg_table> tables = new();
|
public List<tlg_table> tables = new();
|
||||||
|
public List<string> independents = new();
|
||||||
|
public List<string> dependents = new();
|
||||||
|
|
||||||
public tlg_database(string path) {
|
public tlg_database(string path) {
|
||||||
readfile(path);
|
readfile(path);
|
||||||
@ -37,29 +39,31 @@
|
|||||||
currentblock = block_types.NONE;
|
currentblock = block_types.NONE;
|
||||||
|
|
||||||
} else {
|
} 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) {
|
switch (currentblock) {
|
||||||
|
|
||||||
case block_types.NONE:
|
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)) {
|
if (line.StartsWith("INCLUDE,", StringComparison.InvariantCultureIgnoreCase)) {
|
||||||
|
// recursively call the function to handle include lines
|
||||||
string includepath = line[8..].Trim();
|
string includepath = line[8..].Trim();
|
||||||
if (File.Exists(includepath)) {
|
if (File.Exists(includepath)) {
|
||||||
readfile(includepath);
|
readfile(includepath);
|
||||||
@ -70,7 +74,8 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case block_types.REFERENCE_DATA:
|
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) {
|
if (splitline.Length != 2) {
|
||||||
throw new Exception("Syntax error in reference parameter " + splitline[0]);
|
throw new Exception("Syntax error in reference parameter " + splitline[0]);
|
||||||
} else {
|
} else {
|
||||||
@ -80,14 +85,14 @@
|
|||||||
} else {
|
} else {
|
||||||
throw new Exception("Could not parse reference parameter " + splitline[0]);
|
throw new Exception("Could not parse reference parameter " + splitline[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case block_types.BASIC_TABLE:
|
case block_types.BASIC_TABLE:
|
||||||
case block_types.INCREMENT_TABLE:
|
case block_types.INCREMENT_TABLE:
|
||||||
case block_types.DERIVATIVE_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));
|
tables.Add(new tlg_table(fs));
|
||||||
currentblock = block_types.NONE;
|
currentblock = block_types.NONE;
|
||||||
break;
|
break;
|
||||||
@ -95,6 +100,7 @@
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentblock != block_types.NONE) {
|
if (currentblock != block_types.NONE) {
|
||||||
|
@ -7,13 +7,93 @@
|
|||||||
}
|
}
|
||||||
public string name = "";
|
public string name = "";
|
||||||
public extrap_type extrap_method = extrap_type.EXTRAP_LINEAR;
|
public extrap_type extrap_method = extrap_type.EXTRAP_LINEAR;
|
||||||
public string[] indeps = { };
|
public string[] indeps;
|
||||||
public string[] deps = { };
|
public string[] deps;
|
||||||
public string[] multiply_output_by = { };
|
public string[] multiply_output_by;
|
||||||
|
public double[] multiply_output_by_num;
|
||||||
|
public bool scalar_multiplier;
|
||||||
public bool regular;
|
public bool regular;
|
||||||
|
|
||||||
public tlg_table(StreamReader fs) {
|
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() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user