Home > matlabmk > chanlocs_from_crw.m

chanlocs_from_crw

PURPOSE ^

function use_chanlocs=chanlocs_from_crw(crwfile,logfile,presam,cprecis,decimat,exclude_chans,include_chans)

SYNOPSIS ^

function use_chanlocs=chanlocs_from_crw(crwfile,logfile,presam,cprecis,decimat,exclude_chans,include_chans)

DESCRIPTION ^

function use_chanlocs=chanlocs_from_crw(crwfile,logfile,presam,cprecis,decimat,exclude_chans,include_chans)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function use_chanlocs=chanlocs_from_crw(crwfile,logfile,presam,cprecis,decimat,exclude_chans,include_chans)
0002 %function use_chanlocs=chanlocs_from_crw(crwfile,logfile,presam,cprecis,decimat,exclude_chans,include_chans)
0003 
0004 global VERBLEVEL;
0005 
0006 if ~isempty(exclude_chans) && ~isempty(include_chans)
0007     error('You can''t use both "exclude_chans" and "include_chans" input arguments.');
0008 end
0009 
0010 fid_crw=erpio('openraw',crwfile,logfile,presam,cprecis,decimat);
0011 if (erpio('get_errno') == 0),
0012     VerbReport(sprintf('Opening crw file %s went OK', crwfile), 3, VERBLEVEL);
0013 else
0014     err_msg=erpio('get_errstr');
0015     erpio('close',fid_crw);
0016     error(err_msg);
0017 end
0018 
0019 n_chans=erpio('get_hdrvar', fid_crw, 'chans',0);
0020 
0021 %Try to create chanlocs from library of locations for initial
0022 %subject
0023 if n_chans>=59,
0024     %Try to match with 59 channel cap "chanlocs" variable
0025     load('/usr/local/matlab-toolboxes/matlabmk/mk66locs');
0026 else
0027     %Try to match with 26 channel cap "chanlocs" variable
0028     load('/usr/local/matlab-toolboxes/matlabmk/mk33locs');
0029 end
0030 n_chanlocs=length(chanlocs);
0031 crw_chanlabels=cell(1,n_chans);
0032 used_chan_ct=0;
0033 excluded_chan_ct=0;
0034 for c=1:n_chans,
0035     chan_label=erpio('get_hdrvar',fid_crw,'chndesc',c-1,1); %for chan #c, bin #1
0036     crw_chanlabels{c}=chan_label;
0037     use_chans(c)=1;    
0038     if ~isempty(exclude_chans) && ismember(chan_label,exclude_chans),
0039         excluded_chan_ct=excluded_chan_ct+1;
0040         excluded_chans{excluded_chan_ct}=chan_label;
0041         use_chans(c)=0;
0042     end
0043     if ~isempty(include_chans) && ~ismember(chan_label,include_chans),
0044         use_chans(c)=0;
0045     end
0046     if use_chans(c),
0047         used_chan_ct=used_chan_ct+1;
0048         %Standardize Channel Names
0049         if strcmpi(chan_label,'lle'),
0050             avg_label='LLEy';
0051         elseif strcmpi(chan_label,'rle'),
0052             avg_label='RLEy';
0053         elseif strcmpi(chan_label,'lhe') || strcmpi(chan_label,'lhz') || ...
0054                 strcmpi(chan_label,'lhrz'),
0055             avg_label='LHEy';
0056         elseif strcmpi(chan_label,'rhe') || strcmpi(chan_label,'rhz') || ...
0057                 strcmpi(chan_label,'rhrz'),
0058             avg_label='RHEy';
0059         elseif strcmpi(chan_label,'HE'),
0060             avg_label='HEOG';
0061         elseif strcmpi(chan_label,'VE'),
0062             avg_label='VEOG';
0063         else
0064             avg_label=chan_label;
0065         end
0066         found=0;
0067         for d=1:n_chanlocs,
0068             if strcmpi(avg_label,chanlocs(d).labels),
0069                 if used_chan_ct==1,
0070                     use_chanlocs=chanlocs(d); %create new struct
0071                 else
0072                     use_chanlocs(used_chan_ct)=chanlocs(d);
0073                 end
0074                 use_chanlocs(used_chan_ct).labels=chan_label;
0075                 found=1;
0076             end
0077         end
0078         if ~found,
0079             watchit(sprintf(['Could not find a default coordinate for channel %s. ' ...
0080                 'Giving it the bogus coordinate of a few inches in front of the nose.\n'],chan_label));
0081             use_chanlocs(used_chan_ct)=chanlocs(n_chanlocs); %the last electrode should be VEOG
0082             use_chanlocs(used_chan_ct).labels=chan_label;
0083         end
0084     end
0085 end
0086 erpio('close',fid_crw);
0087 use_chan_labels=cell(1,used_chan_ct);
0088 for d=1:used_chan_ct,
0089     use_chan_labels{d}=use_chanlocs(d).labels;
0090 end
0091 
0092 % Figure out if any channels were missed
0093 if ~isempty(exclude_chans),
0094     missing=setdiff(exclude_chans,excluded_chans);
0095     err_msg=sprintf('You asked to exclude the following channels but they are not in %s:',crwfile);
0096     for a=1:length(missing),
0097        err_msg=[err_msg ' ' missing{a}]; 
0098     end
0099     if ~isempty(missing),
0100         watchit(err_msg);
0101     end
0102 elseif ~isempty(include_chans),
0103     missing=setdiff(include_chans,use_chan_labels);
0104     err_msg=sprintf('You asked to include the following channels but they are not in %s:',crwfile);
0105     for a=1:length(missing),
0106        err_msg=[err_msg ' ' missing{a}]; 
0107     end
0108     if ~isempty(missing),
0109         watchit(err_msg);
0110     end
0111 end

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005