function T = setchild(T, indx, child, level)
% function T = setchild(T, indx, child)
%
% Dr. A. I. Hanna (2007)
if nargin<4
    level = indx;
end
if isempty(indx)
    T = setdata(T, getdata(child));

    
    return;
end
if length(T.children)<indx(1)
    T.children{indx(1)} = tree(); 
end
if length(indx)==1
    if isempty(getchildren(T.children{indx}))
        child.level = level;
        T.children{indx} = child;
        
    else
        T.children{indx} = setdata(T.children{indx}, getdata(child));
    end
    return;
end

T.children{indx(1)} = setchild(T.children{indx(1)}, indx(2:end), child, level);
return;