common block error (padding of bytes) in gfortran

3.1k Views Asked by At

I am trying to write a fortran code, but when I am trying to pass data from one variable in subroutine to another, error is coming as: common /c/kf,eff,q
1 Warning: Padding of 4 bytes required before 'q' in COMMON 'c' at (1); reorder elements or use -fno-align-commons.

The value of q from subroutine input to calculation is not being passed. If the value of q at subroutine input is 5e-3, the value of q at subroutine calculation is 3.57e-315

Kindly help

See the code

    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

There are 1 best solutions below

0
On

It doesn’t look like you define variable q as real*8 in subroutine input. You don’t specify implicit none in the input subroutine, so it’ll be implicitly declared real*4. That means your common blocks are mapping out two different regions in memory starting from the same initial memory address. Fortran interprets memory in common blocks according to the variable types and their order. That means in one subroutine q is a double and in the other it’s a float. That’s why you’re getting the value change.