function s = i4_to_oct ( i4 )

%*****************************************************************************80
%
%% I4_TO_OCT converts an integer to a corresponding octal string.
%
%  Example:
%
%     I4      S
%    ---    ----
%      0     '0'
%      9    '11'
%     10    '12'
%     15    '17'
%     16    '20'
%    100   '144'
%    -12   '-14'
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 April 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I4, the integer to be represented.
%
%  Output:
%
%    string S, the octal representation.
%
  s = [ ];

  if ( i4 < 0 )
    isgn = - 1;
    i4 = - i4;
  elseif ( i4 == 0 )
    s = strcat ( '0', s );
    return
  else
    isgn = 1;
  end
%
%  Moving left, fill in the next digit of the string.
%
  while ( i4 ~= 0 )

    digit = mod ( i4, 8 );
    i4 = floor ( i4 / 8 );

    c = digit_oct_to_ch ( digit );

    s = strcat ( c, s );

  end

  if ( isgn == - 1 )
    s = strcat ( '-', s );
  end

  return
end
