1 /*
2
3 Copyright (C) 2009-2016 Lukas F. Reichlin
4
5 This file is part of LTI Syncope.
6
7 LTI Syncope is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 LTI Syncope is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19
20 Common code for oct-files.
21
22 Author: Lukas Reichlin <lukas.reichlin@gmail.com>
23 Created: April 2010
24 Version: 0.4
25
26 */
27
28
29 #include <sstream>
30 #include <octave/oct.h>
31
32 #include "common.h"
33
max(F77_INT a,F77_INT b)34 F77_INT max (F77_INT a, F77_INT b)
35 {
36 if (a > b)
37 return a;
38 else
39 return b;
40 }
41
max(F77_INT a,F77_INT b,F77_INT c)42 F77_INT max (F77_INT a, F77_INT b, F77_INT c)
43 {
44 return max (max (a, b), c);
45 }
46
max(F77_INT a,F77_INT b,F77_INT c,F77_INT d)47 F77_INT max (F77_INT a, F77_INT b, F77_INT c, F77_INT d)
48 {
49 return max (max (a, b), max (c, d));
50 }
51
max(F77_INT a,F77_INT b,F77_INT c,F77_INT d,F77_INT e)52 F77_INT max (F77_INT a, F77_INT b, F77_INT c, F77_INT d, F77_INT e)
53 {
54 return max (max (a, b, c, d), e);
55 }
56
min(F77_INT a,F77_INT b)57 F77_INT min (F77_INT a, F77_INT b)
58 {
59 if (a < b)
60 return a;
61 else
62 return b;
63 }
64
error_msg(const char name[],octave_idx_type index,octave_idx_type max,const char * msg[])65 void error_msg (const char name[], octave_idx_type index, octave_idx_type max, const char* msg[])
66 {
67 if (index == 0)
68 return;
69
70 std::ostringstream os;
71
72 if (index < 0)
73 os << name << ": the " << index << "-th argument had an invalid value";
74 else if (index <= max)
75 os << name << ": " << msg[index];
76 else
77 os << name << ": unknown error, info = " << index;
78
79 error ("%s", os.str ().c_str ());
80 }
81
warning_msg(const char name[],octave_idx_type index,octave_idx_type max,const char * msg[])82 void warning_msg (const char name[], octave_idx_type index, octave_idx_type max, const char* msg[])
83 {
84 if (index == 0)
85 return;
86
87 std::ostringstream os;
88
89 if (index > 0 && index <= max)
90 os << name << ": " << msg[index];
91 else
92 os << name << ": unknown warning, iwarn = " << index;
93
94 warning ("%s", os.str ().c_str ());
95 }
96
warning_msg(const char name[],octave_idx_type index,octave_idx_type max,const char * msg[],octave_idx_type offset)97 void warning_msg (const char name[], octave_idx_type index, octave_idx_type max, const char* msg[], octave_idx_type offset)
98 {
99 if (index == 0)
100 return;
101
102 std::ostringstream os;
103
104 if (index > 0 && index <= max)
105 os << name << ": " << msg[index];
106 else if (index > offset)
107 os << name << ": " << offset << "+" << (index - offset) << ": " << (index - offset) << " " << msg[max+1];
108 else
109 os << name << ": unknown warning, iwarn = " << index;
110
111 warning ("%s", os.str ().c_str ());
112 }
113