Skip to content

Commit

Permalink
Update pop_writebva.m
Browse files Browse the repository at this point in the history
Warning for exporting data
  • Loading branch information
arnodelorme authored Jun 21, 2022
1 parent 0170428 commit 6a89aca
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions pop_writebva.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@
if nargin < 1
help pop_writebva;
return;
end;
end

if length(EEG) > 1
error('This function can only export one dataset at a time');
end

if nargin < 2
[filename, filepath] = uiputfile('*', 'Output file');
if length( filepath ) == 0 return; end;
filename = [ filepath filename ];
end;
end

% remove extension if any
% -----------------------
posdot = find(filename == '.');
if ~isempty(posdot), filename = filename(1:posdot(end)-1); end;
if ~isempty(posdot), filename = filename(1:posdot(end)-1); end

% open output file
% ----------------
Expand All @@ -56,7 +60,7 @@
% ----------
for index = 1:EEG.nbchan
fwrite(fid3, EEG.data(index,:), 'float' );
end;
end

% write header
% ------------
Expand All @@ -67,7 +71,7 @@
fprintf(fid1, 'DataFile=%s\n', [ basename '.dat' ]);
if ~isempty(EEG.event)
fprintf(fid1, 'MarkerFile=%s\n', [ basename '.vmrk' ]);
end;
end
fprintf(fid1, 'DataFormat=BINARY\n');
fprintf(fid1, '; Data orientation: VECTORIZED=ch1,pt1, ch1,pt2..., MULTIPLEXED=ch1,pt1, ch2,pt1 ...\n');
fprintf(fid1, 'DataOrientation=VECTORIZED\n');
Expand All @@ -79,7 +83,7 @@
fprintf(fid1, 'SamplingInterval=%d\n', 1000000/EEG.srate);
if EEG.trials > 1
fprintf(fid1, 'SegmentationType=MARKERBASED\n');
end;
end
fprintf(fid1, '\n');
fprintf(fid1, '[Binary Infos]\n');
fprintf(fid1, 'BinaryFormat=IEEE_FLOAT_32\n');
Expand All @@ -92,7 +96,7 @@
fprintf(fid1, '; Commas in channel names are coded as "\1".\n');
for index = 1:EEG.nbchan
fprintf(fid1, 'Ch%d=%s,, \n', index, EEG.chanlocs(index).labels);
end;
end
fprintf(fid1, '\n');

disp('Warning: channel location were not exported to BVA (it will use default');
Expand All @@ -106,7 +110,7 @@
% round(loc(index).sph_phi_besa), 0);
% end;
%end;
end;
end

% export event information
% ------------------------
Expand All @@ -130,14 +134,14 @@
for index = 1:length(EEG.event)
EEG.event(index).comment = EEG.event(index).type;
EEG.event(index).type = 'Stimulus';
end;
end

% make event cell array
% ---------------------
for index = 1:EEG.trials
EEG.event(end+1).type = 'New Segment';
EEG.event(end ).latency = (index-1)*EEG.pnts+1;
end;
end
tmpevent = EEG.event;
[tmp latorder ] = sort( [ tmpevent.latency ] );
EEG.event = EEG.event(latorder);
Expand All @@ -152,7 +156,7 @@
for index = 1:length(notduplist)
EEG.event(notduplist(index)).type = 'New Segment'; % Recode boundary event type
EEG.event(notduplist(index)).comment = ''; % Recode boundary event comment
end;
end
EEG.event(duplist) = []; % Remove duplicate New Segment events

% rename latency events
Expand All @@ -162,12 +166,12 @@
if mod( EEG.event(index).latency, EEG.pnts) == -EEG.xmin*EEG.srate+1
time0ind = [ time0ind index ];
end;
end;
end
for index = length(time0ind):-1:1
EEG.event(time0ind(index)+1:end+1) = EEG.event(time0ind(index):end);
EEG.event(time0ind(index)).type = 'Time 0';
EEG.event(time0ind(index)).comment = '';
end;
end

% write events
% ------------
Expand All @@ -182,7 +186,7 @@
else tmpdur = 0;
end;
else tmpdur = 0;
end;
end

% comment field
% -------------
Expand All @@ -192,10 +196,10 @@
else tmpcom = '';
end;
else tmpcom = num2str(e(index).type);
end;
end

fprintf(fid2, 'Mk%d=%s,%s,%d,%d,0,0\n', index, num2str(e(index).type), num2str(tmpcom), round(e(index).latency), tmpdur);
end;
end
end
fclose(fid1);
fclose(fid2);
Expand Down

0 comments on commit 6a89aca

Please sign in to comment.