Fortran90ã®ãã¹ãããã°ã©ã ã§ããé
åããµãã«ã¼ãã³ã«åã渡ãæ¹æ³ã¨ãã¡ã¢ãªã®åç確ä¿ã®æ¹æ³ãæ´çããããã«ç°¡åãªãã¹ãããã°ã©ã ãä½ãã¾ããã
ç°¡åãªããã°ã©ã ãªã®ã§ã³ã¡ã³ãã¯ããã¾ããã
é©å½ãª2次å
é
åãã»ããããset_matrixã¨ããªã³ãããprint_matrixãµãã«ã¼ãã³ãããã ãã§ãã
matrix.f90
program main implicit none real(kind=8), allocatable, dimension(:,:):: a integer(kind=8), parameter :: d = 5 integer(kind=8) :: i allocate(a(d,d)) a(:,:) = 0.1d0 i = 1 call print_matrix(a, i) call set_matrix(a, i) call print_matrix(a, i) call set_matrix(a, i) call print_matrix(a, i) deallocate(a) contains subroutine set_matrix(rarg, iarg) implicit none real(kind=8), intent(inout), dimension(:,:) :: rarg integer(kind=8), intent(inout) :: iarg integer(kind=8) :: d1, d2 integer(kind=8) :: n, m d1 = size(rarg, 1) d2 = size(rarg, 2) do n=1, d1 do m=1, d2 rarg(n, m) = (m*n+1)*rarg(n,m) enddo enddo iarg = iarg + 1 end subroutine set_matrix subroutine print_matrix(rarg, iarg) implicit none real(kind=8), intent(in), dimension(:,:) :: rarg integer(kind=8), intent(in) :: iarg integer(kind=8) :: d1, d2 integer(kind=8) :: n, m d1 = size(rarg, 1) d2 = size(rarg, 2) write(*, fmt='(a)') "matrix = " do n=1, d1 do m=1, d2 write(*, fmt='(f10.5)', advance='no') rarg(n, m) enddo write(*, *) enddo write(*, fmt='(a, i5)') "factor = ", iarg write(*, *) end subroutine print_matrix end program main
FC=gfortran FCFLAGS=-O3 OBJS= TARGS=matrix all: matrix matrix: matrix.f90 $(FC) $(FCFLAGS) -o $@ $< ./$@ clean: $(RM) -f $(TRGS) .SUFFIXES: .f90 .o