我希望有人协助将此代码转换为C ++
c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c Variables Used ...
c T ... temperature (K)
c P ... vapor pressure (MPa)
c V ... volume (m^3/kmol)
c ----------------------------------------------------------------------
c Instructor: Nam Sun Wang
c ----------------------------------------------------------------------
common /cblock/T
c Program Header -------------------------------------------------------
print *, 'This program calculates pressure based on the'
print *, 'generalized Peng-Robinson equation of state for water.'
print *, ' '
c Temperature ----------------------------------------------------------
print *, 'Enter temperature (K): '
read *, T
c Generate a table of P at different values of V in 0.5 increments.
print *, ' '
print *, '------------------------'
print *, ' Volume Pressure '
print *, '(m^3/kmol) (MPa) '
print *, '------------------------'
c xx.x123456789012345678 --- ruler
do i=1, 100
V = 0.5*float(i)
print 650, V, P(V)
end do
c Some formats ---------------------------------------------------------
650 format(f7.1, 1p, e18.6)
end
c ----------------------------------------------------------------------
function P(V)
c ----------------------------------------------------------------------
c Calculate pressure based on the generalized Peng-Robinson equation of state.
c for water.
c ----------------------------------------------------------------------
common /cblock/T
c Gas Constant ---------------------------------------------------------
R = 8.314E-3 ! (in MPa m3/kmol K)
c Critical parameters for water ----------------------------------------
Tc = 647.3 ! (critical temperature in K)
Pc = 22.048 ! (critical pressure in MPa)
w = 0.344 ! (acentric factor, dimensionless)
c Peng-Robinson EOS parameters -----------------------------------------
xk = 0.37464 + 1.54226*w - 0.26992*w*w
alpha = ( 1. + xk*(1.-sqrt(T/Tc)) )**2
a = 0.45724*R*R*Tc*Tc*alpha/Pc
b = 0.07780*R*Tc/Pc
P = R*T/(V-b) - a/(V*(V+b)+b*(V-b))
end
答案 0 :(得分:3)
以下是一些针对您的转化,请先发布,然后发布结果。然后我们可以帮助您完成它。
消息
print *, '...'
替换为
cout << "..."
计数循环
do i=1, 100
...
end do
替换为
for(int i = 1; i <= 100; ++i) {
....
}
评论
......!评论
替换为
...; //评论
变量
X = 99.879
替换为
float X = 99.879
功能
function P(V)
.
.
.
P = .... ! the result
替换为
double P(double V){
.
.
.
return ....; // the result
}
答案 1 :(得分:0)
我知道这已经很晚了,但我来到这里寻找答案并找到了另一种解决方案。
试试包f2c。我只是在你的代码示例中使用它,它工作得很好。虽然它有点难看,因为它链接到模拟Fortran函数的库,比如print,但你可以使用主逻辑部分并自己做I / O.