function [ A ] = read_transaction_data( filename )
%
% READ_TRANSACTION_MATRIX  Read a transaction data file
%        
% [ A ] = read_transaction_data( filename );
%

% Copyright © Regents of the University of Minnesota. All rights reserved.

fid = fopen( filename );

% Read the transactions one line at a time
rows = zeros( 10000000, 1 );
cols = zeros( 10000000, 1 );
done = 0;
k = 0;
num_lines = 0;
while ~done
    current_line = fgetl( fid );
    if current_line == -1
        break;
    end;
    [ data count ] = sscanf( current_line, '%f' );
    if count == 0
        break;
    end;
    num_lines = num_lines + 1;
    if mod( num_lines, 200) == 0 
        disp( num_lines )
    end;
    for i = 1 : count 
        k = k + 1;
        rows( k ) = num_lines;
        cols( k ) = data( i );
    end;
end;
rows = rows( 1:k);
cols = cols(1:k);
num_cols = max( cols );
A = sparse( rows, cols, ones( k, 1), num_lines, num_cols );
fclose( fid );

