Fixed writing of Matrices (follows Julia order)
This commit is contained in:
parent
47a988246d
commit
79a5bfc12f
@ -226,7 +226,7 @@ function arrays2datablock(args...)
|
|||||||
|
|
||||||
# All scalars
|
# All scalars
|
||||||
if minimum(dims) == 0
|
if minimum(dims) == 0
|
||||||
#@info "Case 0"
|
# @info "Case 0" # debug
|
||||||
@assert maximum(dims) == 0 "Input data are ambiguous: either use all scalar or arrays of floats"
|
@assert maximum(dims) == 0 "Input data are ambiguous: either use all scalar or arrays of floats"
|
||||||
v = ""
|
v = ""
|
||||||
for iarg in 1:length(args)
|
for iarg in 1:length(args)
|
||||||
@ -241,7 +241,7 @@ function arrays2datablock(args...)
|
|||||||
|
|
||||||
# All 1D
|
# All 1D
|
||||||
if firstMultiDim == 0
|
if firstMultiDim == 0
|
||||||
#@info "Case 1"
|
# @info "Case 1" # debug
|
||||||
@assert minimum(lengths) == maximum(lengths) "Array size are incompatible"
|
@assert minimum(lengths) == maximum(lengths) "Array size are incompatible"
|
||||||
for i in 1:lengths[1]
|
for i in 1:lengths[1]
|
||||||
v = ""
|
v = ""
|
||||||
@ -256,10 +256,10 @@ function arrays2datablock(args...)
|
|||||||
|
|
||||||
# Multidimensional, no independent 1D indices
|
# Multidimensional, no independent 1D indices
|
||||||
if firstMultiDim == 1
|
if firstMultiDim == 1
|
||||||
#@info "Case 2"
|
# @info "Case 2" # debug
|
||||||
@assert minimum(lengths) == maximum(lengths) "Array size are incompatible"
|
@assert minimum(lengths) == maximum(lengths) "Array size are incompatible"
|
||||||
i = 1
|
i = 1
|
||||||
for CIndex in CartesianIndices(size(args[1]))
|
for CIndex in CartesianIndices(size(args[1]'))
|
||||||
indices = Tuple(CIndex)
|
indices = Tuple(CIndex)
|
||||||
(i > 1) && (indices[end-1] == 1) && (push!(accum, "")) # blank line
|
(i > 1) && (indices[end-1] == 1) && (push!(accum, "")) # blank line
|
||||||
if length(args) == 1
|
if length(args) == 1
|
||||||
@ -270,7 +270,7 @@ function arrays2datablock(args...)
|
|||||||
v = ""
|
v = ""
|
||||||
end
|
end
|
||||||
for iarg in 1:length(args)
|
for iarg in 1:length(args)
|
||||||
d = args[iarg]
|
d = args[iarg]'
|
||||||
v *= " " * tostring(d[i])
|
v *= " " * tostring(d[i])
|
||||||
end
|
end
|
||||||
i += 1
|
i += 1
|
||||||
@ -285,7 +285,7 @@ function arrays2datablock(args...)
|
|||||||
@assert all(lengths[firstMultiDim:end] .== refLength) "Array size are incompatible"
|
@assert all(lengths[firstMultiDim:end] .== refLength) "Array size are incompatible"
|
||||||
|
|
||||||
if lengths[1] < refLength
|
if lengths[1] < refLength
|
||||||
#@info "Case 3"
|
# @info "Case 3" # debug
|
||||||
# Cartesian product of Independent variables
|
# Cartesian product of Independent variables
|
||||||
checkLength = prod(lengths[1:firstMultiDim-1])
|
checkLength = prod(lengths[1:firstMultiDim-1])
|
||||||
@assert prod(lengths[1:firstMultiDim-1]) == refLength "Array size are incompatible"
|
@assert prod(lengths[1:firstMultiDim-1]) == refLength "Array size are incompatible"
|
||||||
@ -308,7 +308,7 @@ function arrays2datablock(args...)
|
|||||||
end
|
end
|
||||||
return accum
|
return accum
|
||||||
else
|
else
|
||||||
#@info "Case 4"
|
# @info "Case 4" # debug
|
||||||
# All Independent variables have the same length as the main multidimensional data
|
# All Independent variables have the same length as the main multidimensional data
|
||||||
@assert all(lengths[1:firstMultiDim-1] .== refLength) "Array size are incompatible"
|
@assert all(lengths[1:firstMultiDim-1] .== refLength) "Array size are incompatible"
|
||||||
|
|
||||||
@ -592,15 +592,17 @@ function DatasetBin(VM::Vararg{AbstractMatrix{T}, N}) where {T <: Real, N}
|
|||||||
end
|
end
|
||||||
s = size(VM[1])
|
s = size(VM[1])
|
||||||
(path, io) = mktemp()
|
(path, io) = mktemp()
|
||||||
for j in 1:s[2]
|
|
||||||
for i in 1:s[1]
|
for i in 1:s[1]
|
||||||
|
for j in 1:s[2]
|
||||||
for k in 1:N
|
for k in 1:N
|
||||||
write(io, Float32(VM[k][i,j]))
|
write(io, Float32(VM[k][i,j]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
source = " '$path' binary array=(" * join(string.(reverse(s)), ", ") * ")"
|
||||||
|
# Note: can't add `using` here, otherwise we can't append `flipy`.
|
||||||
close(io)
|
close(io)
|
||||||
source = " '$path' binary array=(" * join(string.(s), ", ") * ")"
|
|
||||||
return DatasetBin(Val(:inner), path, source)
|
return DatasetBin(Val(:inner), path, source)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -686,14 +688,30 @@ function useBinaryMethod(args...)
|
|||||||
elseif options.preferred_format == :auto
|
elseif options.preferred_format == :auto
|
||||||
if (length(args) == 1) && isa(args[1], AbstractMatrix)
|
if (length(args) == 1) && isa(args[1], AbstractMatrix)
|
||||||
binary = true
|
binary = true
|
||||||
elseif length(args[1]) > 10^4
|
else
|
||||||
binary = true
|
s = sum(length.(args))
|
||||||
|
if s > 1e4
|
||||||
|
binary = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return binary
|
return binary
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
function Dataset(accum)
|
||||||
|
if useBinaryMethod(accum...)
|
||||||
|
try
|
||||||
|
return DatasetBin(accum...)
|
||||||
|
catch err
|
||||||
|
isa(err, MethodError) || rethrow()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return DatasetText(accum...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function add_cmd(gp::Session, v::String)
|
function add_cmd(gp::Session, v::String)
|
||||||
(v != "") && (push!(gp.plots[gp.curmid].cmds, v))
|
(v != "") && (push!(gp.plots[gp.curmid].cmds, v))
|
||||||
@ -1009,18 +1027,13 @@ function parseArguments(_args...)
|
|||||||
@assert mm[1] == mm[2] "At least one input array is empty, while other(s) are not"
|
@assert mm[1] == mm[2] "At least one input array is empty, while other(s) are not"
|
||||||
d = DatasetEmpty()
|
d = DatasetEmpty()
|
||||||
else
|
else
|
||||||
if useBinaryMethod(accum...)
|
d = Dataset(accum)
|
||||||
d = DatasetBin(accum...)
|
|
||||||
else
|
|
||||||
d = DatasetText(accum...)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
insert!(args, pos, d)
|
insert!(args, pos, d)
|
||||||
end
|
end
|
||||||
pos += 1
|
pos += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Fourth pass: collect PlotElement objects
|
# Fourth pass: collect PlotElement objects
|
||||||
mid = 0
|
mid = 0
|
||||||
name = ""
|
name = ""
|
||||||
|
|||||||
@ -17,29 +17,29 @@ recipe(h::Histogram2D) =
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Images
|
# Images
|
||||||
recipe(M::Matrix{ColorTypes.RGB{T}}; rot="-90deg", opt="") where T =
|
recipe(M::Matrix{ColorTypes.RGB{T}}; opt="flipy") where T =
|
||||||
PlotElement(cmds=["set autoscale fix", "set size square"],
|
PlotElement(cmds=["set autoscale fix", "set size ratio -1"],
|
||||||
data=DatasetBin(256 .* getfield.(M, :r),
|
data=DatasetBin(256 .* getfield.(M, :r),
|
||||||
256 .* getfield.(M, :g),
|
256 .* getfield.(M, :g),
|
||||||
256 .* getfield.(M, :b)),
|
256 .* getfield.(M, :b)),
|
||||||
plot="rotate=$rot $opt with rgbimage notit")
|
plot="$opt with rgbimage notit")
|
||||||
|
|
||||||
recipe(M::Matrix{ColorTypes.RGBA{T}}; rot="-90deg", opt="") where T =
|
recipe(M::Matrix{ColorTypes.RGBA{T}}; opt="flipy") where T =
|
||||||
PlotElement(cmds=["set autoscale fix", "set size square"],
|
PlotElement(cmds=["set autoscale fix", "set size ratio -1"],
|
||||||
data=DatasetBin(256 .* getfield.(M, :r),
|
data=DatasetBin(256 .* getfield.(M, :r),
|
||||||
256 .* getfield.(M, :g),
|
256 .* getfield.(M, :g),
|
||||||
256 .* getfield.(M, :b)),
|
256 .* getfield.(M, :b)),
|
||||||
plot="rotate=$rot $opt with rgbimage notit")
|
plot="$opt with rgbimage notit")
|
||||||
|
|
||||||
recipe(M::Matrix{ColorTypes.Gray{T}}; rot="-90deg", opt="") where T =
|
recipe(M::Matrix{ColorTypes.Gray{T}}; opt="flipy") where T =
|
||||||
PlotElement(cmds=["set autoscale fix", "set size square"],
|
PlotElement(cmds=["set autoscale fix", "set size ratio -1"],
|
||||||
data=DatasetBin(256 .* getfield.(M, :val)),
|
data=DatasetBin(256 .* getfield.(M, :val)),
|
||||||
plot="rotate=$rot $opt with image notit")
|
plot="$opt with image notit")
|
||||||
|
|
||||||
recipe(M::Matrix{ColorTypes.GrayA{T}}; rot="-90deg", opt="") where T =
|
recipe(M::Matrix{ColorTypes.GrayA{T}}; opt="flipy") where T =
|
||||||
PlotElement(cmds=["set autoscale fix", "set size square"],
|
PlotElement(cmds=["set autoscale fix", "set size ratio -1"],
|
||||||
data=DatasetBin(256 .* getfield.(M, :val)),
|
data=DatasetBin(256 .* getfield.(M, :val)),
|
||||||
plot="rotate=$rot $opt with image notit")
|
plot="$opt with image notit")
|
||||||
|
|
||||||
|
|
||||||
# ╭───────────────────────────────────────────────────────────────────╮
|
# ╭───────────────────────────────────────────────────────────────────╮
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user