Merge pull request #1654 from ma-laforge/hdf5

Deal w/deprecation of Nullable.
This commit is contained in:
Michael Krabbe Borregaard 2018-08-14 22:57:17 +02:00 committed by GitHub
commit 07a6700ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,7 @@ end
#==Useful constants #==Useful constants
===============================================================================# ===============================================================================#
const _hdf5_nullable{T} = Union{T, Nothing}
const _hdf5_plotroot = "plot" const _hdf5_plotroot = "plot"
const _hdf5_dataroot = "data" #TODO: Eventually move data to different root (easier to locate)? const _hdf5_dataroot = "data" #TODO: Eventually move data to different root (easier to locate)?
const _hdf5plot_datatypeid = "TYPE" #Attribute identifying type const _hdf5plot_datatypeid = "TYPE" #Attribute identifying type
@ -129,7 +130,7 @@ if length(HDF5PLOT_MAP_TELEM2STR) < 1
"AXIS" => Axis, "AXIS" => Axis,
"SURFACE" => Surface, "SURFACE" => Surface,
"SUBPLOT" => Subplot, "SUBPLOT" => Subplot,
"NULLABLE" => Nullable, "NULLABLE" => _hdf5_nullable,
) )
merge!(HDF5PLOT_MAP_STR2TELEM, telem2str) merge!(HDF5PLOT_MAP_STR2TELEM, telem2str)
merge!(HDF5PLOT_MAP_TELEM2STR, Dict{Type, String}(v=>k for (k,v) in HDF5PLOT_MAP_STR2TELEM)) merge!(HDF5PLOT_MAP_TELEM2STR, Dict{Type, String}(v=>k for (k,v) in HDF5PLOT_MAP_STR2TELEM))
@ -344,9 +345,10 @@ function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T
vgrp = HDF5.g_create(grp, k) vgrp = HDF5.g_create(grp, k)
_hdf5plot_writetype(vgrp, Array) #ANY _hdf5plot_writetype(vgrp, Array) #ANY
sz = size(v) sz = size(v)
lidx = LinearIndices(sz)
for iter in eachindex(v) for iter in eachindex(v)
coord = LinearIndices(sz, iter) coord = lidx[iter]
elem = v[iter] elem = v[iter]
idxstr = join(coord, "_") idxstr = join(coord, "_")
_hdf5plot_gwrite(vgrp, "v$idxstr", v[iter]) _hdf5plot_gwrite(vgrp, "v$idxstr", v[iter])
@ -391,7 +393,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Surface)
_hdf5plot_writetype(grp, Surface) _hdf5plot_writetype(grp, Surface)
end end
# #TODO: "Properly" support Nullable using _hdf5plot_writetype? # #TODO: "Properly" support Nullable using _hdf5plot_writetype?
# function _hdf5plot_gwrite(grp, k::String, v::Nullable) # function _hdf5plot_gwrite(grp, k::String, v::_hdf5_nullable)
# if isnull(v) # if isnull(v)
# _hdf5plot_gwrite(grp, k, nothing) # _hdf5plot_gwrite(grp, k, nothing)
# else # else
@ -508,10 +510,11 @@ function _hdf5plot_read(grp, k::String, T::Type{Array}, dtid) #ANY
sz = _hdf5plot_read(grp, "dim") sz = _hdf5plot_read(grp, "dim")
if [0] == sz; return []; end if [0] == sz; return []; end
sz = tuple(sz...) sz = tuple(sz...)
result = Array{Any}(sz) result = Array{Any}(undef, sz)
lidx = LinearIndices(sz)
for iter in eachindex(result) for iter in eachindex(result)
coord = LinearIndices(sz, iter) coord = lidx[iter]
idxstr = join(coord, "_") idxstr = join(coord, "_")
result[iter] = _hdf5plot_read(grp, "v$idxstr") result[iter] = _hdf5plot_read(grp, "v$idxstr")
end end