Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28602 Discussions

error #7976: An allocatable dummy argument may only be argument associated with an allocatable actual argument.

Jun_G_
Beginner
2,411 Views

I am a beginner of fortran, now I have a code which debugging with error 7976.

 Program test_main
    implicit none
    integer NP,ele_n,NE,NNE,npt,num
    integer,pointer :: ele_concentrate( : ),ele_c( : )
    double precision,pointer::vcl( : , : )                           
interface

    subroutine new_node(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)
    implicit none
    integer NP,ele_n,NE,NNE,npt,num
    integer,allocatable :: ele_concentrate(:),ele_c(:)
    double precision,allocatable :: vcl(:,:)
    end subroutine new_node

    subroutine zhaobian_gj01(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)
    implicit none
    integer NP,ele_n,NE,NNE,npt,num
    integer,allocatable :: ele_concentrate(:),ele_c(:)
    double precision,allocatable ::vcl(:,:)
    end subroutine zhaobian_gj01
 end interface

call zhaobian_gj01(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)   
call new_node(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)
end

The compiler whines when  calling subroutine zhaobian_gj01 and new_node, with error #7976: An allocatable dummy argument may only be argument associated with an allocatable actual argument.  (ele_concentrate,ele_c,vcl)

How can I solve this problem? Thanks. 

0 Kudos
1 Solution
jimdempseyatthecove
Honored Contributor III
2,411 Views

In Fortran, you are permitted to have

a) An allocatable array
b) A pointer, to an allocatable array

These are two different entities (object types). In the first case (allocatable), you have an object that is an array descriptor. In the second case (pointer) your have a pointer (which may be NULL) that points to an array descriptor.

Although your code dereferences each the same, the underlying code is different.

Both arg types should be the same (both allocatable or both pointer to allocatable)

Jim Dempsey

View solution in original post

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
2,412 Views

In Fortran, you are permitted to have

a) An allocatable array
b) A pointer, to an allocatable array

These are two different entities (object types). In the first case (allocatable), you have an object that is an array descriptor. In the second case (pointer) your have a pointer (which may be NULL) that points to an array descriptor.

Although your code dereferences each the same, the underlying code is different.

Both arg types should be the same (both allocatable or both pointer to allocatable)

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
2,411 Views

Typically you don't want to declare a dummy argument to be ALLOCATABLE unless you will be changing its allocation status inside the routine. Most likely the solution is to remove ALLOCATABLE as an attribute in the interface (and the actual routine).

Also, it is considered "bad form" to have a separate interface block for a Fortran routine (unless you're declaring a generic.) Better is to put the procedure in a module or make it a contained procedure. But if you're modifying an existing application, sometimes it can be useful to use interface blocks, as long as you make sure to keep them consistent with the actual routine.

0 Kudos
Jun_G_
Beginner
2,411 Views

jimdempseyatthecove wrote:

In Fortran, you are permitted to have

a) An allocatable array
b) A pointer, to an allocatable array

These are two different entities (object types). In the first case (allocatable), you have an object that is an array descriptor. In the second case (pointer) your have a pointer (which may be NULL) that points to an array descriptor.

Although your code dereferences each the same, the underlying code is different.

Both arg types should be the same (both allocatable or both pointer to allocatable)

Jim Dempsey

 

Thank you very much for your suggestion, I'm glad to tell you that this problem has been sloved!

0 Kudos
Jun_G_
Beginner
2,411 Views

jimdempseyatthecove wrote:

In Fortran, you are permitted to have

a) An allocatable array
b) A pointer, to an allocatable array

These are two different entities (object types). In the first case (allocatable), you have an object that is an array descriptor. In the second case (pointer) your have a pointer (which may be NULL) that points to an array descriptor.

Although your code dereferences each the same, the underlying code is different.

Both arg types should be the same (both allocatable or both pointer to allocatable)

Jim Dempsey

 

I am very sorry to trouble you for my new problem. I have changed my code as your advice and it runs successfully until subroutine 'new_node'. Then I found that the value of allocatable array 'ele_n' has not been passed to subroutine 'new_node' form subroutine ' zhaobian_gj01' (the value has been allocated in  ' zhaobian_gj01').  The subroutines have been run successfully  befor, I don't know why it comes wrong.

The code of  subroutine 'new_node' is:

subroutine new_node (NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)

    double precision t
    integer i,j,k,ele_n,NP,NE,KK,NNE,NNP,m,n1,n2,n3,n4,s,npt,num,ele_concentrate(NE),ele_c(NNE)               
    integer ele_inital(NE,ele_n)
    double precision node_xy(NP,2),vcl(2,npt)
    double precision::new_point(400,2)                                                  
    double precision::new_node_xy(100,2),node_xy_local_1(400,4),node_xy_local_2(400,4)

...

end 

The main program is:

Program test_main
   implicit none

    interface
    subroutine new_node(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)
    implicit none
    integer NP,ele_n,NE,NNE,npt,num
    integer,allocatable :: ele_concentrate(:),ele_c(:)
    double precision,allocatable :: vcl(:,:)
    end subroutine new_node

    subroutine zhaobian_gj01(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)
    implicit none
    integer NP,ele_n,NE,NNE,npt,num
    integer,allocatable :: ele_concentrate(:),ele_c(:)
    double precision,allocatable ::vcl(:,:)
    end subroutine zhaobian_gj01
    end interface
    
    integer NP,ele_n,NE,NNE,npt,num
    integer,allocatable :: ele_concentrate(:),ele_c(:)
    double precision,allocatable::vcl(:,:)
   

 call zhaobian_gj01(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)   

 call new_node(NP,ele_n,NE,NNE,ele_concentrate,ele_c,vcl,npt,num)

end

0 Kudos
Reply