fortran - gfortran 中的常见块错误(字节填充)
问题描述
我正在尝试编写一个 fortran 代码,但是当我尝试将数据从子程序中的一个变量传递到另一个变量时,错误是:common /c/kf,eff,q
1 Warning: Padding of 4 bytes required before 'q ' 在 (1) 处的常见 'c' 中;重新排序元素或使用 -fno-align-commons。
从子程序输入到计算的 q 值没有被传递。如果子程序输入时q的值为5e-3,则子程序计算时q的值为3.57e-315
请帮助
查看代码
implicit none
call input
call calculation
stop
end
subroutine input
real*8 n
real*8 l1,l2,l3,d,kf,eff,z1,z2,rho,mu,pin,pout,l4
common /a/l1,l2,l3,l4,d
common /c/kf,eff,q
common /e/z1,z2
common /d/rho,mu,pin,pout
common /b/n
print*,"enter the lengths of the pipe at various sections (4)"
read(*,*) l1,l2,l3,l4
print*,"enter the diameter of the pipe"
read(*,*) d
print*,"enter the volumetric flow rate (m3/s)"
read(*,*) q
print*,"enter the number of elbows to be added"
read(*,*) n
print*,"enter firction coefficient for elbow"
read(*,*) kf
print*,"enter the pump efficiency"
read(*,*) eff
print*,"enter the datum height (m)"
read(*,*)z1
print*,"enter the final height (m)"
read(*,*)z2
print*,"enter the density of the fluid (kg/m3)"
read(*,*)rho
print*,"enter the viscosity of the fluid (kg/ms)"
read(*,*)mu
print*,"enter the inlet and exit pressure (KPa)"
read(*,*) pin,pout
print*,q
end
subroutine calculation
real*8 n
real*8 g,pi,v2,v1,vdif,z2,z1,head,v,q,d
real*8 p,pout,pin,rho,re,mu,f,kc,hc,kf,hf
real*8 kex,hex,l,l1,l2,l3,l4,fp,ft,Ws,Wp,m,power
common /a/l1,l2,l3,l4,d
common /c/kf,eff,q
common /e/z1,z2
common /d/rho,mu,pin,pout
common /b/n
parameter (g=9.8,pi=3.14)
print*,q,d
v= (4*q)!/(pi*(d**2))
v1=v
v2=v
vdif=0.5*((v2**2)-(v1**2))
head=g*(z2-z1)
p=(pout-pin)/(rho)
re=(d*v*rho)/(mu)
print*,v,vdif,p,head,re
if (re>2000) then
f=16/re
else
f=0.079*(re**(-0.25))
endif
kc=0.55
hc=kc*(v**2)/2
hf=n*kf*(v**2)/2
kex=1
hex=kex*(v**2)/2
l=l1+l2+l3+l4
fp=(4*f*l*(v**2))/(2*d)
ft=hc+hf+hex+fp
Ws=-head-vdif-ft
Wp=-(Ws/eff)
m=q*rho
power=m*Wp
print*, "the power required by the pump is", power
end
解决方案
它看起来不像您在子程序输入中将变量 q 定义为 real*8 。您没有在输入子例程中指定隐式 none,因此它将被隐式声明为 real*4。这意味着您的公共块从相同的初始内存地址开始映射出内存中的两个不同区域。Fortran 根据变量类型及其顺序解释公共块中的内存。这意味着在一个子程序中 q 是一个双精度数,而在另一个子程序中它是一个浮点数。这就是为什么你要改变价值。
推荐阅读
- indexing - 在 Clickhouse 中的现有表上创建索引
- python - 根据百分比频率的元素分布
- javascript - React Js中输入的正则表达式验证
- javascript - 431(请求标头字段太大)
- angular - 如何以角度设置相对基本 URL
- php - 使用 PHP(Hor Zebra)对 TinyMCE 生成的表格进行造型
- jquery - 如何使用引导程序和 Jquery 更改状态消息的颜色?
- python - 我的用户如何能够根据需要录制音频,并且还能够在 python 中使用 sounddevice 暂停它?
- oracle-data-integrator - 如何根据条件(Where 条件)从 ODI 目标表中删除记录的方法。ODI12c
- ios - 字典中的自定义键