Home > eeg > egis > meg_code > parseheader.m

parseheader

PURPOSE ^

PARSEHEADER obtain study information from Bti header file

SYNOPSIS ^

function [channels, bfactors, npts, dt] = parseheader(topdir, hdrfile)

DESCRIPTION ^

 PARSEHEADER obtain study information from Bti header file

 Read header file (output of Bti 'convert') for information necessary to
 read Bti data files directly without requiring the database.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [channels, bfactors, npts, dt] = parseheader(topdir, hdrfile)
0002 % PARSEHEADER obtain study information from Bti header file
0003 %
0004 % Read header file (output of Bti 'convert') for information necessary to
0005 % read Bti data files directly without requiring the database.
0006 
0007 if ~exist('hdrfile') hdrfile = []; end
0008 if isempty(hdrfile)            % determine header file name
0009   dd = dir(topdir);
0010   for i=1:length(dd)
0011     if findstr([dd(i).name 'zzz'],'hdr')
0012       hdrfile = dd(i).name
0013     end
0014   end
0015 end
0016 if isempty(hdrfile)
0017   error('Cant find header file');
0018 end
0019 fid = fopen([topdir hdrfile],'rt');    % Open header file
0020 
0021 line = 0;
0022 while line ~= -1            % parse ascii lines within file
0023   tmpline = [line 'zzz'];
0024   if findstr(tmpline, 'Total Channels')
0025     nchans = str2num(line((findstr(line,': ')+2):end));
0026   elseif findstr(tmpline, 'Sample Period')
0027     dt = str2num(line((findstr(line,': ')+2):end));
0028   elseif findstr(tmpline, 'Total Points')
0029     npts = str2num(line((findstr(line,': ')+2):end));
0030   elseif findstr(tmpline, 'MxA')
0031     channels = line;
0032   elseif findstr(tmpline, 'MSI.Conversion')
0033     bfactors = line;
0034   end
0035   line = fgets(fid);
0036 end
0037 
0038 fclose(fid);
0039 
0040 rchans = channels; rfacts = bfactors;
0041 channels = []; factnames = [];
0042 [junk rfacts] = strtok(rfacts);        % readout line label first
0043 for i=1:nchans
0044   [tchan rchans] = strtok(rchans);    % parse channel names
0045   channels = strvcat(channels, tchan);
0046   [tfact rfacts] = strtok(rfacts);    % parse converstion factor strings
0047   factnames = strvcat(factnames, tfact);
0048 end
0049 
0050 bfactors = str2num(factnames);

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003