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 {
|
||||
static void Main(string[] args) {
|
||||
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 List<tlg_table> tables = new();
|
||||
public List<string> independents = new();
|
||||
public List<string> dependents = new();
|
||||
|
||||
public tlg_database(string path) {
|
||||
readfile(path);
|
||||
@ -37,14 +39,12 @@
|
||||
currentblock = block_types.NONE;
|
||||
|
||||
} else {
|
||||
switch (currentblock) {
|
||||
|
||||
case block_types.NONE:
|
||||
// look for data blocks, or an include line
|
||||
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;
|
||||
break;
|
||||
continue;
|
||||
|
||||
case "BEGIN BASIC TABLE BLOCK":
|
||||
currentblock = block_types.BASIC_TABLE;
|
||||
@ -59,7 +59,11 @@
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
switch (currentblock) {
|
||||
case block_types.NONE:
|
||||
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 {
|
||||
@ -87,7 +92,7 @@
|
||||
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) {
|
||||
|
@ -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) {
|
||||
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