function tscollout = vertcat(ts1,ts2)
%VERTCAT Overload vertical concatonation 

%   Author(s): James G. Owen
%   Copyright 1986-2002 The MathWorks, Inc. 
%   $Revision: 1.1.6.1 $ $Date: 2004/12/26 21:36:04 $


% Check that the members match
memberVars1=ts1.getMembers;
memberVars2=ts2.getMembers;
if length(memberVars1) ~= length(memberVars2)
    error('The tscollections have different numbers of member time series')
end
for k=1:length(memberVars1)
    if ~any(strcmp(memberVars1{k},memberVars2))
        error([memberVars1{k} ' member of 1st tscollection is not a member of ' ...
            memberVars2{k}])
    end
end
        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOTE The following code is in common with @timeseries/horzcat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Merge time vectors onto a common basis
[ts1timevec, ts2timevec,outprops] = ...
    timemerge(ts1.timeInfo, ts2.timeInfo,ts1.time,ts2.time);

% Concatonate time and ord data
if ts1timevec(end)>=ts2timevec(1)
    error('Time intervals are overlapping')
end
time = [ts1timevec;ts2timevec];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOTE end of the code in common with @timeseries/horzcat
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Build output tscollection
tscollout = tsdata.tscollection;
initialize(tscollout,time);
set(tscollout.timeInfo,'Startdate',outprops.ref,'Units',outprops.outunits,'Format',outprops.outformat);

% Add concatonated timeseries one at a time
% tscollout.Members = ts1.getMembers;
for k=1:length(memberVars1)
    % TO DO: Handle ArrayAdaptors
    % Concatonate ordinate data
    timeseries1 = get(ts1,memberVars1{k});
    timeseries2 = get(ts2,memberVars2{k});
    try
       ts = vertcat(timeseries1,timeseries2);
    catch
        errstr = ['Cannot concatonate ordindate data from ', memberVars1{k}];
        error(errstr);
    end
    
    % Use the @tscollection data storage for the new time vector
    % update this ts object
    % set(ts,'Time',tscollout.Time,'TimeInfo',tscollout.TimeInfo.copy);
    tmp=ts.getContainer('Time');
    tmp=tscollout.getTimeContainer;
    ts.timeinfo=tscollout.timeinfo;

    % Add new property
    p = schema.prop(tscollout,memberVars1{k},'handle');
    set(tscollout,memberVars1{k},ts);
end
    













