SUBROUTINE ControlDXSystem(DXSystemNum, FirstHVACIteration, HXUnitOn)
          ! SUBROUTINE INFORMATION:
          !       AUTHOR         Richard Liesen
          !       DATE WRITTEN   Feb 2001
          !       MODIFIED       Richard Raustad, FSEC Nov 2003
          !                      Feb 2005 M. J. Witte, GARD Analytics, Inc.
          !                        Add dehumidification controls and support for multimode DX coil
          !                      Jan 2008 R. Raustad, FSEC. Added coolreheat to all coil types
          !                      Feb 2013 Bo Shen, Oak Ridge National Lab
          !                      Add Coil:Cooling:DX:VariableSpeed, capable of both sensible and latent cooling
          !       RE-ENGINEERED  na
          ! PURPOSE OF THIS SUBROUTINE:
          !  This subroutine updates the System outlet nodes.
          ! METHODOLOGY EMPLOYED:
          !  Data is moved from the System data structure to the System outlet nodes.
          ! REFERENCES:
          !  na
          ! USE STATEMENTS:
  USE ScheduleManager
  USE DataEnvironment, ONLY: OutBaroPress
  USE DataHVACGlobals, ONLY: TempControlTol
  USE InputProcessor,  ONLY: FindItemInList
  USE Psychrometrics , ONLY: PsyHFnTdbW, PsyTdpFnWPb
  USE General,         ONLY: SolveRegulaFalsi, RoundSigDigits
  USE DXCoils,         ONLY: SimDXCoil, SimDXCoilMultiSpeed, DXCoilOutletTemp, SimDXCoilMultiMode, DXCoilOutletHumRat
  USE HVACHXAssistedCoolingCoil, ONLY: SimHXAssistedCoolingCoil, HXAssistedCoilOutletTemp, HXAssistedCoilOutletHumRat
  USE VariableSpeedCoils,   ONLY: SimVariableSpeedCoils, VarSpeedCoil
  USE PackagedThermalStorageCoil, ONLY: SimTESCoil
  IMPLICIT NONE    ! Enforce explicit typing of all variables in this routine
          ! SUBROUTINE ARGUMENT DEFINITIONS:
  INTEGER,  Intent(In)    :: DXSystemNum             ! index to DXSystem
  LOGICAL,  Intent(In)    :: FirstHVACIteration      ! First HVAC iteration flag
  LOGICAL,  Intent(InOut) :: HXUnitOn                ! flag to enable heat exchanger heat recovery
          ! SUBROUTINE PARAMETER DEFINITIONS:
  INTEGER, PARAMETER          :: MaxIte    = 500     ! Maximum number of iterations for solver
  REAL(r64), PARAMETER :: Acc       = 1.d-3   ! Accuracy of solver result
  REAL(r64), PARAMETER :: HumRatAcc = 1.d-6   ! Accuracy of solver result
          ! INTERFACE BLOCK SPECIFICATIONS
          !  na
          ! DERIVED TYPE DEFINITIONS
          !  na
          ! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
  CHARACTER(len=MaxNameLength)  :: CompName  ! Name of the DX cooling coil
  REAL(r64)           :: NoOutput            ! Sensible capacity (outlet - inlet) when the compressor is off
  REAL(r64)           :: FullOutput          ! Sensible capacity (outlet - inlet) when the compressor is on
  REAL(r64)           :: ReqOutput           ! Sensible capacity (outlet - inlet) required to meet load or setpoint temperature
  Integer             :: InletNode           ! Inlet node number of the DX cooling coil
  Integer             :: OutletNode          ! Outlet node number of the DX cooling coil
  Integer             :: ControlNode         ! The node number where a setpoint is placed to control the DX cooling coil
  REAL(r64)           :: PartLoadFrac        ! The part-load fraction of the compressor
  REAL(r64)           :: SpeedRatio          ! SpeedRatio = (CompressorSpeed - CompressorSpeedMin) /
                                             !              (CompressorSpeedMax - CompressorSpeedMin)
                                             ! for variable speed or 2 speed compressors
  REAL(r64)           :: CycRatio            ! Cycling part-load ratio for variable speed or 2 speed compressors
  REAL(r64)           :: DesOutTemp          ! Desired outlet temperature of the DX cooling coil
  REAL(r64)           :: DesOutHumRat        ! Desired outlet humidity ratio of the DX cooling coil
  REAL(r64)           :: OutletTempDXCoil    ! Actual outlet temperature of the DX cooling coil
  REAL(r64)           :: OutletTempLS        ! Actual outlet temperature of the variable speed DX cooling coil at low speed
  REAL(r64)           :: OutletTempHS        ! Actual outlet temperature of the variable speed DX cooling coil at high speed
  REAL(r64)           :: OutletHumRatLS      ! Actual outlet humrat of the variable speed DX cooling coil at low speed
  REAL(r64)           :: OutletHumRatHS      ! Actual outlet humrat of the variable speed DX cooling coil at high speed
  REAL(r64)           :: OutletHumRatDXCoil  ! Actual outlet humidity ratio of the DX cooling coil
  INTEGER             :: SolFla              ! Flag of solver
  REAL(r64), DIMENSION(5)  :: Par                 ! Parameter array passed to solver
  LOGICAL             :: SensibleLoad        ! True if there is a sensible cooling load on this system
  LOGICAL             :: LatentLoad          ! True if there is a latent   cooling load on this system
  INTEGER             :: DehumidMode         ! Dehumidification mode (0=normal, 1=enhanced)
  INTEGER             :: FanOpMode           ! Supply air fan operating mode
  REAL(r64)           :: TempMinPLR          ! Used to find latent PLR when max iterations exceeded
  REAL(r64)           :: TempMaxPLR          ! Used to find latent PLR when max iterations exceeded
  REAL(r64)           :: TempOutletTempDXCoil   ! Used to find latent PLR when max iterations exceeded
  REAL(r64)           :: TempOutletHumRatDXCoil ! Used to find latent PLR when max iterations exceeded
  REAL(r64)           :: NoLoadHumRatOut     ! DX coil outlet air humidity ratio with comprssor off
  REAL(r64)           :: FullLoadHumRatOut   ! DX coil outlet air humidity ratio with comprssor full on
  !added variables to call variable speed DX coils
  INTEGER             :: SpeedNum            !speed number of variable speed DX cooling coil
  REAL(r64)           :: QZnReq               ! Zone load (W), input to variable-speed DX coil
  REAL(r64)           :: QLatReq              ! Zone latent load, input to variable-speed DX coil
  REAL(r64)           :: MaxONOFFCyclesperHour        ! Maximum cycling rate of heat pump [cycles/hr]
  REAL(r64)           :: HPTimeConstant               ! Heat pump time constant [s]
  REAL(r64)           :: FanDelayTime                 ! Fan delay time, time delay for the HP's fan to
  REAL(r64)           :: OnOffAirFlowRatio  ! ratio of compressor on flow to average flow over time step
  REAL(r64)           :: TempSpeedOut         ! output at one speed level
  REAL(r64)           :: TempSpeedReqst         ! request capacity at one speed level
  INTEGER             :: NumOfSpeeds      !maximum number of speed
  INTEGER             :: VSCoilIndex      !variable-speed coil index
  INTEGER             :: I               ! interation increment
      ! Set local variables
      ! Retrieve the load on the controlled zone
  OutletNode   = DXCoolingSystem(DXSystemNum)%DXCoolingCoilOutletNodeNum
  InletNode    = DXCoolingSystem(DXSystemNum)%DXCoolingCoilInletNodeNum
  ControlNode  = DXCoolingSystem(DXSystemNum)%DXSystemControlNodeNum
  DesOutTemp   = DXCoolingSystem(DXSystemNum)%DesiredOutletTemp
  DesOutHumRat = DXCoolingSystem(DXSystemNum)%DesiredOutletHumRat
  CompName     = DXCoolingSystem(DXSystemNum)%CoolingCoilName
  FanOpMode    = DXCoolingSystem(DXSystemNum)%FanOpMode
  SpeedRatio   = 0.0d0
  CycRatio     = 0.0d0
  PartLoadFrac = 0.0d0
  DehumidMode  = 0
  SensibleLoad = .FALSE.
  LatentLoad   = .FALSE.
  SpeedNum     = 1
  QZnReq       = 0.0d0
  QLatReq      = 0.0d0
  MaxONOFFCyclesperHour = 4.0d0 !default number
  HPTimeConstant= 0.0d0
  FanDelayTime  = 0.0d0
  OnOffAirFlowRatio = 1.0d0
  TempSpeedOut  = 0.0d0
  TempSpeedReqst  = 0.0d0
  NumOfSpeeds = 0
  VSCoilIndex = 0
  I = 1
  ! If DXCoolingSystem is scheduled on and there is flow
  If((GetCurrentScheduleValue(DXCoolingSystem(DXSystemNum)%SchedPtr) .gt. 0.0d0) .and. &
     (Node(InletNode)%MassFlowRate .gt. MinAirMassFlow)) THEN
    ! Determine if there is a sensible load on this system
    IF((Node(InletNode)%Temp > Node(ControlNode)%TempSetPoint) .and. &
       (Node(InletNode)%Temp > DesOutTemp) .and. &
       (ABS(Node(InletNode)%Temp - DesOutTemp) .gt. TempControlTol) ) SensibleLoad = .true.
    ! Determine if there is a latent load on this system - for future use to serve latent-only loads
    IF((Node(InletNode)%HumRat > Node(ControlNode)%HumRatMax) .and. &
       (Node(InletNode)%HumRat > DesOutHumRat)) LatentLoad = .true.
    ! If DXCoolingSystem runs with a cooling load then set PartLoadFrac on Cooling System and the Mass Flow
    ! Multimode coil will switch to enhanced dehumidification if available and needed, but it
    ! still runs to meet the sensible load. Multimode applies to Multimode or HXAssistedCooling coils.
    IF ((SensibleLoad .and. DXCoolingSystem(DXSystemNum)%RunOnSensibleLoad) .OR. &
        (LatentLoad .and. DXCoolingSystem(DXSystemNum)%RunOnLatentLoad)) THEN
      ! calculate sensible PLR, don't care if latent is true here but need to gaurd for
      ! when LatentLoad=TRUE and SensibleLoad=FALSE
      SELECT CASE(DXCoolingSystem(DXSystemNum)%CoolingCoilType_Num)
        CASE (CoilDX_CoolingSingleSpeed)  ! COIL:DX:COOLINGBYPASSFACTOREMPIRICAL
          ! Get no load result
          PartLoadFrac = 0.0d0
          CALL SimDXCoil(CompName,On,FirstHVACIteration,PartLoadFrac,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,FanOpMode)
          NoOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          NoLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          ! Get full load result
          PartLoadFrac = 1.0d0
          CALL SimDXCoil(CompName,On,FirstHVACIteration,PartLoadFrac,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,FanOpMode)
          FullLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
!         IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
          IF ((NoOutput-ReqOutput) .LT. Acc) THEN
            PartLoadFrac = 0.0d0
!         If the FullOutput is greater than (insufficient cooling) or very near the ReqOutput,
!         run the compressor at PartLoadFrac = 1.
          ELSE IF ((FullOutput - ReqOutput) .GT. Acc) THEN
            PartLoadFrac = 1.0d0
!         Else find the PLR to meet the load
          ELSE
!           OutletTempDXCoil is the full capacity outlet temperature at PartLoadFrac = 1 from the CALL above. If this temp is
!           greater than the desired outlet temp, then run the compressor at PartLoadFrac = 1, otherwise find the operating PLR.
            OutletTempDXCoil = DXCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            IF (OutletTempDXCoil > DesOutTemp) THEN
              PartLoadFrac = 1.0d0
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutTemp
              Par(5) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, DOE2DXCoilResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible '// &
                                          'part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                    CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                END IF
              ELSE IF (SolFla == -2) THEN
                PartLoadFrac = ReqOutput/FullOutput
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit sensible part-'// &
                                    'load ratio calculation failed: part-load ratio limits exceeded, for unit = '// &
                                     TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                      ' failed error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                END IF
              END IF
            END IF
          END IF
!         If system does not operate to meet sensible load, use no load humidity ratio to test against humidity setpoint,
!         else use operating humidity ratio to test against humidity setpoint
          IF (PartLoadFrac .EQ. 0.0d0)THEN
            OutletHumRatDXCoil = NoLoadHumRatOut
          ELSE
            OutletHumRatDXCoil = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          END IF
          ! If humidity setpoint is not satisfied and humidity control type is CoolReheat,
          ! then overcool to meet moisture load
          IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. (PartLoadFrac .LT. 1.0d0) .AND. &
              (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat)) THEN
!           IF NoLoadHumRatOut is lower than (more dehumidification than required) or very near the DesOutHumRat,
!           do not run the compressor
            IF ((NoLoadHumRatOut-DesOutHumRat) .LT. HumRatAcc) THEN
              PartLoadFrac = PartLoadFrac  ! keep part-load fraction from sensible calculation
!           If the FullLoadHumRatOut is greater than (insufficient dehumidification) or very near the DesOutHumRat,
!           run the compressor at PartLoadFrac = 1.
            ELSE IF ((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc) THEN
              PartLoadFrac = 1.0d0
!           Else find the PLR to meet the load
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutHumRat
              Par(5) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, PartLoadFrac, DOE2DXCoilHumRatResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit latent part-load'// &
                                          ' ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                    CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                  ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' latent part-load ratio error continues. Latent PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                END IF
              ELSE IF (SolFla == -2) THEN
!               RegulaFalsi returns PLR = minPLR when a solution cannot be found, recalculate PartLoadFrac.
                IF(NoLoadHumRatOut-FullLoadHumRatOut .NE. 0.0d0)THEN
                  PartLoadFrac = (NoLoadHumRatOut-DesOutHumRat)/(NoLoadHumRatOut-FullLoadHumRatOut)
                ELSE
                  PartLoadFrac = 1.0d0
                END IF
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit latent part-'// &
                                    'load ratio calculation failed: part-load ratio limits exceeded, for unit = '//&
                                    TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                      ' failed error continues. Latent PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFailIndex,PartLoadFrac,PartLoadFrac)
                END IF
              END IF
            END IF
          END IF ! End if humidity ratio setpoint not met - CoolReheat humidity control
          IF(PartLoadFrac.GT.1.0d0) THEN
            PartLoadFrac = 1.0d0
          ELSEIF(PartLoadFrac < 0.0d0) THEN
            PartLoadFrac = 0.0d0
          END IF
        CASE (CoilDX_CoolingHXAssisted)  ! CoilSystem:Cooling:DX:HeatExchangerAssisted
!         Check the dehumidification control type. If it's multimode, turn off the HX to find the sensible PLR. Then check to
!         see if the humidity load is met without the use of the HX. Always run the HX for the other modes.
          IF (DXCoolingSystem(DXSystemNum)%DehumidControlType .NE. DehumidControl_Multimode)THEN
            HXUnitOn = .TRUE.
          ELSE
            HXUnitOn = .FALSE.
          END IF
          ! Get no load result
          PartLoadFrac = 0.0d0
          CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,PartLoadFrac, &
                                        DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                        HXUnitEnable=HXUnitOn,EconomizerFlag=EconomizerFlag)
          NoOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          NoLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          ! Get full load result
          PartLoadFrac = 1.0d0
          CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,PartLoadFrac, &
                                        DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                        HXUnitEnable=HXUnitOn,EconomizerFlag=EconomizerFlag)
          FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          FullLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
!         IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
          IF ((NoOutput-ReqOutput) .LT. Acc) THEN
            PartLoadFrac = 0.0d0
!         If the FullOutput is greater than or very near the ReqOutput, then run the compressor at PartLoadFrac = 1.
          ELSE IF ((FullOutput - ReqOutput) .GT. Acc) THEN
            PartLoadFrac = 1.0d0
!         Else find the PLR to meet the load
          ELSE
!           OutletTempDXCoil is the full capacity outlet temperature at PartLoadFrac = 1 from the CALL above.
!           If this temp is greater than or very near the desired outlet temp, then run the compressor at PartLoadFrac = 1.
!           (i.e. HX iterates to find solution, don't allow the tolerance in solution to trip up RegulaFalsi. So if
!           solution is very near request, run compressor at PLR = 1)
            OutletTempDXCoil = HXAssistedCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            IF ((OutletTempDXCoil > DesOutTemp) .OR. ABS(OutletTempDXCoil - DesOutTemp) .LE. (Acc*2.0d0)) THEN
               PartLoadFrac = 1.0d0
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutTemp
              ! FirstHVACIteration is a logical, Par is REAL(r64), so make TRUE = 1 and FALSE = 0
              IF(FirstHVACIteration)THEN
                Par(3) = 1.0d0
              ELSE
                Par(3) = 0.0d0
              END IF
              IF(HXUnitOn)THEN
                Par(4) = 1.0d0
              ELSE
                Par(4) = 0.0d0
              END IF
              Par(5) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, HXAssistedCoolCoilTempResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
!               RegulaFalsi may not find sensible PLR when the latent degradation model is used.
!               If iteration limit is exceeded, find tighter boundary of solution and repeat RegulaFalsi
                TempMaxPLR = -0.1d0
                TempOutletTempDXCoil = Node(InletNode)%Temp
                DO WHILE((TempOutletTempDXCoil-DesOutTemp) .GT. 0.0d0 .AND. TempMaxPLR .LE. 1.0d0)
!                 find upper limit of PLR
                  TempMaxPLR = TempMaxPLR + 0.1d0
                  CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,TempMaxPLR, &
                                                DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMOde, &
                                                HXUnitEnable=HXUnitOn, EconomizerFlag=EconomizerFlag)
                  TempOutletTempDXCoil = HXAssistedCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                END DO
                TempMinPLR = TempMaxPLR
                DO WHILE((TempOutletTempDXCoil-DesOutTemp) .LT. 0.0d0 .AND. TempMinPLR .GE. 0.0d0)
!                 pull upper limit of PLR down to last valid limit (i.e. outlet temp still exceeds DesOutTemp)
                  TempMaxPLR = TempMinPLR
!                 find minimum limit of PLR
                  TempMinPLR = TempMinPLR - 0.01d0
                  CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,TempMinPLR, &
                                                DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                                HXUnitEnable=HXUnitOn, EconomizerFlag=EconomizerFlag)
                  TempOutletTempDXCoil = HXAssistedCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                END DO
!               Relax boundary slightly to assure a solution can be found using RegulaFalsi (i.e. one boundary may be
!               very near the desired result)
                TempMinPLR = MAX(0.0d0,(TempMinPLR - 0.01d0))
                TempMaxPLR = MIN(1.0d0,(TempMaxPLR + 0.01d0))
!               tighter boundary of solution has been found, call RegulaFalsi a second time
                CALL SolveRegulaFalsi(Acc,MaxIte,SolFla,PartLoadFrac,HXAssistedCoolCoilTempResidual,TempMinPLR,TempMaxPLR,Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRIter = DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - Iteration limit'// &
                                            ' exceeded calculating DX unit sensible part-load ratio for unit = '// &
                                            TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = ReqOutput/FullOutput
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail = DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - DX unit sensible part-load ratio calculation unexpectedly failed: part-load '// &
                                            'ratio limits exceeded, for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                        ' unexpectedly failed error continues. Sensible PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ELSE IF (SolFla == -2) THEN
                PartLoadFrac = ReqOutput/FullOutput
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail2 .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail2 = DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFail2+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - DX unit sensible part-load ratio calculation failed: part-load '// &
                                          'ratio limits exceeded, for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                      ' failed error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%HXAssistedSensPLRFailIndex2,PartLoadFrac,PartLoadFrac)
                END IF
              END IF
            END IF
          END IF
!         If system does not operate to meet sensible load, use no load humidity ratio to test against humidity setpoint,
!         else use operating humidity ratio to test against humidity setpoint
          IF (PartLoadFrac .EQ. 0.0d0)THEN
            OutletHumRatDXCoil = NoLoadHumRatOut
          ELSE
            OutletHumRatDXCoil = HXAssistedCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          END IF
          ! If humidity setpoint is not satisfied and humidity control type is MultiMode,
          ! then enable heat exchanger and run to meet sensible load
          IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. &
              (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_Multimode)) THEN
            ! Determine required part load when heat exchanger is ON
            HXUnitOn = .TRUE.
            PartLoadFrac = 1.0d0
            CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,PartLoadFrac, &
                                          DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                          HXUnitEnable=HXUnitOn, EconomizerFlag=EconomizerFlag)
            OutletTempDXCoil = HXAssistedCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
!           FullOutput will be different than the FullOutput determined above during sensible PLR calculations
            FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
            ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
!           Check to see if the system can meet the load with the compressor off
!           IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
            IF ((NoOutput-ReqOutput) .LT. Acc) THEN
              PartLoadFrac = 0.0d0
!           OutletTempDXCoil is the full capacity outlet temperature at PartLoadFrac = 1 from the CALL above.
!           If this temp is greater than or very near the desired outlet temp, then run the compressor at PartLoadFrac = 1.
            ELSE IF ((OutletTempDXCoil > DesOutTemp) .OR. ABS(OutletTempDXCoil - DesOutTemp) .LE. (Acc*2.0d0)) THEN
               PartLoadFrac = 1.0d0
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutTemp
              ! FirstHVACIteration is a logical, Par is REAL(r64), so make TRUE = 1.0 and FALSE = 0.0
              IF(FirstHVACIteration)THEN
                Par(3) = 1.0d0
              ELSE
                Par(3) = 0.0d0
              END IF
              IF(HXUnitOn)THEN
                Par(4) = 1.0d0
              ELSE
                Par(4) = 0.0d0
              END IF
              Par(5) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, HXAssistedCoolCoilTempResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRIter .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRIter = DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRIter+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit latent'// &
                                          ' part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated latent part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                    CALL ShowContinueError('Calculated latent part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The calculated latent part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' latent part-load ratio error continues. Latent PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                END IF
              ELSE IF (SolFla == -2) THEN
                PartLoadFrac = ReqOutput/FullOutput
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRFail .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRFail = DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRFail+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - DX unit latent part-load ratio calculation failed: part-load '// &
                                          'ratio limits exceeded, for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                      ' failed error continues. Latent PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%HXAssistedLatPLRFailIndex,PartLoadFrac,PartLoadFrac)
                END IF
              END IF
            END IF
          END IF ! End if humidity ratio setpoint not met - Multimode humidity control
          ! If humidity setpoint is not satisfied and humidity control type is CoolReheat, then calculate
          ! a new latent PLR
          IF (OutletHumRatDXCoil .GT. DesOutHumRat .AND. PartLoadFrac .LT. 1.0d0 .AND. &
              DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat) THEN
!           IF NoLoadHumRatOut is lower than (more dehumidification than required) or very near the DesOutHumRat,
!           do not run the compressor
            IF ((NoLoadHumRatOut-DesOutHumRat) .LT. HumRatAcc*2.0d0) THEN
              PartLoadFrac = PartLoadFrac  ! keep part-load fraction from sensible calculation
!           If the FullLoadHumRatOut is greater than (insufficient dehumidification) or very near the DesOutHumRat,
!           run the compressor at PartLoadFrac = 1.
            ELSE IF ((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc*2.0d0) THEN
              PartLoadFrac = 1.0d0
!           Else find the PLR to meet the load
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutHumRat
              ! FirstHVACIteration is a logical, Par is REAL(r64), so make TRUE = 1 and FALSE = 0
              IF(FirstHVACIteration)THEN
                Par(3) = 1.0d0
              ELSE
                Par(3) = 0.0d0
              END IF
              IF(HXUnitOn)THEN
                Par(4) = 1.0d0
              ELSE
                Par(4) = 0.0d0
              END IF
              Par(5) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, PartLoadFrac, HXAssistedCoolCoilHRResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
!               RegulaFalsi may not find latent PLR when the latent degradation model is used.
!               If iteration limit is exceeded, find tighter boundary of solution and repeat RegulaFalsi
                TempMaxPLR = -0.1d0
                TempOutletHumRatDXCoil = OutletHumRatDXCoil
                DO WHILE((OutletHumRatDXCoil - TempOutletHumRatDXCoil) .GE. 0.0d0 .AND. TempMaxPLR .LE. 1.0d0)
!                 find upper limit of LatentPLR
                  TempMaxPLR = TempMaxPLR + 0.1d0
                  CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,TempMaxPLR, &
                                                DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                                HXUnitEnable=HXUnitOn, EconomizerFlag=EconomizerFlag)
                  OutletHumRatDXCoil = HXAssistedCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                END DO
                TempMinPLR = TempMaxPLR
                DO WHILE((OutletHumRatDXCoil - TempOutletHumRatDXCoil) .LE. 0.0d0 .AND. TempMinPLR .GE. 0.0d0)
!                 pull upper limit of LatentPLR down to last valid limit (i.e. latent output still exceeds SystemMoisuterLoad)
                  TempMaxPLR = TempMinPLR
!                 find minimum limit of Latent PLR
                  TempMinPLR = TempMinPLR - 0.01d0
                  CALL SimHXAssistedCoolingCoil(CompName,FirstHVACIteration,On,TempMaxPLR, &
                                                DXCoolingSystem(DXSystemNum)%CoolingCoilIndex, FanOpMode, &
                                                HXUnitEnable=HXUnitOn, EconomizerFlag=EconomizerFlag)
                  OutletHumRatDXCoil = HXAssistedCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                END DO
!               tighter boundary of solution has been found, call RegulaFalsi a second time
                CALL SolveRegulaFalsi(HumRatAcc,MaxIte,SolFla,PartLoadFrac,HXAssistedCoolCoilHRResidual, &
                                      TempMinPLR,TempMaxPLR,Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRIter = DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit latent'// &
                                            ' part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated latent part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated latent part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated latent part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' latent part-load ratio error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = ReqOutput/FullOutput
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail = DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                         ' - DX unit latent part-load ratio calculation failed unexpectedly:'// &
                                         ' part-load ratio limits exceeded, for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                        ' failed unexpectedly error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ELSE IF (SolFla == -2) THEN
                PartLoadFrac = ReqOutput/FullOutput
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail2 .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail2 = DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFail2+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - DX unit latent part-load ratio calculation failed: part-load '// &
                                          'ratio limits exceeded, for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                      ' failed error continues. Latent PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%HXAssistedCRLatPLRFailIndex2,PartLoadFrac,PartLoadFrac)
                END IF
              END IF
            END IF
          END IF ! End if humidity ratio setpoint not met - CoolReheat humidity control
          IF(PartLoadFrac.GT.1.0d0) THEN
            PartLoadFrac = 1.0d0
          ELSEIF(PartLoadFrac < 0.0d0) THEN
            PartLoadFrac = 0.0d0
          END IF
        CASE (CoilDX_CoolingTwoSpeed)  ! Coil:Cooling:DX:TwoSpeed
                                       ! formerly (v3 and beyond)COIL:DX:MULTISPEED:COOLINGEMPIRICAL
!         SUBROUTINE SimDXCoilMultiSpeed(CompName,SpeedRatio,CycRatio,CompIndex,SpeedNum,FanMode,CompOp)
          CALL SimDXCoilMultiSpeed(CompName,0.0d0,1.0d0,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          OutletTempLS = DXCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          IF (OutletTempLS > DesOutTemp .AND. SensibleLoad) THEN
            CycRatio = 1.0d0
            CALL SimDXCoilMultiSpeed(CompName,1.0d0,1.0d0,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            OutletTempHS = DXCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            IF (OutletTempHS < DesOutTemp) THEN
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutTemp
              CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, SpeedRatio, DXCoilVarSpeedResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%MSpdSensPLRIter .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%MSpdSensPLRIter = DXCoolingSystem(DXSystemNum)%MSpdSensPLRIter+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible'// &
                                          ' speed ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Calculated speed ratio = '//RoundSigDigits(SpeedRatio,3))
                    CALL ShowContinueErrorTimeStamp('The calculated speed ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible speed ratio error continues. Sensible speed ratio statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%MSpdSensPLRIterIndex,SpeedRatio,SpeedRatio)
                END IF
              ELSE IF (SolFla == -2) THEN
                IF(.NOT. WarmupFlag) &
                  CALL ShowFatalError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                      ' - compressor speed calculation failed: speed limits exceeded, for unit='// &
                                      TRIM(DXCoolingSystem(DXSystemNum)%Name))
              END IF
            ELSE
              SpeedRatio = 1.0d0
            END IF
          ELSE IF(SensibleLoad)THEN
            SpeedRatio = 0.0d0
            Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
            Par(2) = DesOutTemp
            CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, CycRatio, DXCoilCyclingResidual, 0.0d0,   &
                                            1.0d0, Par)
            IF (SolFla == -1) THEN
              IF(.NOT. WarmupFlag)THEN
                IF(DXCoolingSystem(DXSystemNum)%MSpdCycSensPLRIter .LT. 1)THEN
                  DXCoolingSystem(DXSystemNum)%MSpdCycSensPLRIter = DXCoolingSystem(DXSystemNum)%MSpdCycSensPLRIter+1
                  CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                        ' - Iteration limit exceeded calculating DX unit sensible'// &
                                        ' cycling ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                  CALL ShowContinueError('Calculated cycling ratio = '//RoundSigDigits(CycRatio,3))
                  CALL ShowContinueErrorTimeStamp('The calculated cycling ratio will be used and the simulation'// &
                                                  ' continues. Occurrence info: ')
                END IF
                CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                    //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                    ' sensible cycling ratio error continues. Sensible cycling ratio statistics follow.' &
                    ,DXCoolingSystem(DXSystemNum)%MSpdCycSensPLRIterIndex,CycRatio,CycRatio)
              END IF
            ELSE IF (SolFla == -2) THEN ! should never get here, if it does logic above to protect from this
              IF(.NOT. WarmupFlag) &
                CALL ShowFatalError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                    ' - cycling ratio calculation failed: cycling limits exceeded, for unit='// &
                                    TRIM(DXCoolingSystem(DXSystemNum)%Name))
            END IF
          ELSE
            PartLoadFrac = 0.0d0
            SpeedRatio = 0.0d0
            CycRatio = 0.0d0
            DehumidMode  = 0
          END IF
          IF (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat) THEN
