Fortran common variables, allocatable array

前端 未结 1 1502
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-21 11:52

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

The following program doesn\'t

相关标签:
1条回答
  • 2020-12-21 12:33

    No. You can put pointers into common, but not allocatables.

    The reason is that a concept fundamental to common is storage association, where you can make a contiguous sequence of all the things that are in the common and those sequences are then shared amongst scopes. Allocatables can have their size vary dynamically in a scope, which would make the tracking in the sequence of things in the common block that came after the allocatable rather difficult.

    (Typical implementation of allocatables means that the storage directly associated with the allocatable is just a descriptor - the actual data is kept elsewhere. This practically breaks the concept of a contiguous sequence of storage units, given that the allocation status (as recorded in the descriptor) and the data are both part of the value of the allocatable. The implementation for pointers is similar, but then conceptually the data that is elsewhere in memory is not part of the value of the pointer, so it should not be expected to appear in the contiguous sequence that the common describes - the pointer is in the sequence, but not what it points at.)

    Allocatables require F90. That means that you can use module variables - which are a far better solution than the use of common for global data. If you must do this using common, then use a data pointer.

    0 讨论(0)
提交回复
热议问题