87 lines
2.2 KiB
Matlab
87 lines
2.2 KiB
Matlab
function[obj] = load_data_from_text(obj )
|
|
%% load data from the .asc file
|
|
datafile = obj.datafile;
|
|
samples=[];
|
|
events ={};
|
|
load_processed_data = 0;
|
|
|
|
[base file ext] = fileparts(datafile);
|
|
target_dir = [base filesep file '.matlab'];
|
|
|
|
if (exist(target_dir, 'dir') == 0)
|
|
mkdir(target_dir);
|
|
end
|
|
|
|
cd(target_dir);
|
|
|
|
obj.display_and_log(['\tParsing file : ' file], 1);
|
|
obj.display_and_log(['\tDate : ' datestr(now)], 0);
|
|
|
|
target_raw = [target_dir filesep file '_raw.mat'];
|
|
target_processed = [target_dir filesep file '_processed.mat'];
|
|
|
|
if exist([target_dir filesep file '_processed.mat'], 'file');
|
|
display(sprintf('*) Loading data from file : %s', target_processed));
|
|
file_contents = load(target_processed);
|
|
data = file_contents.data;
|
|
load_processed_data = 1;
|
|
|
|
obj.events_ = data.events;
|
|
obj.samples = data.samples;
|
|
|
|
elseif exist([target_dir filesep file '_raw.mat'], 'file');
|
|
display(sprintf('*) Loading data from file : %s', target_raw));
|
|
file_contents= load(target_raw);
|
|
data = file_contents.data;
|
|
|
|
obj.events_ = data.events;
|
|
obj.samples = data.samples;
|
|
|
|
else
|
|
lc=0;
|
|
fp = fopen(datafile,'r');
|
|
i=1; j=1; m=1;
|
|
data_flag = 0;
|
|
[status lines_txt] = system(['wc ' regexprep(datafile,' ', '\\ ') '|awk ''{print $1''}']);
|
|
lines = str2num(lines_txt);
|
|
progressbar = waitbar(0, 'Reading data file...');
|
|
samples = nan(lines, 4);
|
|
while(~feof(fp))
|
|
|
|
if(mod(lc, 1000) ==0)
|
|
display(sprintf('working on line %5d', lc));
|
|
fprintf(repmat(sprintf('\b'),1,21));
|
|
|
|
waitbar(lc / lines, progressbar, sprintf('working on line %d', lc));
|
|
end
|
|
|
|
|
|
line=fgetl(fp);
|
|
|
|
if (data_flag & regexp(line, '^[0-9]*'))
|
|
samples(i,:) = sscanf(line, '%d %f %f %f');
|
|
i=i+1;
|
|
else
|
|
events{j} = line;
|
|
j=j+1;
|
|
end
|
|
|
|
if regexp(line,'^SAMPLES')
|
|
data_flag = 1;
|
|
end
|
|
lc=lc+1;
|
|
end
|
|
fclose(fp)
|
|
obj.samples = samples;
|
|
obj.events_ = events;
|
|
save(target_raw, 'obj');
|
|
|
|
close(progressbar);
|
|
end
|
|
|
|
|
|
%if ~load_processed_data
|
|
% [data] = preprocess_samples(data,settings);
|
|
%end
|
|
|