Skip to content

Instantly share code, notes, and snippets.

@dryman
Created January 2, 2023 16:29
Show Gist options
  • Save dryman/6ce675a865da4c0096d21243a9555e2d to your computer and use it in GitHub Desktop.
Save dryman/6ce675a865da4c0096d21243a9555e2d to your computer and use it in GitHub Desktop.
! Demo fortran program for some syntax candies
program fortran_candies
implicit none ! Disallow F77 naming conventions
integer, parameter :: M = 4, N = 3 ! parameter attribute declares constant
real :: A(M, N)
! Creates a random matrix
call random_number(A)
call print_matrix(A, 'A')
! Numpy-style slice and set value
A(1:M, 1:N) = 0
call print_matrix(A, 'A')
contains
subroutine print_matrix(A, var_name)
real, intent(in) :: A(:,:)
character(len = *), intent(in) :: var_name
integer :: i
print *, var_name
do i = 1, size(A, 1)
print *, A(i, :)
end do
end subroutine print_matrix
end program fortran_candies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment