Non-variable expression in variable definition context compilation error

1.7k views Asked by At

I am getting this compilation error with gfortran 5.4 and a .f90 code

call abc_output(struc,nx,ny,nz,'AB'   ,get_ab_dat(p_f),&
                                                1
Error: Non-variable expression in variable definition context (actual argument to INTENT = OUT/INOUT) at (1)

The method call that is generating the compilation error is shown below and the error is on get_ab_dat

type(b_f)                :: p_f
call abc_output(struc,nx,ny,nz,'AB'   ,get_ab_dat(p_f),&
                               'BD'   ,get_bc_dat(p_f),&
                               'EF' ,  aaa )

The function get_ab_dat is shown below

function get_ab_dat(bf) result(qx_arr)
  type(b_f),intent(in) :: bf
  real,dimension(:,:,:),allocatable :: qx_arr
  qx_arr = bf%qx
end function get_ab_dat


subroutine abc_output (struc,nx,ny,nz,dname1,data1,&
       dname2,data2,dname3,data3,dname4,data4)

type(c_s),intent(in)                 :: struc
integer,intent(in)                           :: nx,ny,nz     
character(len=*),intent(in)                  :: dname1
real,dimension(:,:,:),allocatable,intent(inout)          :: data1
character(len=*),intent(in),optional         :: dname2,dname3,dname4    
real,dimension(:,:,:),allocatable,intent(inout),optional ::                 data2,data3,data4

Can somebody explain what that error means and how I can fix it ?

1

There are 1 answers

0
Vladimir F Героям слава On BEST ANSWER

You cannot post an expression or a constant to an intent(OUT) or intent(INOUT) argument. You must always pass a variable, because it can be changed in the procedure you are calling.

So because the sixth argument of abc_output is intent(OUT) or (more likely) intent(INOUT) you first have to assign the value of get_ab_dat(p_f) to a variable and you have to pass the variable to abc_output. Be careful about argument aliasing.

In this particular case the argument is also allocatable, so the variable must be allocatable as well.