Home > utils > generic_pres_proc.m

generic_pres_proc

PURPOSE ^

[data,meta] = generic_pres_proc(fname,params)

SYNOPSIS ^

function [data,meta] = generic_pres_proc(fname,p)

DESCRIPTION ^

 [data,meta] = generic_pres_proc(fname,params)

 fname - Presentation file to parse
 params - a structure that controls details of the parse and what meta data
          should be returned

 Options for params structure
 
 'skipline','delim','verbose' - control loadtxt() behavior
 'strip_colnames' - if true, the first row of data containing column names is stripped
 'mask' - a structure array specifying if and how any masks should be created

 Fields within the  mask structure
 'name' - name of the mask which becomes the field name in the output structure
 'crit_col_lbl' - name in the PL (column indexing) structure to be used
 'crits' - criteria (events) to match
 'is_partial' - is the value in crits a partial search string

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [data,meta] = generic_pres_proc(fname,p)
0002 % [data,meta] = generic_pres_proc(fname,params)
0003 %
0004 % fname - Presentation file to parse
0005 % params - a structure that controls details of the parse and what meta data
0006 %          should be returned
0007 %
0008 % Options for params structure
0009 %
0010 % 'skipline','delim','verbose' - control loadtxt() behavior
0011 % 'strip_colnames' - if true, the first row of data containing column names is stripped
0012 % 'mask' - a structure array specifying if and how any masks should be created
0013 %
0014 % Fields within the  mask structure
0015 % 'name' - name of the mask which becomes the field name in the output structure
0016 % 'crit_col_lbl' - name in the PL (column indexing) structure to be used
0017 % 'crits' - criteria (events) to match
0018 % 'is_partial' - is the value in crits a partial search string
0019 
0020 % 12/25/06 Petr Janata
0021 data = [];
0022 meta = [];
0023 
0024 if nargin < 2
0025   p = struct([]);
0026 end
0027 
0028 p = proc_input_params(p);
0029   
0030 if ~exist(fname)
0031   fprintf('Did not find file: %s\n', fname);
0032   return
0033 end
0034 
0035 % Load the data from the Presentation file using the EEGLAB function loadtxt
0036 data = loadtxt(fname, 'skipline', p.skipline, 'delim', p.delim, 'verbose', p.verbose);
0037 col_names = data(1,:);
0038 
0039 % Map the column names to column index values
0040 PL = set_pres_col_const(col_names);
0041 meta.PL = PL;
0042 
0043 % Strip the row of column names
0044 if p.strip_colnames
0045   data(1,:) = [];
0046 end
0047 
0048 % Create masks if desired
0049 nmasks = length(p.mask);
0050 for imask = 1:nmasks
0051   mask_name = p.mask(imask).name;
0052   crit_col = p.mask(imask).crit_col_lbl;
0053   mask_crit = p.mask(imask).crits;
0054   if ~iscell(mask_crit)
0055     mask_crit = {mask_crit};
0056   end
0057   
0058   tmpdata = data(:,PL.(crit_col));
0059   % We have to set up some handling for mixed string and numeric types
0060   str_mask = cellfun(@isstr,tmpdata);
0061   num_mask = cellfun(@isnumeric,tmpdata);
0062   
0063   is_crit_str = cellfun(@isstr, mask_crit);
0064   is_crit_num = cellfun(@isnumeric, mask_crit);
0065   
0066   if ~(all(is_crit_str) | all(is_crit_num))
0067     fprintf(['generic_pres_proc: Cannot handle mixed type criteria right now' ...
0068       ' ...\n']);
0069     continue
0070   end
0071   
0072   meta.(mask_name) = false(size(tmpdata,1),1);
0073   if all(is_crit_str)
0074     if ~p.mask(imask).is_partial;
0075       meta.(mask_name)(str_mask) = ismember(tmpdata(str_mask), mask_crit);
0076     else
0077       items = strfind(tmpdata(str_mask), mask_crit{1});
0078       meta.(mask_name)(str_mask) = ~cellfun(@isempty,items);
0079     end
0080   else
0081     meta.(mask_name)(num_mask) = ismember([tmpdata{num_mask}], [mask_crit{:}]);
0082   end
0083   
0084 end % for imask
0085   
0086 end
0087 
0088 function p = proc_input_params(p)
0089   % Parameters for loadtxt
0090   if ~isfield(p,'skipline') p.skipline = 3; end
0091   if ~isfield(p,'delim') p.delim = 9; end
0092   if ~isfield(p,'verbose') p.verbose = 'off'; end
0093 
0094   % Post-processing of loaded file
0095   if ~isfield(p,'strip_colnames') p.strip_colnames = true; end
0096   
0097   % Mask creation
0098   if ~isfield(p,'mask') p.mask = []; end
0099   
0100 end

Generated on Sun 24-Mar-2019 04:00:51 by m2html © 2003