-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathParse_Load_Buffers.m
157 lines (150 loc) · 5.04 KB
/
Parse_Load_Buffers.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
function Parse_Load_Buffers(parseon,useGUI)
%
% This function loads stimuli into buffer.
%
% USAGE
% Parse_Load_Buffers(parseon)
%
% Input
% parseon 0 or 1.
%
% parseon=1 loads default settings. This is called in
% exp.initialize and should be called at the beginning of each
% experiment.
%
% parseon=0 loads buffers specified in StimParams. This function
% should be called after a new stimulus was written so that the
% bmp or buf files are loaded into memory.
% The relevant fields in StimParams are stimpath, fprefix,
% sframe, eframe and fext. The function will load all files in
% the stimpath with the prefix, frame numbers and fext according
% to the values passed in each field. sframe = start frame
% (e.g. 2), eframe = end frame (e.g. 4). The function would the
% load files with the correct prefix (e.g. frame) and ext (i.e.
% bmp or buf) between 2 and 4, inclusive.
%
% useGUI 0 or 1
%
% 0 preserves calls to gui handles, 1 allows use of
% Parse_Load_Buffers without aom gui. can leave blank for default
% usage
%
% OUTPUT
% Nothing. The stimulus files are loaded into memory.
%
% 4/23/22 jtp added gui flag to bypass aom gui handles, allows use
% without aom control gui
%
if nargin < 2
useGUI = 1;
end
global SYSPARAMS StimParams OrigFrame;
if (exist('handles','var') == 0) && useGUI
handles = get_aom_gui_handle();
end
if parseon == 1
dirname = StimParams.stimpath;
d=dir(dirname);
imfnamesbmp={};
imfnamesbuf={};
mapfname={};
indexbmp = 1;
indexbuf = 1;
seqfname = [];
fext = [];
for j = 1:size(d,1)
fname = d(j).name;
if size(fname,2) > 5
fext = fname(size(fname,2)-2:end);
if (strcmp(fext,'bmp') || strcmp(fext,'BMP'))
imfnamesbmp(indexbmp) = cellstr(fname); %#ok<AGROW>
indexbmp = indexbmp+1;
elseif (strcmp(fext,'buf') || strcmp(fext,'BUF'))
imfnamesbuf(indexbuf) = cellstr(fname); %#ok<AGROW>
indexbuf = indexbuf+1;
elseif (strcmp(fext,'map') || strcmp(fext,'MAP'))
mapfname = fname;
elseif (strcmp(fext,'seq') || strcmp(fext,'SEQ'))
seqfname = fname;
elseif (strcmp(fext,'loc') || strcmp(fext,'LOC'))
locfname = fname;
else
end
end
end
if (indexbmp == 1 && indexbuf == 1)
if useGUI
set(handles.aom1_state, 'String',...
['Error loading image sequence: You must select a folder' ...
'that contains at least one bitmap file. Please try again.']);
end
return
end
fprefixes = {};
findices = [];
h = waitbar(0,'Parsing stimuli...');
if indexbuf > 1
numfiles = size(imfnamesbuf,2);
fext = 'buf';
else
numfiles = size(imfnamesbmp,2);
fext = 'bmp';
end
for k = 1:numfiles
fprefix = [];
findex = [];
if indexbuf > 1
fname = char(imfnamesbuf{k});
else
fname = char(imfnamesbmp{k});
end
fnamesize = size(fname,2);
for i = 1:fnamesize
if isempty(str2num(fname(i))) == 1 || fname(i) == 'j' || fname(i) == 'i'
fprefix = [fprefix,fname(i)]; %#ok<AGROW>
elseif isempty(str2num(fname(i))) == 0
findex = [findex, fname(i)]; %#ok<AGROW>
end
end
fpresize = size(fprefix,2);
fprefix = fprefix(1:fpresize-4);
fprefixes(k) = {fprefix}; %#ok<AGROW>
findices(k) = str2num(findex); %#ok<AGROW>
waitbar(k/numfiles);
end
close(h);
if iscell(seqfname) == 0
else
StimParams.seqfname = char(seqfname);
end
fprefix = char(fprefixes(1));
aomindex = 1+size(findices,2);
if SYSPARAMS.realsystem == 1
if aomindex>1
command = ['Load#1#' dirname '#' fprefix '#' ...
num2str(min(findices)) '#' num2str(max(findices)) '#' ...
fext '#']; %#ok<NASGU>
netcomm('write',SYSPARAMS.netcommobj,int8(command));
end
end
pause((max(findices)-min(findices))*0.0005);
if useGUI
set(handles.aom1_state, 'String','Done Loading AOM Buffers');
end
StimParams.fprefix = fprefix;
StimParams.fprefixes = fprefixes;
StimParams.stimpath = dirname;
StimParams.findices = findices;
StimParams.fext = fext;
StimParams.mapfname = mapfname;
else
if SYSPARAMS.realsystem == 1
command = ['Load#1#' StimParams.stimpath '#' ...
StimParams.fprefix '#' num2str(StimParams.sframe) '#' ...
num2str(StimParams.eframe) '#' StimParams.fext '#']; %#ok<NASGU>
netcomm('write',SYSPARAMS.netcommobj,int8(command));
pause((StimParams.eframe - StimParams.sframe)*0.005);
end
OrigFrame = zeros(SYSPARAMS.rasterH, SYSPARAMS.rasterV,4);
OrigFrame(:,:,1) = 50;
end