function X = ReadMetal(filename, format)

% X = ReadMetal(filename, format)
%
% Reads metal detector data from filename.
% format = 'txt', plain text file, no header. - DEFAULT if format not specified.
%
% returns X = -100 if failure

% Liam Pedersen, May 1999, CMU.
% version 1.0
  
% Liam Pedersen, September 1999, CMU.
% version 1.1 - port to LINUX

Err = 0;

% get path
i = find(filename == '/');
if (isempty(i))
   i = 0;
   mpath = './';			% default case
else
   i = max(i);
   mpath = filename(1:i);
end

% get extension
j = find(filename == '.');
if (isempty(j))
   ext = 'txt';			% default case
   j = length(filename)+1;
else
   ext = filename(j+1:length(filename));
end

% get root file name
fn = filename(i+1:j-1);

% check input arguments
if (nargin == 1)
   format = ext;
end

% case 'TXT'
if (strcmp(format,'txt') | strcmp(format,'TXT'))
   ld = ['load ' filename '; X = ' fn ';'];  
   fail = 'Err = 1;';
   eval(ld,fail);
end

if (Err)
  X = -100;
end


