1function line_warning(caller, MSG, varargin)
2% LINE_WARNING(
CALLER, ERRMSG)
4% Copyright (c) 2012-2026, Imperial College London
7if ~coder.target(
'MATLAB')
8 return; % No-op in codegen mode
11%global GlobalConstants.Verbose
12persistent lastWarning;
13persistent suppressedWarnings;
14persistent suppressedWarningsTic;
15persistent lastWarningTime;
16persistent suppressedAnnouncement;
18if GlobalConstants.Verbose == VerboseLevel.SILENT
22suppressedAnnouncement =
false;
23errmsg=sprintf(MSG, varargin{:});
24w = warning(
'QUERY',
'ALL');
25w(1).state =
'on'; % always print warnings by
default
28 %warning(
'[%s] %s',caller,MSG);
29 finalmsg = sprintf(
'Warning [%s.m]: %s',caller,errmsg);
30 % Terminate the warning with a newline, as line_warning_always and the
31 % Python/JAR loggers
do. line_printf writes the
string verbatim, so a
32 % call site that does not embed a trailing
'\n' leaves the next
33 % printout glued to the warning (e.g.
'reference tasks only.AvgTable =').
34 if isempty(finalmsg) || finalmsg(end) ~= sprintf(
'\n')
35 finalmsg = [finalmsg, sprintf('\n')];
38 % Time since suppression began. The previous
form,
39 % toc(suppressedWarningsTic)-toc(lastWarningTime), cancels the
40 % current time and evaluates to lastWarningTime-suppressedWarningsTic,
41 % a fixed gap between two past instants that
is ~0 because both are
42 % set in the same call. It therefore never exceeded 60 and an
43 % identical message stayed suppressed for the whole session rather
44 % than for a minute, diverging from the JAR and Python
45 % implementations which both measure elapsed time.
46 if ~strcmp(finalmsg, lastWarning) || toc(suppressedWarningsTic)>60
47 line_printf(finalmsg);
49 lastWarning = finalmsg;
50 suppressedWarnings = false;
51 suppressedWarningsTic = tic;
53 if ~suppressedWarnings && ~suppressedAnnouncement
54 %line_printf(finalmsg);
56 finalmsg = sprintf('\nWarning [%s.m]: %s',caller,errmsg);
57 line_printf(sprintf('[%s.m] %s',caller,'Message casted more than once, repetitions will not be printed on screen for 60 seconds.\n'));
58 %warning(sprintf('[%s.m] %s',caller,'Message casted more than once, repetitions will not be printed on screen for 60 seconds.'));
59 suppressedAnnouncement = true;
60 suppressedWarnings = true;
61 suppressedWarningsTic = tic;
67 case 'MATLAB:toc:callTicFirstNoInputs'
69 line_printf(finalmsg);
70 lastWarning = finalmsg;
71 suppressedWarnings = false;
72 suppressedWarningsTic = -1;
77 %line_printf(sprintf('Warning [%s.m]: %s',caller,errmsg));