[Fortran] 纯文本查看 复制代码
SUBROUTINE BIANXING(data_2d, data_1d, nrow, ncol)
implicit none
REAL, DIMENSION(:,:), POINTER, INTENT(INOUT) :: data_2d
REAL, DIMENSION(:), POINTER, INTENT(IN) :: data_1d
INTEGER, INTENT(IN) :: nrow
INTEGER, INTENT(IN) :: ncol
INTEGER i
DO i=1, nrow
! PRINT *, "i=", i, 1+(i-1)*ncol, i*ncol
data_2d(i:i, 1:ncol) => data_1d(1+(i-1)*ncol : (i-1)*ncol+ncol)
PRINT *, data_2d(i:i, 1:ncol)
END DO
END SUBROUTINE BIANXING
PROGRAM MAIN
implicit none
INTERFACE
SUBROUTINE BIANXING(data_2d, data_1d, nrow, ncol)
implicit none
REAL, DIMENSION(:,:), POINTER, INTENT(INOUT) :: data_2d
REAL, DIMENSION(:), POINTER, INTENT(IN) :: data_1d
INTEGER, INTENT(IN) :: nrow
INTEGER, INTENT(IN) :: ncol
END SUBROUTINE BIANXING
END INTERFACE
REAL, DIMENSION(12), TARGET :: arr
REAL, DIMENSION(:), POINTER :: p_1d
REAL, DIMENSION(:, :), POINTER :: p_2d
INTEGER :: i
arr = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12/)
p_1d => arr
call BIANXING(p_2d, p_1d, 3, 4)
PRINT *, "===================================="
DO i=1, 3
PRINT *, p_2d(i, 1:4)
END DO
END PROGRAM MAIN