Home > eeg > egis > egis_file_utils > read_edc.m

read_edc

PURPOSE ^

read_edc.m -- reads an edit codes file

SYNOPSIS ^

function edit_codes = read_edc(fname, fhdr, chdr, nchan)

DESCRIPTION ^

 read_edc.m  -- reads an edit codes file

 fhdr: EGIS format specific vector
 chdr: EGIS format specific vector

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edit_codes = read_edc(fname, fhdr, chdr, nchan)
0002 % read_edc.m  -- reads an edit codes file
0003 %
0004 % fhdr: EGIS format specific vector
0005 % chdr: EGIS format specific vector
0006 %
0007 
0008 % Modification history:
0009 % 7/7/95        Written by Petr Janata
0010 %
0011 % 7/15/01 PJ - Modified to read .edc format file without relying on any EGIS
0012 % format information
0013 
0014 mode = 'GENERIC';
0015 
0016 if nargin > 1 & nargin < 4
0017   mode = 'EGIS';
0018 end
0019 
0020 if nargin == 4
0021   mode = 'GENERIC';
0022 end
0023 
0024 if nargin < 1
0025   nchan = input('How many channels: ');
0026 end
0027 
0028 % Initialize some things
0029 switch mode
0030   case 'EGIS'
0031     ses_hdr_offsets_v;
0032     edit_codes = ones(sum(chdr(:,NTrials)), fhdr(NChan));
0033   case 'GENERIC'
0034     edit_codes = ones(1,nchan);
0035 end
0036 
0037 fid = fopen(fname);
0038 if fid == -1
0039   error(sprintf('Error opening edit codes file: %s', fname))
0040 end
0041 
0042 disp(['Reading edit codes file <' fname '>']);
0043 done = 0; 
0044 lines_read = 0;
0045 
0046 while ~done
0047   theline = fgetl(fid);
0048   if theline == -1
0049     done = 1;
0050     disp(['Finished reading edit codes file (' int2str(lines_read) ' lines)']);
0051   else
0052     lines_read = lines_read + 1;
0053     theline = sscanf(theline, '%d');
0054     nelem = length(theline);
0055     thecell = theline(1); 
0056     thetrial = theline(2);
0057     max_trials(thecell) = thetrial;
0058     
0059     switch mode
0060       case 'EGIS'
0061     if (thecell <= 0) | (thecell > fhdr(NCells))
0062       warning(['Invalid cell (' int2str(thecell) ') specified']);
0063     end
0064     if (thetrial > chdr(thecell, NTrials))
0065       warning(['Invalid trial number (' int2str(thetrial) ') for cell ' ...
0066         int2str(thecell) ]);
0067     end
0068     
0069     trial_offset = sum(chdr(1:current_cell, NTrials)) - chdr(current_cell, ...
0070         NTrials) + thetrial;
0071     
0072     if (theline(3) >= 2)
0073       edit_codes(trial_offset, :) = zeros(1, size(edit_codes,2));
0074     end
0075     if (nelem > 3) & (theline(3) == 1)
0076       for i = 4:nelem
0077         if (theline(i) < 0) | (theline(i) > fhdr(NChan))
0078           disp(['Abnormality in line ' int2str(lines_read + 1) ' of edit codes file']);
0079         elseif theline(i) ~= 0
0080           edit_codes(trial_offset, theline(i)) = 0;
0081         end
0082       end
0083     end % case EGIS
0084       case 'GENERIC'
0085     trial_offset = sum(max_trials(1:thecell));
0086     if theline(3) >=2
0087       edit_codes(trial_offset, 1:nchan) = 0;
0088     else
0089       edit_codes(trial_offset, 1:nchan) = 1;
0090     end
0091     if (nelem > 3) & (theline(3) == 1)
0092       edit_codes(trial_offset, theline(4:end)) = 0;
0093     end
0094     end % switch mode
0095   end % if theline == -1
0096 end % while ~done
0097 
0098 fclose(fid);

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