usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
191 stars 126 forks source link

Include Refprop dll in Fortran #164

Closed KayvanA closed 5 years ago

KayvanA commented 5 years ago

I am using Reprop 10.0.

I am trying to make a simple program in Intel Visual Fortran that would call Refprop. So far I only am using 1 command from Refprop: just trying to set the fluid via SETFLUIDS command. However, when I compile the project, I get the errors below. I think it means that I am not including the DLL file in my project.

Errors: error LNK2019: unresolved external symbol _SETFLUIDS referenced in function _TEST_CALL fatal error LNK1120: 1 unresolved externals

I have included a copy of Refprop folder next to my project and have included it in ‘Additional Include Directories’.

I have also added Refprop.dll into the project tree by right-clicking on the project, clicking ‘Add’ and then ‘Existing Item…’, as shown below.

So Refprop.dll shows at the end of the project tree list.

However, I still get the errors that I mentioned. Could you please help me rectify these errors? If you have an example Fortran Project that calls RefProp that would be helpful.

Thank you, Kayvan

ianhbell commented 5 years ago

You need to add the .lib to your visual studio project as well. The REFPRP64.lib file includes the import functions that you will need to call in your FORTRAN code and should fix this. If the Intel FORTRAN versions are different, you may need to compile REFPROP yourself: https://github.com/usnistgov/REFPROP-cmake

KayvanA commented 5 years ago

Thank you, Ian, for your response. Could you please tell me how I should include the library in my Intel Fortran project? Should I use a command within my code text?

-The file REFPRP64.lib is already in the folder that I had included in the project, using 'Additional Include Directories' under the project Properties->Fortran->General. Please see the attached pictures 1 and 2.

-I also added REFPRP64.lib into the project tree by right-clicking on the project, clicking ‘Add’ and then ‘Existing Item…’, as shown in the attached picture 3.

Is there something else I should do?

Thanks, Kayvan

1 2 3

ianhbell commented 5 years ago

In the linker, you need to specify this import library (REFPRP64.lib). I'm not 100% sure how to properly set up the DLL dependency in VS, but I think you need to add the DLL, right-click on it, and say copy to build, or so.

KayvanA commented 5 years ago

I tried adding REFPRP64.lib under Linker as well, but it gave me new errors and was unable to open it (pictures attached). I tried with and without including the folder name, but still got the same errors.

4 5 6

ianhbell commented 5 years ago

Provide the absolute path to the LIB file

KayvanA commented 5 years ago

I tried this as well. Unfortunately for me, it did not work. It first did not like the spaces in the absolute folder name. So I also copied all the files to C:\REFPROP and changed all the references to this folder, but I still got the attached errors.

I also noticed that under Fortran there is an item called Libraries. Should I do something there? It does not seem to have a place to insert the file though. Please see the last attached picture.

Thanks, Kayvan

9 7 8

KayvanA commented 5 years ago

Any other comments, Ian? Is there anything else I can do to get it to work?

ianhbell commented 5 years ago

I think there is a fundamental miscommunication here that I should have picked up on before. Do you want to call the shared library of REFPROP, or to compile the FORTRAN source of REFPROP into your project? The solutions are very different for these two methods.

