This code executes the user function CP_set_reference_state, which is a wrapper for the CoolProp.set_reference_stateS() function, used to set the H/S reference states based on a standard state string of "IIR", "ASHRAE", "NBP", or "DEF".
| 246 | // the CoolProp.set_reference_stateS() function, used to set the H/S reference states |
| 247 | // based on a standard state string of "IIR", "ASHRAE", "NBP", or "DEF". |
| 248 | static LRESULT CP_set_reference_state(LPCOMPLEXSCALAR Conf, // output (dummy value) |
| 249 | LPCMCSTRING FluidName, // name of fluid (string) to retrieve |
| 250 | LPCMCSTRING StateStr) // name of standard state (string) to set |
| 251 | { |
| 252 | // Invoke the set_reference_stateS() function, no result from this void function. |
| 253 | try { |
| 254 | CoolProp::set_reference_stateS(FluidName->str, StateStr->str); |
| 255 | } catch (const CoolProp::ValueError& e) { |
| 256 | std::string emsg(e.what()); |
| 257 | CoolProp::set_error_string(emsg); |
| 258 | |
| 259 | // Normalize the error message to lowercase to simplify substring checks and |
| 260 | // avoid repeating checks for different capitalizations. |
| 261 | std::string emsg_l = emsg; |
| 262 | std::transform(emsg_l.begin(), emsg_l.end(), emsg_l.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); |
| 263 | |
| 264 | if (emsg_l.find("key") != std::string::npos) |
| 265 | return MAKELRESULT(BAD_FLUID, 1); |
| 266 | else if ((emsg_l.find("cannot use") != std::string::npos) || (emsg_l.find("temperature to qt_flash") != std::string::npos)) |
| 267 | return MAKELRESULT(BAD_REF, 2); |
| 268 | else if (emsg_l.find("reference state") != std::string::npos) |
| 269 | return MAKELRESULT(BAD_PARAMETER, 2); |
| 270 | else |
| 271 | return MAKELRESULT(UNKNOWN, 1); |
| 272 | } |
| 273 | |
| 274 | // assign the dummy return value |
| 275 | Conf->real = 0; |
| 276 | |
| 277 | // normal return |
| 278 | return 0; |
| 279 | } |
| 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) { |
nothing calls this directly
no test coverage detected