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 if ~strcmp(finalmsg, lastWarning) || (toc(suppressedWarningsTic)-toc(lastWarningTime))>60
32 line_printf(finalmsg);
34 lastWarning = finalmsg;
35 suppressedWarnings =
false;
36 suppressedWarningsTic = tic;
38 if ~suppressedWarnings && ~suppressedAnnouncement
39 %line_printf(finalmsg);
41 finalmsg = sprintf(
'\nWarning [%s.m]: %s',caller,errmsg);
42 line_printf(sprintf(
'[%s.m] %s',caller,
'Message casted more than once, repetitions will not be printed on screen for 60 seconds.\n'));
43 %warning(sprintf(
'[%s.m] %s',caller,
'Message casted more than once, repetitions will not be printed on screen for 60 seconds.'));
44 suppressedAnnouncement =
true;
45 suppressedWarnings =
true;
46 suppressedWarningsTic = tic;
52 case 'MATLAB:toc:callTicFirstNoInputs'
54 line_printf(finalmsg);
55 lastWarning = finalmsg;
56 suppressedWarnings =
false;
57 suppressedWarningsTic = -1;
62 %line_printf(sprintf(
'Warning [%s.m]: %s',caller,errmsg));