-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_data_file.m
executable file
·55 lines (45 loc) · 1.14 KB
/
setup_data_file.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%setup_data_file.m
% set up files, directories
start_path=pwd;
if ~exist('filename','var')
disp('Subject name not provided, using test as name');
filename = sprintf('test');
end
%note: fileparts and fullfile would be better, os-independent way to do
%this!
if ispc
if ~isdir('c:\data\bartc')
mkdir('c:\data\bartc')
end
cd C:\data\bartc
dat_dir=sprintf('%s\\%s',pwd,filename);
elseif ismac
if ~isdir('/data/bartc')
mkdir('/data/bartc')
end
cd /data/bartc
dat_dir=sprintf('%s/%s',pwd,filename);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
try
if ~exist(dat_dir,'dir')
mkdir(dat_dir)
end
catch q
Screen('closeall')
end
cd(filename)
% get file names
data_dir=dir(pwd);
dirnames={data_dir.name};
expr=sprintf('(\?<=%s.)\\d+',filename); %regexp to get number of run
runnames_cell=regexp(dirnames,expr,'match');
runnames_cell=runnames_cell(~cellfun(@isempty,runnames_cell)); %get rid of empties
runnames=cellfun(@str2double,runnames_cell);
if ~isempty(runnames)
lastrun=max(runnames);
else
lastrun=0;
end
fname_short=sprintf('%s.%d',filename,lastrun+1);
fname=sprintf('%s.bartc.mat',fname_short);