Skip to content

Commit

Permalink
Fix #9150 - Correctly set up Meters when using a wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Feb 22, 2022
1 parent 2aa1935 commit de18532
Showing 1 changed file with 33 additions and 52 deletions.
85 changes: 33 additions & 52 deletions src/EnergyPlus/OutputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6454,10 +6454,8 @@ void UpdateMeterReporting(EnergyPlusData &state)
int NumAlpha;
int NumNumbers;
int IOStat;
std::string::size_type varnameLen;
int NumReqMeters;
int NumReqMeterFOs;
ReportingFrequency ReportFreq;

bool ErrorsFound(false); // If errors detected in input
auto &op(state.dataOutputProcessor);
Expand All @@ -6468,26 +6466,37 @@ void UpdateMeterReporting(EnergyPlusData &state)
}

// Helper lambda to locate a meter index from its name. Returns a negative value if not found
auto findMeterIndexFromMeterName = [&state](std::string const &name) -> int {
auto &op(state.dataOutputProcessor);
auto setupMeterFromMeterName =
[&state](std::string &name, std::string const &freqString, bool MeterFileOnlyIndicator, bool CumulativeIndicator) -> bool {
bool result = false;

// Return a value <= 0 if not found
int meterIndex = -99;
auto varnameLen = index(name, '[');
if (varnameLen != std::string::npos) {
name.erase(varnameLen);
}

auto &op(state.dataOutputProcessor);

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

if (wildCardPosition == std::string::npos) {
meterIndex = UtilityRoutines::FindItem(name, op->EnergyMeters);
int meterIndex = UtilityRoutines::FindItem(name, op->EnergyMeters);
if (meterIndex > 0) {
ReportingFrequency ReportFreq = determineFrequency(state, freqString);
SetInitialMeterReportingAndOutputNames(state, meterIndex, MeterFileOnlyIndicator, ReportFreq, CumulativeIndicator);
result = true;
}
} else { // Wildcard input
for (int Meter = 1; Meter <= op->NumEnergyMeters; ++Meter) {
if (UtilityRoutines::SameString(op->EnergyMeters(Meter).Name.substr(0, wildCardPosition), name.substr(0, wildCardPosition))) {
meterIndex = Meter;
break;
ReportingFrequency ReportFreq = determineFrequency(state, freqString);
for (int meterIndex = 1; meterIndex <= op->NumEnergyMeters; ++meterIndex) {
if (UtilityRoutines::SameString(op->EnergyMeters(meterIndex).Name.substr(0, wildCardPosition), name.substr(0, wildCardPosition))) {
SetInitialMeterReportingAndOutputNames(state, meterIndex, MeterFileOnlyIndicator, ReportFreq, CumulativeIndicator);
result = true;
}
}
}

return meterIndex;
return result;
};

auto &cCurrentModuleObject = state.dataIPShortCut->cCurrentModuleObject;
Expand All @@ -6509,16 +6518,9 @@ void UpdateMeterReporting(EnergyPlusData &state)
state.dataIPShortCut->cAlphaFieldNames,
state.dataIPShortCut->cNumericFieldNames);

varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

ReportFreq = determineFrequency(state, Alphas(2));

int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is false, CumulativeIndicator is false
SetInitialMeterReportingAndOutputNames(state, meterIndex, false, ReportFreq, false);
} else {
bool meterFileOnlyIndicator = false;
bool cumulativeIndicator = false;
if (!setupMeterFromMeterName(Alphas(1), Alphas(2), meterFileOnlyIndicator, cumulativeIndicator)) {
ShowWarningError(state,
cCurrentModuleObject + ": invalid " + state.dataIPShortCut->cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
Expand All @@ -6541,16 +6543,9 @@ void UpdateMeterReporting(EnergyPlusData &state)
state.dataIPShortCut->cAlphaFieldNames,
state.dataIPShortCut->cNumericFieldNames);

varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

ReportFreq = determineFrequency(state, Alphas(2));

int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is true, CumulativeIndicator is false
SetInitialMeterReportingAndOutputNames(state, meterIndex, true, ReportFreq, false);
} else {
bool meterFileOnlyIndicator = true;
bool cumulativeIndicator = false;
if (!setupMeterFromMeterName(Alphas(1), Alphas(2), meterFileOnlyIndicator, cumulativeIndicator)) {
ShowWarningError(state,
cCurrentModuleObject + ": invalid " + state.dataIPShortCut->cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
Expand All @@ -6574,16 +6569,9 @@ void UpdateMeterReporting(EnergyPlusData &state)
state.dataIPShortCut->cAlphaFieldNames,
state.dataIPShortCut->cNumericFieldNames);

varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

ReportFreq = determineFrequency(state, Alphas(2));

int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is false, CumulativeIndicator is true
SetInitialMeterReportingAndOutputNames(state, meterIndex, false, ReportFreq, true);
} else {
bool meterFileOnlyIndicator = false;
bool cumulativeIndicator = true;
if (!setupMeterFromMeterName(Alphas(1), Alphas(2), meterFileOnlyIndicator, cumulativeIndicator)) {
ShowWarningError(state,
cCurrentModuleObject + ": invalid " + state.dataIPShortCut->cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
Expand All @@ -6606,16 +6594,9 @@ void UpdateMeterReporting(EnergyPlusData &state)
state.dataIPShortCut->cAlphaFieldNames,
state.dataIPShortCut->cNumericFieldNames);

varnameLen = index(Alphas(1), '[');
if (varnameLen != std::string::npos) Alphas(1).erase(varnameLen);

ReportFreq = determineFrequency(state, Alphas(2));

int meterIndex = findMeterIndexFromMeterName(Alphas(1));
if (meterIndex > 0) {
// MeterFileOnlyIndicator is true, CumulativeIndicator is true
SetInitialMeterReportingAndOutputNames(state, meterIndex, true, ReportFreq, true);
} else {
bool meterFileOnlyIndicator = true;
bool cumulativeIndicator = true;
if (!setupMeterFromMeterName(Alphas(1), Alphas(2), meterFileOnlyIndicator, cumulativeIndicator)) {
ShowWarningError(state,
cCurrentModuleObject + ": invalid " + state.dataIPShortCut->cAlphaFieldNames(1) + "=\"" + Alphas(1) + "\" - not found.");
}
Expand Down

5 comments on commit de18532

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

9150_Meter_WildCard (jmarrec) - Win64-Windows-10-VisualStudio-16: OK (2463 of 2463 tests passed, 0 test warnings)

Build Badge Test 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.

9150_Meter_WildCard (jmarrec) - x86_64-MacOS-10.15-clang-11.0.0: OK (3227 of 3227 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

9150_Meter_WildCard (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3268 of 3268 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

9150_Meter_WildCard (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1742 of 1742 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

9150_Meter_WildCard (jmarrec) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (746 of 746 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.