function mlfwrite(FILE, LABELS)
%
% mlfwrite(FILE, LABELS)
% 
% Write LABELS to the HTK master label file FILE
%
% FILE (string) - the name of the file to be written
% LABELS (N) - a struct array containing
%      LABELS(n).t - an (NSEGx2) matrix of start and end times
%      LABELS(n).l - an (NSEGxDEPTH) cell array of labels
%      LABELS(n).f - string: name of the nth .lab file
%
% Mark Hasegawa-Johnson
% Last revised 12/7/2003

fid=fopen(FILE,'w');
fprintf(fid,'#!MLF!#\n');

for nfiles=1:length(LABELS),
    % Print filename
    fprintf(fid,'%s\n',LABELS(nfiles).f);
     
    % Print segments
    for nseg=1:size(LABELS(nfiles).t,1),
	fprintf(fid,'%d  ', round(1e7*LABELS(nfiles).t(nseg,:)));
        fprintf(fid,'%s  ',LABELS(nfiles).l{nseg,:});
	fprintf(fid,'\n');
    end

    % Print file-ending dot
    fprintf(fid,'.\n');
end

fclose(fid);



			 