LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
line_warning.m
1function line_warning(caller, MSG, varargin)
2% LINE_WARNING(CALLER, ERRMSG)
3
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
7if ~coder.target('MATLAB')
8 return; % No-op in codegen mode
9end
10
11%global GlobalConstants.Verbose
12persistent lastWarning;
13persistent suppressedWarnings;
14persistent suppressedWarningsTic;
15persistent lastWarningTime;
16persistent suppressedAnnouncement;
17
18if GlobalConstants.Verbose == VerboseLevel.SILENT
19 return
20end
21
22suppressedAnnouncement = false;
23errmsg=sprintf(MSG, varargin{:});
24w = warning('QUERY','ALL');
25w(1).state = 'on'; % always print warnings by default
26switch w(1).state
27 case 'on'
28 %warning('[%s] %s',caller,MSG);
29 finalmsg = sprintf('Warning [%s.m]: %s',caller,errmsg);
30 try
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);
41 %warning(finalmsg);
42 lastWarning = finalmsg;
43 suppressedWarnings = false;
44 suppressedWarningsTic = tic;
45 else
46 if ~suppressedWarnings && ~suppressedAnnouncement
47 %line_printf(finalmsg);
48 %warning(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;
55 end
56 end
57 lastWarningTime=tic;
58 catch ME
59 switch ME.identifier
60 case 'MATLAB:toc:callTicFirstNoInputs'
61 %warning(finalmsg);
62 line_printf(finalmsg);
63 lastWarning = finalmsg;
64 suppressedWarnings = false;
65 suppressedWarningsTic = -1;
66 lastWarningTime=tic;
67 end
68 end
69 case 'off'
70 %line_printf(sprintf('Warning [%s.m]: %s',caller,errmsg));
71end
72end
Definition Station.m:245