Skip to content

Commit

Permalink
[Matlab] Fix error handling for nAtoms to avoid false positives
Browse files Browse the repository at this point in the history
Species can have negative "atoms" of an "element" in the case where the element
is an electron and the species is a positive ion.
  • Loading branch information
speth committed Sep 8, 2015
1 parent 54a71b8 commit 0e4b0cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ extern "C" {
try {
return ThermoCabinet::item(n).nAtoms(k,m);
} catch (...) {
return handleAllExceptions(-1, ERR);
return handleAllExceptions(ERR, ERR);
}
}

Expand Down
33 changes: 29 additions & 4 deletions src/matlab/phasemethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,46 @@ void phasemethods(int nlhs, mxArray* plhs[],
case 1:
// floating-point attributes
vv = phase_temperature(ph);
if (vv == DERR) {
reportError();
}
break;
case 2:
vv = phase_density(ph);
if (vv == DERR) {
reportError();
}
break;
case 3:
vv = phase_molarDensity(ph);
if (vv == DERR) {
reportError();
}
break;
case 4:
vv = phase_meanMolecularWeight(ph);
if (vv == DERR) {
reportError();
}
break;
case 8:
vv = 1.0/phase_density(ph);
vv = phase_density(ph);
if (vv == DERR) {
reportError();
}
vv = 1.0/vv;
break;
case 10:
vv = static_cast<int>(phase_nElements(ph));
if (vv == -1) {
reportError();
}
break;
case 11:
vv = static_cast<int>(phase_nSpecies(ph));
if (vv == -1) {
reportError();
}
break;
case 12:
input_buf = getString(prhs[3]);
Expand All @@ -143,18 +165,21 @@ void phasemethods(int nlhs, mxArray* plhs[],
k = getInt(prhs[3]);
m = getInt(prhs[4]);
vv = phase_nAtoms(ph,k-1,m-1);
if (vv == ERR) {
reportError();
}
break;
case 15:
show_thermo = getInt(prhs[3]);
threshold = getDouble(prhs[4]);
vv = write_phase(ph,show_thermo,threshold);
if (vv == -1 || vv == ERR) {
reportError();
}
break;
default:
mexErrMsgTxt("Unknown job number");
}
if (vv == DERR || vv == -1 || vv == ERR) {
reportError();
}
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double* h = mxGetPr(plhs[0]);
*h = vv;
Expand Down

0 comments on commit 0e4b0cb

Please sign in to comment.