Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
18 Views

How to use scalar dummy argument to array-type actual argument??

Hello,

I'm using the visual studio 2017 compilier and intel parallel studio 2018.

I wonder if there is a way to use a scalar dummy argument when the actual argument is an arbitrary size of array.

Although assignment operation is allowed to scalar to be assigned to an array, for example, the following is valid,

B (an array) = 0.d0

similar subroutine augmentation gives error due to mismatch of shape.

The following is the simple minimal example of the issue is presented in the below. 

I want to know the way to use scalar dummy argument for array-type actual argument.

Thanks.

================

      PROGRAM Example
     
      IMPLICIT NONE
      DOUBLE PRECISION A(5),B(5),C(5)
     
      A = 1.D0
      B = 2.D0
     
      CALL TEST_SUM(A,B,C)     
      WRITE(*,*) C
     
      CALL TEST_SUM(0.D0,B,C) ! error!!
      WRITE(*,*) C
     
      END
           
      SUBROUTINE TEST_SUM(A,B,C)
     
      IMPLICIT NONE
      DOUBLE PRECISION A(5)
      DOUBLE PRECISION B(5)
      DOUBLE PRECISION C(5)
     
      C = A + B
     
      END

========================

0 Kudos
1 Reply
Highlighted
Valued Contributor III
18 Views

Well the simple answer is passing a scalar to and array is not allowed. There are  some cludgy way you could get around this but it is best not going there. A couple of thing below that can be applied.

 CALL TEST_SUM( [0.D0,0.D0,0.D0,0.D0,0.D0], B, C ) ! array constuctor

block
double precision :: A(5) ! this is a new  temp A and only exists within the block
A = 0.d0 ! assign array
CALL TEST_SUM( A, B, C) 
end block

 

0 Kudos