!           Simulate MultiSpeed DX coil at sensible result
            CALL SimDXCoilMultiSpeed(CompName,SpeedRatio,CycRatio,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            OutletHumRatDXCoil = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            ! If humidity setpoint is not satisfied and humidity control type is CoolReheat,
            ! then overcool to meet moisture load
            IF (OutletHumRatDXCoil > DesOutHumRat) THEN
              CycRatio = 0.0d0
              SpeedRatio = 0.0d0
!             SUBROUTINE SimDXCoilMultiSpeed(CompName,SpeedRatio,CycRatio,CompIndex,SpeedNum,FanMode,CompOp)
              CALL SimDXCoilMultiSpeed(CompName,0.0d0,1.0d0,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
              OutletHumRatLS = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
              IF (OutletHumRatLS > DesOutHumRat) THEN
                CycRatio = 1.0d0
                CALL SimDXCoilMultiSpeed(CompName,1.0d0,1.0d0,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                OutletHumRatHS = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
                IF (OutletHumRatHS < DesOutHumRat) THEN
                  Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                  Par(2) = DesOutHumRat
                  CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, SpeedRatio, DXCoilVarSpeedHumRatResidual, 0.0d0,   &
                                            1.0d0, Par)
                  IF (SolFla == -1) THEN
                    IF(.NOT. WarmupFlag)THEN
                      IF(DXCoolingSystem(DXSystemNum)%MSpdLatPLRIter .LT. 1)THEN
                        DXCoolingSystem(DXSystemNum)%MSpdLatPLRIter = DXCoolingSystem(DXSystemNum)%MSpdLatPLRIter+1
                        CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                              ' - Iteration limit exceeded calculating DX unit latent'// &
                                              ' speed ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                        CALL ShowContinueError('Calculated speed ratio = '//RoundSigDigits(SpeedRatio,3))
                        CALL ShowContinueErrorTimeStamp('The calculated speed ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                      END IF
                      CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                          //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                          ' latent speed ratio error continues. Latent speed ratio statistics follow.' &
                          ,DXCoolingSystem(DXSystemNum)%MSpdLatPLRIterIndex,SpeedRatio,SpeedRatio)
                    END IF
                  ELSE IF (SolFla == -2) THEN
                    IF(.NOT. WarmupFlag) &
                      CALL ShowFatalError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - compressor speed'// &
                                          ' calculation failed:speed limits exceeded, for unit='// &
                                          TRIM(DXCoolingSystem(DXSystemNum)%Name))
                  END IF
                ELSE
                  SpeedRatio = 1.0d0
                END IF
              ELSE
                SpeedRatio = 0.0d0
                Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                Par(2) = DesOutHumRat
                CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, CycRatio, DXCoilCyclingHumRatResidual, 0.0d0,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%MSpdCycLatPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%MSpdCycLatPLRIter = DXCoolingSystem(DXSystemNum)%MSpdCycLatPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit latent'// &
                                            ' cycling ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Calculated cycling ratio = '//RoundSigDigits(CycRatio,3))
                      CALL ShowContinueErrorTimeStamp('The calculated cycling ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' latent cycling ratio error continues. Latent cycling ratio statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%MSpdCycLatPLRIterIndex,CycRatio,CycRatio)
                  END IF
                ELSE IF (SolFla == -2) THEN ! should never get here, if it does logic above to protect from this
                  IF(.NOT. WarmupFlag) &
                    CALL ShowFatalError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - cycling ratio' // &
                                        ' calculation failed: cycling limits exceeded, for unit='// &
                                        TRIM(DXCoolingSystem(DXSystemNum)%Name))
                END IF
              END IF
            END IF
          END IF
        CASE (CoilDX_CoolingTwoStageWHumControl) ! Coil:Cooling:DX:TwoStageWithHumidityControlMode
                                        ! formerly (v3 and beyond) COIL:DX:MULTIMODE:COOLINGEMPIRICAL)
          ! Get no load result
          PartLoadFrac = 0.0d0
          CALL SimDXCoilMultiMode(CompName,On,FirstHVACIteration,PartLoadFrac,DehumidMode,  &
                                  DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,FanOpMode)
          NoOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          NoLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          ! Get full load result
          PartLoadFrac = 1.0d0
          CALL SimDXCoilMultiMode(CompName,On,FirstHVACIteration,PartLoadFrac,DehumidMode,  &
                                  DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,FanOpMode)
          FullLoadHumRatOut = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
!         IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
          IF ((NoOutput-ReqOutput) .LT. Acc) THEN
            PartLoadFrac = 0.0d0
!         If the FullOutput is greater than (insufficient cooling) or very near the ReqOutput,
!         run the compressor at PartLoadFrac = 1.
          ELSE IF ((FullOutput - ReqOutput) .GT. Acc) THEN
            PartLoadFrac = 1.0d0
!         Else find the PLR to meet the load
          ELSE
            OutletTempDXCoil = DXCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
            IF (OutletTempDXCoil > DesOutTemp) THEN
              PartLoadFrac = 1.0d0
            ELSE
              Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
              Par(2) = DesOutTemp
              ! Dehumidification mode = 0 for normal mode, 1+ for enhanced mode
              Par(3) = REAL(DehumidMode,r64)
              Par(4) = REAL(FanOpMode,r64)
              CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, MultiModeDXCoilResidual, 0.0d0,   &
                                            1.0d0, Par)
              IF (SolFla == -1) THEN
                IF(.NOT. WarmupFlag)THEN
                  IF(DXCoolingSystem(DXSystemNum)%MModeSensPLRIter .LT. 1)THEN
                    DXCoolingSystem(DXSystemNum)%MModeSensPLRIter = DXCoolingSystem(DXSystemNum)%MModeSensPLRIter+1
                    CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible'// &
                                          ' part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                    CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                    CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                  END IF
                  CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%MModeSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                END IF
              ELSE IF (SolFla == -2) THEN
                IF(.NOT. WarmupFlag) THEN
                  CALL ShowSevereError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                       ' : part-load ratio calculation failed: '//  &
                                       'part-load ratio limits exceeded, for unit='// &
                                       TRIM(DXCoolingSystem(DXSystemNum)%Name))
                  CALL ShowFatalError('Program terminates due to previous condition.')
                END IF
              END IF
            END IF
          END IF
          OutletHumRatDXCoil = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          ! If humidity setpoint is not satisfied and humidity control type is Multimode,
          ! then turn on enhanced dehumidification mode 1
          IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. &
              (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_Multimode)) THEN
            ! Determine required part load for enhanced dehumidification mode 1
            ! Get full load result
            PartLoadFrac = 1.0d0
            DehumidMode  = 1
            DXCoolingSystem(DXSystemNum)%DehumidificationMode = DehumidMode
            CALL SimDXCoilMultiMode(CompName,On,FirstHVACIteration,PartLoadFrac,DehumidMode,  &
                                    DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,FanOpMode)
            FullOutput = Node(InletNode)%MassFlowRate *  &
                         (PsyHFnTdbW(Node(OutletNode)%Temp,Node(InletNode)%HumRat)  &
                          - PsyHFnTdbW(Node(InletNode)%Temp,Node(InletNode)%HumRat))
            ReqOutput = Node(InletNode)%MassFlowRate *  &
                         (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(InletNode)%HumRat) - &
                          PsyHFnTdbW(Node(InletNode)%Temp,Node(InletNode)%HumRat))
            ! Since we are cooling, we expect FullOutput to be < 0 and FullOutput < NoCoolOutput
            ! Check that this is the case; if not set PartLoadFrac = 0.0d0 (off) and return
            ! Calculate the part load fraction
            IF (FullOutput .GE. 0) THEN
              PartLoadFrac = 0.0d0
            ELSE
              OutletTempDXCoil = DXCoilOutletTemp(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
              OutletHumRatDXCoil = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
              ! if sensible load and setpoint cannot be met, set PLR = 1. If no sensible load and
              ! latent load exists and setpoint cannot be met, set PLR = 1.
              IF ((OutletTempDXCoil >= DesOutTemp .AND. SensibleLoad .and. DXCoolingSystem(DXSystemNum)%RunOnSensibleLoad) .OR. &
                  (OutletHumRatDXCoil >= DesOutHumRat .AND. &
                  .NOT. SensibleLoad .AND. LatentLoad .AND. DXCoolingSystem(DXSystemNum)%RunOnLatentLoad)) THEN
                PartLoadFrac = 1.0d0
              ! if no sensible load and latent load can be met, find PLR
              ELSE IF (.NOT. SensibleLoad .AND. &
                  (OutletHumRatDXCoil < DesOutHumRat .AND. LatentLoad .AND. DXCoolingSystem(DXSystemNum)%RunOnLatentLoad)) THEN
                ! is a latent load with no sensible load, iterate on humidity ratio
                Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                Par(2) = DesOutHumRat
                ! Dehumidification mode = 0 for normal mode, 1+ for enhanced mode
                Par(3) = REAL(DehumidMode,r64)
                Par(4) = REAL(FanOpMode,r64)
                CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, MultiModeDXCoilHumRatResidual, 0.0d0,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%MModeLatPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%MModeLatPLRIter = DXCoolingSystem(DXSystemNum)%MModeLatPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit multimode'// &
                                            ' latent (no sensible) part-load ratio for unit = '// &
                                            TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      IF(NoLoadHumRatOut-OutletHumRatDXCoil > 0.d0)THEN
                        TempMinPLR = (DesOutHumRat-OutletHumRatDXCoil)/(NoLoadHumRatOut-OutletHumRatDXCoil)
                      ELSE
                        TempMinPLR = PartLoadFrac + 0.001d0
                      END IF
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits(TempMinPLR,3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' multimode latent (no sensible) part-load ratio error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%MModeLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  IF(.NOT. WarmupFlag) THEN
                    CALL ShowSevereError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                         ' : part-load ratio calculation failed: '//  &
                                         'part-load ratio limits exceeded, for unit='// &
                                         TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowFatalError('Program terminates due to previous condition.')
                  END IF
                END IF
              ELSE ! must be a sensible load so find PLR
                PartLoadFrac = ReqOutput/FullOutput
                Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                Par(2) = DesOutTemp
                ! Dehumidification mode = 0 for normal mode, 1+ for enhanced mode
                Par(3) = REAL(DehumidMode,r64)
                Par(4) = REAL(FanOpMode,r64)
                CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, MultiModeDXCoilResidual, 0.0d0,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%MModeLatPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%MModeLatPLRIter = DXCoolingSystem(DXSystemNum)%MModeLatPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit multimode'// &
                                            ' latent part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' multimode latent part-load ratio error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%MModeLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  IF(.NOT. WarmupFlag) THEN
                    CALL ShowSevereError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                         ' : part-load ratio calculation failed: '//  &
                                         'part-load ratio limits exceeded, for unit='// &
                                         TRIM(DXCoolingSystem(DXSystemNum)%Name))
                    CALL ShowFatalError('Program terminates due to previous condition.')
                  END IF
                END IF
              END IF
            ENDIF
          END IF ! End if humidity ratio setpoint not met - multimode humidity control
!         If humidity setpoint is not satisfied and humidity control type is CoolReheat, then run to meet latent load
!         If system does not operate to meet sensible load, use no load humidity ratio to test against humidity setpoint,
!         else use operating humidity ratio to test against humidity setpoint
          IF (PartLoadFrac .EQ. 0.0d0)THEN
              OutletHumRatDXCoil = NoLoadHumRatOut
          ELSE
              OutletHumRatDXCoil = DXCoilOutletHumRat(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)
          END IF
          IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. &
                (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat)) THEN
