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 ComputePresentValue
! SUBROUTINE INFORMATION:
! AUTHOR Jason Glazer of GARD Analytics, Inc.
! DATE WRITTEN August 2010
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! For each cashflow, compute the present value
! METHODOLOGY EMPLOYED:
! REFERENCES:
! na
! USE STATEMENTS:
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
! na
! SUBROUTINE PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
REAL(r64) :: totalPV
INTEGER :: curCategory
INTEGER :: curResource
REAL(r64) :: curDiscountRate
INTEGER :: iCashFlow
INTEGER :: jYear
INTEGER :: kResource
INTEGER :: nUsePriceEsc
REAL(r64) :: effectiveYear
! identify how each cashflow should be treated
DO iCashFlow = 1, numCashFlow
SELECT CASE (CashFlow(iCashFlow)%SourceKind)
CASE (skResource)
!only for real fuels purchased such as electricity, natural gas, etc..
IF ((CashFlow(iCashFlow)%Resource) .GE. iRT_Electricity .AND. (CashFlow(iCashFlow)%Resource .LE. iRT_ResidualOil)) THEN
CashFlow(iCashFlow)%pvKind = pvkEnergy
ELSE
CashFlow(iCashFlow)%pvKind = pvkNonEnergy
END IF
CASE (skRecurring, skNonrecurring)
IF (CashFlow(iCashFlow)%Category .EQ. costCatEnergy) THEN
CashFlow(iCashFlow)%pvKind = pvkEnergy
ELSE
CashFlow(iCashFlow)%pvKind = pvkNonEnergy
END IF
CASE (skSum)
CashFlow(iCashFlow)%pvKind = pvkNotComputed
CASE DEFAULT
CashFlow(iCashFlow)%pvKind = pvkNotComputed
END SELECT
END DO
! compute the Single Present Value factors based on the discount rate
ALLOCATE(SPV(lengthStudyYears))
ALLOCATE(energySPV(NumOfResourceTypes,lengthStudyYears))
! Depending if using Constant or Current Dollar analysis
! use the appropriate discount rate
IF (inflationApproach .EQ. inflAppConstantDollar) THEN
curDiscountRate = realDiscountRate
ELSEIF (inflationApproach .EQ. inflAppCurrentDollar) THEN
curDiscountRate = nominalDiscountRate
END IF
!compute single present values based on real discount rates
DO jYear = 1, lengthStudyYears
! NIST 155 D.2.1.1 - Single Present Value (SPV) formula
SELECT CASE (discountConvension)
CASE (disConvBeginOfYear)
effectiveYear = REAL(jYear,r64) - 1.0d0
CASE (disConvMidYear)
effectiveYear = REAL(jYear,r64) - 0.5d0
CASE (disConvEndOfYear)
effectiveYear = REAL(jYear,r64)
CASE DEFAULT
END SELECT
SPV(jYear) = 1.0d0 / ((1.0d0 + curDiscountRate) ** effectiveYear)
END DO
!use SPV as default values for all energy types
DO jYear = 1, lengthStudyYears
DO kResource = 1,NumOfResourceTypes
energySPV(kResource,jYear) = SPV(jYear)
END DO
END DO
!loop through the resources and if they match a UseEscalation use those values instead
DO nUsePriceEsc = 1,numUsePriceEscalation
curResource = UsePriceEscalation(nUsePriceEsc)%resource - ResourceTypeInitialOffset
IF ((curResource .GE. 1) .AND. (curResource .LT. NumOfResourceTypes)) THEN
DO jYear = 1, lengthStudyYears
!the following is based on UPV* formula from NIST 135 supplement but is for a single year
SELECT CASE (discountConvension)
CASE (disConvBeginOfYear)
effectiveYear = REAL(jYear,r64) - 1.0d0
CASE (disConvMidYear)
effectiveYear = REAL(jYear,r64) - 0.5d0
CASE (disConvEndOfYear)
effectiveYear = REAL(jYear,r64)
CASE DEFAULT
END SELECT
energySPV(curResource,jYear) = UsePriceEscalation(nUsePriceEsc)%Escalation(jYear) / &
((1.0d0 + curDiscountRate) ** effectiveYear)
END DO
END IF
END DO
DO iCashFlow = 1, numCashFlow
SELECT CASE (CashFlow(iCashFlow)%pvKind)
CASE (pvkNonEnergy)
totalPV = 0.0d0
DO jYear = 1,lengthStudyYears
CashFlow(iCashFlow)%yrPresVal(jYear) = CashFlow(iCashFlow)%yrAmount(jYear) * SPV(jYear)
totalPV = totalPV + CashFlow(iCashFlow)%yrPresVal(jYear)
END DO
CashFlow(iCashFlow)%presentValue = totalPV
CASE (pvkEnergy)
curResource = CashFlow(iCashFlow)%Resource - ResourceTypeInitialOffset
IF ((curResource .GE. 1) .AND. (curResource .LT. NumOfResourceTypes)) THEN
totalPV = 0.0d0
DO jYear = 1,lengthStudyYears
CashFlow(iCashFlow)%yrPresVal(jYear) = CashFlow(iCashFlow)%yrAmount(jYear) * energySPV(curResource,jYear)
totalPV = totalPV + CashFlow(iCashFlow)%yrPresVal(jYear)
END DO
CashFlow(iCashFlow)%presentValue = totalPV
END IF
CASE (pvkNotComputed)
! do nothing
END SELECT
END DO
! sum by category
DO iCashFlow = countOfCostCat + 1, numCashFlow
curCategory = CashFlow(iCashFlow)%Category
IF ((curCategory .LE. countOfCostCat) .AND. (curCategory .GE. 1)) THEN
CashFlow(curCategory)%presentValue = CashFlow(curCategory)%presentValue + CashFlow(iCashFlow)%presentValue
DO jYear = 1,lengthStudyYears
CashFlow(curCategory)%yrPresVal(jYear) = CashFlow(curCategory)%yrPresVal(jYear) + CashFlow(iCashFlow)%yrPresVal(jYear)
END DO
END IF
END DO
!create total categories
CashFlow(costCatTotEnergy)%presentValue = CashFlow(costCatEnergy)%presentValue
CashFlow(costCatTotOper)%presentValue = CashFlow(costCatMaintenance)%presentValue + &
CashFlow(costCatRepair)%presentValue + &
CashFlow(costCatOperation)%presentValue + &
CashFlow(costCatReplacement)%presentValue + &
CashFlow(costCatMinorOverhaul)%presentValue + &
CashFlow(costCatMajorOverhaul)%presentValue + &
CashFlow(costCatOtherOperational)%presentValue + &
CashFlow(costCatWater)%presentValue + &
CashFlow(costCatEnergy)%presentValue
CashFlow(costCatTotCaptl)%presentValue = CashFlow(costCatConstruction)%presentValue + &
CashFlow(costCatSalvage)%presentValue + &
CashFlow(costCatOtherCapital)%presentValue
CashFlow(costCatTotGrand)%presentValue = CashFlow(costCatTotOper)%presentValue + &
CashFlow(costCatTotCaptl)%presentValue
DO jYear = 1,lengthStudyYears
CashFlow(costCatTotEnergy)%yrPresVal(jYear) = CashFlow(costCatEnergy)%yrPresVal(jYear)
CashFlow(costCatTotOper)%yrPresVal(jYear) = CashFlow(costCatMaintenance)%yrPresVal(jYear) + &
CashFlow(costCatRepair)%yrPresVal(jYear) + &
CashFlow(costCatOperation)%yrPresVal(jYear) + &
CashFlow(costCatReplacement)%yrPresVal(jYear) + &
CashFlow(costCatMinorOverhaul)%yrPresVal(jYear) + &
CashFlow(costCatMajorOverhaul)%yrPresVal(jYear) + &
CashFlow(costCatOtherOperational)%yrPresVal(jYear) + &
CashFlow(costCatWater)%yrPresVal(jYear) + &
CashFlow(costCatEnergy)%yrPresVal(jYear)
CashFlow(costCatTotCaptl)%yrPresVal(jYear) = CashFlow(costCatConstruction)%yrPresVal(jYear) + &
CashFlow(costCatSalvage)%yrPresVal(jYear) + &
CashFlow(costCatOtherCapital)%yrPresVal(jYear)
CashFlow(costCatTotGrand)%yrPresVal(jYear) = CashFlow(costCatTotOper)%yrPresVal(jYear) + &
CashFlow(costCatTotCaptl)%yrPresVal(jYear)
END DO
END SUBROUTINE ComputePresentValue