diff --git a/loadh5.m b/loadh5.m index add67ce..0e6e54c 100644 --- a/loadh5.m +++ b/loadh5.m @@ -61,6 +61,16 @@ path=varargin{1}; end +opt.dotranspose=jsonopt('Transpose',1,opt); + +if(exist('OCTAVE_VERSION', 'builtin') ~= 0) + [varargout{1:nargout}]=load(filename, '-hdf5'); + if(opt.dotranspose) + varargout{1}=transposemat(varargout{1}); + end + return; +end + if(isa(filename,'H5ML.id')) loc=filename; else @@ -77,13 +87,6 @@ opt.complexformat={'Real','Imag'}; end -opt.dotranspose=jsonopt('Transpose',1,opt); - -if(exist('OCTAVE_VERSION', 'builtin') ~= 0) - [varargout{1:nargout}]=load(filename, '-hdf5'); - return; -end - opt.releaseid=0; vers=ver('MATLAB'); if(~isempty(vers)) diff --git a/transposemat.m b/transposemat.m new file mode 100644 index 0000000..a81f440 --- /dev/null +++ b/transposemat.m @@ -0,0 +1,40 @@ +function data=transposemat(input) +% +% data=transposemat(input) +% +% Iterate over struct/cell and transpose 2D or higher-dimensional numerical +% array to match Octave loaded HDF5 array elements with loadh5 default setting +% +% author: Qianqian Fang (q.fang neu.edu) +% +% input: +% name: a matlab variable, can be a cell, struct, containers.Map, numeric array or strings +% +% output: +% newname: the restored original string +% +% example: +% a=struct('a', ones(2,3), 'b', 'a string', 'c', uint8(zeros(2,3,4))); +% b=transposemat(a) +% +% this file is part of EasyH5 Toolbox: https://github.com/NeuroJSON/easyh5 +% +% License: GPLv3 or 3-clause BSD license, see https://github.com/NeuroJSON/easyh5 for details +% + +if(isstruct(input)) + data=structfun(@transposemat, input, 'UniformOutput',false); +elseif(iscell(input)) + data=cellfun(@transposemat, input, 'UniformOutput', 'false'); +elseif(isa(input, 'containers.Map')) + allkeys=keys(input); + for i = 1:length(allkeys) + input(allkeys(i))=transposemat(allkeys(i)); + end +elseif(isnumeric(input) && (ndims(input)>2 || all(size(input)>1))) + data=sub_data=permute(input,ndims(input):-1:1); +elseif(ischar(input) && ndims(input)==2 && size(input,1)==1 && size(input,2)>1 && input(end)==' ') + data=input(1:end-1); +else + data=input; +end