% compare_cmc_rra_acc.m
% Purpose:  Reads the set of motion files output by Darryl's executables
%           corresponding to subjectID and generates plots of the
%           RRA Residuals
%
% Input:    subjectID is the prefix ('string') of the following input files, 
%           generated from the preprocessing step and Darryl's executables:
%               subjectID.mot
%               subjectIDik.mot
%               subjectIDrea.mot
%               subjectIDcmc.mot
%
% Called Functions:  read_motionfile.m
%                    
% ASA, 3-05


% Set flag for printing (1 = print to printer; 0 = print to screen only)
close all
clear
clc

print_flag = 0;

% Set flag for pausing between figures (1 = pause, 0 = do not pause)
pause_flag = 0;



rra_acc = read_motionfile('quickhop_6_RRA_Kinematics_q.mot');
cmc_acc = read_motionfile('quickhop6_cmc_SLS_Kinematics_q.mot');
% Read files subjectIDcmc.mot
% fname = strcat(subjectID, '_cmc.mot');
% fname = strcat(subjectID, '_cmc_presw2pk.mot');

% Generate plots
set(0, 'Units', 'pixels');
scnsize = get(0, 'ScreenSize');
scnwidth = scnsize(3);
scnheight = scnsize(4);
figpos_whole = [0.1*scnwidth, 0.4*scnheight, 0.8*scnwidth, 0.5*scnheight];
    
figure()
    clf
    set(gcf, 'Position', figpos_whole, 'Color', 'w');
    set(gcf, 'PaperOrientation', 'landscape');
    set(gcf, 'PaperPosition', [1 1 9 6.5]);
    
    subplot(2,2,1)
%     p = plot(true_exc(:,1), true_exc(:,2));
%     set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
%     hold on
    cid_time = find(strcmpi(rra_acc.labels, 'time'));
    cid_1 = find(strcmpi(rra_acc.labels, 'hip_flexion_r'));
    p = plot(rra_acc.data(:,cid_time), rra_acc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    cid_time = find(strcmpi(cmc_acc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_acc.labels, 'hip_flexion_r'));
    p = plot(cmc_acc.data(:,cid_time), cmc_acc.data(:,cid_1));
    title_string = 'hip flexion r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('angular acceleration', 'FontSize', 9, 'VerticalAlignment', 'bottom');
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2,2,2)
%     p = plot(true_exc(:,1), true_exc(:,2));
%     set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
%     hold on
    cid_time = find(strcmpi(rra_acc.labels, 'time'));
    cid_1 = find(strcmpi(rra_acc.labels, 'knee_angle_r'));
    p = plot(rra_acc.data(:,cid_time), rra_acc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    cid_time = find(strcmpi(cmc_acc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_acc.labels, 'knee_angle_r'));
    p = plot(cmc_acc.data(:,cid_time), cmc_acc.data(:,cid_1));
    title_string = 'knee angle r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('angular acceleration', 'FontSize', 9, 'VerticalAlignment', 'bottom');
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    
    subplot(2,2,3)
%     p = plot(true_exc(:,1), true_exc(:,2));
%     set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
%     hold on
    cid_time = find(strcmpi(rra_acc.labels, 'time'));
    cid_1 = find(strcmpi(rra_acc.labels, 'ankle_angle_r'));
    p = plot(rra_acc.data(:,cid_time), rra_acc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    cid_time = find(strcmpi(cmc_acc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_acc.labels, 'ankle_angle_r'));
    p = plot(cmc_acc.data(:,cid_time), cmc_acc.data(:,cid_1));
    title_string = 'ankle angle r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('angular acceleration', 'FontSize', 9, 'VerticalAlignment', 'bottom');
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
        
    subplot(2,2,4)
%     p = plot(true_exc(:,1), true_exc(:,2));
%     set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
%     hold on
    cid_time = find(strcmpi(rra_acc.labels, 'time'));
    cid_1 = find(strcmpi(rra_acc.labels, 'lumbar_extension'));
    p = plot(rra_acc.data(:,cid_time), rra_acc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    cid_time = find(strcmpi(cmc_acc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_acc.labels, 'lumbar_extension'));
    p = plot(cmc_acc.data(:,cid_time), cmc_acc.data(:,cid_1));
    title_string = 'lumbar extension r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('angular acceleration', 'FontSize', 9, 'VerticalAlignment', 'bottom');
    set(gca, 'Box', 'off', 'FontSize', 8);
    ytickpositions = get(gca, 'Ytick');
    if length(ytickpositions) > 5
        new_ytickpositions = ytickpositions(1:2:length(ytickpositions));
        set(gca, 'Ytick', new_ytickpositions);
    end
    hlegend = legend('{\itRRA}', '{\itCMC}', 0);
    set(hlegend, 'Box', 'off', 'XColor', 'w', 'YColor', 'w');