function S = alt2str(ALT,FORMAT,TO)
% alt2str  [Not a public function] Convert vector to compact list.
%
% Backend IRIS function.
% No help provided.

% -IRIS Toolbox. 2008/10/20.
% -Copyright 2007-2012 Jaromir Benes.

try
    FORMAT = strtrim(FORMAT);
catch %#ok<CTCH>
    FORMAT = '#%g';
end

try
    TO = strtrim(TO);
catch %#ok<CTCH>
    TO = '-';
end

%**************************************************************************

S = '';
if islogical(ALT)
    ALT = find(ALT);
end
ALT = ALT(:).';
if isempty(ALT)
    return
end

n = length(ALT);
c = cell(1,n);
for i = 1 : n
    c{i} = sprintf([' ',FORMAT],ALT(i));
end

d = diff(ALT) == 1;
d1 = [false,d];
d2 = [d,false];
index = d1 & d2;
c(index) = {'-'};
S = [c{:}];
S = regexprep(S,'-+ ',TO);

end