Code covered by the BSD License  

Highlights from
DFiltInt

image thumbnail
from DFiltInt by Peter Kabal
DFiltInt designs an interpolating filter given a signal power spectrum

StartDiaryFile (LogFile, RefFile)
function StopDiaryFile = StartDiaryFile (LogFile, RefFile)
% This routine is used for test scripts. All output from the test script
% is written to the log file. Using the companion routine CheckDiaryFile,
% the log file is compared with the reference file. This routine returns
% a pointer to CheckDiaryFile.
%
% 1. If the log file name is not empty, the Matlab diary is redirected to
%    the log file.
% 2. Save the current output format parameters.
% 3. Set the output format to 'short' and 'compact'.
%
% StartDiaryFile should be called at the beginning of the test script and
% StopDiaryFile should be called at the end of the test script.
%   StopDiaryFile = StartDiaryFile(LogFile, RefFile)
%   ...
%   StopDiaryFile();

% $Id: StartDiaryFile.m,v 1.4 2009/06/08 20:19:36 pkabal Exp $

if (~ isempty(LogFile))
  diary off;
  if (exist(LogFile, 'file'))
    delete(LogFile);  % If it exists, we don't want to append to it
  end
  diary(LogFile);
end

DFormat = get(0, 'Format');
DFormatSpacing = get(0, 'FormatSpacing');
format
format compact

StopDiaryFile = @CheckDiaryFile;

return

% ----- begin nested function

function CheckDiaryFile ()
% This function compares a log file with a reference file. It is the
% companion function to SetDiaryFile. The parameters are inherited
% from StartDiaryFile.
%
% 1. Close the diary file if it was invoked.
% 2. Reset the output formatting to the settings prior to calling
%    SetDiaryFile.
% 3a) If the log file name is empty, no further action is taken.
% 3b) If the log file name is the same as the reference file name, this
%     file is retained as the reference file.
% 3c) If the log file name is not empty and differs from the reference
%     file name, these files are compared using the system file comparison
%     tool. The log file is deleted.
% Note that when Matlab displays the contents of a matrix, the number of
% elements displayed per line depends on the width of the Matlab command
% window. The workaround is to print matrices using formatted I/O.

if (~isempty(LogFile))
  diary off;
end

set(0, 'Format', DFormat);
set(0, 'FormatSpacing', DFormatSpacing);

if (~isempty(LogFile))
  fprintf('\n***** ***** ***** *****\n');
  if (~strcmp(LogFile, RefFile))
    if (ispc)
      eval(['!FC ', LogFile, ' ', RefFile]);
    else
      eval(['!diff ', LogFile, ' ', RefFile]);
    end
    delete(LogFile);
  else
    fprintf('New reference file: %s\n', RefFile);
  end
end

return
end

% ----- end nested function
end

Contact us at files@mathworks.com