function do_conf( T_short, N_future )

% function do_conf( T_short, N_future )
%
% Implementation of confident short-term clustering,
% applied on all files "DATA/synth*.mat" (inputs),
% writing out other ".mat" files (outputs).
%
% This really is a wrapper for the "do_stc.m" function.
%
% -> location estimates are partitioned. 
% -> in the output files, two location estimates belong to
%    the same cluster iff they have the same tag.
%
% This code can be useful to demonstrate short-term clustering.
% See IDIAP RR 04-14 (2004) or Lathoud's PhD thesis (2006).
%
% By Guillaume Lathoud, 2006 - lathoud@idiap.ch


  if nargin < 2
    error( [ mfilename ' needs 2 input arguments.' ] );
  end
  
  a_dir = 'DATA';

  d = dir( fullfile( a_dir, 'synth*.mat' ) );

  d = d( find( ~[ d.isdir ] ) );
  d = d( find( [ d.bytes ] ) );

  n = numel( d );

  for a = 1:n
    
    infilename = fullfile( a_dir, d( a ).name );

    disp( ' ' );
    disp( sprintf( [ mfilename ': processing file %d/%d: "%s"...' ], a, n, infilename ) );
    
    % Load location estimates
    % "r" is a structure array with two fields:
    %   r( i ).theta is the azimuth in radians.
    %   r( i ).T     is the integer time frame index.

    load( infilename, 'r' );

    % A new field "tag" is added to the "r" structure

    disp( [ mfilename ': calling "do_stc"...' ] );
    
    r = do_stc( r, T_short, N_future, 'conf' );

    % Save the result

    outfilename = fullfile( a_dir, sprintf( [ mfilename '-Tshort_%d-Nfuture_%d-' d( a ).name ], T_short, N_future ) );
    save( outfilename, 'r' );
    disp( [ mfilename ' wrote out "' outfilename '".' ] );
    
  end
  