From fa2b9d74049fb832de0453948e765cbf36a92aa6 Mon Sep 17 00:00:00 2001 From: amirroth Date: Sun, 10 Dec 2023 15:18:21 -0500 Subject: [PATCH] Seventh time is the charm (probably not) --- src/EnergyPlus/EMSManager.cc | 4 +- src/EnergyPlus/OutputProcessor.cc | 69 +++++++++++++++---------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/EnergyPlus/EMSManager.cc b/src/EnergyPlus/EMSManager.cc index 11b5519fed5..4a09a51f637 100644 --- a/src/EnergyPlus/EMSManager.cc +++ b/src/EnergyPlus/EMSManager.cc @@ -601,7 +601,7 @@ namespace EMSManager { thisSensor.OutputVarName = cAlphaArgs(3); int VarIndex = GetMeterIndex(state, cAlphaArgs(3)); - if (VarIndex > 0) { + if (VarIndex > -1) { if (!lAlphaFieldBlanks(2)) { ShowWarningError(state, format("Unused{}={}", cAlphaFieldNames(2), cAlphaArgs(2))); ShowContinueError(state, format("Entered in {}={}", cCurrentModuleObject, cAlphaArgs(1))); @@ -1221,6 +1221,8 @@ namespace EMSManager { if (VarType == OutputProcessor::VariableType::Schedule) { VarIndex = KeyIndex(1); + } else if (keyName(1) == "ENVIRONMENT") { + VarIndex = KeyIndex(1); } else { for (int KeyNum = 1; KeyNum <= NumKeys; ++KeyNum) { if (state.dataOutputProcessor->outVars[KeyIndex(KeyNum)]->keyUC == VarKeyName) { diff --git a/src/EnergyPlus/OutputProcessor.cc b/src/EnergyPlus/OutputProcessor.cc index 32111b2931e..b9d165eaeb3 100644 --- a/src/EnergyPlus/OutputProcessor.cc +++ b/src/EnergyPlus/OutputProcessor.cc @@ -4327,7 +4327,7 @@ Real64 GetInstantMeterValue(EnergyPlusData &state, auto &op = state.dataOutputProcessor; auto *meter = op->meters[meterNum]; - if (meter->type == MeterType::Normal) { + if (meter->type == MeterType::Normal || meter->type == MeterType::Custom) { for (int srcVarNum : meter->srcVarNums) { auto *var = op->outVars[srcVarNum]; // Separate the Zone variables from the HVAC variables using TimeStepType @@ -4848,17 +4848,6 @@ void ProduceRDDMDD(EnergyPlusData &state) std::string VarOption2; bool DoReport; bool SortByName; - int ItemPtr; - - struct VariableTypes - { - // Members - int RealIntegerType = 0; // Real= 1, Integer=2 - int VarPtr = 0; // pointer to real/integer VariableTypes structures - int TimeStepType = 0; - int StoreType = 0; - std::string UnitsString; - }; auto &op = state.dataOutputProcessor; auto &rf = state.dataResultsFramework->resultsFramework; @@ -4897,9 +4886,22 @@ void ProduceRDDMDD(EnergyPlusData &state) } if (op->ProduceReportVDD == ReportVDD::Yes || op->ProduceReportVDD == ReportVDD::IDF) { + auto miVar = op->ddOutVarMap.begin(); - for (int aiVar = 0; aiVar < (int)op->ddOutVars.size() && miVar != op->ddOutVarMap.end(); ++aiVar, ++miVar) { - int iVar = (SortByName) ? miVar->second : aiVar; // Choose either map (sorted) order or array (unsorted) order + int aiVar = 0; + for (;;) { + int iVar = -1; + // Too complicated to do this logic in the for loop header + if (SortByName) { + if (miVar == op->ddOutVarMap.end()) break; + iVar = miVar->second; + ++miVar; + } else { + if (aiVar == (int)op->ddOutVars.size()) break; + iVar = aiVar; + ++aiVar; + } + auto *ddVar = op->ddOutVars[iVar]; if (ddVar->ReportedOnDDFile) continue; @@ -4917,28 +4919,25 @@ void ProduceRDDMDD(EnergyPlusData &state) } ddVar->ReportedOnDDFile = true; - while (ddVar->Next != -1) { - if (SortByName) { - ++ItemPtr; - } else { - ItemPtr = ddVar->Next; - } - ddVar = op->ddOutVars[ItemPtr]; - - std::string_view timeStepName = timeStepNames[(int)ddVar->timeStepType]; - std::string_view storeTypeName = storeTypeNames[(int)ddVar->storeType]; - std::string_view varName = ddVar->name; - std::string_view unitName = (ddVar->units == Constant::Units::customEMS) ? ddVar->unitNameCustomEMS : Constant::unitNames[(int)ddVar->units]; + if (SortByName) { + while (ddVar->Next != -1) { + ddVar = op->ddOutVars[ddVar->Next]; + + std::string_view timeStepName = timeStepNames[(int)ddVar->timeStepType]; + std::string_view storeTypeName = storeTypeNames[(int)ddVar->storeType]; + std::string_view varName = ddVar->name; + std::string_view unitName = (ddVar->units == Constant::Units::customEMS) ? ddVar->unitNameCustomEMS : Constant::unitNames[(int)ddVar->units]; - if (op->ProduceReportVDD == ReportVDD::Yes) { - print(state.files.rdd, "{},{},{} [{}]\n", timeStepName, storeTypeName, varName, unitName); - rf->RDD.push_back(format("{},{},{} [{}]", timeStepName, storeTypeName, varName, unitName)); - } else { - print(state.files.rdd, "Output:Variable,*,{},hourly; !- {} {} [{}]\n", varName, timeStepName, storeTypeName, unitName); - rf->RDD.push_back(format("{},{},{} [{}]", timeStepName, storeTypeName, varName, unitName)); - } - ddVar->ReportedOnDDFile = true; - } // while (ddVar->Next != 0) + if (op->ProduceReportVDD == ReportVDD::Yes) { + print(state.files.rdd, "{},{},{} [{}]\n", timeStepName, storeTypeName, varName, unitName); + rf->RDD.push_back(format("{},{},{} [{}]", timeStepName, storeTypeName, varName, unitName)); + } else { + print(state.files.rdd, "Output:Variable,*,{},hourly; !- {} {} [{}]\n", varName, timeStepName, storeTypeName, unitName); + rf->RDD.push_back(format("{},{},{} [{}]", timeStepName, storeTypeName, varName, unitName)); + } + ddVar->ReportedOnDDFile = true; + } // while (ddVar->Next != 0) + } // if (SortByName) } // for (aiVar, miVar) } // if (produceReportVDD) state.files.rdd.close();