function labels = labels_extract ( filename )

%*****************************************************************************80
%
%% labels_extract() extracts the labels from a table in a file.
%
%  Discussion:
%
%    A file contains a number of lines of text.
%    Each line is assumed to be a list of one or more integers.
%    Each integer is a label.
%    The first integer line I is the I-th label.
%    Subsequent integers on that line are labels associated with other lines.
%
%    This function extracts the first label on each line, creating a
%    list vector LABELS.
%
%    The label associated with a line should be unique, but this is
%    not checked.
%
%    No line should be blank, but this is not checked.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    01 March 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    string FILENAME, the name of the input file.
%
%  Output:
%
%    integer LABELS(*), the list of labels.
%
  input = fopen ( filename );

  if ( input < 0 ) 
    fprintf ( 1, '\n' );
    fprintf ( 1, 'labels_extract - Error!\n' );
    fprintf ( 1, '  Could not open the file "%s".\n', filename );
    error ( 'labels_extract - Error!' );
  end

  i = 0;
  labels = [];

  while ( true )

    line = fgets ( input );

    if ( line == -1 )
      break;
    end

    [ x, count ] = sscanf ( line, '%d' );

    if ( 0 < count )
      i = i + 1;
      labels(i) = x(1);
    end

  end

  fclose ( input );

  return
end
