function setMembers(h,oldname,newname)
%SETMEMBERS Change the name of the selected @timeseries objects
%
% SETMEMBERS(h,OLD,NEW) replaces the old name OLD with NEW in the
% tscollection object h. 

%   Author(s): James G. Owen, Rong Chen
%   Copyright 1986-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2004/12/26 21:35:57 $
%
if ~(isvarname(oldname) && isvarname(newname))
    error('two input arguments should be valid matlab variable names.')
end
memberVars = h.getMembers;
if any(strcmp(oldname,memberVars))
    tmp=get(h,oldname);
    delete(findprop(h,oldname));
    p = schema.prop(h,newname,'handle');
    set(h,newname,tmp);
    try
        delete(h.Listeners_.(oldname));
    catch
    end
    tmp.name=newname;
    h.Listeners_.(newname) = handle.listener(tmp, findprop(tmp,'Name'), 'PropertyPreSet', @(es,ed) tsNameChanged(h,es,ed));
else
    error(['The time series ' oldname ' doesn''t exist.'])
end

