Skip to content

Commit

Permalink
DFLOW uses standard harmonic mean method and write out error during b…
Browse files Browse the repository at this point in the history
…atch run

- address issue #51
  • Loading branch information
TongZhai committed Jul 6, 2022
1 parent cb0954d commit ac80f6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
17 changes: 2 additions & 15 deletions atcIntegratedDesignFlow/DFLOWCalcs.vb
Original file line number Diff line number Diff line change
Expand Up @@ -885,21 +885,8 @@ Public Class DFLOWCalcs
End If

' ===== Harmonic mean of flows
Dim lHFlow As Double = 0
Dim lNH As Integer = 0
Dim lHFlowAdj As Double = 0
For lI = 1 To UBound(lTS) '0 To UBound(lTS) - 1
If (Not Double.IsNaN(lTS(lI))) AndAlso (lTS(lI) > 0) Then 'And (lTS(lI) <> 0)
lNH = lNH + 1
lHFlow = lHFlow + 1 / lTS(lI)
End If
Next
If lHFlow <> 0 Then
lHFlow = lNH / lHFlow
If UBound(lTS) > 0 Then lHFlowAdj = lHFlow * ((1.0 * lNH) / (1.0 * UBound(lTS)))
End If
'Dim lHM As Double = lTimeSeries.Attributes.GetValue("Harmonic Mean")
'Dim lHMAdj As Double = lTimeSeries.Attributes.GetValue("Harmonic Mean Adj")
Dim lHFlow As Double = lHydrologicTS2.Attributes.GetValue("Harmonic Mean")
Dim lHFlowAdj As Double = lHydrologicTS2.Attributes.GetValue("Harmonic Mean Adj")

' ===== Calculate percentiles
Dim lNMiss As Integer = 0
Expand Down
16 changes: 16 additions & 0 deletions atcIntegratedDesignFlow/clsBatchSpecDFLOW.vb
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,11 @@ Public Class clsBatchSpecDFLOW
End If
End Try
lConfigFile = New IO.StreamWriter(IO.Path.Combine(lBFOpnDir, "Config.txt"), False)
Dim lhasError As Boolean = False
For Each lStation As clsBatchUnitStation In lBFOpn
If Not String.IsNullOrEmpty(lStation.Message) AndAlso lStation.Message.StartsWith("Error", True, Nothing) Then
lhasError = True
End If
Dim lDataFilename As String = ListBatchUnitsData.ItemByKey(lStation.StationID)
If String.IsNullOrEmpty(lDataFilename) Then
lDataFilename = lStation.StationDataFilename
Expand Down Expand Up @@ -745,6 +749,18 @@ Public Class clsBatchSpecDFLOW
lConfigFile.Close()
lConfigFile = Nothing

If lhasError Then
Dim lErrorFile As IO.StreamWriter = New IO.StreamWriter(IO.Path.Combine(lBFOpnDir, "Error.txt"), False)
For Each lStation As clsBatchUnitStation In lBFOpn
If Not String.IsNullOrEmpty(lStation.Message) AndAlso lStation.Message.StartsWith("Error", True, Nothing) Then
lErrorFile.WriteLine("Station " + lStation.StationID + ": " + lStation.Message)
End If
Next
lErrorFile.Flush()
lErrorFile.Close()
lErrorFile = Nothing
End If

If DFLOWCalcs.DFLOWMessage IsNot Nothing AndAlso DFLOWCalcs.DFLOWMessage.Length > 0 Then
Dim log As New IO.StreamWriter(IO.Path.Combine(lBFOpnDir, "DFLOW_Log_" & SafeFilename(DateTime.Now()) & ".txt"), False)
log.WriteLine(DFLOWCalcs.DFLOWMessage.ToString())
Expand Down

0 comments on commit ac80f6c

Please sign in to comment.