!            CoolReheat operates cooling stage 1 and/or 2 to meet DesOutHumRat. Dehumidification mode is not active.
             DehumidMode  = 0
!            IF NoLoadHumRatOut is lower than (more dehumidification than required) or very near the DesOutHumRat,
!            do not run the compressor
             IF ((NoLoadHumRatOut-DesOutHumRat) .LT. HumRatAcc) THEN
                PartLoadFrac = PartLoadFrac  ! keep part-load fraction from sensible calculation
!            If the FullLoadHumRatOut is greater than (insufficient dehumidification) or very near the DesOutHumRat,
!            run the compressor at PartLoadFrac = 1.
             ELSE IF ((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc) THEN
                PartLoadFrac = 1.0d0
!            Else find the PLR to meet the load
             ELSE
               Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
               Par(2) = DesOutHumRat
               ! Dehumidification mode = 0 for normal mode, 1+ for enhanced mode
               Par(3) = REAL(DehumidMode,r64)
               Par(4) = REAL(FanOpMode,r64)
               CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, MultiModeDXCoilHumRatResidual, 0.0d0,   &
                                           1.0d0, Par)
               IF (SolFla == -1) THEN
                 IF(.NOT. WarmupFlag)THEN
                   IF(DXCoolingSystem(DXSystemNum)%MModeLatPLRIter2 .LT. 1)THEN
                     DXCoolingSystem(DXSystemNum)%MModeLatPLRIter2 = DXCoolingSystem(DXSystemNum)%MModeLatPLRIter2+1
                     CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                           ' - Iteration limit exceeded calculating DX unit coolreheat'// &
                                           ' latent part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                     CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                     CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                     CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                   END IF
                   CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                       //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                       ' coolreheat latent part-load ratio error continues. Latent PLR statistics follow.' &
                       ,DXCoolingSystem(DXSystemNum)%MModeLatPLRIterIndex2,PartLoadFrac,PartLoadFrac)
                 END IF
               ELSE IF (SolFla == -2) THEN
                 IF(.NOT. WarmupFlag) THEN
                   CALL ShowSevereError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                        ' : part-load ratio calculation failed: '//  &
                                        'part-load ratio limits exceeded, for unit='// &
                                        TRIM(DXCoolingSystem(DXSystemNum)%Name))
                   CALL ShowFatalError('Program terminates due to previous condition.')
                 END IF
               END IF
             END IF
          END IF ! End if humidity ratio setpoint not met - CoolReheat humidity control
          IF(PartLoadFrac.GT.1.0d0) THEN
            PartLoadFrac = 1.0d0
          ELSEIF(PartLoadFrac < 0.0d0) THEN
            PartLoadFrac = 0.0d0
          END IF
        CASE (Coil_CoolingAirToAirVariableSpeed)  ! Coil:Cooling:DX:VariableSpeed
        !variable-speed air-to-air cooling coil, begin -------------------------
          ! Get no load result
          PartLoadFrac = 0.0d0
          SpeedNum     = 1
          QZnReq       = 0.0d0
          QLatReq      = 0.0d0
          MaxONOFFCyclesperHour = 4.0d0 !default number
          HPTimeConstant= 0.0d0
          FanDelayTime  = 0.0d0
          OnOffAirFlowRatio = 1.0d0
          SpeedRatio = 0.0d0
         Call SimVariableSpeedCoils(CompName,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,&
           FanOpMode,MaxONOFFCyclesperHour, &
           HPTimeConstant,FanDelayTime,&
           On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio, QZnReq, QLatReq)
          VSCoilIndex = DXCoolingSystem(DXSystemNum)%CoolingCoilIndex
          NumOfSpeeds = VarSpeedCoil(VSCoilIndex)%NumOfSpeeds
          NoOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          NoLoadHumRatOut = VarSpeedCoil(VSCoilIndex)%OutletAirHumRat
          ! Get full load result
          PartLoadFrac = 1.0d0
          SpeedNum     = NumOfSpeeds
          SpeedRatio = 1.0d0
          QZnReq = 0.001d0  !to indicate the coil is running
          Call SimVariableSpeedCoils(CompName,VSCoilIndex,&
           FanOpMode,MaxONOFFCyclesperHour, &
           HPTimeConstant,FanDelayTime,&
           On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio,QZnReq, QLatReq)
          FullLoadHumRatOut = VarSpeedCoil(VSCoilIndex)%OutletAirHumRat
          FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
          ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
!         IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
          IF ((NoOutput-ReqOutput) .LT. Acc) THEN
            PartLoadFrac = 0.0d0
            SpeedNum = 1
            SpeedRatio = 0.0d0
!         If the FullOutput is greater than (insufficient cooling) or very near the ReqOutput,
!         run the compressor at PartLoadFrac = 1.
          ELSE IF ((FullOutput - ReqOutput) .GT. Acc) THEN
            PartLoadFrac = 1.0d0
            SpeedNum = NumOfSpeeds
            SpeedRatio = 1.0d0
!         Else find the PLR to meet the load
          ELSE
