0001 function [channels, bfactors, npts, dt] = parseheader(topdir, hdrfile)
0002
0003
0004
0005
0006
0007 if ~exist('hdrfile') hdrfile = []; end
0008 if isempty(hdrfile)
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');
0020
0021 line = 0;
0022 while line ~= -1
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);
0043 for i=1:nchans
0044 [tchan rchans] = strtok(rchans);
0045 channels = strvcat(channels, tchan);
0046 [tfact rfacts] = strtok(rfacts);
0047 factnames = strvcat(factnames, tfact);
0048 end
0049
0050 bfactors = str2num(factnames);