diff --git a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs index d31bbded99f69f144b4c5fa3816f4f263205612a..36ea70b5635c7be4bc09436eb3807337cefa232c 100644 --- a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs @@ -482,7 +482,28 @@ namespace TUGraz.VectoCore.InputData.Reader return true; } - public abstract IEnumerable<DrivingCycleData.DrivingCycleEntry> Parse(DataTable table, bool crossWindRequired); + protected static bool CheckColumnsPredicatedOnAnotherMissing(DataColumnCollection header, string[] cols, string[] others, bool throwExceptions) + { + var otherCount = header.Cast<DataColumn>().Count(other => others.Select(x => x.ToLowerInvariant()) + .Contains(other.ColumnName.ToLowerInvariant())); + + if (otherCount < others.Count()) { + var headerStr = header.Cast<DataColumn>().Select(col => col.ColumnName.ToLowerInvariant()).ToArray(); + var diff = cols.Select(x => x.ToLowerInvariant()).Except(headerStr).ToList(); + + if (diff.Any()) { + if (throwExceptions) { + throw new VectoException("Column(s) required: " + string.Join(", ", diff)); + } + + return false; + } + } + + return true; + } + + public abstract IEnumerable<DrivingCycleData.DrivingCycleEntry> Parse(DataTable table, bool crossWindRequired); } private class DistanceBasedCycleDataParser : AbstractCycleDataParser @@ -889,7 +910,6 @@ namespace TUGraz.VectoCore.InputData.Reader Fields.CombustionEngineTorque, Fields.COMassFlow, Fields.NOxMassFlow, - Fields.THCMassFlow, Fields.CO2MassFlow, Fields.PMNumberFlow }; @@ -926,7 +946,13 @@ namespace TUGraz.VectoCore.InputData.Reader header, new[] { Fields.CH4MassFlow, Fields.NMHCMassFlow }, FuelTypeHelper.GetLabelsForNonGaseous("fc_"), - throwExceptions); + throwExceptions) + && CheckColumnsPredicatedOnAnotherMissing( + header, + new[] { Fields.THCMassFlow }, + new[] { Fields.CH4MassFlow, Fields.NMHCMassFlow }, + throwExceptions + ); } } diff --git a/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs b/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs index 32726cc8eec975475294bc1ee38770b9697a56b2..2f88661ba08d3d36d92e0700c6a43e4c7ca6456f 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs @@ -215,8 +215,8 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation // Verification test simulation TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_DIESEL CI>,<tq_eng>,<CO>,<NOx>,<THC>,<CO2>,<PN>", CycleType.VTP), TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_DIESEL CI>,<gear>,<tq_eng>,<CO>,<NOx>,<THC>,<CO2>,<PN>", CycleType.VTP), - TestCase("<t>,<v>,<n_eng>,<Pel_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_DIESEL CI>,<gear>,<tq_eng>,<CH4>,<CO>,<NMHC>,<NOx>,<THC>,<CO2>,<PN>", CycleType.VTP), - TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_NG CI>,<tq_eng>,<CH4>,<CO>,<NMHC>,<NOx>,<THC>,<CO2>,<PN>", CycleType.VTP), + TestCase("<t>,<v>,<n_eng>,<Pel_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_DIESEL CI>,<gear>,<tq_eng>,<CH4>,<CO>,<NMHC>,<NOx>,<CO2>,<PN>", CycleType.VTP), + TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_NG CI>,<tq_eng>,<CH4>,<CO>,<NMHC>,<NOx>,<CO2>,<PN>", CycleType.VTP), TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_NG CI>,<fc_DIESEL CI>,<tq_eng>,<CH4>,<CO>,<NMHC>,<NOx>,<THC>,<CO2>,<PN>", CycleType.VTP) ] public void DrivingCycle_AutoDetect(string cycle, CycleType type) @@ -244,6 +244,8 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation CycleType.VTP), TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_NG CI>,<tq_eng>,<CH4>,<NMHC>,<CO>,<NOx>,<THC>,<CO2>", CycleType.VTP), + TestCase("<t>,<v>,<n_eng>,<n_fan>,<tq_left>,<tq_right>,<n_wh_left>,<n_wh_right>,<fc_NG CI>,<tq_eng>,<CO>,<NOx>,<CO2>,<PN>", + CycleType.VTP), ] public void DrivingCycle_AutoDetect_Exception(string cycle, CycleType type) {