Skip to content

Commit

Permalink
Changed some thermo_set methods to use geterr for error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssun30 authored and speth committed May 11, 2023
1 parent b980351 commit a8e6790
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 66 deletions.
66 changes: 3 additions & 63 deletions interfaces/matlab_experimental/Base/ThermoPhase.m
Expand Up @@ -93,10 +93,10 @@ function display(tp, threshold)
if nargin < 2 || ~isnumeric(threshold)
threshold = 1e-14;
end
buflen = 0 - callct('thermo_report', tp.tpID, 0, '', 1);
buflen = 0 - calllib(ct, 'thermo_report', tp.tpID, 0, '', 1);
aa = char(ones(1, buflen));
ptr = libpointer('cstring', aa);
[iok, bb] = callct('thermo_report', tp.tpID, buflen, ptr, 1);
[iok, bb] = calllib(ct, 'thermo_report', tp.tpID, buflen, ptr, 1);
if iok < 0
error(geterr);
else
Expand Down Expand Up @@ -503,7 +503,7 @@ function tpClear(tp)
for j = 1:n
ksp = k(i, j) - 1;
output = callct2('thermo_getSpeciesName', tp.tpID, ksp);
nm{i, j} = aa;
nm{i, j} = output;
end
end
end
Expand Down Expand Up @@ -1355,9 +1355,6 @@ function tpClear(tp)
% :param pressure:
% Pressure. Units: Pa
%
if pressure <= 0
error('The pressure must be positive');
end
callct('thermo_setPressure', tp.tpID, pressure);
end

Expand All @@ -1371,9 +1368,6 @@ function tpClear(tp)
% :param density:
% Density. Units: kg/m**3
%
if density <= 0
error('The density must be positive');
end
callct('thermo_setDensity', tp.tpID, density);
end

Expand Down Expand Up @@ -1449,12 +1443,6 @@ function tpClear(tp)
function set.DP(tp, input)
d = input{1};
p = input{2};
if d <= 0
error('The density must be positive');
end
if p <= 0
error('The pressure must be positive');
end
callct('thermo_set_RP', tp.tpID, [d, p]);
end

Expand All @@ -1471,9 +1459,6 @@ function tpClear(tp)
function set.HP(tp, input)
h = input{1};
p = input{2};
if p <= 0
error('The pressure must be positive');
end
callct('thermo_set_HP', tp.tpID, [h, p]);
end

Expand All @@ -1490,12 +1475,6 @@ function tpClear(tp)
function set.PV(tp, input)
p = input{1};
v = input{2};
if p <= 0
error('The pressure must be positive');
end
if v <= 0
error('The specific volume must be positive');
end
callct('thermo_set_PV', tp.tpID, [p, v]);
end

Expand Down Expand Up @@ -1528,9 +1507,6 @@ function tpClear(tp)
function set.SP(tp, input)
s = input{1};
p = input{2};
if p <= 0
error('The pressure must be positive');
end
callct('thermo_set_SP', tp.tpID, [s, p]);
end

Expand All @@ -1547,9 +1523,6 @@ function tpClear(tp)
function set.ST(tp, input)
s = input{1};
t = input{2};
if t <= 0
error('The temperature must be positive');
end
callct('thermo_set_ST', tp.tpID, [s, t]);
end

Expand All @@ -1566,9 +1539,6 @@ function tpClear(tp)
function set.SV(tp, input)
s = input{1};
v = input{2};
if v <= 0
error('The specific volume must be positive');
end
callct('thermo_set_SV', tp.tpID, [s, v]);
end

Expand All @@ -1585,12 +1555,6 @@ function tpClear(tp)
function set.TD(tp, input)
t = input{1};
d = input{2};
if t <= 0
error('The temperature must be positive');
end
if d <= 0
error('The density must be positive');
end
tp.T = t;
tp.D = d;
end
Expand All @@ -1607,9 +1571,6 @@ function tpClear(tp)

function set.TH(tp, input)
t = input{1};
if t <= 0
error('The temperature must be positive');
end
h = input{2};
callct('thermo_set_TH', tp.tpID, [t, h]);
end
Expand All @@ -1627,12 +1588,6 @@ function tpClear(tp)
function set.TP(tp, input)
t = input{1};
p = input{2};
if t <= 0
error('The temperature must be positive');
end
if p <= 0
error('The pressure must be positive');
end
tp.T = t;
tp.P = p;
end
Expand All @@ -1650,12 +1605,6 @@ function tpClear(tp)
function set.TV(tp, input)
t = input{1};
v = input{2};
if t <= 0
error('The temperature must be positive');
end
if v <= 0
error('The specific volume must be positive');
end
callct('thermo_set_TV', tp.tpID, [t, v]);
end

Expand All @@ -1672,9 +1621,6 @@ function tpClear(tp)
function set.UP(tp, input)
u = input{1};
p = input{2};
if p <= 0
error('The pressure must be positive');
end
callct('thermo_set_UP', tp.tpID, [u, p]);
end

Expand All @@ -1691,9 +1637,6 @@ function tpClear(tp)
function set.UV(tp, input)
u = input{1};
v = input{2};
if v <= 0
error('The specific volume must be positive');
end
callct('thermo_set_UV', tp.tpID, [u, v]);
end

Expand All @@ -1710,9 +1653,6 @@ function tpClear(tp)
function set.VH(tp, input)
v = input{1};
h = input{2};
if v <= 0
error('The specific volume must be positive');
end
callct('thermo_set_VH', tp.tpID, [v, h]);
end

Expand Down
3 changes: 2 additions & 1 deletion interfaces/matlab_experimental/Utility/callct.m
Expand Up @@ -7,7 +7,8 @@
err2 = -999.999;
err3 = double(intmax('uint64'));

output = calllib(ct, varargin);
funcName = varargin{1};
output = calllib(ct, funcName, varargin{2:end});
if output == err2 || output == err3
output = err1;
end
Expand Down
5 changes: 3 additions & 2 deletions interfaces/matlab_experimental/Utility/callct2.m
Expand Up @@ -5,11 +5,12 @@

err1 = -1;

buflen = calllib(ct, varargin, 0, '');
funcName = varargin{1};
buflen = calllib(ct, funcName, varargin{2:end}, 0, '');
if buflen > 0
aa = char(ones(1, buflen));
ptr = libpointer('cstring', aa);
[iok, bb] = calllib(ct, varargin, buflen, ptr);
[iok, bb] = calllib(ct, funcName, varargin{2:end}, buflen, ptr);
output = bb;
clear aa bb ptr;
else
Expand Down

0 comments on commit a8e6790

Please sign in to comment.