% % @file cds_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 . % % @authors % (in alphabetical order) % @author Trach-Minh Tran % function [mata, diag] = cds_mat(file, dset) n=double(hdf5read(file,dset, 'RANK')); dists=double(hdf5read(file, strcat(dset,'/dists'))); val=hdf5read(file, strcat(dset,'/vals')); %% Shift the off-diagonals %% for k=1:length(dists) d=dists(k); if d < 0 val(1:n+d,k) = val(1-d:n,k); elseif d > 0 val(n:-1:d+1,k) = val(n-d:-1:1,k); end end mata = spdiags(val, dists, n,n); if nargout == 2 idiag = find(dists==0); diag = val(:,idiag); end