Nodes of different colours represent the following:
Solid arrows point from a parent (sub)module to the submodule which is descended from it. Dashed arrows point from a module being used to the module or program unit using it. 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.
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 WriteMonthlyTables
! SUBROUTINE INFORMATION:
! AUTHOR Jason Glazer
! DATE WRITTEN August 2003
! MODIFIED January 2010, Kyle Benne
! Added SQLite output
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Set up the monthly tabular report results
! METHODOLOGY EMPLOYED:
! Creates several arrays that are passed to the writeTable
! routine. All arrays are strings so numbers need to be
! converted prior to calling writeTable.
USE SQLiteProcedures, ONLY: CreateSQLiteTabularDataRecords
IMPLICIT NONE
! SUBROUTINE ARGUMENT DEFINITIONS:
! na
! SUBROUTINE PARAMETER DEFINITIONS:
! na
! INTERFACE BLOCK SPECIFICATIONS:
! na
! DERIVED TYPE DEFINITIONS:
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
CHARACTER(len=MaxNameLength*2), ALLOCATABLE, DIMENSION(:) :: columnHead
INTEGER,ALLOCATABLE,DIMENSION(:) :: columnWidth
CHARACTER(len=MaxNameLength), DIMENSION(16) :: rowHead
CHARACTER(len=MaxNameLength), ALLOCATABLE, DIMENSION(:,:) :: tableBody
CHARACTER(len=MaxNameLength), DIMENSION(13) :: aggString
CHARACTER(len=MaxNameLength) :: curAggString
INTEGER :: iInput
INTEGER :: jTable
INTEGER :: kColumn
INTEGER :: lMonth
INTEGER :: curTable
INTEGER :: curCol
REAL(r64) :: curVal
REAL(r64) :: curConversionFactor
REAL(r64) :: curConversionOffset = 0.0d0
INTEGER :: columnUsedCount
INTEGER :: columnRecount
INTEGER :: digitsShown
REAL(r64) :: minVal,maxVal,sumVal,sumDuration
CHARACTER(len=MaxNameLength) :: curUnits
CHARACTER(len=MaxNameLength) :: energyUnitsString
REAL(r64) :: energyUnitsConversionFactor
INTEGER :: indexUnitConv
CHARACTER(len=MaxNameLength) :: varNameWithUnits
REAL(r64) :: veryLarge
REAL(r64) :: verySmall
rowHead(1) = 'January'
rowHead(2) = 'February'
rowHead(3) = 'March'
rowHead(4) = 'April'
rowHead(5) = 'May'
rowHead(6) = 'June'
rowHead(7) = 'July'
rowHead(8) = 'August'
rowHead(9) = 'September'
rowHead(10) = 'October'
rowHead(11) = 'November'
rowHead(12) = 'December'
rowHead(13) = ''
rowHead(14) = 'Annual Sum or Average'
rowHead(15) = 'Minimum of Months'
rowHead(16) = 'Maximum of Months'
aggString(aggTypeSumOrAvg) = ''
aggString(aggTypeMaximum) = ' Maximum '
aggString(aggTypeMinimum) = ' MINIMUM '
aggString(aggTypeValueWhenMaxMin) = ' AT MAX/MIN '
aggString(aggTypeHoursZero) = ' HOURS ZERO '
aggString(aggTypeHoursNonZero) = ' HOURS NON-ZERO '
aggString(aggTypeHoursPositive) = ' HOURS POSITIVE '
aggString(aggTypeHoursNonPositive) = ' HOURS NON-POSITIVE '
aggString(aggTypeHoursNegative) = ' HOURS NEGATIVE '
aggString(aggTypeHoursNonNegative) = ' HOURS NON-NEGATIVE '
aggString(aggTypeSumOrAverageHoursShown) = ' FOR HOURS SHOWN '
aggString(aggTypeMaximumDuringHoursShown) = ' MAX FOR HOURS SHOWN '
aggString(aggTypeMinimumDuringHoursShown) = ' MIN FOR HOURS SHOWN '
veryLarge = 1.0D280
verySmall = -1.0D280
! set the unit conversion
SELECT CASE (unitsStyle)
CASE (unitsStyleNone)
energyUnitsString = 'J '
energyUnitsConversionFactor = 1.0d0
CASE (unitsStyleJtoKWH)
energyUnitsString = 'kWh'
energyUnitsConversionFactor = 1.0d0/3600000.0d0
CASE (unitsStyleJtoMJ)
energyUnitsString = 'MJ '
energyUnitsConversionFactor = 1.0d0/1000000.0d0
CASE (unitsStyleJtoGJ)
energyUnitsString = 'GJ '
energyUnitsConversionFactor = 1.0d0/1000000000.0d0
END SELECT
! loop through each input to get the name of the tables
DO iInput = 1, MonthlyInputCount
! loop through each report and
digitsShown = MonthlyInput(iInput)%showDigits
DO jTable = 1 , MonthlyInput(iInput)%numTables
curTable =jTable + MonthlyInput(iInput)%firstTable - 1
! first loop through and count how many 'columns' are defined
! since max and min actually define two columns (the value
! and the timestamp).
columnUsedCount = 0
DO kColumn = 1, MonthlyTables(curTable)%numColumns
curCol = kColumn + MonthlyTables(curTable)%firstColumn - 1
SELECT CASE (MonthlyColumns(curCol)%aggType)
CASE (aggTypeSumOrAvg, aggTypeValueWhenMaxMin, &
aggTypeHoursZero, aggTypeHoursNonZero, &
aggTypeHoursPositive, aggTypeHoursNonPositive, &
aggTypeHoursNegative, aggTypeHoursNonNegative, &
aggTypeSumOrAverageHoursShown)
columnUsedCount = columnUsedCount + 1
CASE (aggTypeMaximum,aggTypeMinimum, &
aggTypeMaximumDuringHoursShown, aggTypeMinimumDuringHoursShown)
columnUsedCount = columnUsedCount + 2
END SELECT
END DO !jColumn
ALLOCATE (columnHead(columnUsedCount))
ALLOCATE (columnWidth(columnUsedCount))
columnWidth = 14 !array assignment - same for all columns
ALLOCATE (tableBody(16,columnUsedCount))
tableBody = "" !set entire table to blank as default
columnRecount = 0
DO kColumn = 1, MonthlyTables(curTable)%numColumns
curCol = kColumn + MonthlyTables(curTable)%firstColumn - 1
curAggString = aggString(MonthlyColumns(curCol)%aggType)
IF (LEN_TRIM(curAggString) .GT. 0) THEN
curAggString = ' {' // TRIM(ADJUSTL(curAggString)) // '}'
END IF
!do the unit conversions
IF (unitsStyle .EQ. unitsStyleInchPound) THEN
varNameWithUnits = TRIM(MonthlyColumns(curCol)%varName) // '[' // &
TRIM(MonthlyColumns(curCol)%units) // ']'
CALL LookupSItoIP(varNameWithUnits, indexUnitConv, curUnits)
CALL GetUnitConversion(indexUnitConv, curConversionFactor, curConversionOffset, curUnits)
ELSE !just do the Joule conversion
!if units is in Joules, convert if specified
IF (sameString(MonthlyColumns(curCol)%units,'J')) THEN
curUnits = energyUnitsString
curConversionFactor = energyUnitsConversionFactor
curConversionOffset = 0.0d0
ELSE !if not joules don't perform conversion
curUnits = MonthlyColumns(curCol)%units
curConversionFactor = 1.0d0
curConversionOffset = 0.0d0
END IF
END IF
SELECT CASE (MonthlyColumns(curCol)%aggType)
CASE (aggTypeSumOrAvg,aggTypeSumOrAverageHoursShown)
columnRecount = columnRecount + 1
! put in the name of the variable for the column
columnHead(columnRecount) = TRIM(MonthlyColumns(curCol)%varName) // TRIM(curAggString) // &
' [' // TRIM(curUnits) // ']'
sumVal = 0.0d0
sumDuration = 0.0d0
maxVal = -HUGE(maxVal)
minVal = HUGE(maxVal)
DO lMonth = 1, 12
IF (MonthlyColumns(curCol)%avgSum .EQ. isAverage) THEN ! if it is a average variable divide by duration
IF (MonthlyColumns(curCol)%duration(lMonth) .NE. 0) THEN
curVal = ((MonthlyColumns(curCol)%reslt(lMonth) / MonthlyColumns(curCol)%duration(lMonth)) &
* curConversionFactor) + curConversionOffset
ELSE
curVal = 0.0d0
END IF
sumVal = sumVal + (MonthlyColumns(curCol)%reslt(lMonth) * curConversionFactor) + curConversionOffset
sumDuration = sumDuration + MonthlyColumns(curCol)%duration(lMonth)
ELSE
curVal = (MonthlyColumns(curCol)%reslt(lMonth) * curConversionFactor) + curConversionOffset
sumVal = sumVal + curVal
END IF
IF (IsMonthGathered(lMonth)) THEN
tableBody(lMonth,columnRecount) = TRIM(RealToStr(curVal,digitsShown))
IF (curVal .GT. maxVal) maxVal = curVal
IF (curVal .LT. minVal) minVal = curVal
ELSE
tableBody(lMonth,columnRecount) = '-'
END IF
END DO !lMonth
! add the summary to bottom
IF (MonthlyColumns(curCol)%avgSum .EQ. isAverage) THEN ! if it is a average variable divide by duration
IF (sumDuration .GT. 0) THEN
tableBody(14,columnRecount) = TRIM(RealToStr(sumVal/sumDuration,digitsShown))
ELSE
tableBody(14,columnRecount) = ''
END IF
ELSE
tableBody(14,columnRecount) = TRIM(RealToStr(sumVal,digitsShown))
ENDIF
IF (minVal .NE. HUGE(maxVal)) THEN
tableBody(15,columnRecount) = TRIM(RealToStr(minVal,digitsShown))
END IF
IF (maxVal .NE. -HUGE(maxVal)) THEN
tableBody(16,columnRecount) = TRIM(RealToStr(maxVal,digitsShown))
END IF
CASE (aggTypeHoursZero, aggTypeHoursNonZero, &
aggTypeHoursPositive, aggTypeHoursNonPositive, &
aggTypeHoursNegative, aggTypeHoursNonNegative)
columnRecount = columnRecount + 1
! put in the name of the variable for the column
columnHead(columnRecount) = TRIM(MonthlyColumns(curCol)%varName) // TRIM(curAggString) // ' [HOURS]'
sumVal = 0.0d0
maxVal = -HUGE(maxVal)
minVal = HUGE(maxVal)
DO lMonth = 1, 12
curVal = MonthlyColumns(curCol)%reslt(lMonth)
IF (IsMonthGathered(lMonth)) THEN
tableBody(lMonth,columnRecount) = TRIM(RealToStr(curVal,digitsShown))
sumVal = sumVal + curVal
IF (curVal .GT. maxVal) maxVal = curVal
IF (curVal .LT. minVal) minVal = curVal
ELSE
tableBody(lMonth,columnRecount) = '-'
END IF
END DO !lMonth
! add the summary to bottom
tableBody(14,columnRecount) = TRIM(RealToStr(sumVal,digitsShown))
IF (minVal .NE. HUGE(maxVal)) THEN
tableBody(15,columnRecount) = TRIM(RealToStr(minVal,digitsShown))
END IF
IF (maxVal .NE. -HUGE(maxVal)) THEN
tableBody(16,columnRecount) = TRIM(RealToStr(maxVal,digitsShown))
END IF
CASE (aggTypeValueWhenMaxMin)
columnRecount = columnRecount + 1
IF (MonthlyColumns(curCol)%avgSum .EQ. isSum) THEN
curUnits = TRIM(curUnits) // '/s'
END IF
IF (sameString(curUnits,'J/s')) THEN
curUnits = 'W'
END IF
!CR7783 fix
IF (sameString(curUnits,'kWh/s')) THEN
curUnits = 'W'
curConversionFactor = curConversionFactor * 3600000.0d0
END IF
IF (sameString(curUnits,'GJ/s')) THEN
curUnits = 'kW'
curConversionFactor = curConversionFactor * 1000000.0d0
END IF
IF (sameString(curUnits,'MJ/s')) THEN
curUnits = 'kW'
curConversionFactor = curConversionFactor * 1000.0d0
END IF
IF (sameString(curUnits,'therm/s')) THEN
curUnits = 'kBtu/h'
curConversionFactor = curConversionFactor * 360000.0d0
END IF
IF (sameString(curUnits,'kBtu/s')) THEN
curUnits = 'kBtu/h'
curConversionFactor = curConversionFactor * 3600.0d0
END IF
IF (sameString(curUnits,'ton-hrs/s')) THEN
curUnits = 'ton'
curConversionFactor = curConversionFactor * 3600.0d0
END IF
columnHead(columnRecount) = TRIM(MonthlyColumns(curCol)%varName) // TRIM(curAggString) // ' [' &
// TRIM(curUnits) //']'
maxVal = -HUGE(maxVal)
minVal = HUGE(maxVal)
DO lMonth = 1, 12
curVal = MonthlyColumns(curCol)%reslt(lMonth) * curConversionFactor + curConversionOffset
IF (IsMonthGathered(lMonth)) THEN
tableBody(lMonth,columnRecount) = TRIM(RealToStr(curVal,digitsShown))
IF (curVal .GT. maxVal) maxVal = curVal
IF (curVal .LT. minVal) minVal = curVal
ELSE
tableBody(lMonth,columnRecount) = '-'
END IF
END DO !lMonth
! add the summary to bottom
IF (minVal .NE. HUGE(maxVal)) THEN
tableBody(15,columnRecount) = TRIM(RealToStr(minVal,digitsShown))
END IF
IF (maxVal .NE. -HUGE(maxVal)) THEN
tableBody(16,columnRecount) = TRIM(RealToStr(maxVal,digitsShown))
END IF
CASE (aggTypeMaximum,aggTypeMinimum,aggTypeMaximumDuringHoursShown,aggTypeMinimumDuringHoursShown)
columnRecount = columnRecount + 2
! put in the name of the variable for the column
IF (MonthlyColumns(curCol)%avgSum .EQ. isSum) THEN ! if it is a summed variable
curUnits = TRIM(curUnits) // '/s'
ENDIF
IF (sameString(curUnits,'J/s')) THEN
curUnits = 'W'
END IF
!CR7783 fix
IF (sameString(curUnits,'kWh/s')) THEN
curUnits = 'W'
curConversionFactor = curConversionFactor * 3600000.0d0
END IF
IF (sameString(curUnits,'GJ/s')) THEN
curUnits = 'kW'
curConversionFactor = curConversionFactor * 1000000.0d0
END IF
IF (sameString(curUnits,'MJ/s')) THEN
curUnits = 'kW'
curConversionFactor = curConversionFactor * 1000.0d0
END IF
IF (sameString(curUnits,'therm/s')) THEN
curUnits = 'kBtu/h'
curConversionFactor = curConversionFactor * 360000.0d0
END IF
IF (sameString(curUnits,'kBtu/s')) THEN
curUnits = 'kBtu/h'
curConversionFactor = curConversionFactor * 3600.0d0
END IF
IF (sameString(curUnits,'ton-hrs/s')) THEN
curUnits = 'ton'
curConversionFactor = curConversionFactor * 3600.0d0
END IF
columnHead(columnRecount - 1) = TRIM(MonthlyColumns(curCol)%varName) // TRIM(curAggString) // &
'[' // TRIM(curUnits) // ']'
columnHead(columnRecount) = TRIM(MonthlyColumns(curCol)%varName) // ' {TIMESTAMP} '
maxVal = -HUGE(maxVal)
minVal = HUGE(maxVal)
DO lMonth = 1, 12
IF (IsMonthGathered(lMonth)) THEN
curVal = MonthlyColumns(curCol)%reslt(lMonth)
!CR7788 the conversion factors were causing an overflow for the InchPound case since the
!value was very small
!restructured the following lines to hide showing HUGE and -HUGE values in output table CR8154 Glazer
IF ((curVal .LT. veryLarge) .AND. (curVal .GT. verySmall)) THEN
curVal = curVal * curConversionFactor + curConversionOffset
IF (curVal .GT. maxVal) maxVal = curVal
IF (curVal .LT. minVal) minVal = curVal
IF (curVal .LT. veryLarge .AND. curVal .GT. verySmall) THEN
tableBody(lMonth,columnRecount - 1) = TRIM(RealToStr(curVal,digitsShown))
ELSE
tableBody(lMonth,columnRecount - 1) = '-'
END IF
tableBody(lMonth,columnRecount) = TRIM(DateToString(MonthlyColumns(curCol)%timeStamp(lMonth)))
ELSE
tableBody(lMonth,columnRecount - 1) = '-'
tableBody(lMonth,columnRecount) = '-'
END IF
ELSE
tableBody(lMonth,columnRecount - 1) = '-'
tableBody(lMonth,columnRecount) = '-'
END IF
END DO !lMonth
! add the summary to bottom
! Don't include if the original min and max values are still present
IF (minVal .LT. veryLarge) THEN
tableBody(15,columnRecount - 1) = TRIM(RealToStr(minVal,digitsShown))
ELSE
tableBody(15,columnRecount - 1) = '-'
END IF
IF (maxVal .GT. verySmall) THEN
tableBody(16,columnRecount - 1) = TRIM(RealToStr(maxVal,digitsShown))
ELSE
tableBody(15,columnRecount - 1) = '-'
END IF
END SELECT
END DO !KColumn
CALL WriteReportHeaders(MonthlyInput(iInput)%name,MonthlyTables(curTable)%keyValue,isAverage)
CALL WriteSubtitle("Custom Monthly Report")
CALL writeTable(tableBody,rowHead,columnHead,columnWidth,.TRUE.) !transpose monthly XML tables.
CALL CreateSQLiteTabularDataRecords(tableBody,rowHead,columnHead,&
MonthlyInput(iInput)%name,&
MonthlyTables(curTable)%keyValue,&
'Custom Monthly Report')
DEALLOCATE (columnHead)
DEALLOCATE (columnWidth)
DEALLOCATE (tableBody)
END DO !jTables
END DO ! iInput
END SUBROUTINE WriteMonthlyTables