!           OutletTempDXCoil is the full capacity outlet temperature at PartLoadFrac = 1 from the CALL above. If this temp is
!           greater than the desired outlet temp, then run the compressor at PartLoadFrac = 1, otherwise find the operating PLR.
            OutletTempDXCoil = VarSpeedCoil(VSCoilIndex)%OutletAirDBTemp
            IF (OutletTempDXCoil > DesOutTemp) THEN
              PartLoadFrac = 1.0d0
              SpeedNum = NumOfSpeeds
              SpeedRatio = 1.0d0
            ELSE
              PartLoadFrac = 1.0d0
              SpeedNum     = 1
              SpeedRatio = 1.0d0
              QZnReq = 0.001d0  !to indicate the coil is running
              Call SimVariableSpeedCoils(CompName,VSCoilIndex,&
                 FanOpMode,MaxONOFFCyclesperHour, &
                 HPTimeConstant,FanDelayTime,&
                 On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio,QZnReq, QLatReq)
              TempSpeedOut =  Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
              TempSpeedReqst = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
              IF((TempSpeedOut - TempSpeedReqst) .GT. Acc) THEN
                   ! Check to see which speed to meet the load
                PartLoadFrac = 1.0d0
                SpeedRatio = 1.0d0
                DO I=2,NumOfSpeeds
                  SpeedNum = I
                  Call SimVariableSpeedCoils(CompName,VSCoilIndex,&
                     FanOpMode,MaxONOFFCyclesperHour, &
                     HPTimeConstant,FanDelayTime,&
                     On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio,QZnReq, QLatReq)
                  TempSpeedOut =  Node(InletNode)%MassFlowRate *  &
                           (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                            - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
                  TempSpeedReqst = Node(InletNode)%MassFlowRate *  &
                           (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                            PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
                  IF ((TempSpeedOut - TempSpeedReqst) .LT. Acc) THEN
                    SpeedNum = I
                    Exit
                  END IF
                END DO
                Par(1) = REAL(VSCoilIndex,r64)
                Par(2) = DesOutTemp
                Par(5) = REAL(FanOpMode,r64)
                Par(3) = REAL(SpeedNum,r64)
                CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, SpeedRatio, VSCoilSpeedResidual, 1.0d-10, 1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible '// &
                                          'part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = TempSpeedReqst/TempSpeedOut
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                    ' - DX unit sensible part-'// &
                                    'load ratio calculation failed: part-load ratio limits exceeded, for unit = '// &
                                     TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                      ' failed error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ELSE
                Par(1) = REAL(VSCoilIndex,r64)
                Par(2) = DesOutTemp
                Par(5) = REAL(FanOpMode,r64)
                CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, VSCoilCyclingResidual, 1.0d-10,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible '// &
                                          'part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = TempSpeedReqst/TempSpeedOut
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                    ' - DX unit sensible part-'// &
                                    'load ratio calculation failed: part-load ratio limits exceeded, for unit = '// &
                                     TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                      ' failed error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              END IF
            END IF
          END IF
!         If system does not operate to meet sensible load, use no load humidity ratio to test against humidity setpoint,
!         else use operating humidity ratio to test against humidity setpoint
          IF (PartLoadFrac .EQ. 0.0d0)THEN
            OutletHumRatDXCoil = NoLoadHumRatOut
          ELSE
            OutletHumRatDXCoil = VarSpeedCoil(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex)%OutletAirHumRat
          END IF
          ! If humidity setpoint is not satisfied and humidity control type is CoolReheat,
          ! then overcool to meet moisture load
          IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. (PartLoadFrac .LT. 1.0d0) .AND. &
              (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat)) THEN
!           IF NoLoadHumRatOut is lower than (more dehumidification than required) or very near the DesOutHumRat,
!           do not run the compressor
            IF ((NoLoadHumRatOut-DesOutHumRat) .LT. HumRatAcc) THEN
              PartLoadFrac = PartLoadFrac  ! keep part-load fraction from sensible calculation
!           If the FullLoadHumRatOut is greater than (insufficient dehumidification) or very near the DesOutHumRat,
!           run the compressor at PartLoadFrac = 1.
            ELSE IF ((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc) THEN
              PartLoadFrac = 1.0d0
!           Else find the PLR to meet the load
            ELSE
              PartLoadFrac = 1.0d0
              SpeedNum     = 1
              SpeedRatio = 1.0d0
              QZnReq = 0.001d0  !to indicate the coil is running
              Call SimVariableSpeedCoils(CompName,VSCoilIndex,&
                 FanOpMode,MaxONOFFCyclesperHour, &
                 HPTimeConstant,FanDelayTime,&
                 On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio,QZnReq, QLatReq)
              TempSpeedOut =  VarSpeedCoil(VSCoilIndex)%OutletAirHumRat
              IF((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc) THEN
                   ! Check to see which speed to meet the load
                PartLoadFrac = 1.0d0
                SpeedRatio = 1.0d0
                DO I=2,NumOfSpeeds
                  SpeedNum = I
                  Call SimVariableSpeedCoils(CompName,VSCoilIndex,&
                     FanOpMode,MaxONOFFCyclesperHour, &
                     HPTimeConstant,FanDelayTime,&
                     On, PartLoadFrac, OnOffAirFlowRatio,SpeedNum, SpeedRatio,QZnReq, QLatReq)
                  TempSpeedOut =  VarSpeedCoil(VSCoilIndex)%OutletAirHumRat
                  IF ((DesOutHumRat-TempSpeedOut) .GT. HumRatAcc) THEN
                    SpeedNum = I
                    Exit
                  END IF
                END DO
                Par(1) = REAL(VSCoilIndex,r64)
                Par(2) = DesOutHumRat
                Par(5) = REAL(FanOpMode,r64)
                Par(3) = REAL(SpeedNum,r64)
                CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, SpeedRatio, VSCoilSpeedHumResidual, 1.0d-10, 1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                          ' - Iteration limit exceeded calculating DX unit sensible '// &
                                          'part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                      ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = TempSpeedReqst/TempSpeedOut
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit sensible part-'// &
                                    'load ratio calculation failed: part-load ratio limits exceeded, for unit = '// &
                                     TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                      //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                      ' failed error continues. Sensible PLR statistics follow.' &
                      ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ELSE
                  Par(1) = REAL(VSCoilIndex,r64)
                  Par(2) = DesOutHumRat
                  Par(5) = REAL(FanOpMode,r64)
                  CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, PartLoadFrac, VSCoilCyclingHumResidual, 1.0d-10,   &
                                                1.0d0, Par)
                  IF (SolFla == -1) THEN
                    IF(.NOT. WarmupFlag)THEN
                      IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter .LT. 1)THEN
                        DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter+1
                        CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                              ' - Iteration limit exceeded calculating DX unit latent part-load'// &
                                              ' ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                        CALL ShowContinueError('Estimated part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                        CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                        CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                      END IF
                      CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                          //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                          ' latent part-load ratio error continues. Latent PLR statistics follow.' &
                          ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                    END IF
                  ELSE IF (SolFla == -2) THEN
    !               RegulaFalsi returns PLR = minPLR when a solution cannot be found, recalculate PartLoadFrac.
                    IF(NoLoadHumRatOut-FullLoadHumRatOut .NE. 0.0d0)THEN
                      PartLoadFrac = (NoLoadHumRatOut-DesOutHumRat)/(NoLoadHumRatOut-FullLoadHumRatOut)
                    ELSE
                      PartLoadFrac = 1.0d0
                    END IF
                    IF(.NOT. WarmupFlag)THEN
                      IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail .LT. 1)THEN
                        DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail+1
                        CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit latent part-'// &
                                        'load ratio calculation failed: part-load ratio limits exceeded, for unit = '//&
                                        TRIM(DXCoolingSystem(DXSystemNum)%Name))
                        CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                        CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                        ' continues. Occurrence info: ')
                      END IF
                      CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                          //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                          ' failed error continues. Latent PLR statistics follow.' &
                          ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFailIndex,PartLoadFrac,PartLoadFrac)
                    END IF
                  END IF
               END IF
            END IF
          END IF ! End if humidity ratio setpoint not met - CoolReheat humidity control
          IF(PartLoadFrac.GT.1.0d0) THEN
            PartLoadFrac = 1.0d0
          ELSEIF(PartLoadFrac < 0.0d0) THEN
            PartLoadFrac = 0.0d0
          END IF
        !variable-speed air-to-air cooling coil, end -------------------------
        CASE (CoilDX_PackagedThermalStorageCooling)
          ! First get the control mode that the child coil is in
          CALL SimTESCoil( CompName,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,&
               DXCoolingSystem(DXSystemNum)%FanOpMode, DXCoolingSystem(DXSystemNum)%TESOpMode, &
               DXCoolingSystem(DXSystemNum)%PartLoadFrac)
          IF (DXCoolingSystem(DXSystemNum)%TESOpMode == OffMode .or. &
              DXCoolingSystem(DXSystemNum)%TESOpMode == ChargeOnlyMode) THEN ! cannot cool
            PartLoadFrac = 0.0d0
          ELSE
            ! Get no load result
            PartLoadFrac = 0.0d0
            CALL SimTESCoil( CompName,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,&
               DXCoolingSystem(DXSystemNum)%FanOpMode, DXCoolingSystem(DXSystemNum)%TESOpMode, &
               PartLoadFrac)
            NoOutput = Node(InletNode)%MassFlowRate *  &
                         (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                          - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
            NoLoadHumRatOut = Node(OutletNode)%HumRat
            ! Get full load result
            PartLoadFrac = 1.0d0
            CALL SimTESCoil( CompName,DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,&
               DXCoolingSystem(DXSystemNum)%FanOpMode, DXCoolingSystem(DXSystemNum)%TESOpMode, &
               PartLoadFrac)
            FullOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(Node(OutletNode)%Temp,Node(OutletNode)%HumRat)  &
                        - PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
            FullLoadHumRatOut  = Node(OutletNode)%HumRat
            ReqOutput = Node(InletNode)%MassFlowRate *  &
                       (PsyHFnTdbW(DXCoolingSystem(DXSystemNum)%DesiredOutletTemp,Node(OutletNode)%HumRat) - &
                        PsyHFnTdbW(Node(InletNode)%Temp,Node(OutletNode)%HumRat))
  !         IF NoOutput is lower than (more cooling than required) or very near the ReqOutput, do not run the compressor
            IF ((NoOutput-ReqOutput) .LT. Acc) THEN
              PartLoadFrac = 0.0d0
  !         If the FullOutput is greater than (insufficient cooling) or very near the ReqOutput,
  !         run the compressor at PartLoadFrac = 1.
            ELSE IF ((FullOutput - ReqOutput) .GT. Acc) THEN
              PartLoadFrac = 1.0d0
  !         Else find the PLR to meet the load
            ELSE
              IF (Node(OutletNode)%Temp > DesOutTemp) THEN
                PartLoadFrac = 1.0d0
              ELSE
                Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                Par(2) = DesOutTemp
                Par(3) = DXCoolingSystem(DXSystemNum)%TESOpMode
                Par(4) = DXCoolingSystem(DXSystemNum)%DXCoolingCoilOutletNodeNum
                Par(5) = REAL(FanOpMode,r64)
                CALL SolveRegulaFalsi(Acc, MaxIte, SolFla, PartLoadFrac, TESCoilResidual, 0.0d0,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit sensible '// &
                                            'part-load ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio  = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' sensible part-load ratio error continues. Sensible PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
                  PartLoadFrac = ReqOutput/FullOutput
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit sensible part-'// &
                                      'load ratio calculation failed: part-load ratio limits exceeded, for unit = '// &
                                       TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit sensible part-load ratio calculation'// &
                        ' failed error continues. Sensible PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%DXCoilSensPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ENDIF
            ENDIF
  !         If system does not operate to meet sensible load, use no load humidity ratio to test against humidity setpoint,
  !         else use operating humidity ratio to test against humidity setpoint
            IF (PartLoadFrac .EQ. 0.0d0)THEN
              OutletHumRatDXCoil = NoLoadHumRatOut
            ELSE
              OutletHumRatDXCoil = Node(OutletNode)%HumRat
            END IF
            ! If humidity setpoint is not satisfied and humidity control type is CoolReheat,
            ! then overcool to meet moisture load
            IF (( OutletHumRatDXCoil > DesOutHumRat) .AND. (PartLoadFrac .LT. 1.0d0) .AND. &
                (DXCoolingSystem(DXSystemNum)%DehumidControlType .EQ. DehumidControl_CoolReheat)) THEN
  !           IF NoLoadHumRatOut is lower than (more dehumidification than required) or very near the DesOutHumRat,
  !           do not run the compressor
              IF ((NoLoadHumRatOut-DesOutHumRat) .LT. HumRatAcc) THEN
                PartLoadFrac = PartLoadFrac  ! keep part-load fraction from sensible calculation
  !           If the FullLoadHumRatOut is greater than (insufficient dehumidification) or very near the DesOutHumRat,
  !           run the compressor at PartLoadFrac = 1.
              ELSE IF ((DesOutHumRat-FullLoadHumRatOut) .LT. HumRatAcc) THEN
                PartLoadFrac = 1.0d0
  !           Else find the PLR to meet the load
              ELSE
                Par(1) = REAL(DXCoolingSystem(DXSystemNum)%CoolingCoilIndex,r64)
                Par(2) = DesOutHumRat
                Par(3) = DXCoolingSystem(DXSystemNum)%TESOpMode
                Par(4) = DXCoolingSystem(DXSystemNum)%DXCoolingCoilOutletNodeNum
                Par(5) = REAL(FanOpMode,r64)
                CALL SolveRegulaFalsi(HumRatAcc, MaxIte, SolFla, PartLoadFrac, TESCoilHumRatResidual, 0.0d0,   &
                                            1.0d0, Par)
                IF (SolFla == -1) THEN
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIter+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)// &
                                            ' - Iteration limit exceeded calculating DX unit latent part-load'// &
                                            ' ratio for unit = '//TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio   = '//RoundSigDigits((ReqOutput/FullOutput),3))
                      CALL ShowContinueError('Calculated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The calculated part-load ratio will be used and the simulation'// &
                                                    ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - Iteration limit exceeded calculating'// &
                        ' latent part-load ratio error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRIterIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                ELSE IF (SolFla == -2) THEN
  !               RegulaFalsi returns PLR = minPLR when a solution cannot be found, recalculate PartLoadFrac.
                  IF(NoLoadHumRatOut-FullLoadHumRatOut .NE. 0.0d0)THEN
                    PartLoadFrac = (NoLoadHumRatOut-DesOutHumRat)/(NoLoadHumRatOut-FullLoadHumRatOut)
                  ELSE
                    PartLoadFrac = 1.0d0
                  END IF
                  IF(.NOT. WarmupFlag)THEN
                    IF(DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail .LT. 1)THEN
                      DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail = DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFail+1
                      CALL ShowWarningError(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' - DX unit latent part-'// &
                                      'load ratio calculation failed: part-load ratio limits exceeded, for unit = '//&
                                      TRIM(DXCoolingSystem(DXSystemNum)%Name))
                      CALL ShowContinueError('Estimated part-load ratio = '//RoundSigDigits(PartLoadFrac,3))
                      CALL ShowContinueErrorTimeStamp('The estimated part-load ratio will be used and the simulation'// &
                                                      ' continues. Occurrence info: ')
                    END IF
                    CALL ShowRecurringWarningErrorAtEnd(TRIM(DXCoolingSystem(DXSystemNum)%DXCoolingSystemType)//' "'&
                        //TRIM(DXCoolingSystem(DXSystemNum)%Name)//'" - DX unit latent part-load ratio calculation'// &
                        ' failed error continues. Latent PLR statistics follow.' &
                        ,DXCoolingSystem(DXSystemNum)%DXCoilLatPLRFailIndex,PartLoadFrac,PartLoadFrac)
                  END IF
                END IF
              ENDIF
            ENDIF ! End if humidity ratio setpoint not met - CoolReheat humidity control
          ENDIF ! operating mode can cool
          IF(PartLoadFrac.GT.1.0d0) THEN
            PartLoadFrac = 1.0d0
          ELSEIF(PartLoadFrac < 0.0d0) THEN
            PartLoadFrac = 0.0d0
          END IF
        CASE DEFAULT
          CALL ShowFatalError('ControlDXSystem: Invalid DXCoolingSystem coil type = '//  &
                              TRIM(DXCoolingSystem(DXSystemNum)%CoolingCoilType))
      END SELECT
    END IF ! End of cooling load type (sensible or latent) if block
  END IF   ! End of If DXCoolingSystem is scheduled on and there is flow
  !Set the final results
  DXCoolingSystem(DXSystemNum)%PartLoadFrac = PartLoadFrac
  DXCoolingSystem(DXSystemNum)%SpeedRatio = SpeedRatio
  DXCoolingSystem(DXSystemNum)%CycRatio = CycRatio
  DXCoolingSystem(DXSystemNum)%DehumidificationMode = DehumidMode
  DXCoolingSystem(DXSystemNum)%SpeedNum = SpeedNum
RETURN
END Subroutine ControlDXSystem