Skip to content

Commit

Permalink
use correct data type when filling
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanharvey1 committed Nov 6, 2024
1 parent 155262f commit e2a68a9
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions preProcessing/fillMissingDats.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,50 @@ function fillMissingDats(varargin)
% (at your option) any later version.

p = inputParser;
otherdattypes = {'analogin';'digitalin';'auxiliary';'time';'supply'};
isFileType = @(x) sum(strcmp(x,otherdattypes))==1;
addParameter(p,'basepath',pwd,@isfolder)
addParameter(p,'fileType',[],isFileType)
otherdattypes = {'analogin'; 'digitalin'; 'auxiliary'; 'time'; 'supply'};
isFileType = @(x) sum(strcmp(x, otherdattypes)) == 1;
addParameter(p, 'basepath', pwd, @isfolder)
addParameter(p, 'fileType', [], isFileType)

parse(p,varargin{:})
parse(p, varargin{:})
basepath = p.Results.basepath;
fileType = p.Results.fileType;

% get file types and data types
files_table = table();
files_table.files = {'amplifier', 'auxiliary', 'digitalin', 'digitalout', 'analogin', 'time', 'supply'}';
files_table.data_type = {'int16', 'uint16', 'uint16', 'uint16', 'uint16', 'int32', 'uint16'}';

%% Get session info
session = getSession('basepath',basepath); % Peter's sessionInfo
session = getSession('basepath', basepath); % Peter's sessionInfo
basename = session.general.name;
ampNch = session.extracellular.nChannels;

%% check location of each file and what to concat
typeFiles = dir([basepath,filesep,'*',filesep,fileType,'.dat']);
ampFiles = dir([basepath,filesep,'*',filesep,'amplifier.dat']);
typeFiles = dir([basepath, filesep, '*', filesep, fileType, '.dat']);
ampFiles = dir([basepath, filesep, '*', filesep, 'amplifier.dat']);
typeFolders = {typeFiles.folder};
ampFolders = {ampFiles.folder};

fillInds = find(~ismember(ampFolders,typeFolders)); %index of folders that need fill
fillInds = find(~ismember(ampFolders, typeFolders)); %index of folders that need fill

% calculate number of channels to for fill file
refTypeInd = find(ismember(typeFolders,ampFolders),1);
refTypeInd = find(ismember(typeFolders, ampFolders), 1);
refTypeSize = typeFiles(refTypeInd).bytes;
refAmpInd = find(strcmp(ampFolders,typeFiles(refTypeInd).folder));
refAmpInd = find(strcmp(ampFolders, typeFiles(refTypeInd).folder));
refAmpSize = ampFiles(refAmpInd).bytes;
typeNch = refTypeSize*ampNch/refAmpSize;
typeNch = refTypeSize * ampNch / refAmpSize;

%% Fill in missing files
for ii = 1:length(fillInds)
fillIdx = fillInds(ii);
localAmpSize = ampFiles(fillIdx).bytes;
nPoints = localAmpSize/(ampNch*2);
zeroData = zeros(typeNch,nPoints);
filepath = [ampFiles(fillIdx).folder,filesep,fileType,'.dat'];
fid = fopen(filepath,'w');
fwrite(fid,zeroData,'int16');
nPoints = localAmpSize / (ampNch * 2);

zeroData = zeros(typeNch, nPoints);

filepath = [ampFiles(fillIdx).folder, filesep, fileType, '.dat'];
fid = fopen(filepath, 'w');
fwrite(fid, zeroData, files_table.data_type{contains(files_table.files, fileType)});
fclose(fid);
end

0 comments on commit e2a68a9

Please sign in to comment.