Skip to content

Commit

Permalink
Debugging regiongrid functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Jul 26, 2022
1 parent d29f613 commit 0c73ae8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoRegions"
uuid = "b001f823-fa75-4bff-bf55-6610c8f3688a"
authors = ["natgeo-wong <[email protected]>"]
version = "3.0.0"
version = "3.0.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
27 changes: 17 additions & 10 deletions src/Extract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,32 @@ function regiongrid(gridbounds::Vector{<:Real},rlon::Vector{<:Real},rlat::Vector

N,S,E,W = gridbounds; isgridinregion(gridbounds,rlon,rlat)

if rlon[2] > rlon[1]; EgW = true; else; EgW = false end
if rlat[2] > rlat[1]; NgS = true; else; NgS = false end

E = mod(E,360); W = mod(W,360); nlon = mod.(rlon,360);
iN = argmin(abs.(rlat.-N)); iS = argmin(abs.(rlat.-S)); iW = argmin(abs.(nlon.-W));
if E == W;
if gridbounds[3] != gridbounds[4]
if iW != 1; iE = iW - 1; else; iE = length(nlon); end
else; iE = iW
if iW != 1; iE = iW - 1; else; iE = length(nlon); end
else
if EgW
if iW > 1; iE = iW - 1; else; iE = length(rlon) end
else
if iW < length(rlon); iE = iW + 1; else; iE = 1 end
end
end
else; iE = argmin(abs.(nlon.-E));
end

if rlon[2] > rlon[1]; EgW = true; else; EgW = false end
if rlat[2] > rlat[1]; NgS = true; else; NgS = false end

while mod(rlon[iW],360) < mod(W,360)
if EgW; iW += 1; else; iW -= 1 end
end
if !(E==W) || (gridbounds[3] == gridbounds[4])
while mod(rlon[iW],360) < mod(W,360)
if EgW; iW += 1; else; iW -= 1 end
end

while mod(rlon[iE],360) > mod(E,360)
if EgW; iE -= 1; else; iE += 1 end
while mod(rlon[iE],360) > mod(E,360)
if EgW; iE -= 1; else; iE += 1 end
end
end

while rlat[iS] < S
Expand Down

0 comments on commit 0c73ae8

Please sign in to comment.