function grava_matriz(pasta,nome,S)
m = size(S,1);
n = size(S,2);
arq = fopen(sprintf('%s/%s.txt',pasta,nome),'wt');
assert(arq > 0);
for i =1:m
    for j = 1:n
        Sij = S(i,j);
        Sij = full(Sij);
        if Sij ~= 0
            fprintf(arq,'%6d %6d %22.14e\n',i,j,Sij);
        end
    end
end
fclose(arq);