%
% @file zmumps_mat.m
%
% @brief
%
% @copyright
% Copyright (©) 2021 EPFL (Ecole Polytechnique Fédérale de Lausanne)
% SPC (Swiss Plasma Center)
%
% SPClibs is free software: you can redistribute it and/or modify it under
% the terms of the GNU Lesser General Public License as published by the Free
% Software Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% SPClibs is distributed in the hope that it will be useful, but WITHOUT ANY
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License
% along with this program. If not, see .
%
% @author
% (in alphabetical order)
% @author Trach-Minh Tran
%
function [mata, diag] = zmumps_mat(file, dset)
n=hdf5read(file,dset, 'RANK');
Nnz=hdf5read(file,dset, 'NNZ');
cols=hdf5read(file, strcat(dset,'/cols'));
irow=hdf5read(file, strcat(dset,'/irow'));
irn=hdf5read(file, strcat(dset,'/mumps_par/IRN'));
val=h5Complex_ll(file, strcat(dset,'/val'));
idiag=int32(find((irn-cols)==0));
for i=1:n
s = irow(i);
e = irow(i+1)-1;
rows(s:e) = i;
end
cols=double(cols);
rows=double(rows);
mata = sparse(rows,cols,val);
if nargout == 2
diag = val(idiag);
end