Skip to content

Commit

Permalink
Finish work on issue #21
Browse files Browse the repository at this point in the history
Selectively include PE and SR obs
  • Loading branch information
lbross committed Nov 19, 2015
1 parent 481f4ec commit fc66c64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
8 changes: 7 additions & 1 deletion src/BAGIS_P/Forms/FrmExportParametersEwsf.vb
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,13 @@ Public Class FrmExportParametersEwsf
' 7. find AOI-level in nmonths table and overwrite them with calculated values
Dim nmonthsTable As ParameterTable = m_tablesTable(NMONTHS)
If nmonthsTable IsNot Nothing Then
nmonthsTable = BA_UpdateParametersInNmonthsTable(nmonthsTable, m_aoiParamTable)
Dim paramNamesToUpdate As IList(Of String) = New List(Of String)
paramNamesToUpdate.Add(BA_Aoi_Parameter_jh_coef)
If CkPeAndSrObs.Checked Then
paramNamesToUpdate.Add(BA_Aoi_Parameter_PE_Obs)
paramNamesToUpdate.Add(BA_Aoi_Parameter_SR_Obs)
End If
nmonthsTable = BA_UpdateParametersInNmonthsTable(nmonthsTable, m_aoiParamTable, paramNamesToUpdate)
m_tablesTable(NMONTHS) = nmonthsTable
End If

Expand Down
73 changes: 39 additions & 34 deletions src/BAGIS_P/MethodModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ Module MethodModule
Return result
End Function

Public Function BA_UpdateParametersInNmonthsTable(ByRef nmonthsTable As ParameterTable, ByVal updateTable As IDictionary(Of String, AoiParameter)) As ParameterTable
Public Function BA_UpdateParametersInNmonthsTable(ByRef nmonthsTable As ParameterTable, ByVal updateTable As IDictionary(Of String, AoiParameter), _
ByVal paramNamesToExport As IList(Of String)) As ParameterTable
'Put ParameterTable information into structures that are easier to use
Dim headerList As List(Of String) = New List(Of String)
headerList.AddRange(nmonthsTable.Headers)
Expand All @@ -685,46 +686,50 @@ Module MethodModule
monthsList.Add(paramsList)
Next

For Each pName As String In updateTable.Keys
Dim nextParam As AoiParameter = updateTable(pName)
Dim idxCol As Short = -1
'Looking for the column existing in the table
For i As Short = 0 To headerList.Count - 1
If headerList(i).Equals(pName) Then
idxCol = i
Exit For
End If
Next

'Add the column header if we didn't find it
If idxCol = -1 Then
headerList.Add(pName)
idxCol = headerList.Count - 1
'Add an entry to each paramList too
For Each paramList As List(Of String) In monthsList
paramList.Add(BA_9999)
Next
End If

'We found the column
If idxCol > -1 Then
Dim i As Short = 0
For Each paramList As List(Of String) In monthsList
''The parameter is a single value and should be populated to all months
If Not String.IsNullOrEmpty(nextParam.Value) Then
Dim nextParamValue As String = nextParam.Value
paramList(idxCol) = nextParamValue
ElseIf nextParam.ValuesList IsNot Nothing AndAlso nextParam.ValuesList.Count = NUM_MONTHS Then
paramList(idxCol) = nextParam.ValuesList(i)
'Loop through the parameters we want to export
For Each pName As String In paramNamesToExport
Dim nextParam As AoiParameter = Nothing
If updateTable.ContainsKey(pName) Then nextParam = updateTable(pName)
If nextParam IsNot Nothing Then
Dim idxCol As Short = -1
'Looking for the column existing in the table
For i As Short = 0 To headerList.Count - 1
If headerList(i).Equals(pName) Then
idxCol = i
Exit For
End If
i += 1
Next

'Add the column header if we didn't find it
If idxCol = -1 Then
headerList.Add(pName)
idxCol = headerList.Count - 1
'Add an entry to each paramList too
For Each paramList As List(Of String) In monthsList
paramList.Add(BA_9999)
Next
End If

'We found the column
If idxCol > -1 Then
Dim i As Short = 0
For Each paramList As List(Of String) In monthsList
''The parameter is a single value and should be populated to all months
If Not String.IsNullOrEmpty(nextParam.Value) Then
Dim nextParamValue As String = nextParam.Value
paramList(idxCol) = nextParamValue
ElseIf nextParam.ValuesList IsNot Nothing AndAlso nextParam.ValuesList.Count = NUM_MONTHS Then
paramList(idxCol) = nextParam.ValuesList(i)
End If
i += 1
Next
End If
End If
Next

'Reassemble the data in ParameterTable structure
Dim updatedHeaders() As String = headerList.ToArray
Dim updatedValues(monthsList.Count, headerList.Count) As String
Dim updatedValues(monthsList.Count - 1, headerList.Count - 1) As String
Dim m As Short = 0
For Each paramList As List(Of String) In monthsList
Dim p As Integer = 0
Expand Down

0 comments on commit fc66c64

Please sign in to comment.