function [ LABELS, TIMES ] = readlabel(FILES)
%
% [ LABELS, TIMES ] = readlabel(FILES)
% 
% Read the NIST label files specified in FILES, and return TIMES and LABELS.
%
% FILES (string) - the name of the file to be read
% LABELS (1x3) - a cell array containing:
%      LABELS{1,1} - a vector of start times
%      LABELS{1,2} - a vector of end times
%      LABELS{1,3} - a cell array containing the label texts
%
% If FILES is a cell array containing multiple filenames, then LABELS
% will have one row per input filename.
%
% Mark Hasegawa-Johnson
% Last revised 2/18/2002

% If input is not cell array, make it a cell array, for easier bookkeeping
if ~iscell(FILES),
   FILES = { FILES };
end

% Read in label files
for ifile=1:length(FILES),
   % First, figure out whether or not the first column is numeric.
   % If not, assume that the file is 4-column (Switchboard); 
   % If so, assume that the file is 3-column (TIMIT)
   fid=fopen(FILES{ifile});
   test=fscanf(fid,'%c1.1');
   fclose(fid);
   if ~isempty(findstr(test,'0123456789')),
      FORMAT='%f %f %s';
   else
      FORMAT='%*s %f %f %s';
   end
      
   [ LABELS{ifile,1}, LABELS{ifile,2}, LABELS{ifile,3} ] = textread(FILES{ifile}, FORMAT);
   if nargout>1,
      TIMES{ifile} = [ LABELS{ifile,1} LABELS{ifile,2} ];
   end
   
end
