mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Detailed example working with gfortran/g++ mixed compilation, but without module
Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
27
wrappers/Fortran/detailed_example/README.md
Normal file
27
wrappers/Fortran/detailed_example/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
FORTRAN example without module
|
||||
==============================
|
||||
|
||||
To build static library
|
||||
-----------------------
|
||||
|
||||
Start in root folder of repo
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
mkdir gccstatic
|
||||
cd gccstatic
|
||||
cmake ../.. -G "MinGW Makefiles" -DCOOLPROP_STATIC_LIBRARY=ON
|
||||
cmake --build .
|
||||
|
||||
This will generate the file libCoolProp.a which is a GCC static library that can be linked with GCC/GFORTRAN code
|
||||
|
||||
Make sure that the macro COOLPROP_LIB is defined and that the macro CONVENTION=__cdecl is set.
|
||||
|
||||
Copy this .a file into the directory with the coolprop FORTRAN example
|
||||
|
||||
To build FORTRAN example
|
||||
------------------------
|
||||
|
||||
gfortran -c cool_fortran_bind.f90
|
||||
gfortran libCoolProp.a cool_fortran_bind.f90 -o main -lstdc++
|
||||
main
|
||||
69
wrappers/Fortran/detailed_example/cool_fortran_bind.f90
Normal file
69
wrappers/Fortran/detailed_example/cool_fortran_bind.f90
Normal file
@@ -0,0 +1,69 @@
|
||||
program hello
|
||||
|
||||
!Use TestData ! Include a Module with the interface, Optional (to not re-write the Interface every at Subroutine or Program)
|
||||
|
||||
use iso_c_binding
|
||||
implicit none
|
||||
|
||||
!The interface to use the PropsSI Function
|
||||
INTERFACE
|
||||
FUNCTION PropsSI &
|
||||
(output, name1, prop1, name2, prop2, fluidname) &
|
||||
BIND(C, NAME='PropsSI')
|
||||
use iso_c_binding
|
||||
real(C_DOUBLE) :: PropsSI
|
||||
character(KIND=c_char) :: output(*)
|
||||
character(c_char) :: name1(*)
|
||||
real(C_DOUBLE), VALUE :: prop1
|
||||
character(c_char) :: name2(*)
|
||||
real(C_DOUBLE), VALUE :: prop2
|
||||
character(kind=c_char) :: fluidname(*)
|
||||
|
||||
END FUNCTION PropsSI
|
||||
|
||||
END INTERFACE
|
||||
|
||||
|
||||
!Here Start the programa
|
||||
|
||||
|
||||
!Initializate the variables used in the example
|
||||
!implicit none
|
||||
double precision T,Q,D,h,s
|
||||
character(LEN=32) fluid, PropName
|
||||
character(LEN=32) out1, n1, n2
|
||||
double precision dens1, dens2, prop1, prop2
|
||||
|
||||
|
||||
!----------------------
|
||||
!Example calculates: (Example Code for MATLAB)
|
||||
!
|
||||
!Density of saturated liquid Propane at 300 K:
|
||||
!---------------------
|
||||
|
||||
|
||||
T = 300 ! Defining the temperature
|
||||
Q = 0 ! Defining the quality
|
||||
!D = 1250;
|
||||
|
||||
|
||||
out1 = "D"//CHAR(0) ! String with of the output Propertie
|
||||
n1 = "T"//CHAR(0) ! String with of the input Propertie #1
|
||||
n2 = "Q"//CHAR(0) ! String with of the input Propertie #2
|
||||
fluid = "Propane"//CHAR(0) ! String with the fluid name
|
||||
|
||||
|
||||
! From the CoolProp 4.2.1 documentation ->> CoolProp.CoolProp.Props
|
||||
! Call Type #2:
|
||||
! Props(OutputName,InputName1,InputProp1,InputName2,InputProp2,Fluid) --> float
|
||||
!
|
||||
|
||||
dens1 = PropsSI(out1, n1, T, n2, Q, fluid) !calling props, strings are Variables
|
||||
|
||||
dens2 = PropsSI("D"//CHAR(0), "T"//CHAR(0), T, "Q"//CHAR(0), Q, fluid) !calling props deffinig the strings directlly in the arguments
|
||||
|
||||
|
||||
Print *, dens1
|
||||
|
||||
|
||||
end program hello
|
||||
Reference in New Issue
Block a user