Home > database > add2filt.m

add2filt

PURPOSE ^

Adds filtering fields in the newfilt structure to the oldfilt structure.

SYNOPSIS ^

function outfilt = add2filt(oldfilt,newfilt)

DESCRIPTION ^

 Adds filtering fields in the newfilt structure to the oldfilt structure.

 outfilt = add2filt(oldfilt,newfilt);

 These are the filtering fields that are used by ensemble_apply_crit()

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function outfilt = add2filt(oldfilt,newfilt)
0002 % Adds filtering fields in the newfilt structure to the oldfilt structure.
0003 %
0004 % outfilt = add2filt(oldfilt,newfilt);
0005 %
0006 % These are the filtering fields that are used by ensemble_apply_crit()
0007 %
0008 
0009 % 01/26/07 Petr Janata
0010 % 02/21/07 PJ - turned into a recursive function
0011 % 05/02/07 PJ - fixed a bug that prevented concatenation of old and new values
0012 %               for the same fieldname. Thanks to Jason Golubock.
0013 %          JG - add validation check for empty input structs
0014 
0015 if( ~length( newfilt ) )
0016     outfilt = oldfilt;
0017     return;
0018 end
0019 
0020 if( ~length( oldfilt ) )
0021     outfilt = newfilt;
0022     return;
0023 end
0024 
0025 outfilt = oldfilt;
0026 
0027 old_flds = fieldnames(oldfilt);
0028 new_flds = fieldnames(newfilt);
0029 
0030 for inew = 1:length(new_flds)
0031   currfldname = new_flds{inew};
0032   oldidx = strmatch(currfldname,old_flds);
0033   if isempty(oldidx)
0034     outfilt.(currfldname) = newfilt.(currfldname);
0035   else
0036     % Check to see if we are dealing with a struct. If so, compare the
0037     % sub-fields
0038     if isstruct(newfilt.(currfldname)) && isstruct(oldfilt.(currfldname))
0039       outfilt.(currfldname) = add2filt(oldfilt.(currfldname),newfilt.(currfldname));
0040     elseif ~isstruct(newfilt.(currfldname)) & ~isstruct(oldfilt.(currfldname))
0041       % Combine field values
0042       new_vals = ...
0043       newfilt.(currfldname)(~ismember(newfilt.(currfldname),oldfilt.(currfldname)));
0044       old_vals = oldfilt.(currfldname);
0045       outfilt.(currfldname) = [old_vals new_vals];
0046     else
0047       fprintf('%s: Field type mismatch in field: %s\n',  mfilename, currfldname);
0048     end
0049   end % if isempty(oldidx)
0050 end % for inew

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