Fortran操作函數

cshift(array, shift, dim)

eoshift(array, shift, boundary, dim)

transpose (matrix)

program arrayShift implicit none

real, dimension(1:6) :: a = (/ 21.0, 22.0, 23.0, 24.0, 25.0, 26.0 /) real, dimension(1:6) :: x, y
write(*,10) a

x = cshift ( a, shift = 2) write(*,10) x

y = cshift (a, shift = -2) write(*,10) y

x = eoshift ( a, shift = 2) write(*,10) x

y = eoshift ( a, shift = -2) write(*,10) y 10 format(1x,6f6.1) end program arrayShift

21.0 22.0 23.0 24.0 25.0 26.0
23.0 24.0 25.0 26.0 21.0 22.0
25.0 26.0 21.0 22.0 23.0 24.0
23.0 24.0 25.0 26.0 0.0 0.0
0.0 0.0 21.0 22.0 23.0 24.0

program matrixTranspose implicit none interface subroutine write_matrix(a) integer, dimension(:,:) :: a end subroutine write_matrix end interface integer, dimension(3,3) :: a, b
integer :: i, j do i = 1, 3 do j = 1, 3 a(i, j) = i end do end do print *, 'Matrix Transpose: A Matrix' call write_matrix(a) b = transpose(a) print *, 'Transposed Matrix:' call write_matrix(b) end program matrixTranspose

subroutine write_matrix(a) integer, dimension(:,:) :: a
write(*,*) do i = lbound(a,1), ubound(a,1) write(*,*) (a(i,j), j = lbound(a,2), ubound(a,2)) end do end subroutine write_matrix

Matrix Transpose: A Matrix

1 1 1
2 2 2
3 3 3
Transposed Matrix:

1 2 3
1 2 3
1 2 3