Imports System
Imports System.Linq
Imports System.Collections.Generic

Namespace RasterCode
  Public Class Processor
    Public Shared Function ProcessTile(inputTiles As List(of Single())) As Single()
      Const NoData As Single = -9999.0
      Dim length As Integer = inputTiles.First().Length
      For Each tile As Single() In inputTiles
        If tile Is Nothing OrElse tile.Length <> length Then Throw New ArgumentException("Tile has invalid dimensions.")
      Next

      Dim returnArray(length - 1) as Single
      For i as Integer = 0 to length - 1
        Dim wse As Single = inputTiles(0)(i)
        Dim v As Single = inputTiles(1)(i)
        Dim Skagit_Terrain_R0m As Single = inputTiles(2)(i)
        Dim Output As Single = NoData

' #BEGINSCRIPT:
'  Hazard Example: depth and velocity criteria for general flood hazard classification
'                  for a given Profile (do NOT use for Max D*V)
'  Requirements: Water Surface Elevation, 'WSE' and Velocity, 'v'
'                Terrain, 'Skagit_Terrain_R0m'
' #VARIABLES:
'  'wse' is the cell value from 'wse = Exist_Coastal_10 | elevation | -1 | Dynamic'
'  'v' is the cell value from 'v = Exist_Coastal_10 | velocity | -1 | Dynamic'
'  'Skagit_Terrain_R0m' is the cell value from 'Skagit_Terrain_R0m'
'-------------------------------------------------------
  Const H1 As Single = 1
  Const H2 As Single = 2
  Const H3 As Single = 3
  Const H4 As Single = 4
  Const H5 As Single = 5
  Const H6 As Single = 6
  Dim CONVERSION As Single = 0.3048
  Dim d as Single
  Dim dv as Single
  If WSE = NoData OrElse v = NoData Then
    Output = NoData
  Else
    d = WSE - Skagit_Terrain_R0m
    '  Conversion from Feet to Meters for evaluation criteria
    d = d * CONVERSION
    v = v * CONVERSION
    dv = d * v
    '  H6 Evaluation - EXTREME
    If d > 4.0 Or v > 4.0 Then
      Output = H6
    ElseIf dv > 4.0 Then
      Output = H6
    '  H5 Evaluation - SEVERE
    ElseIf d > 2.0 Or v > 2.0 Then
      Output = H5
    ElseIf dv > 1.0 Then
      Output = H5
    '  H4 Evaluation - SIGNIFICANT
    ElseIf d > 1.2
      Output = H4
    ElseIf dv > 0.6 Then
      Output = H4
    '  H3 Evaluation - MODERATE
    ElseIf d > 0.5
      Output = H3
    ElseIf dv > 0.3 Then
      Output = H3
    '  H2 Evaluation - CAUTION
    ElseIf d > 0.3 Then
      Output = H2
    ElseIf dv > 0.3 Then
      Output = H2
    Else
    '  H1 Evaluation - LOW
      Output = H1
    End If
  End If
' #ENDSCRIPT:

        returnArray(i) = Output
      Next

      return returnArray
    End Function
  End Class
End Namespace

' #VARIABLE: wse = Exist_Coastal_10 | elevation | -1 | Dynamic
' #VARIABLE: v = Exist_Coastal_10 | velocity | -1 | Dynamic

' #TERRAIN: Skagit_Terrain_R0m = Skagit_Terrain_R0m

