function [infoPackets, version] = openCCF(filename) % openCCF % % This script reads a .ccf file and outputs it in a structure. % % filename: Name of the file to be opened. If the fname is omitted % the user will be prompted to select a file. % DEFAULT: Will open Open File UI. % % Channels 1-128 are neural channels % Channels 129-144 are external analog inputs % Channels 145-148 are external analog outpus % Channels % % Kian Torab % kian@blackrockmicro.com % Blackrock Microsystems % Version 2.1.0.0 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Version History % % 1.0.0.0: % - Initial release. % % 1.2.3.0: % - Minor bug fix that led to a crash in certain cases. % % 1.2.4.0: % - Minor bug fix regarding passing a filename variable to the function. % % 2.0.0.0: % - Implemented XML CCF file format. % % 2.1.0.0: % - Fixed a bug in loading nTrode groups with a base of 0. % % 2.2.0.0 April 29, 2020 % - Fixed an error where N-Trodes with less than 4 members read an extra % 1 as the extra non-existent members. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% infoPackets.openCCFVersion = '2.1.0.0'; %% Parameters % Which versions of .ccf's are supported supportedVersions = {'3.6', '3.7', '3.8', '3.9'}; % Number of cbPKT_CHANINFO packets to read in the file nValidPKT_CHANINFO = 160; if( nargin ~= 1 ) [filename, pathname] = getFile('*.ccf'); if ~filename disp('No file was selected.'); return; end fullfilename = [pathname filename]; elseif (nargin == 1) fullfilename = filename; else if strcmpi(filename, 'ver') disp(['Version is ' infoPackets.openCCFVersion]); infoPackets = []; return; end end %% Open file [fid, message] = fopen( fullfilename, 'rb', 'l'); if( fid == -1 ), warning(['Unable to open file: ' fullfilename '. Error message ' message]); return; end; %% Read header incl. version head = fread(fid, 16, 'uint8=>char*1' )'; if strcmp(head(1:5), 'cbCCF') version = deblank(strtrim(head(6:end))); % Strip possible leading space and trailing nulls elseif strcmp(head(1:5), '