在 fortran 中排列数组

Arranged array in gfortran

Program allo
  Implicit none
  integer :: A,ok,i,B,k
  Real, Dimension (:,:), Allocatable :: note

  Print*, "enter line A"
  Read*, A
  Print*, "enter range B"
  Read* ,B

  Allocate (note(A,B), STAT=ok)
  If (ok/=0) then 
    print*, "failed"
    STOP
  end if

  Do i=1,A
    Do k=1,B    
      Read*, note(i,k)
    End do
  End do

  print*,shape(note, /A,B/)

  Deallocate (note) 
End Program allo

当我在没有 "shape" 选项的情况下正常编译它时,它在 1 行上给我一个数组,我想要 (A,B) 数组。我试图塑造它以获得完美的 table 但它给了我错误。

shape 内在 returns 数组的形状,这里的结果将是一个数组 [ A, B ]

您要做的是重塑数组,为此您需要使用 reshape 内在函数。 但是,阵列已经处于所需的形状。它只是没有那样打印。

我建议使用一个循环来打印数组:

  do i=1,A
    print *, note(i,:)
  enddo !i