Home > RAVEN > dispEM.m

dispEM

PURPOSE ^

dispEM

SYNOPSIS ^

function dispEM(string,throwErrors,toList,trimWarnings)

DESCRIPTION ^

 dispEM
   Helper function to print warning/errors

   string          the warning/error to show. "WARNING: " is appended automatically
                   if a warning
   throwErrors     true if the function should throw an error (opt, default true)
   toList          a cell array of items to list. If supplied, then the
                   string will be printed followed by each element in
                   toList. If it is supplied but empty then nothing is
                   printed (opt, default {})
   trimWarnings    true if only a maximal of 10 items should be displayed in
                   a given error/warning (opt, default true)

   Usage: dispEM(string,throwErrors,toList,trimWarnings)

   Rasmus Agren, 2013-08-01

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dispEM(string,throwErrors,toList,trimWarnings)
0002 % dispEM
0003 %   Helper function to print warning/errors
0004 %
0005 %   string          the warning/error to show. "WARNING: " is appended automatically
0006 %                   if a warning
0007 %   throwErrors     true if the function should throw an error (opt, default true)
0008 %   toList          a cell array of items to list. If supplied, then the
0009 %                   string will be printed followed by each element in
0010 %                   toList. If it is supplied but empty then nothing is
0011 %                   printed (opt, default {})
0012 %   trimWarnings    true if only a maximal of 10 items should be displayed in
0013 %                   a given error/warning (opt, default true)
0014 %
0015 %   Usage: dispEM(string,throwErrors,toList,trimWarnings)
0016 %
0017 %   Rasmus Agren, 2013-08-01
0018 %
0019 
0020 if nargin<2
0021     throwErrors=true;
0022 end
0023 if nargin<3
0024     toList=[];
0025 else
0026     if isempty(toList)
0027         return;
0028     end
0029 end
0030 if nargin<4
0031     trimWarnings=true;
0032 end
0033 if numel(toList)>10 && trimWarnings==true
0034    toList{10}=['...and ' num2str(numel(toList)-9) ' more'];
0035    toList(11:end)=[];
0036 end
0037 if throwErrors==false
0038     errorText=['WARNING: ' string '\n'];
0039 else
0040     errorText=[string '\n'];
0041 end
0042 if ~isempty(toList)
0043     for i=1:numel(toList)
0044         errorText=[errorText '\t' toList{i} '\n'];
0045     end
0046 end
0047 if throwErrors==false
0048     fprintf([errorText '\n']);
0049 else
0050     throw(MException('',errorText));
0051 end
0052 end

Generated on Mon 06-Jan-2014 14:58:12 by m2html © 2005