Skip to content

Commit

Permalink
Dry up code in UpdateMeterReporting
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Oct 19, 2020
1 parent 2ac343f commit 4fcf280
Showing 1 changed file with 47 additions and 104 deletions.
151 changes: 47 additions & 104 deletions src/EnergyPlus/OutputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6807,14 +6807,10 @@ void UpdateMeterReporting(EnergyPlusData &state)
int NumAlpha;
int NumNumbers;
int IOStat;
std::string::size_type WildCard;
std::string::size_type TestLen(0);
std::string::size_type varnameLen;
int NumReqMeters;
int NumReqMeterFOs;
int Meter;
ReportingFrequency ReportFreq;
bool NeverFound;

static bool ErrorsFound(false); // If errors detected in input

Expand All @@ -6823,6 +6819,29 @@ void UpdateMeterReporting(EnergyPlusData &state)
ErrorsLogged = true;
}

// Helper lambda to locate a meter index from its name. Returns a negative value if not found
auto findMeterIndexFromMeterName = [](std::string const &name) -> int {
// Return a value <= 0 if not found
int meterIndex = -99;

std::string::size_type wildCardPosition = index(name, '*');

if (wildCardPosition == std::string::npos) {
meterIndex = UtilityRoutines::FindItem(name, OutputProcessor::EnergyMeters);
} else { // Wildcard input
for (int Meter = 1; Meter <= OutputProcessor::NumEnergyMeters; ++Meter) {
if (UtilityRoutines::SameString(OutputProcessor::EnergyMeters(Meter).Name.substr(0, wildCardPosition),
name.substr(0, wildCardPosition)))
{
meterIndex = Meter;
break;
}
}
}

return meterIndex;
};

cCurrentModuleObject = "Output:Meter";
NumReqMeters = inputProcessor->getNumObjectsFound(cCurrentModuleObject);

Expand All @@ -6844,33 +6863,14 @@ void UpdateMeterReporting(EnergyPlusData &state)
varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

WildCard = index(Alphas(1), '*');
if (WildCard != std::string::npos) {
TestLen = WildCard;
}

ReportFreq = determineFrequency(Alphas(2));

if (WildCard == std::string::npos) {
Meter = UtilityRoutines::FindItem(Alphas(1), EnergyMeters);
if (Meter == 0) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
continue;
}

SetInitialMeterReportingAndOutputNames(state, Meter, false, ReportFreq, false);

} else { // Wildcard input
NeverFound = true;
for (Meter = 1; Meter <= NumEnergyMeters; ++Meter) {
if (!UtilityRoutines::SameString(EnergyMeters(Meter).Name.substr(0, TestLen), Alphas(1).substr(0, TestLen))) continue;
NeverFound = false;

SetInitialMeterReportingAndOutputNames(state, Meter, false, ReportFreq, false);
}
if (NeverFound) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is false, CumulativeIndicator is false
SetInitialMeterReportingAndOutputNames(state, meterIndex, false, ReportFreq, false);
} else {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
}

Expand All @@ -6894,33 +6894,14 @@ void UpdateMeterReporting(EnergyPlusData &state)
varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

WildCard = index(Alphas(1), '*');
if (WildCard != std::string::npos) {
TestLen = WildCard;
}

ReportFreq = determineFrequency(Alphas(2));

if (WildCard == std::string::npos) {
Meter = UtilityRoutines::FindItem(Alphas(1), EnergyMeters);
if (Meter == 0) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
continue;
}

SetInitialMeterReportingAndOutputNames(state, Meter, true, ReportFreq, false);

} else { // Wildcard input
NeverFound = true;
for (Meter = 1; Meter <= NumEnergyMeters; ++Meter) {
if (!UtilityRoutines::SameString(EnergyMeters(Meter).Name.substr(0, TestLen), Alphas(1).substr(0, TestLen))) continue;
NeverFound = false;

SetInitialMeterReportingAndOutputNames(state, Meter, true, ReportFreq, false);
}
if (NeverFound) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is true, CumulativeIndicator is false
SetInitialMeterReportingAndOutputNames(state, meterIndex, true, ReportFreq, false);
} else {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
}

Expand All @@ -6945,33 +6926,14 @@ void UpdateMeterReporting(EnergyPlusData &state)
varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

WildCard = index(Alphas(1), '*');
if (WildCard != std::string::npos) {
TestLen = WildCard;
}

ReportFreq = determineFrequency(Alphas(2));

if (WildCard == std::string::npos) {
Meter = UtilityRoutines::FindItem(Alphas(1), EnergyMeters);
if (Meter == 0) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
continue;
}

SetInitialMeterReportingAndOutputNames(state, Meter, false, ReportFreq, true);

} else { // Wildcard input
NeverFound = true;
for (Meter = 1; Meter <= NumEnergyMeters; ++Meter) {
if (!UtilityRoutines::SameString(EnergyMeters(Meter).Name.substr(0, TestLen), Alphas(1).substr(0, TestLen))) continue;
NeverFound = false;

SetInitialMeterReportingAndOutputNames(state, Meter, false, ReportFreq, true);
}
if (NeverFound) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is false, CumulativeIndicator is true
SetInitialMeterReportingAndOutputNames(state, meterIndex, false, ReportFreq, true);
} else {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
}

Expand All @@ -6995,33 +6957,14 @@ void UpdateMeterReporting(EnergyPlusData &state)
varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

WildCard = index(Alphas(1), '*');
if (WildCard != std::string::npos) {
TestLen = WildCard;
}

ReportFreq = determineFrequency(Alphas(2));

if (WildCard == std::string::npos) {
Meter = UtilityRoutines::FindItem(Alphas(1), EnergyMeters);
if (Meter == 0) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
continue;
}

SetInitialMeterReportingAndOutputNames(state, Meter, true, ReportFreq, true);

} else { // Wildcard input
NeverFound = true;
for (Meter = 1; Meter <= NumEnergyMeters; ++Meter) {
if (!UtilityRoutines::SameString(EnergyMeters(Meter).Name.substr(0, TestLen), Alphas(1).substr(0, TestLen))) continue;
NeverFound = false;

SetInitialMeterReportingAndOutputNames(state, Meter, true, ReportFreq, true);
}
if (NeverFound) {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is true, CumulativeIndicator is true
SetInitialMeterReportingAndOutputNames(state, meterIndex, true, ReportFreq, true);
} else {
ShowWarningError(cCurrentModuleObject + ": invalid " + cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
}

Expand Down

5 comments on commit 4fcf280

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8317_ValidateOutputTableMonthly (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3024 of 3025 tests passed, 0 test warnings)

Messages:\n

  • 1 test had: EIO diffs.
  • 1 test had: ESO small diffs.
  • 1 test had: MTR small diffs.
  • 1 test had: Table big diffs.

Failures:\n

regression Test Summary

  • Passed: 736
  • Failed: 1

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8317_ValidateOutputTableMonthly (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1549 of 1549 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8317_ValidateOutputTableMonthly (jmarrec) - x86_64-MacOS-10.15-clang-11.0.0: OK (2985 of 2985 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8317_ValidateOutputTableMonthly (jmarrec) - Win64-Windows-10-VisualStudio-16: OK (2241 of 2241 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8317_ValidateOutputTableMonthly (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (722 of 722 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.