function writeTGF(A, filename)

filename_out = sprintf(filename);

[ind_i,ind_j,val] = find(A);

nnz_ = length(ind_i);
[m,n]=  size(A);

out = fopen(filename_out,'w');

for i=1:m
    fprintf(out,'%d %d\n',i,i);
end

fprintf(out,'#\n');

for k=1:nnz_
    fprintf(out,'%d %d %f\n',ind_i(k),ind_j(k), val(k));
end

fclose(out);

end