%
% 12.03.2001, c
% function [out] = insertRecord( fields, varargin )
%
function [out] = insertRecord( fields, varargin )
global errmsg;

aux = [];
msg = nargchk( 1, 2, nargin );
if (~isempty( msg ))
  disp( msg );
  return
end

if (~iscell( fields ))
  disp( errmsg{1} );
  return
end

if ((nargin == 2) & (~isempty( varargin{1} )))
  if (~isstruct( varargin{1} ))
    disp( errmsg{2} );
    return
  else
    arg2 = fieldnames( varargin{1} );
    for field = fields(:)'
      if (sum( strcmp( field, arg2 ) ) ~= 1)
	disp( errmsg{2} );
	fields
	arg2
	return
      end
    end
  end
  out = varargin{1};
else
  out = [];
end

for field = fields(:)'
%  field
  fs = field{1};
  demand = ['  input field ''' fs ''': '];
  aux = setfield( aux, fs, input( demand ) );
end

if (isempty( out ))
  out = aux;
else
  out(length( out )+1) = aux;
end
