SUBROUTINE InitEnergyReports
! SUBROUTINE INFORMATION:
! AUTHOR Dan Fisher
! DATE WRITTEN April 2005
! MODIFIED
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Initializes the energy components of the data structures
! METHODOLOGY EMPLOYED:
! Once all compsets have been established (second iteration) find all components
! subcomponents, etc.
! REFERENCES:
! na
! USE STATEMENTS:
Use DataEnvironment, ONLY: StdBaroPress, OutHumRat
USE SplitterComponent, ONLY: SplitterCond, NumSplitters
USE InputProcessor, ONLY: FindItemInList
USE Psychrometrics, ONLY: PsyHFnTdbW,PsyRhoAirFnPbTdbW
USE ZonePlenum, ONLY: ZoneSupPlenCond, NumZoneSupplyPlenums
USE DataConvergParams, ONLY: HVACFlowRateToler
USE DataGlobalConstants
IMPLICIT NONE
! SUBROUTINE ARGUMENT DEFINITIONS
! SUBROUTINE PARAMETER DEFINITIONS:
INTEGER, PARAMETER :: TypeComp = 1
INTEGER, PARAMETER :: TypeSubComp = 2
INTEGER, PARAMETER :: TypeSubSubComp = 3
INTEGER, PARAMETER :: EnergyTransfer = 1
! INTERFACE BLOCK SPECIFICATIONS
! na
INTEGER :: AirDistUnitNum
INTEGER :: MatchLoop
INTEGER :: MatchLoopType
INTEGER :: MatchBranch
INTEGER :: MatchComp
INTEGER :: AirLoopNum
INTEGER :: BranchNum
INTEGER :: ZoneInletNodeNum
INTEGER :: CompNum
INTEGER :: VarNum
INTEGER :: SubCompNum
INTEGER :: SubSubCompNum
INTEGER :: EquipNum
INTEGER :: SubEquipNum
INTEGER :: SubSubEquipNum
INTEGER :: CtrlZoneNum
INTEGER :: NodeIndex
INTEGER :: Index
INTEGER :: TempIndex
INTEGER :: ListNum
INTEGER :: SAPNum
INTEGER :: SAPOutNode
INTEGER :: MainBranchNum
INTEGER :: SupplyCoolBranchNum
INTEGER :: SupplyHeatBranchNum
INTEGER :: VarType
INTEGER :: VarIndex
INTEGER :: OutNum
INTEGER :: NodeCount
INTEGER :: PlantLoopNum
INTEGER :: NumZoneConnectComps
INTEGER :: NumZoneConnectSubComps
INTEGER :: NumZoneConnectSubSubComps
INTEGER :: NumAirSysConnectComps
INTEGER :: NumAirSysConnectSubComps
INTEGER :: NumAirSysConnectSubSubComps
INTEGER :: ArrayCount
INTEGER :: LoopType
INTEGER :: LoopNum
INTEGER :: FirstIndex
INTEGER :: LastIndex
INTEGER :: LoopCount
CHARACTER(len=MaxNameLength) ::CompType
CHARACTER(len=MaxNameLength) ::CompName
LOGICAL :: MatchFound
LOGICAL,Save :: OneTimeFlag = .True. ! Flag set to make sure you initialize reports one time
LOGICAL :: Duplicate
LOGICAL :: ConnectionFlag
IF (.not. VentReportStructureCreated) RETURN
IF (OneTimeFlag) THEN
! ***I think we need to preprocess the main components on the branch to get them in order***
! This needs to be done before we start in on the component loop
! GetChildrenData will put all of the subcomponents in order for us
DO CtrlZoneNum=1,NumOfZones
IF (.not. ZoneEquipConfig(CtrlZoneNum)%IsControlled) CYCLE
AirLoopNum = ZoneEquipConfig(CtrlZoneNum)%AirLoopNum
ZoneEquipConfig(CtrlZoneNum)%EquipListIndex = &
finditeminlist(ZoneEquipConfig(CtrlZoneNum)%EquipListName, ZoneEquipList%Name,NumofZones)
ListNum = ZoneEquipConfig(CtrlZoneNum)%EquipListIndex
DO ZoneInletNodeNum=1,ZoneEquipConfig(CtrlZoneNum)%NumInletNodes
DO CompNum = 1, ZoneEquipList(ListNum)%NumOfEquipTypes
DO NodeCount = 1, ZoneEquipList(ListNum)%EquipData(CompNum)%NumOutlets
IF (ZoneEquipList(ListNum)%EquipData(CompNum)%OutletNodeNums(NodeCount) == &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%OutNode)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%AirDistUnitIndex = CompNum
IF (ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyAirPathExists)THEN
DO SAPNum = 1, numsupplyairpaths
DO SAPOutNode = 1, SupplyAirPath(SAPNum)%NumOutletNodes
IF (ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%InNode== &
SupplyAirPath(SAPNum)%OutletNode(SAPOutNode))THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyAirPathIndex = SAPNum
DO OutNum=1,AirToZoneNodeInfo(AirLoopNum)%NumSupplyNodes
IF (AirToZoneNodeInfo(AirLoopNum)%ZoneEquipSupplyNodeNum(OutNum) == &
SupplyAirPath(SAPNum)%InletNodeNum)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyBranchIndex = &
PrimaryAirSystem(AirLoopNum)%OutletBranchNum(OutNum)
IF (PrimaryAirSystem(AirLoopNum)%Splitter%Exists)THEN
DO MainBranchNum = 1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF (PrimaryAirSystem(AirLoopNum)%Branch(MainBranchNum)%NodeNumOut == &
PrimaryAirSystem(AirLoopNum)%Splitter%NodeNumIn)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%MainBranchIndex = MainBranchNum
END IF
END DO
ELSE !no splitter
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%MainBranchIndex = &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyBranchIndex
END IF
END IF
END DO
END IF
END DO
END DO
ELSE !no supply air path
IF (AirLoopNum > 0) THEN
DO NodeIndex = 1, AirToZoneNodeInfo(AirLoopNum)%NumSupplyNodes
IF(AirToZoneNodeInfo(AirLoopNum)%ZoneEquipSupplyNodeNum(NodeIndex) == &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%InNode)THEN
DO BranchNum =1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%NodeNumOut == &
AirToZoneNodeInfo(AirLoopNum)%AirLoopSupplyNodeNum(NodeIndex))THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyBranchIndex = BranchNum
IF(PrimaryAirSystem(AirLoopNum)%Splitter%Exists)THEN
DO MainBranchNum = 1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(MainBranchNum)%NodeNumOut == &
PrimaryAirSystem(AirLoopNum)%Splitter%NodeNumIn)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%MainBranchIndex = MainBranchNum
END IF
END DO
ELSE !no splitter
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%MainBranchIndex = &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyAirPathIndex
END IF
END IF
END DO
END IF
END DO
END IF
END IF
ELSE IF(ZoneEquipList(ListNum)%EquipData(CompNum)%OutletNodeNums(NodeCount) == &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%InNode)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%AirDistUnitIndex = CompNum
IF(ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyAirPathExists)THEN
DO SAPNum = 1, numsupplyairpaths
DO NodeIndex = 1, AirToZoneNodeInfo(AirLoopNum)%NumSupplyNodes
IF(AirToZoneNodeInfo(AirLoopNum)%ZoneEquipSupplyNodeNum(NodeIndex) == &
SupplyAirPath(SAPNum)%InletNodeNum)THEN
DO BranchNum =1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%NodeNumOut == &
AirToZoneNodeInfo(AirLoopNum)%AirLoopSupplyNodeNum(NodeIndex))THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyBranchIndex = BranchNum
IF(PrimaryAirSystem(AirLoopNum)%Splitter%Exists)THEN
DO MainBranchNum = 1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(MainBranchNum)%NodeNumOut == &
PrimaryAirSystem(AirLoopNum)%Splitter%NodeNumIn)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%MainBranchIndex = MainBranchNum
END IF
END DO
ELSE !no splitter
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%MainBranchIndex = &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyAirPathIndex
END IF
END IF
END DO
END IF
END DO
DO SAPOutNode = 1, SupplyAirPath(SAPNum)%NumOutletNodes
IF( ZoneInletNodeNum == SupplyAirPath(SAPNum)%OutletNode(SAPOutNode))THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyAirPathIndex = SAPNum
END IF
END DO
END DO
ELSE !no supply air path
IF (AirLoopNum > 0) THEN
DO NodeIndex = 1, AirToZoneNodeInfo(AirLoopNum)%NumSupplyNodes
IF(AirToZoneNodeInfo(AirLoopNum)%ZoneEquipSupplyNodeNum(NodeIndex) == &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%InNode)THEN
DO BranchNum =1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%NodeNumOut == &
AirToZoneNodeInfo(AirLoopNum)%AirLoopSupplyNodeNum(NodeIndex))THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyBranchIndex = BranchNum
IF(PrimaryAirSystem(AirLoopNum)%Splitter%Exists)THEN
DO MainBranchNum = 1, PrimaryAirSystem(AirLoopNum)%NumBranches
IF(PrimaryAirSystem(AirLoopNum)%Branch(MainBranchNum)%NodeNumOut == &
PrimaryAirSystem(AirLoopNum)%Splitter%NodeNumIn)THEN
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%MainBranchIndex = MainBranchNum
END IF
END DO
ELSE !no splitter
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%MainBranchIndex = &
ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyAirPathIndex
END IF
END IF
END DO
END IF
END DO
END IF
END IF
ELSE
Continue
!Can't tell if there's an error based on this code...need to check logical flags separately
END IF
END DO
END DO
END DO
END DO
DO CtrlZoneNum=1,NumOfZones
IF (.not. ZoneEquipConfig(CtrlZoneNum)%IsControlled) CYCLE
AirLoopNum = ZoneEquipConfig(CtrlZoneNum)%AirLoopNum
ZoneEquipConfig(CtrlZoneNum)%EquipListIndex = &
finditeminlist(ZoneEquipConfig(CtrlZoneNum)%EquipListName, ZoneEquipList%Name,NumofZones)
ListNum = ZoneEquipConfig(CtrlZoneNum)%EquipListIndex
!loop over the zone supply air path inlet nodes
DO ZoneInletNodeNum=1,ZoneEquipConfig(CtrlZoneNum)%NumInletNodes
! 1. Find HVAC component plant loop connections
MainBranchNum = ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%MainBranchIndex
MainBranchNum = MAX(MainBranchNum,ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%MainBranchIndex)
IF(MainBranchNum > 0)CALL MatchPlantSys(AirLoopNum,MainBranchNum)
SupplyCoolBranchNum = ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%SupplyBranchIndex
IF(SupplyCoolBranchNum > 0 .AND. (SupplyCoolBranchNum .NE. MainBranchNum))CALL MatchPlantSys(AirLoopNum,SupplyCoolBranchNum)
SupplyHeatBranchNum = ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%SupplyBranchIndex
IF(SupplyHeatBranchNum > 0 .AND. (SupplyHeatBranchNum .NE. MainBranchNum))CALL MatchPlantSys(AirLoopNum,SupplyHeatBranchNum)
AirDistUnitNum = ZoneEquipConfig(CtrlZoneNum)%AirDistUnitCool(ZoneInletNodeNum)%AirDistUnitIndex
AirDistUnitNum = MAX(AirDistUnitNum,ZoneEquipConfig(CtrlZoneNum)%AirDistUnitHeat(ZoneInletNodeNum)%AirDistUnitIndex)
IF(ListNum > 0 .AND. AirDistUnitNum >0)THEN
DO VarNum = 1, ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%NumMeteredVars
IF(ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%MeteredVar(VarNum)%ResourceType == iRT_EnergyTransfer) THEN
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%EnergyTransComp = EnergyTransfer
CompType = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%TypeOf
CompName = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%Name
Index = 0
CALL FindDemandSideMatch(CompType,CompName,MatchFound,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
IF(MatchFound)CALL UpdateZoneCompPtrArray(Index,ListNum,AirDistUnitNum,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%ZoneEqToPlantPtr = Index
EXIT
END IF
END DO
DO SubEquipNum = 1, ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%NumSubEquip
DO VarNum = 1, ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%NumMeteredVars
IF(ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
MeteredVar(VarNum)%ResourceType == iRT_EnergyTransfer) THEN
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%EnergyTransComp = EnergyTransfer
CompType = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%TypeOf
CompName = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%Name
Index = 0
CALL FindDemandSideMatch(CompType,CompName,MatchFound,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
IF(MatchFound) &
CALL UpdateZoneSubCompPtrArray(Index,ListNum,AirDistUnitNum,SubEquipNum,MatchLoopType, &
MatchLoop,MatchBranch,MatchComp)
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%ZoneEqToPlantPtr = Index
EXIT
END IF
END DO
DO SubSubEquipNum = 1, ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)%NumSubSubEquip
DO VarNum = 1, ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%NumMeteredVars
IF(ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%MeteredVar(VarNum)%ResourceType == iRT_EnergyTransfer) THEN
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%EnergyTransComp = EnergyTransfer
CompType = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%TypeOf
CompName = ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%Name
Index = 0
CALL FindDemandSideMatch(CompType,CompName,MatchFound,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
IF(MatchFound) &
CALL UpdateZoneSubSubCompPtrArray(Index,ListNum,AirDistUnitNum,SubEquipNum,SubSubEquipNum,MatchLoopType, &
MatchLoop,MatchBranch,MatchComp)
ZoneEquipList(ListNum)%EquipData(AirDistUnitNum)%SubEquipData(SubEquipNum)% &
SubSubEquipData(SubSubEquipNum)%ZoneEqToPlantPtr = Index
EXIT
END IF
END DO
END DO
END DO
END IF
!Eliminate duplicates in the connection arrays
IF (ALLOCATED(ZoneCompToPlant)) THEN
EquipNum = SIZE(ZoneCompToPlant)
ELSE
EquipNum = 0
ENDIF
IF (ALLOCATED(ZoneSubCompToPlant)) THEN
SubEquipNum = SIZE(ZoneSubCompToPlant)
ELSE
SubEquipNum = 0
ENDIF
IF (ALLOCATED(ZoneSubSubCompToPlant)) THEN
SubSubEquipNum = SIZE(ZoneSubSubCompToPlant)
ELSE
SubSubEquipNum = 0
ENDIF
IF (ALLOCATED(AirSysCompToPlant)) THEN
CompNum = SIZE(AirSysCompToPlant)
ELSE
CompNum = 0
ENDIF
IF (ALLOCATED(AirSysSubCompToPlant)) THEN
SubCompNum = SIZE(AirSysSubCompToPlant)
ELSE
SubCompNum = 0
ENDIF
IF (ALLOCATED(AirSysSubSubCompToPlant)) THEN
SubSubCompNum = SIZE(AirSysSubSubCompToPlant)
ELSE
SubSubCompNum = 0
ENDIF
IF (EquipNum > 0) THEN
TempZoneCompToPlant%ZoneEqListNum = 0
TempZoneCompToPlant%ZoneEqCompNum = 0
TempZoneCompToPlant%PlantLoopType = 0
TempZoneCompToPlant%PlantLoopNum = 0
TempZoneCompToPlant%PlantLoopBranch = 0
TempZoneCompToPlant%PlantLoopComp = 0
TempZoneCompToPlant%FirstDemandSidePtr = 0
TempZoneCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, EquipNum
Duplicate = .FALSE.
DO TempIndex = 1,Equipnum
IF (ZoneCompToPlant(Index)%ZoneEqListNum == TempZoneCompToPlant(TempIndex)%ZoneEqListNum .AND. &
ZoneCompToPlant(Index)%ZoneEqCompNum == ZoneCompToPlant(TempIndex)%ZoneEqCompNum)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempZoneCompToPlant(ArrayCount)%ZoneEqListNum = ZoneCompToPlant(Index)%ZoneEqListNum
TempZoneCompToPlant(ArrayCount)%ZoneEqCompNum = ZoneCompToPlant(Index)%ZoneEqCompNum
TempZoneCompToPlant(ArrayCount)%PlantLoopType = ZoneCompToPlant(Index)%PlantLoopType
TempZoneCompToPlant(ArrayCount)%PlantLoopNum = ZoneCompToPlant(Index)%PlantLoopNum
TempZoneCompToPlant(ArrayCount)%PlantLoopBranch = ZoneCompToPlant(Index)%PlantLoopBranch
TempZoneCompToPlant(ArrayCount)%PlantLoopComp = ZoneCompToPlant(Index)%PlantLoopComp
TempZoneCompToPlant(ArrayCount)%FirstDemandSidePtr = ZoneCompToPlant(Index)%FirstDemandSidePtr
TempZoneCompToPlant(ArrayCount)%LastDemandSidePtr = ZoneCompToPlant(Index)%LastDemandSidePtr
ENDIF
END DO
ZoneCompToPlant%ZoneEqListNum = TempZoneCompToPlant%ZoneEqListNum
ZoneCompToPlant%ZoneEqCompNum = TempZoneCompToPlant%ZoneEqCompNum
ZoneCompToPlant%PlantLoopType = TempZoneCompToPlant%PlantLoopType
ZoneCompToPlant%PlantLoopNum = TempZoneCompToPlant%PlantLoopNum
ZoneCompToPlant%PlantLoopBranch = TempZoneCompToPlant%PlantLoopBranch
ZoneCompToPlant%PlantLoopComp = TempZoneCompToPlant%PlantLoopComp
ZoneCompToPlant%FirstDemandSidePtr = TempZoneCompToPlant%FirstDemandSidePtr
ZoneCompToPlant%LastDemandSidePtr = TempZoneCompToPlant%LastDemandSidePtr
ENDIF
IF (SubEquipNum > 0) THEN
TempZoneSubCompToPlant%ZoneEqListNum = 0
TempZoneSubCompToPlant%ZoneEqCompNum = 0
TempZoneSubCompToPlant%ZoneEqSubCompNum = 0
TempZoneSubCompToPlant%PlantLoopType = 0
TempZoneSubCompToPlant%PlantLoopNum = 0
TempZoneSubCompToPlant%PlantLoopBranch = 0
TempZoneSubCompToPlant%PlantLoopComp = 0
TempZoneSubCompToPlant%FirstDemandSidePtr = 0
TempZoneSubCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, SubEquipNum
Duplicate = .FALSE.
DO TempIndex = 1,SubEquipNum
IF (ZoneSubCompToPlant(Index)%ZoneEqListNum == TempZoneSubCompToPlant(TempIndex)%ZoneEqListNum .AND. &
ZoneSubCompToPlant(Index)%ZoneEqCompNum == TempZoneSubCompToPlant(TempIndex)%ZoneEqCompNum .AND. &
ZoneSubCompToPlant(Index)%ZoneEqSubCompNum == TempZoneSubCompToPlant(TempIndex)%ZoneEqSubCompNum)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempZoneSubCompToPlant(ArrayCount)%ZoneEqListNum = ZoneSubCompToPlant(Index)%ZoneEqListNum
TempZoneSubCompToPlant(ArrayCount)%ZoneEqCompNum = ZoneSubCompToPlant(Index)%ZoneEqCompNum
TempZoneSubCompToPlant(ArrayCount)%ZoneEqSubCompNum = ZoneSubCompToPlant(Index)%ZoneEqSubCompNum
TempZoneSubCompToPlant(ArrayCount)%PlantLoopType = ZoneSubCompToPlant(Index)%PlantLoopType
TempZoneSubCompToPlant(ArrayCount)%PlantLoopNum = ZoneSubCompToPlant(Index)%PlantLoopNum
TempZoneSubCompToPlant(ArrayCount)%PlantLoopBranch = ZoneSubCompToPlant(Index)%PlantLoopBranch
TempZoneSubCompToPlant(ArrayCount)%PlantLoopComp = ZoneSubCompToPlant(Index)%PlantLoopComp
TempZoneSubCompToPlant(ArrayCount)%FirstDemandSidePtr = ZoneSubCompToPlant(Index)%FirstDemandSidePtr
TempZoneSubCompToPlant(ArrayCount)%LastDemandSidePtr = ZoneSubCompToPlant(Index)%LastDemandSidePtr
ENDIF
END DO
ZoneSubCompToPlant%ZoneEqListNum = TempZoneSubCompToPlant%ZoneEqListNum
ZoneSubCompToPlant%ZoneEqCompNum = TempZoneSubCompToPlant%ZoneEqCompNum
ZoneSubCompToPlant%ZoneEqSubCompNum = TempZoneSubCompToPlant%ZoneEqSubCompNum
ZoneSubCompToPlant%PlantLoopType = TempZoneSubCompToPlant%PlantLoopType
ZoneSubCompToPlant%PlantLoopNum = TempZoneSubCompToPlant%PlantLoopNum
ZoneSubCompToPlant%PlantLoopBranch = TempZoneSubCompToPlant%PlantLoopBranch
ZoneSubCompToPlant%PlantLoopComp = TempZoneSubCompToPlant%PlantLoopComp
ZoneSubCompToPlant%FirstDemandSidePtr = TempZoneSubCompToPlant%FirstDemandSidePtr
ZoneSubCompToPlant%LastDemandSidePtr = TempZoneSubCompToPlant%LastDemandSidePtr
ENDIF
IF (SubSubEquipNum > 0) THEN
TempZoneSubSubCompToPlant%ZoneEqListNum = 0
TempZoneSubSubCompToPlant%ZoneEqCompNum = 0
TempZoneSubSubCompToPlant%ZoneEqSubCompNum = 0
TempZoneSubSubCompToPlant%ZoneEqSubSubCompNum = 0
TempZoneSubSubCompToPlant%PlantLoopType = 0
TempZoneSubSubCompToPlant%PlantLoopNum = 0
TempZoneSubSubCompToPlant%PlantLoopBranch = 0
TempZoneSubSubCompToPlant%PlantLoopComp = 0
TempZoneSubSubCompToPlant%FirstDemandSidePtr = 0
TempZoneSubSubCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, SubSubEquipNum
Duplicate = .FALSE.
DO TempIndex = 1,SubSubEquipNum
IF (ZoneSubSubCompToPlant(Index)%ZoneEqListNum == TempZoneSubSubCompToPlant(TempIndex)%ZoneEqListNum .AND. &
ZoneSubSubCompToPlant(Index)%ZoneEqCompNum == TempZoneSubSubCompToPlant(TempIndex)%ZoneEqCompNum .AND. &
ZoneSubSubCompToPlant(Index)%ZoneEqSubCompNum == TempZoneSubSubCompToPlant(TempIndex)%ZoneEqSubCompNum.AND. &
ZoneSubSubCompToPlant(Index)%ZoneEqSubSubCompNum == TempZoneSubSubCompToPlant(TempIndex)%ZoneEqSubSubCompNum)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempZoneSubSubCompToPlant(ArrayCount)%ZoneEqListNum = ZoneSubSubCompToPlant(Index)%ZoneEqListNum
TempZoneSubSubCompToPlant(ArrayCount)%ZoneEqCompNum = ZoneSubSubCompToPlant(Index)%ZoneEqCompNum
TempZoneSubSubCompToPlant(ArrayCount)%ZoneEqSubCompNum = ZoneSubSubCompToPlant(Index)%ZoneEqSubCompNum
TempZoneSubSubCompToPlant(ArrayCount)%ZoneEqSubSubCompNum = ZoneSubSubCompToPlant(Index)%ZoneEqSubSubCompNum
TempZoneSubSubCompToPlant(ArrayCount)%PlantLoopType = ZoneSubSubCompToPlant(Index)%PlantLoopType
TempZoneSubSubCompToPlant(ArrayCount)%PlantLoopNum = ZoneSubSubCompToPlant(Index)%PlantLoopNum
TempZoneSubSubCompToPlant(ArrayCount)%PlantLoopBranch = ZoneSubSubCompToPlant(Index)%PlantLoopBranch
TempZoneSubSubCompToPlant(ArrayCount)%PlantLoopComp = ZoneSubSubCompToPlant(Index)%PlantLoopComp
TempZoneSubSubCompToPlant(ArrayCount)%FirstDemandSidePtr = ZoneSubSubCompToPlant(Index)%FirstDemandSidePtr
TempZoneSubSubCompToPlant(ArrayCount)%LastDemandSidePtr = ZoneSubSubCompToPlant(Index)%LastDemandSidePtr
ENDIF
END DO
ZoneSubSubCompToPlant%ZoneEqListNum = TempZoneSubSubCompToPlant%ZoneEqListNum
ZoneSubSubCompToPlant%ZoneEqCompNum = TempZoneSubSubCompToPlant%ZoneEqCompNum
ZoneSubSubCompToPlant%ZoneEqSubCompNum = TempZoneSubSubCompToPlant%ZoneEqSubCompNum
ZoneSubSubCompToPlant%ZoneEqSubSubCompNum = TempZoneSubSubCompToPlant%ZoneEqSubSubCompNum
ZoneSubSubCompToPlant%PlantLoopType = TempZoneSubSubCompToPlant%PlantLoopType
ZoneSubSubCompToPlant%PlantLoopNum = TempZoneSubSubCompToPlant%PlantLoopNum
ZoneSubSubCompToPlant%PlantLoopBranch = TempZoneSubSubCompToPlant%PlantLoopBranch
ZoneSubSubCompToPlant%PlantLoopComp = TempZoneSubSubCompToPlant%PlantLoopComp
ZoneSubSubCompToPlant%FirstDemandSidePtr = TempZoneSubSubCompToPlant%FirstDemandSidePtr
ZoneSubSubCompToPlant%LastDemandSidePtr = TempZoneSubSubCompToPlant%LastDemandSidePtr
ENDIF
IF (CompNum > 0) THEN
TempAirSysCompToPlant%AirLoopNum = 0
TempAirSysCompToPlant%AirLoopBranch = 0
TempAirSysCompToPlant%AirLoopComp = 0
TempAirSysCompToPlant%PlantLoopType = 0
TempAirSysCompToPlant%PlantLoopNum = 0
TempAirSysCompToPlant%PlantLoopBranch = 0
TempAirSysCompToPlant%PlantLoopComp = 0
TempAirSysCompToPlant%FirstDemandSidePtr = 0
TempAirSysCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, CompNum
Duplicate = .FALSE.
DO TempIndex = 1,CompNum
IF (AirSysCompToPlant(Index)%AirLoopNum == TempAirSysCompToPlant(TempIndex)%AirLoopNum .AND. &
AirSysCompToPlant(Index)%AirLoopBranch == TempAirSysCompToPlant(TempIndex)%AirLoopBranch .AND. &
AirSysCompToPlant(Index)%AirLoopComp == TempAirSysCompToPlant(TempIndex)%AirLoopComp)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempAirSysCompToPlant(ArrayCount)%AirLoopNum = AirSysCompToPlant(Index)%AirLoopNum
TempAirSysCompToPlant(ArrayCount)%AirLoopBranch = AirSysCompToPlant(Index)%AirLoopBranch
TempAirSysCompToPlant(ArrayCount)%AirLoopComp = AirSysCompToPlant(Index)%AirLoopComp
TempAirSysCompToPlant(ArrayCount)%PlantLoopType = AirSysCompToPlant(Index)%PlantLoopType
TempAirSysCompToPlant(ArrayCount)%PlantLoopNum = AirSysCompToPlant(Index)%PlantLoopNum
TempAirSysCompToPlant(ArrayCount)%PlantLoopBranch = AirSysCompToPlant(Index)%PlantLoopBranch
TempAirSysCompToPlant(ArrayCount)%PlantLoopComp = AirSysCompToPlant(Index)%PlantLoopComp
TempAirSysCompToPlant(ArrayCount)%FirstDemandSidePtr= AirSysCompToPlant(Index)%FirstDemandSidePtr
TempAirSysCompToPlant(ArrayCount)%LastDemandSidePtr = AirSysCompToPlant(Index)%LastDemandSidePtr
END IF
END DO
AirSysCompToPlant%AirLoopNum = TempAirSysCompToPlant%AirLoopNum
AirSysCompToPlant%AirLoopBranch = TempAirSysCompToPlant%AirLoopBranch
AirSysCompToPlant%AirLoopComp = TempAirSysCompToPlant%AirLoopComp
AirSysCompToPlant%PlantLoopType = TempAirSysCompToPlant%PlantLoopType
AirSysCompToPlant%PlantLoopNum = TempAirSysCompToPlant%PlantLoopNum
AirSysCompToPlant%PlantLoopBranch = TempAirSysCompToPlant%PlantLoopBranch
AirSysCompToPlant%PlantLoopComp = TempAirSysCompToPlant%PlantLoopComp
AirSysCompToPlant%FirstDemandSidePtr = TempAirSysCompToPlant%FirstDemandSidePtr
AirSysCompToPlant%LastDemandSidePtr = TempAirSysCompToPlant%LastDemandSidePtr
ENDIF
IF (SubCompNum > 0) THEN
TempAirSysSubCompToPlant%AirLoopNum = 0
TempAirSysSubCompToPlant%AirLoopBranch = 0
TempAirSysSubCompToPlant%AirLoopComp = 0
TempAirSysSubCompToPlant%AirLoopSubComp = 0
TempAirSysSubCompToPlant%PlantLoopType = 0
TempAirSysSubCompToPlant%PlantLoopNum = 0
TempAirSysSubCompToPlant%PlantLoopBranch = 0
TempAirSysSubCompToPlant%PlantLoopComp = 0
TempAirSysSubCompToPlant%FirstDemandSidePtr = 0
TempAirSysSubCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, SubCompNum
Duplicate = .FALSE.
DO TempIndex = 1,SubCompNum
IF (AirSysSubCompToPlant(Index)%AirLoopNum == TempAirSysSubCompToPlant(TempIndex)%AirLoopNum .AND. &
AirSysSubCompToPlant(Index)%AirLoopBranch == TempAirSysSubCompToPlant(TempIndex)%AirLoopBranch .AND. &
AirSysSubCompToPlant(Index)%AirLoopComp == TempAirSysSubCompToPlant(TempIndex)%AirLoopComp .AND. &
AirSysSubCompToPlant(Index)%AirLoopSubComp == TempAirSysSubCompToPlant(TempIndex)%AirLoopSubComp)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempAirSysSubCompToPlant(ArrayCount)%AirLoopNum = AirSysSubCompToPlant(Index)%AirLoopNum
TempAirSysSubCompToPlant(ArrayCount)%AirLoopBranch = AirSysSubCompToPlant(Index)%AirLoopBranch
TempAirSysSubCompToPlant(ArrayCount)%AirLoopComp = AirSysSubCompToPlant(Index)%AirLoopComp
TempAirSysSubCompToPlant(ArrayCount)%AirLoopSubComp = AirSysSubCompToPlant(Index)%AirLoopSubComp
TempAirSysSubCompToPlant(ArrayCount)%PlantLoopType = AirSysSubCompToPlant(Index)%PlantLoopType
TempAirSysSubCompToPlant(ArrayCount)%PlantLoopNum = AirSysSubCompToPlant(Index)%PlantLoopNum
TempAirSysSubCompToPlant(ArrayCount)%PlantLoopBranch = AirSysSubCompToPlant(Index)%PlantLoopBranch
TempAirSysSubCompToPlant(ArrayCount)%PlantLoopComp = AirSysSubCompToPlant(Index)%PlantLoopComp
TempAirSysSubCompToPlant(ArrayCount)%FirstDemandSidePtr= AirSysSubCompToPlant(Index)%FirstDemandSidePtr
TempAirSysSubCompToPlant(ArrayCount)%LastDemandSidePtr = AirSysSubCompToPlant(Index)%LastDemandSidePtr
END IF
END DO
AirSysSubCompToPlant%AirLoopNum = TempAirSysSubCompToPlant%AirLoopNum
AirSysSubCompToPlant%AirLoopBranch = TempAirSysSubCompToPlant%AirLoopBranch
AirSysSubCompToPlant%AirLoopComp = TempAirSysSubCompToPlant%AirLoopComp
AirSysSubCompToPlant%AirLoopSubComp = TempAirSysSubCompToPlant%AirLoopSubComp
AirSysSubCompToPlant%PlantLoopType = TempAirSysSubCompToPlant%PlantLoopType
AirSysSubCompToPlant%PlantLoopNum = TempAirSysSubCompToPlant%PlantLoopNum
AirSysSubCompToPlant%PlantLoopBranch = TempAirSysSubCompToPlant%PlantLoopBranch
AirSysSubCompToPlant%PlantLoopComp = TempAirSysSubCompToPlant%PlantLoopComp
AirSysSubCompToPlant%FirstDemandSidePtr = TempAirSysSubCompToPlant%FirstDemandSidePtr
AirSysSubCompToPlant%LastDemandSidePtr = TempAirSysSubCompToPlant%LastDemandSidePtr
ENDIF
IF (SubSubCompNum > 0) THEN
TempAirSysSubSubCompToPlant%AirLoopNum = 0
TempAirSysSubSubCompToPlant%AirLoopBranch = 0
TempAirSysSubSubCompToPlant%AirLoopComp = 0
TempAirSysSubSubCompToPlant%AirLoopSubComp = 0
TempAirSysSubSubCompToPlant%AirLoopSubSubComp = 0
TempAirSysSubSubCompToPlant%PlantLoopType = 0
TempAirSysSubSubCompToPlant%PlantLoopNum = 0
TempAirSysSubSubCompToPlant%PlantLoopBranch = 0
TempAirSysSubSubCompToPlant%PlantLoopComp = 0
TempAirSysSubSubCompToPlant%FirstDemandSidePtr = 0
TempAirSysSubSubCompToPlant%LastDemandSidePtr = 0
ArrayCount = 0
DO Index = 1, SubSubCompNum
Duplicate = .FALSE.
DO TempIndex = 1,SubSubCompNum
IF (AirSysSubSubCompToPlant(Index)%AirLoopNum == TempAirSysSubSubCompToPlant(TempIndex)%AirLoopNum .AND. &
AirSysSubSubCompToPlant(Index)%AirLoopBranch == TempAirSysSubSubCompToPlant(TempIndex)%AirLoopBranch .AND. &
AirSysSubSubCompToPlant(Index)%AirLoopComp == TempAirSysSubSubCompToPlant(TempIndex)%AirLoopComp .AND. &
AirSysSubSubCompToPlant(Index)%AirLoopSubComp == TempAirSysSubSubCompToPlant(TempIndex)%AirLoopSubComp .AND. &
AirSysSubSubCompToPlant(Index)%AirLoopSubSubComp == TempAirSysSubSubCompToPlant(TempIndex)%AirLoopSubSubComp)THEN
Duplicate = .TRUE.
EXIT
END IF
END DO
IF(.NOT. Duplicate)THEN
ArrayCount = ArrayCount + 1
TempAirSysSubSubCompToPlant(ArrayCount)%AirLoopNum = AirSysSubSubCompToPlant(Index)%AirLoopNum
TempAirSysSubSubCompToPlant(ArrayCount)%AirLoopBranch = AirSysSubSubCompToPlant(Index)%AirLoopBranch
TempAirSysSubSubCompToPlant(ArrayCount)%AirLoopComp = AirSysSubSubCompToPlant(Index)%AirLoopComp
TempAirSysSubSubCompToPlant(ArrayCount)%AirLoopSubComp = AirSysSubSubCompToPlant(Index)%AirLoopSubComp
TempAirSysSubSubCompToPlant(ArrayCount)%AirLoopSubSubComp = AirSysSubSubCompToPlant(Index)%AirLoopSubSubComp
TempAirSysSubSubCompToPlant(ArrayCount)%PlantLoopType = AirSysSubSubCompToPlant(Index)%PlantLoopType
TempAirSysSubSubCompToPlant(ArrayCount)%PlantLoopNum = AirSysSubSubCompToPlant(Index)%PlantLoopNum
TempAirSysSubSubCompToPlant(ArrayCount)%PlantLoopBranch = AirSysSubSubCompToPlant(Index)%PlantLoopBranch
TempAirSysSubSubCompToPlant(ArrayCount)%PlantLoopComp = AirSysSubSubCompToPlant(Index)%PlantLoopComp
TempAirSysSubSubCompToPlant(ArrayCount)%FirstDemandSidePtr= AirSysSubSubCompToPlant(Index)%FirstDemandSidePtr
TempAirSysSubSubCompToPlant(ArrayCount)%LastDemandSidePtr = AirSysSubSubCompToPlant(Index)%LastDemandSidePtr
END IF
END DO
AirSysSubSubCompToPlant%AirLoopNum = TempAirSysSubSubCompToPlant%AirLoopNum
AirSysSubSubCompToPlant%AirLoopBranch = TempAirSysSubSubCompToPlant%AirLoopBranch
AirSysSubSubCompToPlant%AirLoopComp = TempAirSysSubSubCompToPlant%AirLoopComp
AirSysSubSubCompToPlant%AirLoopSubComp = TempAirSysSubSubCompToPlant%AirLoopSubComp
AirSysSubSubCompToPlant%AirLoopSubSubComp = TempAirSysSubSubCompToPlant%AirLoopSubSubComp
AirSysSubSubCompToPlant%PlantLoopType = TempAirSysSubSubCompToPlant%PlantLoopType
AirSysSubSubCompToPlant%PlantLoopNum = TempAirSysSubSubCompToPlant%PlantLoopNum
AirSysSubSubCompToPlant%PlantLoopBranch = TempAirSysSubSubCompToPlant%PlantLoopBranch
AirSysSubSubCompToPlant%PlantLoopComp = TempAirSysSubSubCompToPlant%PlantLoopComp
AirSysSubSubCompToPlant%FirstDemandSidePtr = TempAirSysSubSubCompToPlant%FirstDemandSidePtr
AirSysSubSubCompToPlant%LastDemandSidePtr = TempAirSysSubSubCompToPlant%LastDemandSidePtr
ENDIF
! 2. Find Supply Side loop for every demand side component
!The demand side components only need to know what supply side loop
!they are connected to. The input and plant data structure will
!force the loop numbers to be the same.
! 3. Find Demand Side Component Corresponding to Supply Side Component
DO PlantLoopNum = 1, NumPlantLoops
DO BranchNum =1, VentRepPlantSupplySide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
CompType = VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%TypeOf
CompName = VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%Name
CALL FindDemandSideMatch(CompType,CompName,MatchFound,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%LoopType = MatchLoopType
VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%LoopNum = MatchLoop
VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%BranchNum = MatchBranch
VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%CompNum = MatchComp
END DO
END DO
END DO
DO PlantLoopNum = 1, NumCondLoops
DO BranchNum =1, VentRepCondSupplySide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
CompType = VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%TypeOf
CompName = VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%Name
CALL FindDemandSideMatch(CompType,CompName,MatchFound,MatchLoopType,MatchLoop,MatchBranch,MatchComp)
VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%LoopType = MatchLoopType
VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%LoopNum = MatchLoop
VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%BranchNum = MatchBranch
VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%ConnectPlant%CompNum = MatchComp
END DO
END DO
END DO
END DO
END DO ! Controlled Zone Loop
!4. Now Load all of the plant supply/demand side connections in a single array with pointers from the
! connection arrays (ZoneCompToPlant, ZoneSubCompToPlant, ZoneSubSubCompToPlant, AirSysCompToPlant, etc.)
IF (ALLOCATED(ZoneCompToPlant)) THEN
NumZoneConnectComps = SIZE(ZoneCompToPlant)
ELSE
NumZoneConnectComps = 0
ENDIF
IF (ALLOCATED(ZoneSubCompToPlant)) THEN
NumZoneConnectSubComps = SIZE(ZoneSubCompToPlant)
ELSE
NumZoneConnectSubComps = 0
ENDIF
IF (ALLOCATED(ZoneSubSubCompToPlant)) THEN
NumZoneConnectSubSubComps = SIZE(ZoneSubSubCompToPlant)
ELSE
NumZoneConnectSubSubComps = 0
ENDIF
IF (ALLOCATED(AirSysCompToPlant)) THEN
NumAirSysConnectComps = SIZE(AirSysCompToPlant)
ELSE
NumAirSysConnectComps = 0
ENDIF
IF (ALLOCATED(AirSysSubCompToPlant)) THEN
NumAirSysConnectSubComps = SIZE(AirSysSubCompToPlant)
ELSE
NumAirSysConnectSubComps = 0
ENDIF
IF (ALLOCATED(AirSysSubSubCompToPlant)) THEN
NumAirSysConnectSubSubComps = SIZE(AirSysSubSubCompToPlant)
ELSE
NumAirSysConnectSubSubComps = 0
ENDIF
OneTimeFlag = .FALSE.
ArrayCount = 0
DO CompNum = 1,NumZoneConnectComps
LoopType = ZoneCompToPlant(CompNum)%PlantLoopType
LoopNum = ZoneCompToPlant(CompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
ZoneCompToPlant(CompNum)%FirstDemandSidePtr = FirstIndex
ZoneCompToPlant(CompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
DO SubCompNum = 1,NumZoneConnectSubComps
LoopType = ZoneSubCompToPlant(SubCompNum)%PlantLoopType
LoopNum = ZoneSubCompToPlant(SubCompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
ZoneSubCompToPlant(SubCompNum)%FirstDemandSidePtr = FirstIndex
ZoneSubCompToPlant(SubCompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
DO SubSubCompNum = 1,NumZoneConnectSubSubComps
LoopType = ZoneSubSubCompToPlant(SubSubCompNum)%PlantLoopType
LoopNum = ZoneSubSubCompToPlant(SubSubCompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
ZoneSubSubCompToPlant(SubSubCompNum)%FirstDemandSidePtr = FirstIndex
ZoneSubSubCompToPlant(SubSubCompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
DO CompNum = 1,NumAirSysConnectComps
LoopType = AirSysCompToPlant(CompNum)%PlantLoopType
LoopNum = AirSysCompToPlant(CompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
AirSysCompToPlant(CompNum)%FirstDemandSidePtr = FirstIndex
AirSysCompToPlant(CompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
DO SubCompNum = 1,NumAirSysConnectSubComps
LoopType = AirSysSubCompToPlant(SubCompNum)%PlantLoopType
LoopNum = AirSysSubCompToPlant(SubCompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
AirSysSubCompToPlant(SubCompNum)%FirstDemandSidePtr = FirstIndex
AirSysSubCompToPlant(SubCompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
DO SubSubCompNum = 1,NumAirSysConnectSubSubComps
LoopType = AirSysSubSubCompToPlant(SubSubCompNum)%PlantLoopType
LoopNum = AirSysSubSubCompToPlant(SubSubCompNum)%PlantLoopNum
FirstIndex = ArrayCount + 1
LoopCount = 1
IF(LoopType > 0 .AND. LoopNum > 0)THEN
CALL FindFirstLastPtr(LoopType,LoopNum,ArrayCount,LoopCount,ConnectionFlag)
END IF
LastIndex = ArrayCount
IF(FirstIndex > LastIndex) FirstIndex = LastIndex
IF(ConnectionFlag)THEN
AirSysSubSubCompToPlant(SubSubCompNum)%FirstDemandSidePtr = FirstIndex
AirSysSubSubCompToPlant(SubSubCompNum)%LastDemandSidePtr = LastIndex
ENDIF
END DO
OneTimeFlag = .FALSE.
END IF
! On every iteration, load the air loop energy data
DO AirLoopNum =1, NumPrimaryAirSys
DO BranchNum = 1, PrimaryAirSystem(AirLoopNum)%NumBranches
DO CompNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%TotalComponents
DO VarNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumMeteredVars
VarType = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarIndex
PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
DO SubCompNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumSubcomps
DO VarNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)%NumMeteredVars
VarType = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
MeteredVar(VarNum)%ReportVarType
VarIndex = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
MeteredVar(VarNum)%ReportVarIndex
PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
DO SubSubCompNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)%NumSubSubComps
DO VarNum = 1, PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
SubSubComp(SubSubCompNum)%NumMeteredVars
VarType = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
SubSubComp(SubSubCompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
SubSubComp(SubSubCompNum)%MeteredVar(VarNum)%ReportVarIndex
PrimaryAirSystem(AirLoopNum)%Branch(BranchNum)%Comp(CompNum)%SubComp(SubCompNum)% &
SubSubComp(SubSubCompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
END DO
END DO
END DO
END DO
END DO
! On every iteration, load the zone equipment energy data
DO ListNum = 1, NumofZones
IF (.not. ZoneEquipConfig(ListNum)%IsControlled) CYCLE
DO CompNum = 1,ZoneEquipList(ListNum)%NumOfEquipTypes
DO VarNum =1,ZoneEquipList(ListNum)%EquipData(CompNum)%NumMeteredVars
VarType = ZoneEquipList(ListNum)%EquipData(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = ZoneEquipList(ListNum)%EquipData(CompNum)%MeteredVar(VarNum)%ReportVarIndex
ZoneEquipList(ListNum)%EquipData(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
DO SubCompNum = 1, ZoneEquipList(ListNum)%EquipData(CompNum)%NumSubEquip
DO VarNum = 1, ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)%NumMeteredVars
VarType = ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)%MeteredVar(VarNum)%ReportVarIndex
ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
DO SubSubCompNum = 1, ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)%NumSubSubEquip
DO VarNum = 1, ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)% &
SubSubEquipData(SubSubCompNum)%NumMeteredVars
VarType = ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)% &
SubSubEquipData(SubSubCompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)% &
SubSubEquipData(SubSubCompNum)%MeteredVar(VarNum)%ReportVarIndex
ZoneEquipList(ListNum)%EquipData(CompNum)%SubEquipData(SubCompNum)% &
SubSubEquipData(SubSubCompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex) !Sankar Corrected zone array
END DO
END DO
END DO
END DO
END DO
! On every iteration, load the Plant Supply Side Data
DO PlantLoopNum = 1, NumPlantLoops
DO BranchNum =1, VentRepPlantSupplySide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
DO VarNum = 1, VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumMeteredVars
VarType = VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarIndex
VentRepPlantSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
END DO
END DO
END DO
! On every iteration, load the Plant Demand Side Data
DO PlantLoopNum = 1, NumPlantLoops
DO BranchNum =1, VentRepPlantDemandSide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepPlantDemandSide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
DO VarNum = 1, VentRepPlantDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumMeteredVars
VarType = VentRepPlantDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = VentRepPlantDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarIndex
VentRepPlantDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
END DO
END DO
END DO
! On every iteration, load the Condenser Supply Side Data
DO PlantLoopNum = 1, NumCondLoops
DO BranchNum =1, VentRepCondSupplySide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
DO VarNum = 1, VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumMeteredVars
VarType = VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarIndex
VentRepCondSupplySide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
END DO
END DO
END DO
! On every iteration, load the Condenser Demand Side Data
DO PlantLoopNum = 1, NumCondLoops
DO BranchNum =1, VentRepCondDemandSide(PlantLoopNum)%TotalBranches
DO CompNum =1, VentRepCondDemandSide(PlantLoopNum)%Branch(BranchNum)%TotalComponents
DO VarNum = 1, VentRepCondDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%NumMeteredVars
VarType = VentRepCondDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarType
VarIndex = VentRepCondDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%ReportVarIndex
VentRepCondDemandSide(PlantLoopNum)%Branch(BranchNum)%Comp(CompNum)%MeteredVar(VarNum)%CurMeterReading = &
GetInternalVariableValue(VarType,VarIndex)
END DO
END DO
END DO
END DO
! initialize energy report variables
END SUBROUTINE InitEnergyReports