mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Added callct2 utility function to handle all string outputs
This commit is contained in:
parent
94f556cb1d
commit
b980351295
@ -222,14 +222,8 @@ classdef Domain1D < handle
|
||||
s = cell(m);
|
||||
for i = 1:n
|
||||
id = index(i)-1;
|
||||
buflen = callct('domain_componentName', ...
|
||||
d.domainID, id, 0, 0);
|
||||
if buflen > 0
|
||||
aa = char(zeros(1, buflen));
|
||||
[out_buf, aa] = callct('domain_componentName', ...
|
||||
d.domainID, id, buflen, aa);
|
||||
s{i} = aa;
|
||||
end
|
||||
output = callct2('domain_componentName', d.domainID, id);
|
||||
s{i} = output;
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -327,14 +327,9 @@ classdef Kinetics < handle
|
||||
rxn = cell(m, n);
|
||||
for i = 1:m
|
||||
for j = 1:n
|
||||
buflen = callct('kin_getReactionString', kin.kinID, ...
|
||||
irxn - 1, 0, '');
|
||||
if buflen > 0
|
||||
aa = char(zeros(1, buflen));
|
||||
[~, aa] = callct('kin_getReactionString', ...
|
||||
kin.kinID, irxn - 1, buflen, aa);
|
||||
rxn{i, j} = aa;
|
||||
end
|
||||
output = callct2('kin_getReactionString', kin.kinID, ...
|
||||
irxn - 1);
|
||||
rxn{i, j} = output;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -94,10 +94,15 @@ classdef ThermoPhase < handle
|
||||
threshold = 1e-14;
|
||||
end
|
||||
buflen = 0 - callct('thermo_report', tp.tpID, 0, '', 1);
|
||||
aa = char([zeros(1, buflen, 'int8')]);
|
||||
aa = char(ones(1, buflen));
|
||||
ptr = libpointer('cstring', aa);
|
||||
[iok, bb] = callct('thermo_report', tp.tpID, buflen, ptr, 1);
|
||||
disp(bb);
|
||||
if iok < 0
|
||||
error(geterr);
|
||||
else
|
||||
disp(bb);
|
||||
end
|
||||
clear aa bb ptr
|
||||
end
|
||||
|
||||
function tpClear(tp)
|
||||
@ -497,14 +502,8 @@ classdef ThermoPhase < handle
|
||||
for i = 1:m
|
||||
for j = 1:n
|
||||
ksp = k(i, j) - 1;
|
||||
buflen = callct('thermo_getSpeciesName', ...
|
||||
tp.tpID, ksp, 0, '');
|
||||
if buflen > 0
|
||||
aa = char(zeros(1, buflen));
|
||||
[~, aa] = callct('thermo_getSpeciesName', ...
|
||||
tp.tpID, ksp, buflen, aa);
|
||||
nm{i, j} = aa;
|
||||
end
|
||||
output = callct2('thermo_getSpeciesName', tp.tpID, ksp);
|
||||
nm{i, j} = aa;
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -826,15 +825,7 @@ classdef ThermoPhase < handle
|
||||
% :return:
|
||||
% An string identifying the equation of state.
|
||||
%
|
||||
buflen = callct('thermo_getEosType', tp.tpID, 0, '');
|
||||
if buflen > 0
|
||||
aa = char([zeros(1, buflen, 'int8')]);
|
||||
ptr = libpointer('cstring', aa);
|
||||
[~, bb] = callct('thermo_getEosType', ...
|
||||
tp.tpID, buflen, ptr);
|
||||
e = bb;
|
||||
clear aa bb ptr;
|
||||
end
|
||||
e = callct2('thermo_getEosType', tp.tpID);
|
||||
end
|
||||
|
||||
function v = isIdealGas(tp)
|
||||
|
@ -1,16 +1,17 @@
|
||||
function output = callct(varargin)
|
||||
% CALLCT
|
||||
% This is a simplified single output variant
|
||||
% Calls Cantera library functions with single outputs and returns
|
||||
% errors if necessary.
|
||||
|
||||
err1 = -1;
|
||||
err2 = -999.999;
|
||||
err3 = double(intmax('uint64'));
|
||||
|
||||
methodname = varargin{1};
|
||||
output = calllib(ct, methodname, varargin{2:end});
|
||||
output = calllib(ct, varargin);
|
||||
if output == err2 || output == err3
|
||||
output = -1;
|
||||
output = err1;
|
||||
end
|
||||
if output == -1
|
||||
geterr;
|
||||
if output == err1
|
||||
error(geterr);
|
||||
end
|
||||
end
|
||||
|
21
interfaces/matlab_experimental/Utility/callct2.m
Normal file
21
interfaces/matlab_experimental/Utility/callct2.m
Normal file
@ -0,0 +1,21 @@
|
||||
function output = callct2(varargin)
|
||||
% CALLCT2
|
||||
% Calls Cantera library functions with string outputs and returns
|
||||
% errors if necessary.
|
||||
|
||||
err1 = -1;
|
||||
|
||||
buflen = calllib(ct, varargin, 0, '');
|
||||
if buflen > 0
|
||||
aa = char(ones(1, buflen));
|
||||
ptr = libpointer('cstring', aa);
|
||||
[iok, bb] = calllib(ct, varargin, buflen, ptr);
|
||||
output = bb;
|
||||
clear aa bb ptr;
|
||||
else
|
||||
error(geterr);
|
||||
end
|
||||
if iok == -err1
|
||||
error(geterr);
|
||||
end
|
||||
end
|
@ -4,9 +4,9 @@ function e = geterr()
|
||||
checklib;
|
||||
try
|
||||
buflen = calllib(ct, 'ct_getCanteraError', 0, '');
|
||||
aa = zeros(1, buflen+1, 'int8');
|
||||
ptr = libpointer('voidPtr', aa);
|
||||
[~, bb] = calllib(ct, 'ct_getCanteraError', buflen, ptr);
|
||||
aa = char(ones(1, buflen));
|
||||
ptr = libpointer('cstring', aa);
|
||||
[iok, bb] = calllib(ct, 'ct_getCanteraError', buflen, ptr);
|
||||
e = bb;
|
||||
clear aa bb ptr
|
||||
catch ME
|
||||
|
Loading…
Reference in New Issue
Block a user