gfortran中的常见块错误(填充字节)

时间:2018-05-21 04:12:00

标签: fortran fortran-common-block

我正在尝试编写一个fortran代码,但是当我尝试将数据从子例程中的一个变量传递到另一个时,错误就会出现:       common / c / kf,eff,q
                1 警告:在(1)的COMMON'c'中'q'之前需要填充4个字节;重新排序元素或使用-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

1 个答案:

答案 0 :(得分:0)

看起来你在子程序输入中将变量q定义为实数* 8。您没有在输入子例程中指定隐式none,因此它将被隐式声明为real * 4。这意味着您的公共块从相同的初始内存地址开始映射到内存中的两个不同区域。 Fortran根据变量类型及其顺序解释公共块中的内存。这意味着在一个子程序中q是双精度而在另一个子程序中它是浮点数。这就是你获得价值变化的原因。