Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | usingVariable |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
SUBROUTINE evaluateRatchet(usingVariable)
! SUBROUTINE INFORMATION:
! AUTHOR Jason Glazer of GARD Analytics, Inc.
! DATE WRITTEN July 2004
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! METHODOLOGY EMPLOYED:
! REFERENCES:
! na
! USE STATEMENTS:
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(IN) :: usingVariable
! SUBROUTINE PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: curTariff
INTEGER :: indexInChg
REAL(r64), DIMENSION(MaxNumMonths) :: baselineVals
REAL(r64), DIMENSION(MaxNumMonths) :: adjustmentVals
REAL(r64), DIMENSION(MaxNumMonths) :: multiplierVals
REAL(r64), DIMENSION(MaxNumMonths) :: offsetVals
REAL(r64), DIMENSION(MaxNumMonths) :: seasonFromMask
REAL(r64), DIMENSION(MaxNumMonths) :: seasonToMask
LOGICAL :: isMonthly
REAL(r64), DIMENSION(MaxNumMonths) :: adjSeasonal
REAL(r64), DIMENSION(MaxNumMonths) :: adjPeak
REAL(r64), DIMENSION(MaxNumMonths) :: maxAdjBase
REAL(r64) :: maximumVal
INTEGER :: iMonth
REAL(r64), DIMENSION(MaxNumMonths) :: finalResult
curTariff = econVar(usingVariable)%tariffIndx
indexInChg = econVar(usingVariable)%index
!check the tariff - make sure they match
IF (ratchet(indexInChg)%namePt .NE. usingVariable) THEN
CALL ShowWarningError('UtilityCost:Tariff Debugging issue. Ratchet index does not match variable pointer.')
CALL ShowContinueError(' Between: ' // TRIM(econVar(usingVariable)%name))
CALL ShowContinueError(' And: ' // TRIM(econVar(ratchet(indexInChg)%namePt)%name))
END IF
IF (ratchet(indexInChg)%tariffIndx .NE. curTariff) THEN
CALL ShowWarningError('UtilityCost:Tariff Debugging issue. Ratchet index does not match tariff index.')
CALL ShowContinueError(' Between: ' // TRIM(tariff(curTariff)%tariffName))
CALL ShowContinueError(' And: ' // TRIM(tariff(ratchet(indexInChg)%tariffIndx)%tariffName))
END IF
! data from the Ratchet
baselineVals = econVar(ratchet(indexInChg)%baselinePt)%values
adjustmentVals = econVar(ratchet(indexInChg)%adjustmentPt)%values
! determine if multiplier should be based on variable or value
IF (ratchet(indexInChg)%multiplierPt .NE. 0) THEN
multiplierVals = econVar(ratchet(indexInChg)%multiplierPt)%values
ELSE
multiplierVals = ratchet(indexInChg)%multiplierVal
END IF
! determine if offset should be based on variable or value
IF (ratchet(indexInChg)%offsetPt .NE. 0) THEN
offsetVals = econVar(ratchet(indexInChg)%offsetPt)%values
ELSE
offsetVals = ratchet(indexInChg)%offsetVal
END IF
! find proper season from mask
SELECT CASE (ratchet(indexInChg)%seasonFrom)
CASE (seasonSummer)
seasonFromMask = econVar(tariff(curTariff)%nativeIsSummer)%values
isMonthly = .FALSE.
CASE (seasonWinter)
seasonFromMask = econVar(tariff(curTariff)%nativeIsWinter)%values
isMonthly = .FALSE.
CASE (seasonSpring)
seasonFromMask = econVar(tariff(curTariff)%nativeIsSpring)%values
isMonthly = .FALSE.
CASE (seasonFall)
seasonFromMask = econVar(tariff(curTariff)%nativeIsAutumn)%values
isMonthly = .FALSE.
CASE (seasonAnnual)
seasonFromMask = 1.0d0 !all months are 1
isMonthly = .FALSE.
CASE (seasonMonthly)
seasonFromMask = 1.0d0 !all months are 1
isMonthly = .TRUE.
END SELECT
! find proper season to mask
SELECT CASE (ratchet(indexInChg)%seasonTo)
CASE (seasonSummer)
seasonToMask = econVar(tariff(curTariff)%nativeIsSummer)%values
CASE (seasonWinter)
seasonToMask = econVar(tariff(curTariff)%nativeIsWinter)%values
CASE (seasonSpring)
seasonToMask = econVar(tariff(curTariff)%nativeIsSpring)%values
CASE (seasonFall)
seasonToMask = econVar(tariff(curTariff)%nativeIsAutumn)%values
CASE (seasonAnnual)
seasonToMask = 1.0d0 !all months are 1
END SELECT
! finally perform calculations
IF (isMonthly) THEN
adjSeasonal = adjustmentVals
ELSE
maximumVal = -HUGE(maximumVal)
DO iMonth = 1, MaxNumMonths
IF (seasonFromMask(iMonth) .EQ. 1) THEN
IF (adjustmentVals(iMonth) .GT. maximumVal) THEN
maximumVal = adjustmentVals(iMonth)
END IF
END IF
END DO
adjSeasonal = maximumVal
END IF
DO iMonth = 1, MaxNumMonths
!calculate adjusted peak value after offset and multiplier
adjPeak(iMonth) = (adjSeasonal(iMonth) + offsetVals(iMonth)) * multiplierVals(iMonth)
!the maximum of the adjustment and the baseline
IF (adjPeak(iMonth) .GT. baselineVals(iMonth)) THEN
maxAdjBase(iMonth) = adjPeak(iMonth)
ELSE
maxAdjBase(iMonth) = baselineVals(iMonth)
END IF
END DO
DO iMonth = 1, MaxNumMonths
IF (seasonToMask(iMonth) .EQ. 1) THEN
finalResult(iMonth) = maxAdjBase(iMonth)
ELSE
finalResult(iMonth) = baselineVals(iMonth)
END IF
END DO
!store the cost in the name of the variable
econVar(usingVariable)%values = finalResult
!set the flag that it has been evaluated so it won't be evaluated multiple times
econVar(usingVariable)%isEvaluated = .TRUE.
END SUBROUTINE evaluateRatchet