我正在尝试编写一个程序,其中我希望可分配数组的A
等级为 1、2 或 3,具体取决于我在运行时的输入。我想这样做,因为后续操作A
是相似的,并且我在模块中定义了一个work
带有模块过程的接口,当执行该模块过程时A
,会给出所需的结果。
我目前正在做的是这样的:
program main
implicit none
integer :: rank,n=10
real*8, allocatable :: A1(:)
real*8, allocatable :: A2(:,:)
read (*,*) rank
if (rank.eq.1) then
allocate (A1(n))
else if (rank.eq.2) then
allocate (A2(n,n))
end if
! operate on the array
if (rank.eq.1) then
call work(A1)
else if (rank.eq.2) then
call work(A2)
end if
end program
Run Code Online (Sandbox Code Playgroud)
如果我可以选择 的等级A
,事情会容易得多,因为这样就if
不需要这些陈述了。也许这是不可能的,但感谢所有帮助。