debugMsg displays a debug message with line number and filename. debugMsg(message) writes the string message to the file that is specified by the global variable DEBUG_FID; if DEBUG_FID is 0, no message is written; if DEBUG_FID is 1, the message is written to stdout; for other values it is assumed that DEBUG_FID is the valid file identifier for an open and writable text file. debug(message,object) writes the message and information about object, which can be: a map structure - min, avg, and max are written out. a pyramid structure - the min, avg, and max for each level map are written out. a numeric array - the min, avg, and max are written out. See also dataStructures.
0001 % debugMsg displays a debug message with line number and filename. 0002 % 0003 % debugMsg(message) 0004 % writes the string message to the file that is specified by the 0005 % global variable DEBUG_FID; if DEBUG_FID is 0, no message is written; 0006 % if DEBUG_FID is 1, the message is written to stdout; 0007 % for other values it is assumed that DEBUG_FID is the valid 0008 % file identifier for an open and writable text file. 0009 % 0010 % debug(message,object) 0011 % writes the message and information about object, which can be: 0012 % a map structure - min, avg, and max are written out. 0013 % a pyramid structure - the min, avg, and max for each 0014 % level map are written out. 0015 % a numeric array - the min, avg, and max are written out. 0016 % 0017 % See also dataStructures. 0018 0019 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2007 0020 % by Dirk B. Walther and the California Institute of Technology. 0021 % See the enclosed LICENSE.TXT document for the license agreement. 0022 % More information about this project is available at: 0023 % http://www.saliencytoolbox.net 0024 0025 function debugMsg(message,varargin) 0026 0027 declareGlobal; 0028 0029 if (DEBUG_FID == 0) 0030 return 0031 end 0032 0033 st = dbstack; 0034 0035 msg = sprintf('%s at %i: %s',st(2).file,st(2).line,message); 0036 0037 if (~isempty(varargin)) 0038 0039 % is struct? 0040 if isstruct(varargin{1}) 0041 fnames = fieldnames(varargin{1}); 0042 0043 % is map? 0044 if (length(strmatch('data',fnames)) > 0) 0045 map = varargin{1}; 0046 lm = length(map); 0047 if (lm > 1) 0048 fprintf(DEBUG_FID,'%s\n',msg); 0049 end 0050 for m = 1:lm 0051 mx = max(map(m).data(:)); 0052 mn = min(map(m).data(:)); 0053 av = mean(map(m).data(:)); 0054 if (lm == 1) 0055 fprintf(DEBUG_FID,'%s %s: [%g; %g; %g]\n',... 0056 msg,map(m).label,mn,av,mx); 0057 else 0058 fprintf(DEBUG_FID,'%s\t%s: [%g; %g; %g]\n',... 0059 msg,map(m).label,mn,av,mx); 0060 end 0061 end 0062 elseif (length(strmatch('levels',fnames)) > 0) 0063 pyr = varargin{1}; 0064 fprintf(DEBUG_FID,'%s pyramid %s:\n',msg,pyr.label); 0065 for i=1:length(pyr.levels) 0066 mx = max(pyr.levels(i).data(:)); 0067 mn = min(pyr.levels(i).data(:)); 0068 av = mean(pyr.levels(i).data(:)); 0069 fprintf(DEBUG_FID,'%s\tlevel %i: [%g; %g; %g]\n',msg,i,mn,av,mx); 0070 end 0071 end 0072 elseif isnumeric(varargin{1}) 0073 % numeric -> print mn,av,mx 0074 fprintf(DEBUG_FID,'%s: [%g; %g; %g]\n',msg,min(varargin{1}(:)),... 0075 mean(varargin{1}(:)),max(varargin{1}(:))); 0076 end 0077 else 0078 fprintf(DEBUG_FID,'%s\n',msg); 0079 end