% FUNCTION TIMECODE = SEC_TO_TIMECODE( T, [ FRAME_RATE = 25 ] )

function timecode = sec_to_timecode( t, frame_rate )

if nargin < 1
  error( 'sec_to_timecode needs at least one parameter.' );
end

if nargin < 2
  frame_rate = 25;
end

hour = fix( t/3600 ); t = rem(t, 3600);
timecode = sprintf('%02d', hour );
minute = fix( t/60 ); t = rem(t, 60);
timecode = [ timecode, sprintf(':%02d', minute) ];
second = fix( t ); t = rem(t,1);
timecode = [ timecode, sprintf(':%02d', second) ];
frame = fix( round( t * frame_rate * 1e6 ) * 1e-6 );
timecode = [ timecode, sprintf(':%02d', frame) ];
