Code covered by the BSD License  

Highlights from
ARMASA

from ARMASA by Piet M T Broersen
Automatic program to estimate the power spectral density with only statistically significant details

ASAerr(varargin)
function string = ASAerr(varargin)
%ASAERR Error string from numbered file
%   STRING = ASAERR(FILE_NUMBER,SUBSTITUTE) returns the contents of a 
%   text file 'ASAid.txt', with id = FILE_NUMBER, in a character string 
%   with a convenient number of blanks in front of each line. A cell 
%   array or character array of strings SUBSTITUTE, is used to replace 
%   subsequently any occurences of the word 'ASAsubst' in the text file, 
%   with the string(s) of SUBSTTUTE.
%   
%   This function is typically used to generate an error message string 
%   for the Matlab ERROR function.
%   
%   See also: ERROR, ASAWARN.

[file_number,substitute]=ASAarg(varargin, ...
{'file_number';'substitute'     }, ...
{'isnumeric'  ;'iscellorcharstr'}, ...
{'file_number'                  }, ...
{'file_number';'substitute'     });

txt_file=['ASA' num2str(file_number) '.txt'];
if ~exist(txt_file,'file')
   error(['    ' txt_file ' does not exist on MATLAB''s search path.']);
end

fid=fopen(txt_file,'rt');
retr_line_new=fgets(fid);
retr_line=retr_line_new;
string=[];
while retr_line~=-1
   string=[string retr_line_new];
   retr_line=fgets(fid);
   retr_line_new=[32*ones(1,4) retr_line];
end
fclose(fid);

subst_index=findstr(string,'ASAsubst');
if ischar(substitute)
   substitute=cellstr(substitute);
end
if lt(length(substitute),length(subst_index))
   error('    Insufficient substitutable strings entered')
end
for i = 1:length(subst_index)
   string(subst_index(i):subst_index(i)+7)=[];
   string=[string(1:subst_index(i)-1) substitute{i} ...
      string(subst_index(i):end)];
   subst_index=subst_index-8+length(substitute{i});
end

%Program history
%======================================================================
%
% Version                Programmer(s)          E-mail address
% -------                -------------          --------------
% [2000 12 30 20 0 0]    W. Wunderink           wwunderink01@freeler.nl

Contact us at files@mathworks.com