Commit 5728befd authored by Wesseling, Jan's avatar Wesseling, Jan
Browse files

Read catchment data

parent f64ce6d5
......@@ -2,5 +2,15 @@ module Types
mutable struct CatchmentData
id :: Int64
area :: Float64
cultivated :: Float64
storage :: Float64
maxHeight :: Float64
runoffCoefficient :: Float64
infiltrationRate :: Float64
infiltrationPercentage :: Float64
outflowTo1 :: Int64
percentage1 :: Float64
outflowTo2 :: Int64
percentage2 :: Float64
end
end
module Types
mutable struct CatchmentData
id :: Int64
area :: Float64
using XLSX
using Dates
using DataFrames
include("Types.jl")
catchment = Nothing
ETp = Nothing
P = Nothing
function createCatchment(aData :: DataFrame)
catchment = Array{Types.CatchmentData}(undef,1)
try
try
resize!(catchment, size(aData,1)-1)
# println(size(catchment,1))
for i in 2:size(aData,1)
id = -1
if !ismissing(aData[i,1])
if typeof(aData[i,1]) == String
if strip(aData[i,1]) != ""
id = tryparse(Int64, aData[i,1])
end
else
id = aData[i,1]
end
end
area = -1.0
if !ismissing(aData[i,2])
if typeof(aData[i,2]) == String
if strip(aData[i,2]) != ""
area = tryparse(Float64, aData[i,2])
end
else
area = aData[i,2]
end
end
cultivated = -1.0
if !ismissing(aData[i,3])
if typeof(aData[i,3]) == String
if strip(aData[i,3]) != ""
cultivated = tryparse(Float64, aData[i,3])
end
else
cultivated = aData[i,3]
end
end
storage = -1.0
if !ismissing(aData[i,4])
if typeof(aData[i,4]) == String
if strip(aData[i,4]) != ""
storage = tryparse(Float64, aData[i,4])
end
else
storage = aData[i,4]
end
end
maxHeight = -1.0
if !ismissing(aData[i,5])
if typeof(aData[i,5]) == String
if strip(aData[i,5]) != ""
maxHeight = tryparse(Float64, aData[i,5])
end
else
maxHeight = aData[i,5]
end
end
runoffCoefficient = -1.0
if !ismissing(aData[i,6])
if typeof(aData[i,6]) == String
if strip(aData[i,6]) != ""
runoffCoefficient = tryparse(Float64, aData[i,6])
end
else
runoffCoefficient = aData[i,6]
end
end
infiltrationRate = -1.0
if !ismissing(aData[i,7])
if typeof(aData[i,7]) == String
if strip(aData[i,7]) != ""
infiltrationRate = tryparse(Float64, aData[i,7])
end
else
infiltrationRate = aData[i,7]
end
end
infiltrationPercentage = -1.0
if !ismissing(aData[i,8])
if typeof(aData[i,8]) == String
if strip(aData[i,8]) != ""
infiltrationPercentage = tryparse(Float64, aData[i,8])
end
else
infiltrationPercentage = aData[i,8]
end
end
outflowsTo1 = -1.0
if !ismissing(aData[i,9])
if typeof(aData[i,9]) == String
if strip(aData[i,9]) != ""
outflowsTo1 = tryparse(Int64, aData[i,9])
end
else
outflowsTo1 = aData[i,9]
end
end
percentage1 = -1.0
if !ismissing(aData[i,10])
if typeof(aData[i,10]) == String
if strip(aData[i,10]) != ""
percentage1 = tryparse(Float64, aData[i,10])
end
else
percentage1 = aData[i,10]
end
end
outflowsTo2 = -1.0
if !ismissing(aData[i,11])
if typeof(aData[i,11]) == String
if strip(aData[i,11]) != ""
outflowsTo2 = tryparse(Int64, aData[i,11])
end
else
outflowsTo2 = aData[i,11]
end
end
percentage2 = -1.0
if !ismissing(aData[i,12])
if typeof(aData[i,12]) == String
if strip(aData[i,12]) != ""
percentage2 = tryparse(Float64, aData[i,12])
end
else
percentage2 = aData[i,12]
end
end
catchment[i-1] = Types.CatchmentData(id,area,cultivated,storage,maxHeight,runoffCoefficient,
infiltrationRate,infiltrationPercentage,outflowsTo1,
percentage1,outflowsTo2,percentage2)
# println(catchment[i-1])
end
catch e
println("???Error in createCatchment: ",e)
end
finally
end
end
function readData()
fileName = "/home/wesseling/DataDisk/Wesseling/Work/Ammar/Original/WHCatch2.xlsm"
try
try
println("Reading....")
xf = XLSX.readxlsx(fileName)
println("After readxlsx")
sheet = xf["Catchment"]
matrix = dropmissing!(DataFrame(sheet[:]))
createCatchment(matrix)
exit(0)
sheet = xf["ETp"]
global ETp = dropmissing!(DataFrame(sheet[:]))
sheet = xf["Rainfall"]
global P = dropmissing!(DataFrame(sheet[:]))
println("OK")
catch e
println("???ERROR in readData: ",e)
end
finally
end
end
function initialize()
readData()
end
initialize()
println("Finished")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment