构建一个矩阵数组

时间:2015-07-13 02:53:44

标签: arrays matrix fortran gfortran

我想将一个大矩阵拆分成更小的2乘2矩阵并将它们放入一个数组中。这是我试过的。

PROGRAM flippableList

  IMPLICIT NONE
  REAL, DIMENSION(4,4) :: TEST
  REAL, DIMENSION(2,2) :: su1
  REAL, DIMENSION(:,:,:), ALLOCATABLE :: breakdown

  REAL :: a1, a2, b1, b2, c1, c2
  INTEGER :: n, i, j

  a1 = 11; a2 = 12
  b1 = 21; b2 = 22
  c1 = 31; c2 = 32

  su1 = RESHAPE ([b1, c2, a2, b2],[2,2])
  TEST = RESHAPE ([c2, a2, a2, a2, a1, c2, a2, a2, &
      a1, a1, c2, a2, a1, a1, a1, c2], [4,4])
  n = 4 ! size of the grid

  ALLOCATE (breakdown(:,:,:))
  breakdown = 0
  DO i = 1, n-1, 1
    DO j = 1, n-1, 1
    breakdown = [breakdown, TEST(i:i+1, j:j+1)]
    END DO
  END DO

PRINT*, breakdown
END PROGRAM flippableList

从使用gfortran编译的错误消息中,我可以看出breakdown维度存在问题。这是错误消息。

分配(分解(:,:,:))             1 错误:(1)中ALLOCATE语句中的数组规范错误 flippableList.f08:28:4:

 breakdown = [breakdown, TEST(i:i+1, j:j+1)]
1

错误:在(1)

的作业中,等级3和1不兼容

0 个答案:

没有答案