diff --git a/src/pscoast.jl b/src/pscoast.jl index 3bb61c966..950679344 100644 --- a/src/pscoast.jl +++ b/src/pscoast.jl @@ -84,20 +84,20 @@ function _coast(cmd0::String, O::Bool, K::Bool, clip::String, d::Dict) gmt_proggy = (IamModern[1]) ? "coast " : "pscoast " first = !O - if ((val = find_in_dict(d, [:getR :getregion :get_region], false)[1]) !== nothing) + if ((val = hlp_desnany_str(d, [:getR :getregion :get_region], false)) !== "") t::String = string(gmt_proggy, " -E", val) - ((Vd = find_in_dict(d, [:Vd], false)[1]) !== nothing) && (Vd_::Int = Vd; Vd_ == 1 ? println(t) : Vd_ > 1 ? (return t) : nothing) + ((Vd = hlp_desnany_int(d, [:Vd])) !== -999) && (Vd == 1 ? println(t) : Vd > 1 ? (return t) : nothing) t = parse_V(d::Dict, t) return gmt(t).text[1]::String end cmd = add_opt(d, "", "M", [:M :dump]) - have_opt_M = (cmd != "") cmd = parse_E_coast(d, [:E, :DCW], cmd) # Process first to avoid warning about "guess" + have_opt_M = contains(cmd, " -M") twoORfour = have_opt_M && contains(cmd, "+z") && contains(cmd, '.') ? "4" : "2" # To use in gmt_main to decide CODE attrib if (cmd != "") # Check for a minimum of points that segments must have - if ((val = find_in_dict(d, [:minpts])[1]) !== nothing) POSTMAN[1]["minpts"] = string(val)::String - elseif (get(POSTMAN[1], "minpts", "") != "") delete!(POSTMAN[1], "minpts") + if ((val = hlp_desnany_str(d, [:minpts])) !== "") POSTMAN[1]["minpts"] = val + elseif (get(POSTMAN[1], "minpts", "") != "") delete!(POSTMAN[1], "minpts") end end @@ -214,22 +214,32 @@ end function parse_E_coast(d::Dict, symbs::Vector{Symbol}, cmd::String) (SHOW_KWARGS[1]) && return print_kwarg_opts(symbs, "NamedTuple | Tuple | Dict | String") if ((val = find_in_dict(d, symbs, false)[1]) !== nothing) - if (isa(val, StrSymb)) # Simple cases, ex E="PT,+gblue" or E=:PT + if (isa(val, StrSymb)) # Simple cases, ex E="PT,+gblue" or E=:PT t::String = string(" -E", val) startswith(t, " -EWD") && (t = " -E=" * t[4:end]) # Let E="WD" work (t == " -E") && (delete!(d, [:E, :DCW]); return cmd) # This lets use E="" like earthregions may do - (!contains(cmd, " -M") && is_in_dict(d, [:R :region :limits :region_llur :limits_llur :limits_diag :region_diag]) === nothing) && - (d[:R] = t[4:end]) # Must also see what to do for the other elseif branches - contains(cmd, " -M") && !contains(t, "+") && (t *= "+z")# If Dump always add country names as attribs - !contains(t, "+") && (t *= "+p0.5") # If only code(s), append pen + contains(cmd, " -M") && !contains(t, "+z") && (t *= "+z")# If Dump always add country names as attribs + !contains(t, "+") && (t *= "+p0.5") # If only code(s), append pen + @label jump_here # Jump here when E=(states="GB",) + if (length(t) >= 6 && t[4] == '+') # A country states request. Check that is valid. + ct = t[5:6] # The country code + ((ind = findfirst(ct .== ("AR", "AU", "BR", "CA", "CN", "GB", "IN", "NO", "RU", "US"))) === nothing) && + error("ERROR: country states are only available for AR, AU, BR, CA, CN, GB, IN, NO, RU, and US. You passed '$ct'") + D = gmt("pscoast -E+L") + M = !contains(cmd, " -M") ? " -M" : "" # Let -M not be set when E=+code and set it here + t = M * " -E" * join(stack(split.(D.text[findall(startswith.(D.text, ct))], '\t'))[1,:], ",") * "+z" # The shit is out comes as ["GB.ENG\tEngland", ...] + end cmd *= t + (!contains(cmd, " -M") && !contains(cmd, "+L") && !contains(cmd, "+l") && + is_in_dict(d, [:R :region :limits :region_llur :limits_llur :limits_diag :region_diag]) === nothing) && (d[:R] = t[4:end]) elseif (isa(val, NamedTuple) || isa(val, AbstractDict)) - cmd = add_opt(d, cmd, "E", [:DCW :E], (country="", name="", continent="=", pen=("+p", add_opt_pen), + cmd = add_opt(d, cmd, "E", [:DCW :E], (country="", name="", continent="=", states="+", pen=("+p", add_opt_pen), fill=("+g", add_opt_fill), file=("+f"), inside=("_+c"), outside=("_+C"), adjust_r=("+r", arg2str), adjust_R=("+R", arg2str), adjust_e=("+e", arg2str), headers=("_+z"))) + startswith(cmd, " -E+") && (t = cmd; cmd = ""; @goto jump_here) # Jum to where this case is processed. elseif (isa(val, Tuple)) cmd = parse_dcw(cmd, val) end - cmd *= " -Vq" # Suppress annoying warnings regarding filling syntax with +r + !contains(cmd, " -M") && (cmd *= " -Vq") # Suppress annoying warnings regarding filling syntax with +r delete!(d, symbs) end return cmd diff --git a/src/utils_types.jl b/src/utils_types.jl index b33016fc9..5e1dbec6c 100644 --- a/src/utils_types.jl +++ b/src/utils_types.jl @@ -2549,7 +2549,7 @@ end # --------------------------------------------------------------------------------------------------- function hlp_desnany_int(d, s, default::Int=-999)::Int - ((val = find_in_dict(d, s)[1]) === nothing) ? default : (isa(val, Bool) ? Int(val) : parse(Int, val)) + ((val = find_in_dict(d, s)[1]) === nothing) ? default : (isa(val, Real) ? round(Int, val) : parse(Int, val)) end # --------------------------------------------------------------------------------------------------- diff --git a/test/test_B-GMTs.jl b/test/test_B-GMTs.jl index 58a52c27c..14189d355 100644 --- a/test/test_B-GMTs.jl +++ b/test/test_B-GMTs.jl @@ -148,8 +148,10 @@ @test gmtselect([1 2], C="aa+d0", Vd=dbg2) == "gmtselect -Caa+d0" @test gmtselect([1 2], C=(pts=[1 2],dist=10), L=(line=[1 2;3 4], dist=10), Vd=dbg2) == "gmtselect -C+d10 -L+d10" cl = coast(dump=:true, res=:c, region=:global); - @test length(coast(M=true, DCW="WD+z")) > 0 cc = GMT.clipbyrect(cl, (-180,0,-90,90)); + @test length(coast(M=true, DCW="WD+z")) > 0 + @test startswith(coast(E="+GB", Vd=2), "pscoast -M -EGB.ENG,GB.NIR,GB.SCT,GB.WLS+z") + @test startswith(coast(E=(states="GB",), Vd=2), "pscoast -M -EGB.ENG,GB.NIR,GB.SCT,GB.WLS+z") println(" GMTSET") gmtset(MAP_FRAME_WIDTH=0.2) diff --git a/test/test_PSs.jl b/test/test_PSs.jl index 11da8c705..a4776bca2 100644 --- a/test/test_PSs.jl +++ b/test/test_PSs.jl @@ -72,7 +72,7 @@ r = coast(region=:g, proj="A300/30/14c", axis=:g, resolution=:crude, title="Hell r = coast(R=:g, N=((level=1,pen=(2,:green)), (level=3,pen=(4,:blue, "--"))), Vd=dbg2); @test startswith(r, "pscoast -Rg -JN180.0/" * split(GMT.DEF_FIG_SIZE, '/')[1] * " -Baf -BWSen -N1/2,green -N3/4,blue,--") r = coast(proj=:Mercator, DCW=((country="GB,IT,FR", fill=:blue, pen=(0.25,:red)), (country="ES,PT,GR", fill=:yellow)), Vd=dbg2); -@test startswith(r, "pscoast -EGB,IT,FR+gblue+p0.25,red -EES,PT,GR+gyellow -Vq") +@test startswith(r, "pscoast -EGB,IT,FR+gblue+p0.25,red -EES,PT,GR+gyellow") @test_throws ErrorException("In Overlay mode you cannot change a fig scale and NOT repeat the projection") coast!(region=(-20,60,-90,90), scale=0.03333, Vd=dbg2) r = coast(DCW=(:AT, "red"), Vd=dbg2) @test startswith(r, "pscoast -EAT+gred")