function [Xstruct, DeploymentName, Syslog] = deploycat( Deployment, vehicle, outmatfolder )

% Concatenate data from all logs in the deployment
% Last modified Aug 24, 2015
% Ben Raanan

[logNames, DeploymentName] = getDeploymentLogNames( Deployment, vehicle );
display(['Loading data from: ' DeploymentName])

% locate, fix and load dataset
%--------------------------------------------------------------------------
n = 1;
Xstruct.time     = [];
Xstruct.u        = [];
Xstruct.v        = [];
Xstruct.w        = [];
Xstruct.z        = [];
Xstruct.dz       = [];
Xstruct.phi      = [];
Xstruct.theta    = [];
Xstruct.psi	     = [];
Xstruct.q        = [];
Xstruct.p        = [];
Xstruct.r        = [];
Xstruct.elev     = [];
Xstruct.rudr     = [];
Xstruct.speedCmd = [];
Xstruct.depthCmd = [];
Xstruct.pitchCmd = [];
Xstruct.dropWeight = [];
Xstruct.buoyancyCmd  = [];
Xstruct.massAction = [];
Xstruct.buoyAction = [];
Xstruct.elevAction = [];
Xstruct.propOmegaAction = [];
Xstruct.massPosition = [];
Xstruct.buoyPosition = [];
Xstruct.verticalMode = [];
Xstruct.avgCurrent   = [];
Xstruct.propOmega    = [];
Xstruct.ThrusterWatt = [];
Xstruct.BuoyancyServo_wattage = [];
Xstruct.Temp = [];
Xstruct.Sal  = [];
Xstruct.rho  = [];
Xstruct.pressure  = [];
Xstruct.buoyancyNeutral	= [];
Xstruct.massDefault     = [];
Xstruct.massPositionLimitAft = [];
Xstruct.massPositionLimitFwd = [];

Xstruct.lon  = [];
Xstruct.lat  = [];

Syslog = cell(1);

% clear textprogressbar
% textprogressbar(['[loadAndFix_LRAUV]: Processing data from: ' DeploymentName '...'])
% update = unique(ceil((0:0.1:1)*numel(logNames)));
for k = 1:numel(logNames);
    
    % get mat file path(s)
    [matpath, ~] = findmat_LRAUV( vehicle, logNames{k} );
    
    % get parameters of intrest and fix time-series
    [ filename ] = processLargeMAT_LRAUV( vehicle, logNames{k}, outmatfolder, 'All' );
    
    if nargout>2
        % read-in syslog and get CRITICAL error msgs and time-stamps
        [ syslog ] = getsyslog( matpath );    % requires connection to LRAUV server
        Syslog = [Syslog; syslog];
    end
    
    % load reduced .mat file (workable format)
    [ time, time_step, xstruct, ~, controls, ] = initialize_LRAUV_SIM( filename{:} );
    
    efc = NaN;
    %{
    try
        [efc] = loadEFCfromVehicle(matpath,time);
    catch
        warning('[loadEFCfromVehicle]: Non-existent field: empericalClassifierFaultDetected.')
        efc = NaN;
    end
    %}
    
    idx = n:n+length(time)-1;
    Xstruct.time(idx)     = time;
    Xstruct.u(idx)        = xstruct.u;
    Xstruct.v(idx)        = xstruct.v;
    Xstruct.w(idx)        = xstruct.w;
    Xstruct.z(idx)        = xstruct.z;
    Xstruct.dz(idx)       = xstruct.z_rate;
    Xstruct.phi(idx)      = rad2deg(xstruct.phi);
    Xstruct.theta(idx)    = rad2deg(xstruct.theta);
    Xstruct.psi(idx)      = rad2deg(xstruct.psi);
    Xstruct.q(idx)        = rad2deg(xstruct.q);
    Xstruct.p(idx)        = rad2deg(xstruct.p);
    Xstruct.r(idx)        = rad2deg(xstruct.r);
    Xstruct.elev(idx)     = rad2deg(controls(:,1));
    Xstruct.rudr(idx)     = rad2deg(controls(:,2));
    Xstruct.massPosition(idx)   = xstruct.mass_p;
    Xstruct.buoyPosition (idx)  = xstruct.buoyancy_p;
    Xstruct.verticalMode(idx)   = xstruct.Cmd.verticalMode;
    Xstruct.speedCmd(idx)       = xstruct.Cmd.speedCmd;
    Xstruct.depthCmd(idx)       = xstruct.Cmd.depthCmd;
    Xstruct.buoyancyCmd(idx)    = xstruct.Cmd.buoyancyCmd;
    Xstruct.pitchCmd(idx)       = rad2deg(xstruct.Cmd.pitchCmd);
    Xstruct.dropWeight(idx)     = xstruct.Cmd.dropWeight;
    Xstruct.massAction(idx)     = xstruct.Cmd.massPositionAction;
    Xstruct.buoyAction(idx)     = xstruct.Cmd.buoyancyAction;
    Xstruct.elevAction(idx)     = rad2deg(xstruct.Cmd.elevatorAngleAction);
    Xstruct.propOmegaAction(idx) = xstruct.Cmd.propOmegaAction;
    Xstruct.avgCurrent(idx)     = xstruct.avgCurrent;
    Xstruct.propOmega(idx)      = xstruct.propOmega;
    Xstruct.ThrusterWatt(idx)   = xstruct.ThrusterServo_wattage;
    Xstruct.BuoyancyServo_wattage(idx)   = xstruct.BuoyancyServo_wattage;
    Xstruct.Altitude(idx)       = xstruct.Altitude;
    Xstruct.Temp(idx)           = xstruct.Temp;
    Xstruct.Sal(idx)            = xstruct.Sal;
    Xstruct.rho(idx)            = xstruct.rho;
    Xstruct.pressure(idx)       = xstruct.pressure;
    Xstruct.lon(idx)            = xstruct.lon;
    Xstruct.lat(idx)            = xstruct.lat;
    Xstruct.EFC(idx)            = efc;
    
    Xstruct.buoyancyNeutral = [Xstruct.buoyancyNeutral, xstruct.buoyancyNeutral];
    Xstruct.massDefault     = [Xstruct.massDefault, xstruct.massDefault];
    Xstruct.massPositionLimitAft = [Xstruct.massPositionLimitAft, xstruct.massPositionLimitAft];
    Xstruct.massPositionLimitFwd = [Xstruct.massPositionLimitFwd, xstruct.massPositionLimitFwd];
    
    Xstruct.time_step = time_step;
    n = n+length(time);
    
    
    
    % if k==any(update)
    %     textprogressbar(100*k/numel(logNames));
    % end
end

Syslog(1)=[];

end
