Helper: centralize text-matching logic for Props1SI error handling
| 280 | |
| 281 | // Helper: centralize text-matching logic for Props1SI error handling |
| 282 | static LRESULT HandleProps1SIError(const std::string& emsg, const std::string& FluidString, const std::string& PropName) { |
| 283 | auto contains = [&](const char* s) { return emsg.find(s) != std::string::npos; }; |
| 284 | std::string mixName = ""; // Temp variable to hold the name of the mixture string argument for error checking, if needed |
| 285 | unsigned int errPos = 0; // Temp variable to hold the position of the error argument for returning to Mathcad, if needed |
| 286 | |
| 287 | // Check for "valid fluid" error first, since it is the most common error and can have multiple causes |
| 288 | // that require parsing the error message to determine the specific error type and position. |
| 289 | if (contains("valid fluid")) { |
| 290 | if (contains("Neither input")) { |
| 291 | if (contains("REFPROP")) { // REFPROP or REFPROP Fluid not found |
| 292 | errPos = (FluidString.find("REFPROP") != std::string::npos) ? 1u : 2u; |
| 293 | return MAKELRESULT(BAD_FLUID, errPos); |
| 294 | } |
| 295 | if (contains("IF97")) { // Something other than "Water" was used to IF97 |
| 296 | errPos = (FluidString.find("IF97") != std::string::npos) ? 1u : 2u; |
| 297 | return MAKELRESULT(BAD_IF97_FLUID, errPos); |
| 298 | } |
| 299 | if (lower(FluidString).find(".mix") != std::string::npos) { // Mixture string error position 1 |
| 300 | errPos = 1u; |
| 301 | mixName = FluidString; |
| 302 | } else if (lower(PropName).find(".mix") != std::string::npos) { // Mixture string error position 2 |
| 303 | errPos = 2u; |
| 304 | mixName = PropName; |
| 305 | } |
| 306 | if (!mixName.empty()) { |
| 307 | Dictionary dict; |
| 308 | if (!CoolProp::is_predefined_mixture(mixName, dict)) // Mixture string was used, but not found in CoolProp's predefined mixtures |
| 309 | return MAKELRESULT(BAD_MIXTURE, errPos); |
| 310 | else |
| 311 | return MAKELRESULT(MISSING_BINARY_PAIR, errPos); // Likely missing a binary interaction pair. |
| 312 | } |
| 313 | return MAKELRESULT(BAD_FLUID, 1); |
| 314 | } else { // "Both inputs" |
| 315 | return MAKELRESULT(BAD_PARAMETER, 2); |
| 316 | } |
| 317 | } |
| 318 | // Check for "invalid parameter" errors next... |
| 319 | // The parameter name will be surrounded by brackets in the error message, so add brackets to the parameter name for searching |
| 320 | std::string PropNameBrackets = "[" + PropName + "]"; |
| 321 | if (contains("Unable to use")) { |
| 322 | errPos = (emsg.find(PropNameBrackets) != std::string::npos) ? 2u : 1u; |
| 323 | if (contains("Output string is invalid")) return MAKELRESULT(BAD_PARAMETER, errPos); |
| 324 | if (contains("non-trivial")) return MAKELRESULT(NON_TRIVIAL, errPos); |
| 325 | if (contains("No outputs")) return MAKELRESULT(NOT_AVAIL, errPos); |
| 326 | return MAKELRESULT(UNKNOWN, errPos); |
| 327 | } |
| 328 | // Otherwise, un-trapped error. Return generic error code and have user check get_global_param_string("errstring") for details |
| 329 | return MAKELRESULT(UNKNOWN, 1); |
| 330 | } |
| 331 | |
| 332 | // This code executes the user function CP_Props1SI, which is a wrapper for |
| 333 | // the CoolProp.Props1SI() function, used to simply extract a |
no test coverage detected