SUBROUTINE CalcOptStartSysAvailMgr(SysAvailNum,PriAirSysNum,AvailStatus,ZoneEquipType, CompNum)
! SUBROUTINE INFORMATION:
! AUTHOR Xiufeng Pang (XP)
! DATE WRITTEN August 2013
! MODIFIED
!
! RE-ENGINEERED
! PURPOSE OF THIS SUBROUTINE:
! Set AvailStatus indicator for a primary air loop, plant loop or ZoneHVAC component
! METHODOLOGY EMPLOYED:
! Sets the AvailStatus indicator according to the
! optimum start algorithm
! REFERENCES:
!
! USE STATEMENTS:
USE DataAirLoop
USE DataZoneEquipment, ONLY: ZoneEquipConfig
USE DataHeatBalFanSys, ONLY: TempZoneThermostatSetpoint, ZoneThermostatSetPointHi, &
ZoneThermostatSetPointLo, TempControlType, TempTstatAir
USE DataEnvironment, ONLY: DSTIndicator, DayOfYear, DayOfWeekTomorrow, DayOfWeek
USE DataZoneControls, ONLY: OccRoomTSetPointHeat, OccRoomTSetPointCool
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT (IN) :: SysAvailNum ! number of the current scheduled system availability manager
INTEGER, INTENT (IN) :: PriAirSysNum ! number of the primary air system affected by this Avail. Manager
INTEGER, INTENT (OUT) :: AvailStatus ! System status indicator
INTEGER, OPTIONAL, INTENT(IN) :: ZoneEquipType ! Type of ZoneHVAC equipment component
INTEGER, OPTIONAL, INTENT(IN) :: CompNum ! Index of ZoneHVAC equipment component
! SUBROUTINE PARAMETER DEFINITIONS:
! INTERFACE BLOCK SPECIFICATIONS:
! DERIVED TYPE DEFINITIONS:
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: ScheduleIndex
INTEGER :: DayScheduleIndex
REAL(r64), ALLOCATABLE, DIMENSION(:,:) :: DayValues
REAL(r64), ALLOCATABLE, DIMENSION(:,:) :: DayValuesTmr
INTEGER :: JDay
INTEGER :: TmrJDay
INTEGER :: CurDayofWeek
INTEGER :: TmrDayOfWeek
INTEGER :: ZoneNum
REAL(r64) :: FanStartTime
REAL(r64) :: FanStartTimeTmr
REAL(r64) :: PreStartTime
REAL(r64) :: PreStartTimeTmr
REAL(r64) :: DeltaTime
INTEGER :: I
INTEGER :: J
REAL(r64) :: TempDiff
REAL(r64), SAVE :: TempDiffHi = 0.0d0
REAL(r64), SAVE :: TempDiffLo = 0.0d0
! LOGICAL, ALLOCATABLE, SAVE, DIMENSION(:) :: ZoneCompOptStartControlType
LOGICAL :: FirstTimeATGFlag = .TRUE.
LOGICAL :: OverNightStartFlag = .False. ! Flag to indicate the optimum start starts before mid night.
LOGICAL :: CycleOnFlag = .False.
LOGICAL :: OSReportVarFlag = .True.
INTEGER :: NumPreDays
INTEGER :: NumOfZonesInList
REAL(r64), ALLOCATABLE, DIMENSION(:), SAVE :: AdaTempGradTrdHeat !Heating temp gradient for previous days
REAL(r64), ALLOCATABLE, DIMENSION(:), SAVE :: AdaTempGradTrdCool !Cooling temp gradient for previous days
REAL(r64), SAVE :: AdaTempGradHeat
REAL(r64), SAVE :: AdaTempGradCool
REAL(r64) :: ATGUpdateTime1 = 0.0d0
REAL(r64) :: ATGUpdateTime2 = 0.0d0
REAL(r64) :: ATGUpdateTemp1 = 0.0d0
REAL(r64) :: ATGUpdateTemp2 = 0.0d0
LOGICAL :: ATGUpdateFlag1 = .False.
LOGICAL :: ATGUpdateFlag2 = .False.
INTEGER :: ATGCounter
INTEGER :: ATGWCZoneNumHi
INTEGER :: ATGWCZoneNumLo
REAL(r64) :: NumHoursBeforeOccupancy = 0.0d0 !Variable to store the number of hours before occupancy in optimum start period
! add or use a new variable OptStartSysAvailMgrData(SysAvailNum)%FanSchIndex
IF (KickOffSimulation) THEN
AvailStatus = NoAction
ELSE
ScheduleIndex=GetScheduleIndex(OptStartSysAvailMgrData(SysAvailNum)%FanSched)
JDay = DayOfYear
TmrJDay = JDay + 1
TmrDayOfWeek = DayOfWeekTomorrow
ALLOCATE (DayValues(24,NumOfTimeStepInHour))
ALLOCATE (DayValuesTmr(24,NumOfTimeStepInHour))
IF (.not.allocated(OptStartData%OptStartFlag)) THEN
ALLOCATE (OptStartData%OptStartFlag(NumOfZones))
ALLOCATE (OptStartData%OccStartTime(NumOfZones))
END IF
IF (.NOT.ALLOCATED(OptStartData%ActualZoneNum)) ALLOCATE(OptStartData%ActualZoneNum(NumOfZones))
OptStartData%OptStartFlag = .FALSE.
OptStartData%OccStartTime = 99.99d0 !initialize the zone occupancy start time
Call GetScheduleValuesForDay(ScheduleIndex,DayValues)
Call GetScheduleValuesForDay(ScheduleIndex,DayValuesTmr, TmrJDay, TmrDayOfWeek)
FanStartTime = 0.0d0
FanStartTimeTmr = 0.0d0
Loop1: DO I = 1, 24
Loop2: DO J = 1, NumOfTimeStepInHour
IF (DayValues(I,J)> 0.0d0) THEN
FanStartTime = I-1 + 1/NumOfTimeStepInHour * J
EXIT Loop1
ENDIF
END DO Loop2
END DO Loop1
Loop3: DO I = 1, 24
Loop4: DO J = 1, NumOfTimeStepInHour
IF (DayValuesTmr(I,J)> 0.0d0) THEN
FanStartTimeTmr = I-1 + 1/NumOfTimeStepInHour * J
EXIT Loop3
ENDIF
END DO Loop4
END DO Loop3
IF (FanStartTimeTmr == 0.0d0) FanStartTimeTmr = 24.0d0
! Pass the start time to ZoneTempPredictorCorrector
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OccStartTime(ZoneEquipConfig(I)%ActualZoneNum)=FanStartTime
OptStartData%ActualZoneNum(ZoneEquipConfig(I)%ActualZoneNum)=ZoneEquipConfig(I)%ActualZoneNum
END IF
END DO
If (DSTIndicator>0) then
FanStartTime = FanStartTime - 1.d0
FanStartTimeTmr = FanStartTimeTmr - 1.d0
End If
IF (BeginDayFlag) THEN
NumHoursBeforeOccupancy = 0.0 !Initialize the hours of optimum start period. This variable is for reporting purpose.
END IF
SELECT CASE(OptStartSysAvailMgrData(SysAvailNum)%CtrlAlgType)
CASE(ConstantStartTime)
IF (OptStartSysAvailMgrData(SysAvailNum)%CtrlType == StayOff) THEN
AvailStatus = NoAction
ELSE
DeltaTime = OptStartSysAvailMgrData(SysAvailNum)%ConstStartTime
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
if (PreStartTime<0.0d0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
If (PreStartTimeTmr<0.0d0) then
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
else
OverNightStartFlag = .False.
end if
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. PreviousHour .GT. FanStartTime) THEN
AvailStatus = NoAction
OSReportVarFlag = .True.
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (HourOfDay .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
OSReportVarFlag = .True.
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
OSReportVarFlag = .True.
END IF
END IF
END IF
CASE(ConstantTemperatureGradient)
IF (OptStartSysAvailMgrData(SysAvailNum)%CtrlType == ControlZone) THEN
ZoneNum = OptStartSysAvailMgrData(SysAvailNum)%ZoneNum
IF ((.Not.allocated(TempTstatAir)) .OR. (.Not.allocated(ZoneThermostatSetPointLo)) .OR. &
(.Not.allocated(ZoneThermostatSetPointHi))) THEN
TempDiff = 0.0d0
ELSE
IF (.NOT. CycleOnFlag) THEN
IF (ALLOCATED(OccRoomTSetPointHeat) .AND. ALLOCATED(OccRoomTSetPointCool)) THEN
TempDiffHi = TempTstatAir(ZoneNum) - OccRoomTSetPointCool(ZoneNum)
TempDiffLo = TempTstatAir(ZoneNum) - OccRoomTSetPointHeat(ZoneNum)
ELSE
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
END IF
END IF
END IF
IF (TempDiffHi<0.0d0) THEN
TempDiff = TempDiffLo
IF (TempDiff .LT. 0.0d0) THEN !Heating Mode
TempDiff = ABS(TempDiff)
DeltaTime = TempDiff/OptStartSysAvailMgrData(SysAvailNum)%ConstTGradHeat
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime) CycleOnFlag = .False.
ELSE IF (PreStartTime .LT. CurrentTime) THEN
AvailStatus = CycleOn
CycleOnFlag = .True.
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime .AND. CurrentTime .LT. PreStartTimeTmr) CycleOnFlag=.False.
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE IF (OccRoomTSetPointCool(ZoneNum) .LT. 50.0d0) THEN ! Cooling Mode
TempDiff = TempDiffHi
DeltaTime = TempDiff/OptStartSysAvailMgrData(SysAvailNum)%ConstTGradCool
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE IF (OptStartSysAvailMgrData(SysAvailNum)%CtrlType == MaximumOfZoneList) THEN
NumOfZonesInList = OptStartSysAvailMgrData(SysAvailNum)%NumOfZones
IF ((.Not.allocated(TempTstatAir)) .OR. (.Not.allocated(ZoneThermostatSetPointLo)) .OR. &
(.Not.allocated(ZoneThermostatSetPointHi))) THEN
TempDiff = 0.0d0
ELSE
IF (.NOT. CycleOnFlag) THEN
IF (ALLOCATED(OccRoomTSetPointHeat) .AND. ALLOCATED(OccRoomTSetPointCool)) THEN
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
DO ZoneNum=1, NumOfZonesInList
TempDiff=TempTstatAir(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)) - &
OccRoomTSetPointCool(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum))
TempDiffHi = Max(TempDiffHi, TempDiff)
TempDiff=TempTstatAir(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)) - &
OccRoomTSetPointHeat(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum))
TempDiffLo = Min(TempDiffLo, TempDiff)
END DO
ELSE
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
END IF
END IF
END IF
IF ((TempDiffHi<0.0d0 .AND. TempDiffLo<0.0d0) .OR. (abs(TempDiffLo)>abs(TempDiffHi) &
.AND. TempDiffLo<0)) THEN !Heating Mode
TempDiff = TempDiffLo
TempDiff = ABS(TempDiff)
DeltaTime = TempDiff/OptStartSysAvailMgrData(SysAvailNum)%ConstTGradHeat
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime) CycleOnFlag = .False.
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime .AND. CurrentTime .LT. PreStartTimeTmr) CycleOnFlag=.False.
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE IF (TempDiffHi<=0.0d0 .AND. TempDiffLo>=0.0d0) THEN ! not heating and not cooling
AvailStatus = NoAction
CycleOnFlag = .False.
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
ELSE IF (TempDiffHi < 30.0d0) THEN ! Cooling Mode
TempDiff = TempDiffHi
DeltaTime = TempDiff/OptStartSysAvailMgrData(SysAvailNum)%ConstTGradCool
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE
AvailStatus = NoAction
END IF
CASE(AdaptiveTemperatureGradient)
NumPreDays = OptStartSysAvailMgrData(SysAvailNum)%NumPreDays
IF (OptStartSysAvailMgrData(SysAvailNum)%CtrlType == ControlZone) THEN
IF (.NOT.ALLOCATED(AdaTempGradTrdHeat)) THEN
ALLOCATE(AdaTempGradTrdHeat(NumPreDays))
ALLOCATE(AdaTempGradTrdCool(NumPreDays))
END IF
ZoneNum = OptStartSysAvailMgrData(SysAvailNum)%ZoneNum
IF ((.Not.allocated(TempTstatAir)) .OR. (.Not.allocated(ZoneThermostatSetPointLo)) .OR. &
(.Not.allocated(ZoneThermostatSetPointHi))) THEN
TempDiff = 0.0d0
ELSE
IF (.NOT. CycleOnFlag) THEN
IF (ALLOCATED(OccRoomTSetPointHeat) .AND. ALLOCATED(OccRoomTSetPointCool)) THEN
TempDiffHi = TempTstatAir(ZoneNum) - OccRoomTSetPointCool(ZoneNum)
TempDiffLo = TempTstatAir(ZoneNum) - OccRoomTSetPointHeat(ZoneNum)
ELSE
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
END IF
END IF
END IF
!Store adaptive temperature gradients for previous days and calculate the adaptive temp gradients
!-----------------------------------------------------------------------------
IF (WarmupFlag) THEN
AdaTempGradHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradCool
ELSE IF (DayOfSim == BeginDay .AND. BeginDayFlag) THEN
AdaTempGradTrdHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradTrdCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
ELSE
IF (BeginDayFlag .AND. FirstTimeATGFlag) THEN
FirstTimeATGFlag = .False.
AdaTempGradHeat = AdaTempGradHeat + AdaTempGradTrdHeat(NumPreDays)/NumPreDays - &
AdaTempGradTrdHeat(1)/NumPreDays
AdaTempGradCool = AdaTempGradCool + AdaTempGradTrdCool(NumPreDays)/NumPreDays - &
AdaTempGradTrdCool(1)/NumPreDays
IF (FanStartTime>0) THEN
DO ATGCounter=1, NumPreDays-1
AdaTempGradTrdHeat(ATGCounter) = AdaTempGradTrdHeat(ATGCounter+1)
AdaTempGradTrdCool(ATGCounter) = AdaTempGradTrdCool(ATGCounter+1)
END DO
END IF
END IF
END IF
IF (CurrentTime >= 1.0d0) FirstTimeATGFlag = .True.
!------------------------------------------------------------------------------
IF (TempDiffHi<0.0d0) THEN
TempDiff = TempDiffLo
IF (TempDiff .LT. 0.0d0) THEN !Heating Mode
TempDiff = ABS(TempDiff)
DeltaTime = TempDiff/AdaTempGradHeat
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0.0d0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0.0d0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime) CycleOnFlag = .False.
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ZoneNum)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ZoneNum) .GE. OccRoomTSetPointHeat(ZoneNum) .AND. ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ZoneNum)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1) > 1.d-10) THEN
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)/(ATGUpdateTime2-ATGUpdateTime1)
ELSE
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)*NumOfTimeStepInHour
END IF
END IF
END IF
!---------------------------------------------------------------------------------
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime .AND. CurrentTime .LT. PreStartTimeTmr) CycleOnFlag=.False.
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ZoneNum)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ZoneNum) .GE. OccRoomTSetPointHeat(ZoneNum) .AND. ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ZoneNum)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1+24.0d0) > 1.d-10) THEN
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)/(ATGUpdateTime2-ATGUpdateTime1+24.0d0)
ELSE
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)*NumOfTimeStepInHour
END IF
END IF
END IF
!---------------------------------------------------------------------------------
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE IF (OccRoomTSetPointCool(ZoneNum) .LT. 50.0d0) THEN ! Cooling Mode
TempDiff = TempDiffHi
DeltaTime = TempDiff/AdaTempGradCool
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0.0d0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0.0d0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ZoneNum)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ZoneNum) .LE. OccRoomTSetPointCool(ZoneNum) .AND. ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ZoneNum)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1) > 1.d-10) THEN
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)/(ATGUpdateTime2-ATGUpdateTime1)
ELSE
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)*NumOfTimeStepInHour
END IF
END IF
END IF
ELSE IF (PreStartTime .LT. CurrentTime) THEN
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ZoneNum)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ZoneNum) .LE. OccRoomTSetPointCool(ZoneNum) .AND. ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ZoneNum)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1+24.0d0) > 1.d-10) THEN
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)/(ATGUpdateTime2-ATGUpdateTime1+24.0d0)
ELSE
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)*NumOfTimeStepInHour
END IF
END IF
END IF
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE !Not heating nor cooling mode
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE IF (OptStartSysAvailMgrData(SysAvailNum)%CtrlType == MaximumOfZoneList) THEN
IF (.NOT. ALLOCATED(AdaTempGradTrdHeat)) THEN
ALLOCATE(AdaTempGradTrdHeat(NumPreDays))
ALLOCATE(AdaTempGradTrdCool(NumPreDays))
END IF
NumOfZonesInList = OptStartSysAvailMgrData(SysAvailNum)%NumOfZones
ATGWCZoneNumHi = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(1)
ATGWCZoneNumLo = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(1)
IF ((.Not.allocated(TempTstatAir)) .OR. (.Not.allocated(ZoneThermostatSetPointLo)) .OR. &
(.Not.allocated(ZoneThermostatSetPointHi))) THEN
TempDiff = 0.0d0
ELSE
IF (.NOT. CycleOnFlag) THEN
IF (ALLOCATED(OccRoomTSetPointHeat) .AND. ALLOCATED(OccRoomTSetPointCool)) THEN
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
DO ZoneNum=1, NumOfZonesInList
TempDiff=TempTstatAir(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)) - &
OccRoomTSetPointCool(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum))
TempDiffHi = Max(TempDiffHi, TempDiff)
!Store the worse case zone number for actual temperature gradient calculation
IF (TempDiff == TempDiffHi) THEN
ATGWCZoneNumHi = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)
ELSE
ATGWCZoneNumHi = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(1)
END IF
TempDiff=TempTstatAir(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)) - &
OccRoomTSetPointHeat(OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum))
TempDiffLo = Min(TempDiffLo, TempDiff)
IF (TempDiff == TempDiffLo) THEN
ATGWCZoneNumLo = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(ZoneNum)
ELSE
ATGWCZoneNumLo = OptStartSysAvailMgrData(SysAvailNum)%ZonePtrs(1)
END IF
END DO
ELSE
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
END IF
END IF
END IF
!Store adaptive temperature gradients for previous days and calculate the adaptive temp gradients
!-----------------------------------------------------------------------------
IF (WarmupFlag) THEN
AdaTempGradHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradCool
ELSE IF (DayOfSim == BeginDay .AND. BeginDayFlag) THEN
AdaTempGradTrdHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradHeat = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradTrdCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
AdaTempGradCool = OptStartSysAvailMgrData(SysAvailNum)%InitTGradHeat
ELSE
IF (BeginDayFlag .AND. FirstTimeATGFlag) THEN
FirstTimeATGFlag = .False.
AdaTempGradHeat = AdaTempGradHeat + AdaTempGradTrdHeat(NumPreDays)/NumPreDays - &
AdaTempGradTrdHeat(1)/NumPreDays
AdaTempGradCool = AdaTempGradCool + AdaTempGradTrdCool(NumPreDays)/NumPreDays - &
AdaTempGradTrdCool(1)/NumPreDays
IF (FanStartTime>0) THEN
DO ATGCounter=1, NumPreDays-1
AdaTempGradTrdHeat(ATGCounter) = AdaTempGradTrdHeat(ATGCounter+1)
AdaTempGradTrdCool(ATGCounter) = AdaTempGradTrdCool(ATGCounter+1)
END DO
END IF
END IF
END IF
IF (CurrentTime >= 1.0d0) FirstTimeATGFlag = .True.
!------------------------------------------------------------------------------
IF ((TempDiffHi<0.0d0 .AND. TempDiffLo<0.0d0) .OR. (abs(TempDiffLo)>abs(TempDiffHi) &
.AND. TempDiffLo<0.0d0)) THEN !Heating Mode
TempDiff = TempDiffLo
TempDiff = ABS(TempDiff)
DeltaTime = TempDiff/AdaTempGradHeat
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0.0d0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0.0d0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
OSReportVarFlag = .True.
AvailStatus = NoAction
CycleOnFlag = .False.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime) CycleOnFlag = .False.
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ATGWCZoneNumLo)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ATGWCZoneNumLo) .GE. OccRoomTSetPointHeat(ATGWCZoneNumLo) .AND. &
ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ATGWCZoneNumLo)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1) > 1.d-10) THEN
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)/(ATGUpdateTime2-ATGUpdateTime1)
ELSE
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)*NumOfTimeStepInHour
END IF
END IF
END IF
!---------------------------------------------------------------------------------
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ATGWCZoneNumLo)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ATGWCZoneNumLo) .GE. OccRoomTSetPointHeat(ATGWCZoneNumLo) .AND. &
ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ATGWCZoneNumLo)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1+24.0d0) > 1.d-10) THEN
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)/(ATGUpdateTime2-ATGUpdateTime1+24.0d0)
ELSE
AdaTempGradTrdHeat(NumPreDays)=(ATGUpdateTemp2-ATGUpdateTemp1)*NumOfTimeStepInHour
END IF
END IF
END IF
!---------------------------------------------------------------------------------
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
IF (CurrentTime .GT. FanStartTime .AND. CurrentTime .LT. PreStartTimeTmr) CycleOnFlag=.False.
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE IF (TempDiffHi<=0.0d0 .AND. TempDiffLo>=0.0d0) THEN ! not heating and not cooling
AvailStatus = NoAction
CycleOnFlag = .False.
TempDiffHi = 0.0d0
TempDiffLo = 0.0d0
ELSE IF (TempDiffHi < 30.0d0) THEN ! Cooling Mode
TempDiff = TempDiffHi
DeltaTime = TempDiff/AdaTempGradCool
IF (DeltaTime>OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime) THEN
DeltaTime=OptStartSysAvailMgrData(SysAvailNum)%MaxOptStartTime
END IF
PreStartTime = FanStartTime - DeltaTime
IF (PreStartTime<0) PreStartTime = -.1d0
PreStartTimeTmr = FanStartTimeTmr - DeltaTime
IF (PreStartTimeTmr<0) THEN
PreStartTimeTmr = PreStartTimeTmr + 24.0d0
OverNightStartFlag = .True.
ELSE
OverNightStartFlag = .False.
END IF
IF (.NOT. OverNightStartFlag) THEN
IF (FanStartTime == 0.0d0 .OR. CurrentTime .GT. FanStartTime) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CyCleOnFlag) THEN
AvailStatus = CycleOn
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ATGWCZoneNumHi)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ATGWCZoneNumHi) .LE. OccRoomTSetPointCool(ATGWCZoneNumHi) .AND. &
ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ATGWCZoneNumHi)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1) > 1.d-10) THEN
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)/(ATGUpdateTime2-ATGUpdateTime1)
ELSE
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)*NumOfTimeStepInHour
ENDIF
END IF
END IF
!---------------------------------------------------------------------------------
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag1 = .True.
ATGUpdateFlag2 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
ELSE
IF (FanStartTime == 0.0d0 .OR. (CurrentTime .GT. FanStartTime .AND. CurrentTime .LE. PreStartTimeTmr)) THEN
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
ELSE IF (CycleOnFlag) THEN
AvailStatus = CycleOn
! Calculate the current day actual temperature gradient --------------------------
IF (.NOT. WarmupFlag) THEN
IF (ATGUpdateFlag1) THEN
ATGUpdateTime1 = CurrentTime
ATGUpdateTemp1 = TempTstatAir(ATGWCZoneNumHi)
ATGUpdateFlag1 = .False.
END IF
IF (TempTstatAir(ATGWCZoneNumHi) .LE. OccRoomTSetPointCool(ATGWCZoneNumHi) .AND. &
ATGUpdateFlag2) THEN
ATGUpdateTime2 = CurrentTime
ATGUpdateTemp2 = TempTstatAir(ATGWCZoneNumHi)
ATGUpdateFlag2 = .False.
IF (ABS(ATGUpdateTime2-ATGUpdateTime1+24.0d0) > 1.d-10) THEN
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)/(ATGUpdateTime2-ATGUpdateTime1+24.0d0)
ELSE
AdaTempGradTrdCool(NumPreDays)=(ATGUpdateTemp1-ATGUpdateTemp2)*NumOfTimeStepInHour
END IF
END IF
END IF
!---------------------------------------------------------------------------------
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE IF (PreStartTime .LT. CurrentTime .OR. PreStartTimeTmr .LT. CurrentTime) THEN
IF (OSReportVarFlag) THEN
NumHoursBeforeOccupancy=DeltaTime
OSReportVarFlag = .False.
END IF
AvailStatus = CycleOn
CycleOnFlag = .True.
ATGUpdateFlag2 = .True.
ATGUpdateFlag1 = .True.
DO I=1, NumOfZones
If (ZoneEquipConfig(I)%AirLoopNum==PriAirSysNum) THEN
OptStartData%OptStartFlag(ZoneEquipConfig(I)%ActualZoneNum)=.TRUE.
END IF
END DO
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
OSReportVarFlag = .True.
END IF
END IF
ELSE
AvailStatus = NoAction
CycleOnFlag = .False.
END IF
ELSE
AvailStatus = NoAction
END IF
CASE(AdaptiveASHRAE)
AvailStatus = NoAction
END SELECT
END IF
OptStartSysAvailMgrData(SysAvailNum)%AvailStatus = AvailStatus
OptStartSysAvailMgrData(SysAvailNum)%NumHoursBeforeOccupancy = NumHoursBeforeOccupancy
RETURN
END SUBROUTINE CalcOptStartSysAvailMgr