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 WSE1 As Single = inputTiles(0)(i)
        Dim WSE2 As Single = inputTiles(1)(i)
        Dim Skagit_Terrain_R0m As Single = inputTiles(2)(i)
        Dim Output As Single = NoData

' #BEGINSCRIPT:
'  Compare WSE Example: compares Water Surface Elevations from two Plans
'  Requirements: Water surfaces, 'WSE1' and 'WSE2'
' #VARIABLES:
'  'WSE1' is the cell value from 'WSE1 = Breach_13.1_100 | elevation | 2147483647 | Fixed Profile'
'  'WSE2' is the cell value from 'WSE2 = Exist_100 | elevation | 2147483647 | Fixed Profile'
'  'Skagit_Terrain_R0m' is the cell value from 'Skagit_Terrain_R0m'
'-------------------------------------------------------
If WSE1 = NoData AndAlso WSE2 = NoData Then
  ' The grid cell is not wet for either plan
  Output = NoData
Else
  '  Compare the Water Surface Elevations
  '  One plan may have a wet cell, while the other does not.
  If WSE1 = NoData Then WSE1 = Skagit_Terrain_R0m
  If WSE2 = NoData Then WSE2 = nodata
  Output = WSE1 - WSE2
End If
' #ENDSCRIPT:

        returnArray(i) = Output
      Next

      return returnArray
    End Function
  End Class
End Namespace

' #VARIABLE: WSE1 = Breach_13.1_100 | elevation | 2147483647 | Fixed Profile
' #VARIABLE: WSE2 = Exist_100 | elevation | 2147483647 | Fixed Profile

' #TERRAIN: Skagit_Terrain_R0m = Skagit_Terrain_R0m

