MATLAB® interface to REFPROP and CoolProp
REFPROP is a fluids property program that calcuates thermodynamic and transport properties, which is created and maintained by NIST.
CoolProp is a fluids property program that calculates thermodynamic and transport properties, which is created and maintained as freeware by Ian Bell.
This repository contains a single MATLAB interface to extract the properties of interest from either program for use in models and simulation.
For the functions in this repository to work properly, the user must have the following installed on their computer: NOTE: The user only needs either REFPROP or CoolProp. It is not necessary to install both programs.
- MATLAB - we recommend the latest release of MATLAB, but it should work for R2020a or later, and it may work in even older releases.
- REFPROP version 10.x
- CoolProp version 6.6.0 (This will likely be installed in C:\users\<userName>\AppData\Roaming\CoolProp)
- A C/C++ compiler - Current MATLAB Release compiler support Previous MATLAB Releases compiler support
This repository contains the following directories and files.
- toolbox directory - this directory contains all the files necessary to use the interface to call REFPROP or CoolProp
- examples directory - this directory contains all the examples the user can refer to for how to use the interface
- helperfunctions directory - this directory contains helper functions used in the desgin cycle examples
- callingCoolProp.m - this script shows the various way the user can use the getFluidProperty function to call CoolProp and obtain desired fluid properties
- callingREFPROP.m - this script shows the various way the user can use the getFluidProperty function to call REFPROP and obtain desired fluid properties
- designCycleSingle_CoolProp.m - this script provides an example of creating TS and PH diagrams using CoolProp.
- designCycleSingle_REFPROP.m - this script provides an example of creating TS and PH diagrams using REFPROP.
- internal directory - this directory contains the necessary files for interfacing with REFPROP.
- include directory - this directory contains the files as include files for interfacing with REFPROP.
- Coolprop.rights - this is the license file for using CoolProp
- REFPROP_lib.h - this is the header file required by hiLevelMexC.cpp to include to use REFPROP.
- hiLevelMexC.cpp - this file is used through mex by MATLAB to interface with REFPROP.
- MLCoolProp.m - this file defines the MLCoolProp class used by getFluidProperty.m to interface to CoolProp
- MLrefprop.m this file defines the function used by MATLAB to interface with REFPROP
- include directory - this directory contains the files as include files for interfacing with REFPROP.
- createREFPROPmex.m - this file defines the function the user should run the to create the mex file necessary to interface with REFPROP.
- getFluidProperty.m - this file defines the interface the user will use to call REFPROP or CoolProp.
- examples directory - this directory contains all the examples the user can refer to for how to use the interface
- .gitattributes - this file is an artifact of the git repo
- .gitignore - this file is an artifact of the git repo
- license.txt - this is the license file for using this MATLAB toolbox
- Matlabinterfacerefpropcoolprop.prj - this file is the MATLAB project file which sets all the necessary paths and provides the user git interface through MATLAB.
- README.md - this is the README file for the git repo
- SECURITY.md - this file provides information on reporting a security vulnerability discovered with this toolbox
Once the user has all requirements fulfilled, they must run the createREFPROPmex.m script. This will compile the C++ file using MEX. The user only needs to complete this step once. If someone makes changes to the header or C++ file this step must be repeated.
- open MATLABInterfaceREFPROPCoolProp.prj
- run createREFPROPmex.m
Now the user is ready to get fluid properties.
Whether the user wants to access REFPROP or CoolProp, the interface through the getFluidProperty function is the same.
The inputs to getFluidProperty are:
- libraryLocation - (string) the location of the REFPROP or CoolProp library files (dll, exe, etc.)
- requestedProperty - (string) the thermodynamic property name for which the value will be returned
- inputProperty1 - (string) name of the 1st property used as the state point
- inputProperty1Value - (double) 1xM array of values of the 1st property used as the state point in the library's expected units
- inputProperty2 - (string) name of the 2nd property used as the state point
- inputProperty2Value - (double) 1xN array of values of the 2nd property used as the state point in the library's expected units
- fluid - (string) indicating the fluid for which the requested property should be calculated e.g.,
- Use standard fluids already available in the library: "Water", "Ethanol", etc.
- User defined fluids: "Nitrogen;Oxygen;Hydrogen;Water" NOTE: if the user defines their own fluid, the species should be listed out as in the last example above using only a semicolon (;) to separate the species
- fluidComposition - (double) array of size 1xP species fraction where 1 <= P <= 20, whose values must sum to 1, P must match the number of species in the fluid e.g.,
- if fluid = "Water", (numSpec = 1) and fluidComposition = 1;
- if fluid = "Nitrogen;Oxygen;Hydrogen;Water", (numSpec = 4) and fluidComposition = [0.71, 0.16, 0.1, 0.03]
- massOrMolar - [REFPROP only] (int) value to determine input composition units: 0 -> Molar, 1 -> Mass
- desiredUnits - [REFPROP only] (char) enum as expected by refprop.dll to determine the units to use e.g., MKS, MASS BASE SI, etc.
- keepLibraryLoaded - [CoolProp only] (boolean) this value should be provided as a (name, value) or name=value pair - defaults to false, which will cause the CoolProp library to load and unload with every call to getFluidProperty. Keep this at default unless it is necessary to make many function calls in the same task. If the user passes in an array of inputs to a single function call, the library will remain loaded. If the user needs to make a function call in a loop, it might be beneficial to set the value to true. This will keep the CoolProp library loaded between calls to getFluidProperty. It takes a couple secods to load and unload the library, and this will impact the runtime of the task. Note: When keeping the library loaded, it is important for the user to remember to unload the library at the end of the task. See the CoolProp example scripts in example directory.
See REFPROP documentation and CoolProp documentation for allowed values for requested and input properties.
requestedPropertyValue = (double) (MxN) array of values for the requested thermodynamic property as calculated by the library in the library's expected units where M is the number of values for the first input property and N is the number of values for the second input property.
Copyright 2025 The MathWorks, Inc.