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);
31 % Time since suppression began. The previous form,
32 % toc(suppressedWarningsTic)-toc(lastWarningTime), cancels
the
33 % current time and evaluates to lastWarningTime-suppressedWarningsTic,
34 % a fixed gap between two past instants that
is ~0 because both are
35 % set in
the same call. It therefore never exceeded 60 and an
36 % identical message stayed suppressed
for the whole session rather
37 % than
for a minute, diverging from
the JAR and Python
38 % implementations which both measure elapsed time.
39 if ~strcmp(finalmsg, lastWarning) || toc(suppressedWarningsTic)>60
40 line_printf(finalmsg);
42 lastWarning = finalmsg;
43 suppressedWarnings =
false;
44 suppressedWarningsTic = tic;
46 if ~suppressedWarnings && ~suppressedAnnouncement
47 %line_printf(finalmsg);
49 finalmsg = sprintf(
'\nWarning [%s.m]: %s',caller,errmsg);
50 line_printf(sprintf(
'[%s.m] %s',caller,
'Message casted more than once, repetitions will not be printed on screen for 60 seconds.\n'));
51 %warning(sprintf(
'[%s.m] %s',caller,
'Message casted more than once, repetitions will not be printed on screen for 60 seconds.'));
52 suppressedAnnouncement =
true;
53 suppressedWarnings =
true;
54 suppressedWarningsTic = tic;
60 case 'MATLAB:toc:callTicFirstNoInputs'
62 line_printf(finalmsg);
63 lastWarning = finalmsg;
64 suppressedWarnings =
false;
65 suppressedWarningsTic = -1;
70 %line_printf(sprintf(
'Warning [%s.m]: %s',caller,errmsg));