function object = getList(thelist,name,allowfail) %getList - get an object from a list based on the name of the objects. % % Parameter: thelist The thelist to be searched % name Name to search for % allowfail Flag to indicate that failure % to find any object is allowed % Returns: object The object found % % Example(s): % tfplan = getList(ex.tflist,'Zipper'); % %% =========================================================================== %% =========================================================================== % Copyright (C): % 1999 by Telia Research AB, Lulea, Sweden; % 2000-2009 by Forschungszentrum Telekommunikation Wien, Austria; % All rights reserved. % Project : FTW's xDSLsimu % Author(s) : Tomas Nordstrom (Tomas.Nordstrom@FTW.at) % : Daniel Bengtsson (Daniel.J.Bengtsson@Telia.se) % : Bo Engstrom (bosse@upzide.com) % % CVS: $Id: getList.m 752 2009-01-02 13:03:52Z tono $ %% =========================================================================== % Change History % 1999-02-25 (ToNo) Created % 2001-06-14 (Bosse) Octave port % 2002-01-17 (StTr) Slow 'for'-loop replaced by equivalent code % 2002-07-30 (ToNo) Octave to Matlab compatibility port % 2003-11-03 (ToNo) Lists now use cell arrays for both Octave and Matlab % 2005-05-19 (ToNo) Changed behaviour for the failure to find anything %% =========================================================================== if nargin<3, allowfail=0; end len=length(thelist); found_idx=zeros(1,len); nofound=0; for i=1:len, if strcmp(thelist{i}.name,name); nofound=nofound+1; found_idx(nofound)=i; end; end; if nofound>0 found_idx=found_idx(1:nofound); else found_idx = []; end; % Check if we found anything and take care of multiple entries if isempty(found_idx) if allowfail, warning(sprintf('Object %s not found in the list!', name)); else error(sprintf('Object %s not found in the list!', name)); end; object=[]; else len_found_idx=length(found_idx); if len_found_idx>1 warning(sprintf('There are multiple entries of object %s in the list!', name)); end % Choose first entry if thelist has multiple entries with the same name % object=thelist(found_idx(1)); % Choose last entry if thelist has multiple entries with the same name % (for full compatibility to old version) object=thelist{found_idx(len_found_idx)}; end