Skip to content

Commit

Permalink
Merge pull request #18 from robertdj/error
Browse files Browse the repository at this point in the history
🐛 Index arrays
  • Loading branch information
robertdj committed Oct 23, 2020
2 parents 00b09e0 + d1ac7ac commit da33aaf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,7 +1,7 @@
name = "Deldir"
uuid = "64db5801-a3ae-51a7-b7d2-a0a5f0813e47"
authors = ["Robert DJ <git@dahl-jacobsen.dk>"]
version = "1.2.1"
version = "1.2.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
32 changes: 21 additions & 11 deletions src/wrapper.jl
Expand Up @@ -44,9 +44,10 @@ macro initialize()
ntdir = 3*npd

# Set up dimensioning constants which might need to be increased
madj = max(20, ceil(Int32, 3*sqrt(ntot)))
tadj = (madj + 1)*(ntot + 4)
ndel = Int32[madj*(madj + 1)/2]
madj_val = max(20, ceil(Int32, 3*sqrt(ntot)))
madj = Int32[madj_val]
tadj = (madj_val + 1)*(ntot + 4)
ndel = Int32[madj_val*(madj_val + 1)/2]
tdel = 6*ndel[]
ndir = copy(ndel)
tdir = 8*ndir[]
Expand Down Expand Up @@ -90,22 +91,31 @@ Handle errors from the deldir Fortran routine
macro error_handling()
esc(quote
if nerror[] == 4
madj = ceil(Int32, 1.2*madj)
tadj = (madj + 1)*(ntot + 4)
ndel = max(ndel, div(madj*(madj + 1), 2))
tdel = 6*ndel[]
madj_val = ceil(Int32, 1.2*madj[])
madj = Int32[madj_val]
tadj = (madj_val + 1)*(ntot + 4)
ndel_val = max(ndel[], div(madj_val*(madj_val + 1), 2))
ndel = Int32[ndel_val]
tdel = 6*ndel_val
ndir = copy(ndel)
tdir = 8*ndir[]
tdir = 8*ndel_val

@info "Fortran error $(nerror[]). Increasing madj to $(madj[])"

@allocate
elseif nerror[] == 14 || nerror[] == 15
ndel = ceil(Int32, 1.2*ndel)
tdel = 6*ndel[]
ndel_val = ceil(Int32, 1.2*ndel[])
ndel = Int32[ndel_val]
tdel = 6*ndel_val
ndir = copy(ndel)
tdir = 8*ndir[]
tdir = 8*ndel_val

@info "Fortran error $(nerror[]). Increasing ndel & ndir to $(ndel[])"

@allocate
elseif nerror[] > 1
@warn "Fortran error $(nerror[])"

error("From `deldir` Fortran, nerror = ", nerror[])
end
end)
Expand Down
12 changes: 11 additions & 1 deletion test/runtests.jl
Expand Up @@ -74,10 +74,20 @@ end
@test_throws DomainError deldir(x, y)
end

@testset "Error number of x's and y's are not equal" begin
@testset "Error when number of x's and y's are not equal" begin
x = rand(rand(2:7))
y = rand(rand(8:12))

@test_throws DimensionMismatch deldir(x, y)
end
end


@testset "Handle Fortran errors" begin
# Data from GitHub issue #17
x = [0.4, 0.3, 0.5, 0.2406, 0.2964, 0.5498, 0.2332, 0.3, 0.5041, 0.0824, 0.0594, 0.0126, 0.4385, 0.3575, 0.7737, 0.1, 0.1997, 0.6806, 0.8219, 0.0098, 0.4568, 0.0136]
y = [0.3856, 0.5588, 0.0, 0.0725, 0.0433, 0.0025, 0.0771, 0.2124, 0.0, 0.2251, 0.7363, 0.3885, 0.0038, 0.0207, 0.0816, 0.2124, 0.1002, 0.0338, 0.3856, 0.4017, 0.0019, 0.616]

@test_logs (:info, "Fortran error 4. Increasing madj to 24") voronoiarea(x, y)
end

0 comments on commit da33aaf

Please sign in to comment.