% -----------------------------------------------------------------------------
% DetectHexError.m
% -----------------------------------------------------------------------------
%
%  This script determines whether there were any runtime errors during 
%  a spatial hexapod simulation or not.
%
% -----------------------------------------------------------------------------
%
%  function errorno = DetectHexError( output );
%
% -----------------------------------------------------------------------------
%  Input Arguments:
%    
%    output : Captured output from the spatial hexapod run(see RunSimSect.m)
%
% -----------------------------------------------------------------------------
%  Outputs :
%
%    errno  : Error number indicating the source of the problem
%
%      0 : No error
%      1 : Startup with both legs on the ground
%      2 : Body toppled over
%      3 : Leg overextension during stance
%      4 : Toe underground during flight
%      5 : No solution to the energy equation for bottom
%      6 : Leg fails to reach full extension
%
% -----------------------------------------------------------------------------
% $Id: DetectHexError.m,v 1.1.1.1 2003/10/28 20:05:59 ulucs Exp $
% -----------------------------------------------------------------------------

function errorno = DetectHexError( output );

errorstrings = {
    'no error.',
    'Body orientation unstable',
    'Body underground',
    'Toe underground',
    'Error: Toe underground during flight',
    'Error: Double stance!' };

for ind = 2:length(errorstrings),
  if ( ~isempty(findstr(output, char( errorstrings( ind ) ) ) ) )
    errorno = ind - 2;
    return;
  end
end

errorno = 0;
    