% compare_exc.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;



cmc_exc = read_motionfile3('quickhop6_cmc_SLS_controls.sto');
true_exc = dlmread('quickhop 6EMG_filtered_short.csv',',',1,0);
% 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(3,3,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(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'tib_ant_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'tib ant r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,2)
    p = plot(true_exc(:,1), true_exc(:,3));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'soleus_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'soleus r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,3)
    p = plot(true_exc(:,1), true_exc(:,4));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'med_gas_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'med gas r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,4)
    p = plot(true_exc(:,1), true_exc(:,4));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'lat_gas_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'lat gas r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,5)
    p = plot(true_exc(:,1), true_exc(:,5));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'bifemlh_r.excitation'));
    cid_2 = find(strcmpi(cmc_exc.labels, 'bifemsh_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_2));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.8 0.3]);
    title_string = 'bicfem lh sh r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,6)
    p = plot(true_exc(:,1), true_exc(:,5));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'sar_r.excitation'));
    cid_2 = find(strcmpi(cmc_exc.labels, 'semimem_r.excitation'));
    cid_3 = find(strcmpi(cmc_exc.labels, 'semiten_r.excitation'));
    cid_4 = find(strcmpi(cmc_exc.labels, 'grac_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_2));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.8 0.3]);
    hold on
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_3));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.8 0.3]);
    hold on
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_4));
    set(p, 'LineWidth', 1, 'Color', [0.0 0.8 0.3]);
    hold on
    title_string = 'med ham r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,7)
    p = plot(true_exc(:,1), true_exc(:,5));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'vas_med_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'vas med r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,8)
    p = plot(true_exc(:,1), true_exc(:,5));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'vas_lat_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'vas lat r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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(3,3,9)
    p = plot(true_exc(:,1), true_exc(:,5));
    set(p, 'LineWidth', 2, 'Color', [0.0 0.0 0.8]);
    hold on
    cid_time = find(strcmpi(cmc_exc.labels, 'time'));
    cid_1 = find(strcmpi(cmc_exc.labels, 'rect_fem_r.excitation'));
    p = plot(cmc_exc.data(:,cid_time), cmc_exc.data(:,cid_1));
    set(p, 'LineWidth', 1, 'Color', [0.8 0.0 0.5]);
    hold on
    title_string = 'rect fem r';
    title(title_string, 'FontSize', 9, 'FontWeight', 'Bold');
    xlabel('time (s)', 'FontSize', 9, 'VerticalAlignment', 'top');
    ylabel('exc', '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  