Fortran 源码高亮测试
- 142
- 1 min
自由格式 Fortran
fortran
module lattice_energy
use iso_fortran_env, only: dp => real64
implicit none
private
public :: compute_total_energy
contains
subroutine compute_total_energy(pos, mass, omega, energy)
real(dp), intent(in) :: pos(:, :)
real(dp), intent(in) :: mass(:)
real(dp), intent(in) :: omega
real(dp), intent(out) :: energy
integer :: iat
real(dp) :: r2
energy = 0.0_dp
do iat = 1, size(pos, 2)
r2 = sum(pos(1:3, iat)**2)
energy = energy + 0.5_dp * mass(iat) * omega**2 * r2
end do
end subroutine compute_total_energy
end module lattice_energy注释与控制流
f90
subroutine normalize_weights(weights, total)
real(dp), intent(inout) :: weights(:)
real(dp), intent(out) :: total
total = sum(weights) ! green comment, not grey
if (total > 0.0_dp) then
weights = weights / total
else
weights = 0.0_dp
end if
end subroutine normalize_weights