Common Fortran Variables, Distributed Array

Is it possible to assign the size and values ​​of a common array in a subroutine, and then use it from other program subroutines?

The following program does not work, but I want to do something like this:

main.f

program main

integer n
integer, allocatable :: co(:)

common n, co

call assign

print *, co(1), co(2)

deallocate(co)
stop
end program main

assign.f

subroutine assign

integer n
integer, allocatable :: co(:)

common n, co

n = 2
allocate(co(n))

co(1) = 1
co(2) = 2

return
end subroutine assign
+2
source share
1 answer

No. You can put pointers in a generic, but not allocatables.

, , , - , , , . , , , .

( allocatables , , allocatable, - . , , ( ), allocatable. , , - , , , , - , , .)

Allocatables F90. , - , . , .

+4

Source: https://habr.com/ru/post/1541354/


All Articles