To compile REFPROP into your project, just add all the FORTRAN files in the FORTRAN folder of the REFPROP install into your project (don't copy them, just add as reference)

KayvanA commented 5 years ago

I am not trying to compile Refprop. I would like to be able to call Refprop as a function within my own program. If you can tell me in baby-steps how I can do that, I would appreciate that.

ianhbell commented 5 years ago

Then you need to call the shared library of REFPROP. I’m working on putting together a functional example of this. Watch this space.

ianhbell commented 5 years ago

You may still need to compile REFPROP, to ensure that the import library is compatible.

Nonetheless, if you want to call the DLL your code needs to call the functions that are exposed in the DLL: https://refprop-docs.readthedocs.io/en/latest/DLL/index.html (you called the FORTRAN equivalent that is not exposed in the DLL)

ianhbell commented 5 years ago

I tried to make an example that would call the REFPROP DLL from FORTRAN, but I don't think it will ever work on windows because FORTRAN isn't case sensitive, but the names of functions in DLL are. It might work on linux.

So the short answer is you need to compile REFPROP into your FORTRAN project.

KayvanA commented 5 years ago

I am using only ONE function that is endorsed by Refprop 10.0 documentation also. It is SETFLUIDS . I also tried using SETFLUIDSdll for the function call. Could you please explain what you mean by "you called the FORTRAN equivalent that is not exposed in the DLL)"?

Also, I was hoping I will not have to compile your code (Refprop) with mine...but if I have to, could you please tell me in baby-steps how I should accomplish this. I looked at this link that you sent earlier, but it's not clear what I should do. https://github.com/usnistgov/REFPROP-cmake

For example, please tell me: 1-download this file(s) 2-Make a folder called XYZ, 3-In Fortran Compiler, under Project Properties, do this, etc. ... Thanks.

ianhbell commented 5 years ago

What documentation are you referring to?

To compile REFPROP source into your visual studio project, right click on your tests project, "add existing..." or equivalent, and find the .FOR files in the "c:\Program Files (x86)\REFPROP\FORTRAN" folder or equivalent, select all of them. Compile.

KayvanA commented 5 years ago

I am referring to Refprop documentation:

https://www.nist.gov/sites/default/files/documents/2018/05/23/refprop10a.pdf

ianhbell commented 5 years ago

This is the documentation for the functions that are exposed by the DLL: https://refprop-docs.readthedocs.io/en/latest/DLL/index.html (not only SETFLUIDS)

KayvanA commented 5 years ago

Thanks, Ian and Eric, compiling the Fortran files directly with my project worked and this time I got no errors. However, I get 0 for saturation pressure when I call Refprop1. Please see my little code below. What am I missing? For saturated vapor, I should get P=0.14388 MPa.

subroutine test_call()

      implicit none
      integer, parameter :: ncmax=150    
      integer, parameter :: ipropmax=200
      double precision P,T,V,Output,z,q 
      dimension z(ncmax)
      dimension Output(ipropmax)
      integer iUnit,iMass,ierr
      character*255 hOut,herr

      iMass=1 ! Mass basis properties
      iUnit=3 ! SI with C; 

      T=20 ! Mpa
      q=1  ! quality
      call SETMIXTURE ('R410A',z,ierr)  
      call REFPROP1 ('TQ','P',iUnit,iMass,T,q,z,P,q,ierr,herr)
      Print *,'Psat at the temperature',T,' (Celsius)is: ',P,'(MPa)'

      Print *,'Program finished successfully.'
  end subroutine
EricLemmon commented 5 years ago

I see two problems, one is that ncmax is set to 150, but it should be 20. Second is that you are sending the variable q twice in the call to REFPROP1. Make the second q something like qcalc and see if that works.

EricLemmon commented 5 years ago

And a third problem: The call to SETMIXTURE always returns the compositions in mole fractions. There is no option in that call to return mass fractions. But in your call to REFPROP1, you send it a flag that indicates the compositions are mass. It would be better to not use SETMIXTURE in this case and do something like this to initialize the R410A mixture:

      call REFPROP ('R410A',' ',' ',iUnit,iMass,iFlag,
     &      0d0,0d0,z,Output,hOut,i,x,y,x3,qcalc,ierr,herr) 
KayvanA commented 5 years ago

Thanks, Eric. I applied the changes that you mentioned. However, now I get -9999990 for saturation pressure. Here is my updated code for reference:

  subroutine test_call()

  implicit none
  integer, parameter :: ncmax=20 
  integer, parameter :: ipropmax=200
  double precision P,T,V,Output,z,q,qcalc
  double precision x_comp1,y_comp1,x3_comp 
  dimension z(ncmax),x_comp1(ncmax),y_comp1(ncmax),x3_comp(ncmax)
  dimension Output(ipropmax)
  integer iUnit,iMass,ierr,iFlag
  character*255 hOut,herr

  iMass=1 ! Mass basis properties
  iUnit=3 ! SI with C; 

  call REFPROP ('R410A',' ',' ',iUnit,iMass,iFlag,
 &0d0,0d0,z,Output,hOut,iUnit,x_comp1,y_comp1,x3_comp,qcalc,
 &ierr,herr)

  T=20 ! Celsius
  q=1  ! quality
  call REFPROP1 ('TQ','P',iUnit,iMass,T,q,z,P,qcalc,ierr,herr)
  Print *,'Psat at the temperature',T,' (Celsius)is: ',P,'(MPa)'

  Print *,'Program finished successfully.'
  end subroutine
EricLemmon commented 5 years ago

In this case you are calling REFPROP with iUnit used twice. The value was changed in the call and that's why your properties did not come back correctly. Instead, try the code below. Note that instead of setting iUnit=3, I called the GETENUM routine to obtain that value. This way if the hardcoded numbers ever change in future versions, the GETENUM routine will update to the correct value. It is extremely unlikely that we will change the unit numbers, at least for the common inputs, but this is best practice. I also changed the call from REFPROP to REFPROP2, which does not contain the x, y, and x3 arrays. But be careful with the iFlag value and be sure to read the comments in the REFPROP2 routine to understand what the inputs are for that variable.

      call GETENUM (0,'SI with C',iUnit,ierr,herr) ! SI with C; 
      iMass=1 ! Mass basis properties

c     call REFPROP ('R410A',' ',' ',iUnit,iMass,iFlag,
c    &0d0,0d0,z,Output,hOut,iOut,x,y,x3,q,ierr,herr) 

      iFlag=3 ! Use mass basis and call splines.
      call REFPROP2 ('R410A',' ',' ',iUnit,iFlag,T,P,z,Output,q,ierr,herr)

      T=20 ! Celsius
      q=1  ! quality
      call REFPROP1 ('TQ','P',iUnit,iMass,T,q,z,P,qcalc,ierr,herr)
KayvanA commented 5 years ago

I incorporated the changes. However, I still get a value that does not agree with what Chemours has published. At 20C, they list the saturated vapor pressure to be 1.4388 MPa. However, REFPROP is giving me 1.4678 MPa. Here is the link to Chemours R410a properties: https://www.chemours.com/Refrigerants/en_US/assets/downloads/h64423_Suva410A_thermo_prop_si.pdf

Also, here is my code for reference:

 subroutine test_call()

  implicit none
  integer, parameter :: ncmax=20
  integer, parameter :: ipropmax=200
  double precision P,T,V,Output,z,q,qcalc
  dimension z(ncmax)
  dimension Output(ipropmax)
  integer iUnit,iMass,ierr,iFlag
  character*255 hOut,herr

  call GETENUM(0,'SI with C',iUnit,ierr,herr) ! SI with C; 
  iMass=1 ! Mass basis properties

  iFlag=3 ! Use mass basis and call splines.
  call REFPROP2('R410A',' ',' ',iUnit,iFlag,T,P,z,Output,q,ierr
 &,herr)

  T=20 ! Celsius
  q=1  ! quality
  call REFPROP1('TQ','P',iUnit,iMass,T,q,z,P,qcalc,ierr,herr)
  Print *,'Psat at the temperature',T,' (Celsius)is: ',P,'(MPa)'

  Print *,'Program finished successfully.'
  end subroutine
KayvanA commented 5 years ago

Also, I just tried Refprop in Excel and it gives a third value, which does not agree with Fortran or Chemours. For R410A, at 20C, below are the three values I got for vapor saturation pressure:

-Refprop in Excel: 1.4429 MPa -Refprop in Fortran: 1.4678 MPa -Chemours website: 1.4388 MPa

EricLemmon commented 5 years ago

Try it again with this code and hopefully it works. Note that I added both dew and bubble point calculations to make sure there's no confusion as to which state is being calculated.

As for Chemours reporting different values, I'll ask some colleagues there to check about the disagreement.

      program test_call
      implicit none
      integer, parameter :: ncmax=20
      integer, parameter :: ipropmax=200
      double precision x(ncmax),y(ncmax),x3(ncmax),z(ncmax)
      double precision P,T,V,Output,q,qcalc
      dimension Output(ipropmax)
      integer iUnit,iMass,ierr,iFlag,iOut
      character*255 hOut,herr

      call GETENUM(0,'SI with C',iUnit,ierr,herr) ! SI with C; 
      iMass=1 ! Mass basis properties

      call REFPROP ('R410A',' ',' ',iUnit,iMass,0,
     &              0d0,0d0,z,Output,hout,iOut,x,y,x3,q,ierr,herr) 

      T=20 ! Celsius
      q=1  ! quality
      call REFPROP1('TQ','P',iUnit,iMass,T,q,z,P,qcalc,ierr,herr)
      Print *,'Dew-point pressure at the temperature',T,' (Celsius)is: ',P,'(MPa)'

      q=0  ! quality
      call REFPROP1('TQ','P',iUnit,iMass,T,q,z,P,qcalc,ierr,herr)
      Print *,'Bubble-point pressure at the temperature',T,' (Celsius)is: ',P,'(MPa)'

      Print *,'Program finished successfully.'
      end
KayvanA commented 5 years ago

Thanks, Eric. Refprop Fortran and Excel agree now, yet the discrepancy between Refprop and Chemours published data still exists. For R410A, at 20C, below are the three values I get for vapor saturation pressure: -Refprop in Excel: 1.44297659378853 MPa -Refprop in Fortran: 1.44297659378839 MPa -Chemours website: 1.4388 MPa

I have two more questions:

1-What was causing the issue in the previous code? Should we not use REFPROP2 to set the fluid? I am asking this to be aware and cautious for my future projects.

2-I realize that Refprop does not interpolate, but it should start from some source/initial data. What is the refrigerant source data for Refprop and where do you get it from? Chemours?

KayvanA commented 5 years ago

Am I making a mistake in the below call?

call REFPROP1('TP','S,H',iUnit,iMass,T_compressor_in, &P_compressor_in,z,Output,qcalc,ierr,herr) s_compressor_in =Output(1) !kJ/(kg.K) h_compressor_in = Output(2) !kJ/kg

It gives me h_compressor_in=-9999990. Below is my full code for reference.

  subroutine test_call()
  implicit none
  integer, parameter :: ncmax=20
  integer, parameter :: ipropmax=200
  double precision dummy1(ncmax),dummy2(ncmax),dummy3(ncmax)
  double precision P,T,V,q,qcalc,z(ncmax),Output(ipropmax)
  double precision P_evaporator,P_condenser
  double precision T_evaporator,T_condenser
  double precision s_compressor_in,s_compressor_out
  double precision h_compressor_in,h_compressor_out
  double precision P_compressor_in,P_compressor_out
  double precision T_compressor_in,T_compressor_out
  double precision dT_superheat,dT_subcool
  integer iUnit,iMass,ierr,iFlag,iOut
  character*255 hOut,herr,Refrigerant

  ! 'SI with C' is used in Refprop. Its units are:
  ! MPa (pressure), kg/m3 (density), kJ/kg (enthalpy), kJ/(kg.K) (entropy), 
  ! cm2/s (kinematic viscosity), uPa.s (viscosity), m/s (speed),
  ! mW/(m.K) (thermal conductivity), mN/m (surface tension), kg/kmol (molar mass)

  Refrigerant='R410A'
  iMass=1 ! Mass basis properties

  ! setting up the units: This way iUnit will be set once and Reforop won't 
  ! have to use 'SI with C' every time, which would slow it down.
  call GETENUM(0,'SI with C',iUnit,ierr,herr)

  ! setting up the refrigerant. This will allow not having to pass refrigerant  
  ! name every time, which will speed up the code.
  call REFPROP (Refrigerant,' ',' ',iUnit,iMass,0,0d0,0d0,z,Output,
 &hout,iOut,dummy1,dummy2,dummy3,q,ierr,herr)   

  P_evaporator=1 !MPa
  P_condenser=2 !MPa
  dT_superheat=10 !C
  dT_subcool=8 !C

  q=1
  call REFPROP1('PQ','T',iUnit,iMass,P_evaporator,q,z,T_evaporator,
 &qcalc,ierr,herr)

  T_compressor_in=T_evaporator+dT_superheat
  P_compressor_in=P_evaporator

  call REFPROP1('TP','S,H',iUnit,iMass,T_compressor_in,
 &P_compressor_in,z,Output,qcalc,ierr,herr)
  s_compressor_in  =Output(1)   !kJ/(kg.K)
  h_compressor_in = Output(2)   !kJ/kg

  s_compressor_out=s_compressor_in

  Print *,'Program finished successfully.'
  end subroutine
EricLemmon commented 5 years ago

I didn't look into why Refprop2 didn't work, I either set a flag wrong, or it might be related to this issue: #74

I got a response back from Chemours telling me that their data on that website were from 2004 and that all users should rely on the Refprop 10.0 calculations when there is a disagreement with those they find on-line.

For the refrigerant data, see the following publication, it shows the incredible amount of data we had for this system:

E.W. Lemmon and R.T Jacobsen, Equations of State for Mixtures of R-32, R-125, R-134a, R-143a, and R-152a, J. Phys. Chem. Ref. Data, Volume 33, Number 2, pp. 593-620, 2004.

KayvanA commented 5 years ago

Thanks, Eric. Any comments on why I am not getting the correct enthalpy in my code?

KayvanA commented 5 years ago

Two more questions, Eric:

1-I started a new code. I am using 'MASS BASE SI' for my units. Is there a way I could have all units the same as 'MASS BASE SI', but change K to C? Could you please show me the command for that?

2- I have a line where I ask for quality, given enthalpy and pressure, but I am getting -9999990 for quality. Am I writing the command correctly? The code works fine up to this line and P_valve_out=1000000Pa and h_valve_out=239597J/kg have proper values.

call REFPROP1('PH','Q',iUnit,iMass,P_valve_out, &h_valve_out,z,x_valve_out,xcalc,ierr,herr)

KayvanA commented 5 years ago

I might have figured out the answer to my second question in the previous comment: I cannot specify quality ('Q') as the second argument (output) in the call to Refprop1. Therefore, the variable 'x_valve_out' will not have a value. Instead, the variable 'xcalc' will get the quality value. Probably, a better call to the function would be: call REFPROP1('PH','T',iUnit,iMass,P_valve_out, &h_valve_out,z,T1,xcalc,ierr,herr) where the temperature and the quality will be the outputs in variables 'T1' and 'xcalc', respectively. Am I correct about not being allowed to have 'Q' as the second argument to REFPROP1?

EricLemmon commented 5 years ago

The REFPROP1 routine only returns one output, so you cannot do as you requested with this call:

call REFPROP1('TP','S,H',iUnit,iMass,T_compressor_in,P_compressor_in,z,Output,qcalc,ierr,herr)

Instead it would need to be something like this:

call REFPROP1('TP','S',iUnit,iMass,T_compressor_in,P_compressor_in,z,S,qcalc,ierr,herr) call REFPROP1('TP','H',iUnit,iMass,T_compressor_in,P_compressor_in,z,H,qcalc,ierr,herr)

If the Q comes back as something as you indicated above, that means the point is single phase. You will only get 0<=q<=1 if it is a saturation state or 2-phase. See if these comments answer your other Q question.

For your units question, check out the comments in the manual or in the REFPROP.FOR file, which I have pasted below:

c    - ``UNITUSER``, ``UNITUSER2``: Set a predefined set of units based on the user's need.
c      Two different sets can be assigned depending on the input sent to the routine.  The variable hIn
c      contains the numbers that are specified by the enumerations in the CONSTS.INC file, separated by semicolons.
c      For example, hIn='0;157;0;0;0;403;0;0;0;0' would set the pressure to use units of atm and the
c      speed of sound to use units of km/h. The numbers are listed in the order of T, P, D, H, S, W, I, E, K, and N
c      (temperature, pressure, density, enthalpy, entropy, speed of sound, kinematic viscosity, viscosity,
c      thermal conductivity, and surface tension).  Because the enumerations might change, it is best to build this
c      string with the enumerations listed in the CONSTS.INC file rather than hard coding the numbers as shown above.

If I remember right, you can first set the units to the MASS BASE SI system, and then call this to change only the temperature units. To use this syntax, the other comments in the Fortran code or manual will explain everything else needed to implement this. Be sure to use the GETENUM function to obtain the values used in this call (assuming your code is for long term applications rather than a quick calculation). Future versions of Refprop may change those numbers to something else (extremely unlikely, but not impossible).

KayvanA commented 5 years ago

The thermodynamic state point does lie in the two-phase zone. It is not in the single phase or superheated vapor zone. At the pressure P=1000000Pa, the enthalpy value h=239597J/kg is between the saturated liquid enthalpy (hf=212237J/kg) and saturated vapor (hg=424527J/kg). Therefore, one can calculate the quality as

x=(h-hf)/(hg-hf)=0.129

I simplified my code to the short version below to illustrate this point. In my call to REFPROP1, I specify Q as the output string, with the output value to be provided in the variable x1, which shows x1=-9999990. In the same call, REFPROP1 gives x2=0.126, which is close to the calculated value above (0.129). This value is shown as x3 in the code below (x3=0.129).

call REFPROP1('PH','Q',iUnit,iMass,P,h,z,x1,x2,ierr,herr)

So my questions are:

  1. Are there any mistakes in my call to REFPROP1? Or is there a bug in REFPROP1 subroutine to calculate quality?

  2. Which quality value is correct? If you think x2=0.126 is correct, could you please explain why/how that value is calculated and why x3=0.129 is incorrect?

      subroutine test_call()
      implicit none
      integer, parameter :: ncmax=20,ipropmax=200
      double precision dummy1(ncmax),dummy2(ncmax),dummy3(ncmax)
      double precision x,xcalc,z(ncmax),Output(ipropmax)
      double precision P,T,x1,x2,x3,h,hf,hg
      integer iUnit,iMass,ierr,iFlag,iOut
      character*255 hOut,herr,Refrigerant
    
      Refrigerant='R410A'
      iMass=1 
      call GETENUM(0,'MASS BASE SI',iUnit,ierr,herr)
      call REFPROP (Refrigerant,' ',' ',iUnit,iMass,0,0d0,0d0,z,Output,
     &hout,iOut,dummy1,dummy2,dummy3,x,ierr,herr)   
    
      P = 1000000 ! Pa 
      h = 239597  ! J/kg
      call REFPROP1('PH','Q',iUnit,iMass,P,h,z,x1,x2,ierr,herr)
    
      x=0
      call REFPROP1('PQ','H',iUnit,iMass,P,x,z,hf,xcalc,ierr,herr)
    
      x=1
      call REFPROP1('PQ','H',iUnit,iMass,P,x,z,hg,xcalc,ierr,herr)
    
      x3=(h-hf)/(hg-hf)
      end subroutine
EricLemmon commented 5 years ago

Change the 'Q' to 'Qmole' in the line below:

call REFPROP1('PH','Q',iUnit,iMass,P,h,z,x1,x2,ierr,herr)

Make sure you check the value of ierr after each Refprop call. This one returned ierr=812, and herr:

[REFPROP error 812] The input code Q is invalid because it is not always clear if the value is given on a mass or mole basis. Use QMOLE or QMASS instead.

Checking that error number is extremely important to make sure all is working.

KayvanA commented 5 years ago

I turned 'Q' to 'QMASS' as I am interested in mass based properties. I still got x1=x2=0.126 and x3=0.129.

From the definition, at the given pressure (P=1000000Pa), the value of x3=(h-hf)/(hg-hf) should be the value of quality. Could you please explain why Refprop value is different and how it is being calculated? If it is calculating the (mass of vapor)/(mass vapor + mass liquid), how does it calculate the mass of vapor? The only way I see is h=(1-x3)(hf)+(x3)(hg) and solve for x3. Is there any other formula?

KayvanA commented 5 years ago

The pressure of P=1000,000Pa pertains to a saturation temperature of T=280.33K. I also tried getting hf and hg at this temperature rather than getting them at the saturation pressure. However, the discrepancy between x1=x2=0.126 and x3=0.129 is still there.

  P = 1000000
  h = 239597 
  call REFPROP1('PH','T',iUnit,iMass,P,h,z,T,x2,ierr,herr) 
  call REFPROP1('TH','QMASS',iUnit,iMass,T,h,z,x1,x2,ierr,herr)

  x=0
  call REFPROP1('TQ','H',iUnit,iMass,T,x,z,hf,xcalc,ierr,herr)          

  x=1
  call REFPROP1('TQ','H',iUnit,iMass,T,x,z,hg,xcalc,ierr,herr) 

  x3=(h-hf)/(hg-hf)
EricLemmon commented 5 years ago

The inputs you have used here to get x3 are not equilibrium states, rather they are simply the states at the bubble point and at the dew point. To get x3 you have to perform a bit of a complicated process that continuously updates the molar mass of the liquid and vapor that are in equilibrium with each other, but which are at different compositions, and then solve an iterative process to find the 2-phase state. The details are beyond the scope of this thread. There's a reason that we use mole fractions in the source code of Refprop, it greatly simplifies many of these issues.

gehadrabee24 commented 7 months ago

Heyy, I'm making a project and i have to call refprop 10 by fortran code, i'm just so confused of how method should i use to do this, REFPROP10 has the dll file, and also many subroutines, but i cant run any of them and I don't know why, i use gfortran compiler on visual studio code, and I think that the subroutines is made by fortran 77 cause the extension of the files is .FOR , I made a code but it does not work correctly, cause it can not read the files, " undefined reference to refprop 10"

program refprop_example

! Declare variables for REFPROP inputs and outputs character(len=255) :: fluid_name, input_variable, output_variable parameter (ncompmax = 10) ! Example for a maximum of 10 components real(kind=8), dimension(ncompmax) :: mole_fractions real(kind=8) :: temperature, pressure, output_property integer :: ierr, istat

! Initialize input variables (replace with your desired values) fluid_name = "Water" input_variable = "T" output_variable = "D" mole_fractions = 1.0 ! Pure component (assuming water) temperature = 300.0 ! Temperature in K pressure = 101325.0 ! Pressure in Pa

! Call REFPROP10 call refprop10(fluid_name, input_variable, output_variable, & mole_fractions, temperature, pressure, & output_property, ierr, istat)

! Check for errors if (ierr .ne. 0) then write (, ) "Error in REFPROP10 call:", ierr else write (, ) "Output property:", output_property endif

end program refprop_example
please tell me what is the easiest way to use refprop 10 in fortran code, aslo i use fortran 90, what is the easiest way to do this? what the way you used ?

ianhbell commented 7 months ago

If you are in fortran, you want to compile your program along with the source files of REFPROP. In gfortran, it would be something like (pseudocode):

gfortran example.f90 REFPROP/FORTRAN/*.FOR
gehadrabee24 commented 7 months ago

image There is no such a directory? and the code i provided is right? at the call statement which file i call exactly cause there is a lot of files as you see in the screenshot

ianhbell commented 7 months ago

That's only the idea. You need to read up on how to compile fortran code.