function nb_stim_plots(speeds,paths,methods,close_first,save_dir)

% Example Usage:

% make_plots({'walk125';'walk150'},{'JB011613'},{'low100'},1)


addpath '~/Dropbox/harvard/processMOT/';  

if close_first == 1
  close all;
end;

%colors = ['y';'b';'r';'k';'m';'g';'c'];

colors = [0 0 1;1 0 0;0 .5 .2; .5 0 1; 1 .6 0; 0 .5 1; .1 .6 0;1 .9 0; 1 0 1;.4 .4 .4];

%colors = [0 0 1; 1 0 0; .1 .6 0; .5 0 1; 0 0 0; 

cnt = 0;

for i = 1:size(speeds,1)
  for j = 1:size(paths,1)
    for k = 1:size(methods,1)
  
      cnt = cnt + 1;
      
      if ischar(speeds) == 0
        speed1  = char(speeds(i));
      else
        speed1  = speeds;
      end;
      if ischar(paths) == 0
        path1   = char(paths(j));
      else
        path1   = paths;
      end;
      if ischar(methods) == 0
        method1 = char(methods(k));
      else
        method1 = methods;
      end;
     
      infile1 = ['~/Documents/MATLAB/data/' path1 '/processed/EMG/avg_act_thresh'];
      infile1 = [infile1 '/' method1 '/' speed1 '.mat']; 

      cmd = ['load ' infile1];
      eval(cmd);
      
      numpts = length(m_sTA);

      figure(1)
      eval(['niceBars(0:(numpts-1),m_sTA,sd_sTA,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sTA,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('TA Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('TA Stimulation Estimate','fontsize',12);
      figure(2)
      eval(['niceBars(0:(numpts-1),m_sSOL,sd_sSOL,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sSOL,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('SOL Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('SOL Stimulation Estimate','fontsize',12);
      figure(3)
      eval(['niceBars(0:(numpts-1),m_sGAS,sd_sGAS,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sGAS,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('GAS Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('GAS Stimulation Estimate','fontsize',12);
      figure(4)
      eval(['niceBars(0:(numpts-1),m_sVAS,sd_sVAS,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sVAS,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('VAS Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('VAS Stimulation Estimate','fontsize',12);
      figure(5)
      eval(['niceBars(0:(numpts-1),m_sBFSH,sd_sBFSH,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sBFSH,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('BFSH Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('BFSH Stimulation Estimate','fontsize',12);
      figure(6)
      eval(['niceBars(0:(numpts-1),m_sRF,sd_sRF,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sRF,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']); 
      title('RF Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('RF Stimulation Estimate','fontsize',12);
      figure(7)
      eval(['niceBars(0:(numpts-1),m_sSMEM,sd_sSMEM,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sSMEM,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('SMEM Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('SMEM Stimulation Estimate','fontsize',12);
      figure(8)
      eval(['niceBars(0:(numpts-1),m_sBFLH,sd_sBFLH,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sBFLH,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('BFLH Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('BFLH Stimulation Estimate','fontsize',12);
      figure(9)
      eval(['niceBars(0:(numpts-1),m_sILL,sd_sILL,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sILL,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('ILL Stimulation Profile','fontsize',12);
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('ILL Stimulation Estimate','fontsize',12);
      figure(10)
      eval(['niceBars(0:(numpts-1),m_sGLU,sd_sGLU,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
      hold on; grid on;
      eval(['plot(0:(numpts-1),m_sGLU,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
      title('GLU Stimulation Profile','fontsize',12);                
      xlabel('Percent Gait Cycle','fontsize',12);
      ylabel('GLU Stimulation Estimate','fontsize',12);
      if exist('m_sGLUU') > 0
        figure(11)
        eval(['niceBars(0:(numpts-1),m_sGLUU,sd_sGLUU,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
        hold on; grid on;
        eval(['plot(0:(numpts-1),m_sGLUU,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
        title('GLU Upp. Stimulation Profile','fontsize',12);                
        xlabel('Percent Gait Cycle','fontsize',12);
        ylabel('GLU Upp. Stimulation Estimate','fontsize',12);
      end;
      if exist('m_sGMED') > 0
        figure(12)
        eval(['niceBars(0:(numpts-1),m_sGMED,sd_sGMED,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
        hold on; grid on;
        eval(['plot(0:(numpts-1),m_sGMED,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
        title('GMED Stimulation Profile','fontsize',12);                
        xlabel('Percent Gait Cycle','fontsize',12);
        ylabel('GMED Stimulation Estimate','fontsize',12);
      end;
      if exist('m_sADDL') > 0
        figure(13)
        eval(['niceBars(0:(numpts-1),m_sADDL,sd_sADDL,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
        hold on; grid on;
        eval(['plot(0:(numpts-1),m_sADDL,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
        title('ADDL Stimulation Profile','fontsize',12);                
        xlabel('Percent Gait Cycle','fontsize',12);
        ylabel('ADDL Stimulation Estimate','fontsize',12);
      end;
      if exist('m_sADDM') > 0
        figure(14)
        eval(['niceBars(0:(numpts-1),m_sADDM,sd_sADDM,[' num2str(colors(mod(cnt,10)+1,:)) '],0.5);']);
        hold on; grid on;
        eval(['plot(0:(numpts-1),m_sADDM,''color'',[' num2str(colors(mod(cnt,10)+1,:)) '],''linewidth'',4);']);
        title('ADDM Stimulation Profile','fontsize',12);                
        xlabel('Percent Gait Cycle','fontsize',12);
        ylabel('ADDM Stimulation Estimate','fontsize',12);
      end;
    end;   
  end;    
end;

load ~/Documents/MATLAB/data/Perry_muscles/stim_act;
figure(1)
plot(0:(numpts-1),p_sTA,'k','linewidth',3);
figure(2)
plot(0:(numpts-1),p_sSOL,'k','linewidth',3);
figure(3)
plot(0:(numpts-1),p_sGAS,'k','linewidth',3);
figure(4)
plot(0:(numpts-1),p_sVLAT,'k','linewidth',3);
figure(5)
plot(0:(numpts-1),p_sBFSH,'k','linewidth',3);
figure(6)
plot(0:(numpts-1),p_sRF,'k','linewidth',3);
figure(7)
plot(0:(numpts-1),p_sSMEM,'k','linewidth',3);
figure(8)
plot(0:(numpts-1),p_sBFLH,'k','linewidth',3);
figure(9)
plot(0:(numpts-1),p_sILL,'k','linewidth',3);
figure(10)
plot(0:(numpts-1),p_sGLU_low,'k','linewidth',3);
figure(11)
plot(0:(numpts-1),p_sGLU_upp,'k','linewidth',3);
figure(12)
plot(0:(numpts-1),p_sGMED,'k','linewidth',3);
figure(13)
plot(0:(numpts-1),p_sAL,'k','linewidth',3);
figure(14)
plot(0:(numpts-1),p_sAM,'k','linewidth',3);

if exist('save_dir');
  figure(1);
  eval(['print -dpng ' save_dir '/nb_stimTA.png;']);
  figure(2);
  eval(['print -dpng ' save_dir '/nb_stimSOL.png;']);
  figure(3);
  eval(['print -dpng ' save_dir '/nb_stimGAS.png;']);
  figure(4);
  eval(['print -dpng ' save_dir '/nb_stimVAS.png;']);
  figure(5);
  eval(['print -dpng ' save_dir '/nb_stimBFSH.png;']);
  figure(6);
  eval(['print -dpng ' save_dir '/nb_stimRF.png;']);
  figure(7);
  eval(['print -dpng ' save_dir '/nb_stimSMEM.png;']);
  figure(8);
  eval(['print -dpng ' save_dir '/nb_stimBFLH.png;']);
  figure(9);
  eval(['print -dpng ' save_dir '/nb_stimILL.png;']);
  figure(10);
  eval(['print -dpng ' save_dir '/nb_stimGLU.png;']);
  if exist('m_sGLUU') > 0
    figure(11);
    eval(['print -dpng ' save_dir '/nb_stimGLUU.png;']);
  end;
  if exist('m_sGMED') > 0
    figure(12);
    eval(['print -dpng ' save_dir '/nb_stimGMED.png;']);
  end;
  if exist('m_sADDL') > 0
    figure(13);
    eval(['print -dpng ' save_dir '/nb_stimADDL.png;']);
  end;
  if exist('m_sADDM') > 0
    figure(14);
    eval(['print -dpng ' save_dir '/nb_stimADDM.png;']);
  end;  
end;
