diff --git a/include/CoolPropLib.h b/include/CoolPropLib.h index 225a7fcc..ab352e10 100644 --- a/include/CoolPropLib.h +++ b/include/CoolPropLib.h @@ -1,5 +1,4 @@ -/** - * This file defines an interface for shared library (DLL) wrapping +/** \brief This file defines an interface for shared library (DLL) wrapping * * In general the functions defined here take strings which are 0-terminated (C-style), * vectors of doubles are passed as double* and length @@ -50,16 +49,20 @@ #if defined(__powerpc__) || defined(EXTERNC) # undef EXPORT_CODE # define EXPORT_CODE extern "C" - #endif + #endif /** * \overload * \sa \ref CoolProp::Props1SI(std::string, std::string) + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE double CONVENTION Props1SI(const char *FluidName, const char* Output); /** *\overload *\sa \ref CoolProp::PropsSI(const std::string &, const std::string &, double, const std::string &, double, const std::string&) + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref); @@ -67,15 +70,25 @@ *\overload *\sa \ref CoolProp::PhaseSI(const std::string &, double, const std::string &, double, const std::string&) * - * \note this function returns the phase string in pre-allocated phase variable. If buffer is not large enough, no copy is made + * \note This function returns the phase string in pre-allocated phase variable. If buffer is not large enough, no copy is made */ EXPORT_CODE long CONVENTION PhaseSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref, char *phase); - + /** + *\overload + *\sa \ref CoolProp::get_global_param_string + * + * @returns error_code 1 = Ok 0 = error + * + * \note This function returns the output string in pre-allocated char buffer. If buffer is not large enough, no copy is made + */ EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char *Output); /** * \overload * \sa \ref CoolProp::get_parameter_information_string + * \note This function returns the output string in pre-allocated char buffer. If buffer is not large enough, no copy is made + * + * @returns error_code 1 = Ok 0 = error */ EXPORT_CODE long CONVENTION get_parameter_information_string(const char *key, char *Output); /** @@ -86,27 +99,34 @@ /** * \overload * \sa \ref CoolProp::get_fluid_param_string + * + * @returns error_code 1 = Ok 0 = error */ EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char *Output); - /** * \overload * \sa \ref CoolProp::set_reference_stateS + * @returns error_code 1 = Ok 0 = error */ EXPORT_CODE int CONVENTION set_reference_stateS(const char *Ref, const char *reference_state); /** * \overload * \sa \ref CoolProp::set_reference_stateD + * @returns error_code 1 = Ok 0 = error */ EXPORT_CODE int CONVENTION set_reference_stateD(const char *Ref, double T, double rho, double h0, double s0); - /** \brief FORTRAN 77 style wrapper of the PropsSI function + * \overload * \sa \ref CoolProp::PropsSI(const std::string &, const std::string &, double, const std::string &, double, const std::string&) + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE void CONVENTION propssi_(const char *Output, const char *Name1, double *Prop1, const char *Name2, double *Prop2, const char * Ref, double *output); - /** + /** \brief An overload of \ref CoolProp::PropsSI with the mole fractions passed as an array of doubles and the number of * \overload * \sa \ref CoolProp::PropsSIZ + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE double CONVENTION PropsSIZ(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *FluidName, const double *z, int n); @@ -114,8 +134,13 @@ EXPORT_CODE double CONVENTION F2K(double T_F); /// Convert from Kelvin to degrees Fahrenheit (useful primarily for testing) EXPORT_CODE double CONVENTION K2F(double T_K); - + /** \brief Get the index for a parameter "T", "P", etc. + * + * @returns index The index as a long + */ EXPORT_CODE long CONVENTION get_param_index(const char *param); + /** \brief Redirect all output that would go to console (stdout) to a file + */ EXPORT_CODE long CONVENTION redirect_stdout(const char *file); // --------------------------------- @@ -135,23 +160,34 @@ /** \brief DLL wrapper of the HAPropsSI function * \sa \ref HumidAir::HAPropsSI(const char *OutputName, const char *Input1Name, double Input1, const char *Input2Name, double Input2, const char *Input3Name, double Input3); + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE double CONVENTION HAPropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Name3, double Prop3); /** \brief FORTRAN 77 style wrapper of the HAPropsSI function * \sa \ref HumidAir::HAPropsSI(const char *OutputName, const char *Input1Name, double Input1, const char *Input2Name, double Input2, const char *Input3Name, double Input3); + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE void CONVENTION hapropssi_(const char *Output, const char *Name1, double *Prop1, const char *Name2, double *Prop2, const char *Name3, double *Prop3, double *output); /** \brief DLL wrapper of the HAProps function + * + * \warning DEPRECATED!! * \sa \ref HumidAir::HAProps(const char *OutputName, const char *Input1Name, double Input1, const char *Input2Name, double Input2, const char *Input3Name, double Input3); + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) */ EXPORT_CODE double CONVENTION HAProps(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Name3, double Prop3); /** \brief FORTRAN 77 style wrapper of the HAProps function * * \warning DEPRECATED!! - * \sa \ref HumidAir::HAProps(const char *OutputName, const char *Input1Name, double Input1, const char *Input2Name, double Input2, const char *Input3Name, double Input3); */ + * \sa \ref HumidAir::HAProps(const char *OutputName, const char *Input1Name, double Input1, const char *Input2Name, double Input2, const char *Input3Name, double Input3); + * + * \note If there is an error, a huge value will be returned, you can get the error message by doing something like get_global_param_string("errstring",output) + */ EXPORT_CODE void CONVENTION haprops_(const char *Output, const char *Name1, double *Prop1, const char *Name2, double *Prop2, const char *Name3, double *Prop3, double *output); diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 8c842668..44c11e41 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -147,9 +147,14 @@ EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, dou EXPORT_CODE long CONVENTION PhaseSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, char *phase) { std::string _Name1 = Name1, _Name2 = Name2, _FluidName = FluidName; - std::string ph = CoolProp::PhaseSI(_Name1, Prop1, _Name2, Prop2, _FluidName); - if (ph.size() > strlen(phase)){ strcpy(phase, ph.c_str()); } - return 0; + std::string s = CoolProp::PhaseSI(_Name1, Prop1, _Name2, Prop2, _FluidName); + if (s.size() < strlen(Output)){ + strcpy(phase, s.c_str()); + return 1; + } + else{ + return 0; + } } EXPORT_CODE double CONVENTION PropsSIZ(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName, const double *z, int n) { @@ -179,27 +184,44 @@ EXPORT_CODE long CONVENTION get_param_index(const char * param){ } EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Output) { - strcpy(Output,CoolProp::get_global_param_string(param).c_str()); - return 0; + std::string s = CoolProp::get_global_param_string(param).c_str(); + if (s.size() < strlen(Output)){ + strcpy(Output, s.c_str()); + return 1; + } + else{ + return 0; + } } EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output) { int key = CoolProp::get_parameter_index(param); if (key >= 0){ - strcpy(Output, CoolProp::get_parameter_information(key, Output).c_str()); + std::string s = CoolProp::get_parameter_information(key, Output); + if (s.size() < strlen(Output)){ + strcpy(Output, s.c_str()); + return 1; + } + else{ + return 0; + } } else{ strcpy(Output, format("parameter is invalid: %s", param).c_str()); + return 0; + } +} +EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char * Output) +{ + std::string s = CoolProp::get_fluid_param_string(std::string(fluid), std::string(param)); + if (s.size() < strlen(Output)){ + strcpy(Output, s.c_str()); + return 1; + } + else{ + return 0; } - return 0; } -//EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char * Output) -//{ -// strcpy(Output, get_fluid_param_string(std::string(fluid), std::string(param)).c_str()); -// return 0; -//} - - EXPORT_CODE double CONVENTION HAPropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * Name3, double Prop3) { std::string _Output = Output, _Name1 = Name1, _Name2 = Name2, _Name3 = Name3;