Skip to content

Commit

Permalink
Fixed a bug with openNSx.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kian Torab committed Sep 3, 2017
1 parent 0a85655 commit cd66f14
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions NPMK/openNSx.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
% - Fixed a bug related to reading data from sample that is not 1 and
% timestamp that used to get reset to 0.
%
% 6.4.3.0: September 3, 2017
% - Removed a redundant block of code that was accidentally placed in the
% script twice.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Defining the NSx data structure and sub-branches.
Expand Down Expand Up @@ -517,43 +521,6 @@
% end
fseek(FID, f.EOexH, 'bof');



%% Added by NH - Feb 19, 2014
% Create incrementing loop to skip from dataheader to dataheader and
% collect the dataheader data in individual cells
headerCount = 0;
if NSx.RawData.PausedFile == 1
while double(ftell(FID)) < f.EOF
headerCount = headerCount + 1;
DataHeader{headerCount} = fread(FID, 9);
fseek(FID,-9,'cof');
fread(FID,5);
DataPoints(headerCount) = fread(FID,1,'uint32');


f.BOData(headerCount) = double(ftell(FID));
fseek(FID, DataPoints(headerCount) * ChannelCount * 2, 'cof');
f.EOData(headerCount) = double(ftell(FID));
end

% Create an array that will contain all of the dataheader data
% collected in the cells above
FinalDataHeader = [];

%Fill the above mentioned pre-created array
for i = 1:headerCount
FinalDataHeader = cat(1,FinalDataHeader,DataHeader(i));
end

% Convert to correct type for interpreting in separatingPausedNSx
FinalDataHeader = cell2mat(FinalDataHeader);

NSx.RawData.DataHeader = FinalDataHeader;

fseek(FID, f.EOexH, 'bof');
end

%% Reading all data headers and calculating all the file pointers for data
% and headers
if strcmpi(NSx.MetaTags.FileTypeID, 'NEURALSG')
Expand Down Expand Up @@ -590,20 +557,6 @@
end
end

%% Temporary removing this code as it's causing a bug in other segments. It
%% does not appear to be neccesary any longer.
% Fixing a bug in 6.03.00.00 TOC where an extra data packet (length 9) was
% written for no reason. Removing the information read for the extra
% invalid packet
% if length(NSx.MetaTags.DataPoints) > 1 && all(NSx.MetaTags.Timestamp(1:2) == [0,0])
% NSx.MetaTags.DataPoints(1) = [];
% NSx.MetaTags.Timestamp(1) = [];
% f.BOData(1) = [];
% f.EOData(1) = [];
% segmentCount = 1;
% end
%%

% Determining if the file has a pause in it
if length(NSx.MetaTags.DataPoints) > 1
NSx.RawData.PausedFile = 1;
Expand All @@ -614,21 +567,17 @@
% end
end


%% Added by NH - Feb 19, 2014
% Create incrementing loop to skip from dataheader to dataheader and
% collect the dataheader data in individual cells

CurrentPlace = ftell(FID);
fseek(FID, f.EOexH, 'bof');
headerCount = 0;
if NSx.RawData.PausedFile == 1
while double(ftell(FID)) < f.EOF
headerCount = headerCount + 1;
DataHeader{headerCount} = fread(FID, 9);
fseek(FID,-9,'cof');
fread(FID,5);
DataPoints(headerCount) = fread(FID,1,'uint32');

fseek(FID, f.EOexH, 'bof');
DataHeader{headerCount} = fread(FID, 9, '*uint8');
DataPoints(headerCount) = typecast(DataHeader{headerCount}(6:9), 'uint32');

f.BOData(headerCount) = double(ftell(FID));
fseek(FID, DataPoints(headerCount) * ChannelCount * 2, 'cof');
Expand All @@ -652,9 +601,6 @@
fseek(FID, f.EOexH, 'bof');
end

fseek(FID,CurrentPlace,'bof');


%% Copying ChannelID to MetaTags for filespec 2.2 and 2.3 for compatibility with filespec 2.1
if strcmpi(NSx.MetaTags.FileTypeID, 'NEURALCD')
NSx.MetaTags.ChannelID = [NSx.ElectrodesInfo.ElectrodeID]';
Expand Down

0 comments on commit cd66f14

Please sign in to comment.