This code executes the user function CP_PhaseSI, which is a wrapper for the CoolProp.PhaseSI() function, used to the fluid phase dependent on the state
| 538 | // This code executes the user function CP_PhaseSI, which is a wrapper for |
| 539 | // the CoolProp.PhaseSI() function, used to the fluid phase dependent on the state |
| 540 | static LRESULT CP_PhaseSI(LPMCSTRING PhaseStr, // output (CoolProp phase string) |
| 541 | LPCMCSTRING InputName1, // CoolProp InputName1 |
| 542 | LPCCOMPLEXSCALAR InputProp1, // CoolProp InputProp1 |
| 543 | LPCMCSTRING InputName2, // CoolProp InputName2 |
| 544 | LPCCOMPLEXSCALAR InputProp2, // CoolProp InputProp2 |
| 545 | LPCMCSTRING FluidName) // CoolProp Fluid |
| 546 | { |
| 547 | std::string ph; |
| 548 | std::string Prop1Name(InputName1->str); |
| 549 | std::string Prop2Name(InputName2->str); |
| 550 | std::string FluidString = FluidName->str; |
| 551 | |
| 552 | // check that the first scalar argument is real |
| 553 | LRESULT r = CheckRealOrError(InputProp1, 2); |
| 554 | if (r) return r; |
| 555 | |
| 556 | // check that the second scalar argument is real |
| 557 | r = CheckRealOrError(InputProp2, 4); |
| 558 | if (r) return r; |
| 559 | |
| 560 | // pass the arguments to the CoolProp.phaseSI() function |
| 561 | ph = CoolProp::PhaseSI(InputName1->str, InputProp1->real, InputName2->str, InputProp2->real, FluidName->str); |
| 562 | |
| 563 | // Note: PhaseSI does not throw exceptions, but instead appends the global parameter "errstring" |
| 564 | // to the returned phase string if there is an error and returns "unknown" for the phase string. |
| 565 | // |
| 566 | // Use string search to see if PhaseSI failed with an error message (appended ": <error>")... |
| 567 | if (ph.find("unknown:") != std::string::npos) { |
| 568 | std::string emsg = ph.substr(ph.find(":") + 2, ph.length() - ph.find(":") + 2); |
| 569 | CoolProp::set_error_string(emsg); // reset error string so Mathcad can retrieve it |
| 570 | // Use PropsSI error handling logic to determine the specific error message but with adjusted argument |
| 571 | // positions for PhaseSI (which has no OutputName argument and thus shifts the positions of the InputName |
| 572 | // and InputProp arguments by 1) |
| 573 | return HandlePropsSIError(emsg, Prop1Name, 1u); |
| 574 | } |
| 575 | |
| 576 | // Must use MathcadAllocate(size) so Mathcad can track and release, using Helper routine above |
| 577 | char* c = AllocMathcadString(ph); |
| 578 | // assign the string to the function's output parameter |
| 579 | PhaseStr->str = c; |
| 580 | |
| 581 | // normal return |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | // Helper: centralize text-matching logic for HAPropsSI error handling |
| 586 | static LRESULT HandleHAPropsSIError(const std::string& emsg, const std::string& OutName, const std::string& Prop1Name, const std::string& Prop2Name, |
nothing calls this directly
no test coverage detected