Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Example of Calling REFPROP From a Mathcad Prime 3.0 Worksheet (via Excel Component)


Example of Calling REFPROP From a Mathcad Prime 3.0 Worksheet (via Excel Component)

I'm an engineer at NASA. We use a NIST Standard Reference Database ( called REFPROP to get the thermodynamic and transport properties needed to support our fluid calcs.

The underlying code base in written in Fortran, but NIST provides several different methods for accessing the property data including:

1) a stand-alone GUI

2) an Excel Add-in

3) instructions for adding wrapper code to create C-code compatible DLL's

I'm a long-time user of the Excel Add-in (and creating a DLL is beyong my programming level), but, given how units-intensive most of my calcs are, I was interested in seeing if Mathcad might be a viable alternative.

I looked at Prime 2.0 last year, but based on how "crippled" it seemed to be relative to 15.0 I held off until Prime 3.0 came out.

With the NIST-supplied REFPROP add-in loaded into my copy of Excel, I opened a Prime 3.0 worksheet, added an Excel component, and entered a REFPROP function call. At first it seemed to work, but later I noticed that, most of the time it didn't (the function call returned a #VALUE error message indicating Excel couldn't find it).

Since I didn't have any 15.0 worksheets to convert I didn't read through the conversion guide, but later I found this note:

"PTC Mathcad Prime 3.0 does not support the use of an Excel component to define functions. If a legacy file contains a function definition that depends on an Excel component, the conversion fails."

Curious as to why it worked at all (sometimes), I played around with it and discovered that if I opened Excel first (which got the add-in loaded successfully) and then opened my test worksheet (attached), the embedded Excel worksheet opened in the existing instance of Excel so it was able to access the Add-in successfully. If I didn't happen to already have a copy of Excel open, the embedded Excel worksheet opened in a new instance of Excel and the Add-in failed to load properly.

A Google search confirmed that the start sequence for embedded OLE files (like the Mathcad Excel Component) is not the same as the normal start sequence and it is a known issue that these differences can cause problems with getting Add-Ins to load properly when the target application is opened using an embedded link (as it is in Mathcad). The recommended fix is to modify the calling code to manually call the add-in, but in this case that isn't an option (since the calling code is part of the Mathcad code base).

Regardless, althought he workaround isn't very elegant, it is simple and does appear to work so figured I'd pass it along in case anyone else was having trouble getting a critical Excel add-in to work with the Prime 3.0 Excel Component feature.

I'm still skeptical that this kludge will turn out to be an acceptable solution for my needs, so unless I can find someone to help me get the DLL written I will probably pass, again, on this version of Mathcad.

P.S. If you're still using Mathcad 15.0 this REFPROP-specific solution appears to work for it ( Given all the conversion issues and the fact that it will eventually be deprecated, probably sooner rather than later, I don't really have any interest in starting my Mathcad calcs in 15.0 rather than Prime.



But I use one other way - create Mathcad function based on Refprop and use its inbcalculation.

One last example


The Refprop author is my friend


I think that Valery might be alluding to this, but NIST provides the Fortran source for these functions with the RefProp package.  You can write

  1. Compile these Fortran functions into a library
  2. Write C wrappers for each function
  3. Register these wrappers into a Custom Function library and compile it as a DLL

This will allow you to call the RefProp functions directly without Excel.  I've done this and know that it works, but unfortunately can't provide you with any code.

Good Luck!

I have used DLLs for RefProp in Mathcad too. But it is very difficult...

But now I use - see above

Hello Valery,


Are you able to share the compiled REFPROP dll you created for use in MathCAD Prime 3.0?

Top Tags