%  dSpace_plot.m
%  This file loads and plots .mat files as generated by dSpace.
%  
%  s => seconds of waveform to plot (end time as begins at 0)
%
clc;
  
filename = input('\n\nEnter .mat file to load from current working directory\n\n','s');

load( [filename '.mat'] );

eval( ['File ='  filename ]);

[row numCaptures] = size(File.Y);

%Grouping
disp(' ')
disp(['There are ' num2str( numCaptures ) ' Captured Plots.' ]);
disp(' ')
disp('They are named ')
disp(' ')
b=0;
for num = 1:numCaptures
    C= strsplit(File.Y(num).Path,'/');
    if (isempty(C{1})==1)   Variables{num}=File.Y(num).Name; end
    if (isempty(C{1})~=1) Variables(num) = C(2); b=0; end
    disp( [ num2str(num) ' ---- ' Variables{num} ] )
end

for num = 1:numCaptures
    name = Variables{num}
%     name = input( ['\nName to be used in matlab for variable ' Variables{num} ' \n'], 's');%num2str(num)
    eval( [  name ' =  File.Y(num).Data;' ] )
end

name = 't'; 
% name= input( '\nName to be used in matlab for time variable\n', 's' );
eval( [ name '= File.X(2).Data; ' ] )   %eval( [ name '= File.X(1).Data; ' ] )  check the data file  

clear filename File name row num numCaptures C %Variables 
whos