%{
    @author: Fujun Luan
    @email : fl356@cornell.edu
%}

function ha = SaveYarn(fn, yarn) 
    fid = fopen(fn, 'w');
    fprintf(fid, '0\n\n');
    
    N = length(yarn);
    
    for i = 1 : N
       vertex = yarn(i, :);
       if new_fiber(vertex) 
          fprintf(fid, '\n');
       else 
          fprintf(fid, '%f %f %f\n', vertex);
       end
    end
    
    fclose(fid);
end

function out = new_fiber(vertex)
    new_fiber_flag = [Inf Inf Inf];
    out = sum(vertex == new_fiber_flag);
end