Skip to content

Commit

Permalink
Fixes from Fortitude linter (#190)
Browse files Browse the repository at this point in the history
* Add fortitude.toml
* Linter fixes (adding intent attributes mostly)
* Ignore S102
* More rule ignores for now
* Apply autofixable fixes
* Fix most of linter errors
* Enable missing-intent rule
  • Loading branch information
danielhollas authored Dec 12, 2024
1 parent a781b39 commit 0750f7a
Show file tree
Hide file tree
Showing 35 changed files with 144 additions and 118 deletions.
12 changes: 12 additions & 0 deletions fortitude.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[check]
ignore = [
"S001", # line-too-long
"S051", # deprecated-relational-operator (fix available)
"S101", # trailing-whitespace
"S102", # incorrect-space-before-comment, we should enable this, autofix enable
"M011", # use-all (should use "only:")
"M001", # procedure-not-in-module (need a per-file ignore for init.F90)
"T042", # assumed-size-character-intent TODO: We should fix all instances!
]
line-length = 132
show-fixes = true
2 changes: 0 additions & 2 deletions src/analysis.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ subroutine analysis(x, y, z, vx, vy, vz, fxc, fyc, fzc, eclas)
use mod_analyze_geometry
use mod_io
use mod_system, only: am
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(in) :: fxc(:, :), fyc(:, :), fzc(:, :)
real(DP), intent(in) :: vx(:, :), vy(:, :), vz(:, :)
Expand Down Expand Up @@ -102,7 +101,6 @@ subroutine trajout(x, y, z, time_step)
use mod_general, only: nwalk, natom, sim_time
use mod_mpi, only: get_mpi_rank
use mod_system, only: names
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
integer, intent(in) :: time_step
integer :: iat, iw
Expand Down
2 changes: 1 addition & 1 deletion src/cmdline.F90
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module mod_cmdline
use mod_interfaces, only: print_compile_info
implicit none
private
public :: get_cmdline

contains

subroutine print_help()
implicit none
integer, dimension(8) :: time_data

call date_and_time(values=time_data)
Expand Down
2 changes: 0 additions & 2 deletions src/ekin.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ subroutine temperature(px, py, pz, amt, eclas)
use mod_nhc, only: inose, get_nhcham
use mod_gle, only: get_langham
use mod_shake, only: nshake
implicit none
integer :: iw, iat
real(DP), intent(in) :: px(:, :), py(:, :), pz(:, :)
real(DP), intent(in) :: amt(:, :)
Expand Down Expand Up @@ -68,7 +67,6 @@ end subroutine temperature
real(DP) function ekin_v(vx, vy, vz)
use mod_general, only: nwalk, natom
use mod_system, only: am
implicit none
real(DP), intent(in) :: vx(:, :), vy(:, :), vz(:, :)
real(DP) :: temp1, ekin_mom
integer :: iw, iat
Expand Down
4 changes: 2 additions & 2 deletions src/en_restraint.F90
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ subroutine energy_restraint(x, y, z, px, py, pz, eclas)

!Iterative procedure
convercrit = 100
do while (convercrit > 0.00001)
do while (convercrit > 0.00001D0)
! deltaE(t+dt) prediction - improves the accuracy
deltaEnext = 0
do iat = 1, natom
Expand Down Expand Up @@ -166,7 +166,7 @@ subroutine energy_restraint(x, y, z, px, py, pz, eclas)
eclas = eclas ! + quadratic_restraint_energy

!Output to en_restraint.dat
write (UERMD, '(I8,F16.8,E20.10,E20.10,F16.8)') it, excE * AUTOEV, deltaE, 0.0, 0.0
write (UERMD, '(I8,F16.8,E20.10,E20.10,F16.8)') it, excE * AUTOEV, deltaE, 0.0D0, 0.0D0

end if

Expand Down
1 change: 1 addition & 0 deletions src/error.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module mod_error

abstract interface
subroutine error(filename, line_number, message)
implicit none
character(len=*), intent(in) :: filename
integer, intent(in) :: line_number
character(len=*), intent(in) :: message
Expand Down
10 changes: 5 additions & 5 deletions src/fftw_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ subroutine fftw_normalmodes_init(nwalk)

deallocate (x_tmp)
deallocate (cx_tmp)
end subroutine
end subroutine fftw_normalmodes_init

! Simple wrapper functions around the FFTW interface.
subroutine dft_normalmode2cart(nm, cart)
Expand Down Expand Up @@ -72,16 +72,16 @@ subroutine fftw_normalmodes_init(nwalk)
end subroutine fftw_normalmodes_init

subroutine dft_normalmode2cart(nm, cart)
complex(C_DOUBLE_COMPLEX), dimension(:) :: nm
real(C_DOUBLE), dimension(:) :: cart
complex(C_DOUBLE_COMPLEX), dimension(:), intent(inout) :: nm
real(C_DOUBLE), dimension(:), intent(inout) :: cart
cart = 0.0D0
nm = (0.0D0, 0.0D0)
call not_compiled_with('FFTW library')
end subroutine dft_normalmode2cart

subroutine dft_cart2normalmode(cart, nm)
complex(C_DOUBLE_COMPLEX), dimension(:) :: nm
real(C_DOUBLE), dimension(:) :: cart
complex(C_DOUBLE_COMPLEX), dimension(:), intent(inout) :: nm
real(C_DOUBLE), dimension(:), intent(inout) :: cart
cart = 0.0D0
nm = (0.0D0, 0.0D0)
call not_compiled_with('FFTW library')
Expand Down
4 changes: 1 addition & 3 deletions src/force_abin.F90
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ real(DP) function read_energy(engrad_unit, abort) result(energy)
!$OMP FLUSH(abort)
return
end if
end function
end function read_energy

subroutine read_forces(fx, fy, fz, num_atom, iw, engrad_unit, abort)
use mod_files, only: stderr
Expand Down Expand Up @@ -209,7 +209,6 @@ subroutine force_abin(x, y, z, fx, fy, fz, eclas, chpot, walkmax)
use mod_lz, only: nstate_lz, tocalc_lz, en_array_lz, istate_lz, write_lz_data
use mod_qmmm, only: natqm
use mod_utils, only: toupper, append_rank
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(out) :: fx(:, :), fy(:, :), fz(:, :)
real(DP), intent(out) :: eclas
Expand Down Expand Up @@ -325,7 +324,6 @@ subroutine oniom(x, y, z, fx, fy, fz, eclas, iw, abort)
use mod_qmmm, only: natqm
use mod_sh_integ, only: nstate
use mod_sh, only: en_array, istate
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(inout) :: fx(:, :), fy(:, :), fz(:, :)
real(DP), intent(inout) :: eclas
Expand Down
6 changes: 3 additions & 3 deletions src/force_bound.F90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ subroutine sbc_init(x, y, z)
write (*, *) 'Calculating cluster radius from given densty.'
rho = rho * fact !conversion from g/L to atomic units
rb_sbc = mass_total / rho * 3 / 4 / PI
rb_sbc = rb_sbc**(1 / 3.)
rb_sbc = rb_sbc**(1 / 3.0D0)
end if

if (rmax > rb_sbc) then
Expand All @@ -73,7 +73,7 @@ subroutine sbc_init(x, y, z)

write (*, *) 'rb_sbc[A]=', rb_sbc / ang

end subroutine
end subroutine sbc_init

subroutine force_sbc(x, y, z, fx, fy, fz, walkmax)
use mod_const, only: ANG
Expand Down Expand Up @@ -118,7 +118,7 @@ subroutine force_sbc(x, y, z, fx, fy, fz, walkmax)
end if

return
end subroutine
end subroutine force_sbc

! TODO: This could be a general purpose routine,
! move to utils
Expand Down
21 changes: 14 additions & 7 deletions src/force_h2o.F90
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ subroutine force_h2o_cvrqd(x, y, z, fx, fy, fz, Eclas, natom, nbeads)
! TODO: Given the small difference between the Schwenke potential,
! we might not need to implement numerical forces here.
! call numerical_forces(x, y, z, fx, fy, fz, Epot, natom, nbeads)
! Just to squash compiler warnings
if (.false.) then
print*,natom
fx = 0.0D0
fy = 0.0D0
fz = 0.0D0
end if

end subroutine force_h2o_cvrqd

Expand Down Expand Up @@ -159,7 +166,7 @@ subroutine numerical_forces(x, y, z, fx, fy, fz, Epot, natom, nbeads)
real(DP) :: Epot_delta(1)

real(DP) :: Eclas_orig
real(DP) :: delta = 5.0E-5_DP
real(DP), parameter :: DELTA = 5.0E-5_DP
integer :: i, j, k

! Calculate forces numerically using central differences
Expand All @@ -180,11 +187,11 @@ subroutine numerical_forces(x, y, z, fx, fy, fz, Epot, natom, nbeads)
! Move the atom forwards
select case (k)
case (1)
x_new_forward(i, j) = x_new_forward(i, j) + delta
x_new_forward(i, j) = x_new_forward(i, j) + DELTA
case (2)
y_new_forward(i, j) = y_new_forward(i, j) + delta
y_new_forward(i, j) = y_new_forward(i, j) + DELTA
case (3)
z_new_forward(i, j) = z_new_forward(i, j) + delta
z_new_forward(i, j) = z_new_forward(i, j) + DELTA
end select

! Calculate the energy for the forward perturbed geometry
Expand All @@ -197,11 +204,11 @@ subroutine numerical_forces(x, y, z, fx, fy, fz, Epot, natom, nbeads)
! Calculate the numerical force
select case (k)
case (1)
fx(i, j) = -(Epot_delta(1) - Eclas_orig) / delta
fx(i, j) = -(Epot_delta(1) - Eclas_orig) / DELTA
case (2)
fy(i, j) = -(Epot_delta(1) - Eclas_orig) / delta
fy(i, j) = -(Epot_delta(1) - Eclas_orig) / DELTA
case (3)
fz(i, j) = -(Epot_delta(1) - Eclas_orig) / delta
fz(i, j) = -(Epot_delta(1) - Eclas_orig) / DELTA
end select
end do
end do
Expand Down
10 changes: 5 additions & 5 deletions src/force_spline.F90
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ subroutine finalize_spline()
if (allocated(second_derivatives)) then
deallocate (second_derivatives)
end if
end subroutine
end subroutine finalize_spline

subroutine read_grid(fname, x_grid, y_grid, grid_size)
use mod_files, only: stdout
Expand Down Expand Up @@ -122,7 +122,7 @@ subroutine read_grid(fname, x_grid, y_grid, grid_size)
end do
close (u)

end subroutine
end subroutine read_grid

subroutine validate_grid(x_grid, ngrid)
real(DP), dimension(ngrid), intent(in) :: x_grid
Expand All @@ -141,7 +141,7 @@ subroutine validate_grid(x_grid, ngrid)
return
end if
end do
end subroutine
end subroutine validate_grid

subroutine print_splined_potential(fname, x_grid, grid_size)
character(len=*), intent(in) :: fname
Expand All @@ -158,6 +158,6 @@ subroutine print_splined_potential(fname, x_grid, grid_size)
x = x + dx
end do
close (u)
end subroutine
end subroutine print_splined_potential

end module
end module mod_splined_grid
2 changes: 1 addition & 1 deletion src/force_tcpb.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module mod_force_tcpb
character(len=1024) :: input_file = ''
! This make TC reuse WF from previous step.
integer :: globaltreatment = 0
end type
end type tcpb_params
type(tcpb_params) :: tcpb
character(len=5), allocatable :: qmattypes(:)
save
Expand Down
6 changes: 3 additions & 3 deletions src/forces.F90
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ subroutine force_quantum(fx, fy, fz, x, y, z, amg, quantum_energy)
fz(j, i) = (z(j, i) - z(j, kplus))
fz(j, i) = fz(j, i) + (z(j, i) - z(j, kminus))
fz(j, i) = -fz(j, i) * ak(j, i)
equant = equant + 0.5 * ak(j, i) * (x(j, i) - x(j, kplus))**2
equant = equant + 0.5 * ak(j, i) * (y(j, i) - y(j, kplus))**2
equant = equant + 0.5 * ak(j, i) * (z(j, i) - z(j, kplus))**2
equant = equant + 0.5D0 * ak(j, i) * (x(j, i) - x(j, kplus))**2
equant = equant + 0.5D0 * ak(j, i) * (y(j, i) - y(j, kplus))**2
equant = equant + 0.5D0 * ak(j, i) * (z(j, i) - z(j, kplus))**2
end do
end do
end if
Expand Down
13 changes: 12 additions & 1 deletion src/fortran_interfaces.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
module mod_interfaces
use, intrinsic :: iso_c_binding, only: C_INT, C_INT32_T
use mod_const, only: DP
implicit none
public
interface

subroutine print_compile_info()
implicit none
end subroutine print_compile_info

subroutine finish(error_code)
implicit none
integer, intent(in) :: error_code
end subroutine finish

subroutine force_clas(fx, fy, fz, x, y, z, eclas, chpot)
import :: DP
implicit none
real(DP), intent(inout) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(inout) :: fx(:, :), fy(:, :), fz(:, :)
real(DP), intent(out) :: eclas
Expand All @@ -26,6 +30,7 @@ end subroutine force_clas

subroutine force_quantum(fx, fy, fz, x, y, z, amg, energy)
import :: DP
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(inout) :: fx(:, :), fy(:, :), fz(:, :)
real(DP), intent(in) :: amg(:, :)
Expand All @@ -34,6 +39,7 @@ end subroutine force_quantum

subroutine force_wrapper(x, y, z, fx, fy, fz, eclas, chpot, walkmax)
import :: DP
implicit none
real(DP), intent(in) :: x(:, :), y(:, :), z(:, :)
real(DP), intent(inout) :: fx(:, :), fy(:, :), fz(:, :)
real(DP), intent(out) :: eclas
Expand All @@ -42,13 +48,15 @@ subroutine force_wrapper(x, y, z, fx, fy, fz, eclas, chpot, walkmax)
end subroutine force_wrapper

subroutine omp_set_num_threads(nthreads)
implicit none
integer, intent(in) :: nthreads
end subroutine omp_set_num_threads

! TODO: This interface currently doesn't work, probably because
! of how we pass the 2D arrays...
!subroutine force_water(x, y, z, fx, fy, fz, eclas, natom, walkmax, watpot) !bind(C)
! use, intrinsic :: iso_c_binding
! implicit none
! real(C_DOUBLE), intent(in) :: x(:, :), y(:, :), z(:, :)
! real(C_DOUBLE), intent(inout) :: fx(:, :), fy(:, :), fz(:, :)
! real(C_DOUBLE), intent(inout) :: eclas
Expand All @@ -59,21 +67,24 @@ end subroutine omp_set_num_threads
! int usleep(useconds_t useconds)
function usleep(useconds) bind(c, name='usleep')
import :: C_INT, C_INT32_T
integer(kind=C_INT32_T), value :: useconds
implicit none
integer(kind=C_INT32_T), intent(in), value :: useconds
integer(kind=C_INT) :: usleep
end function usleep

! Computes potential energy of a water molecule
! using Schwenke potential, see h2o_schwenke.f
subroutine h2o_pot_schwenke(rij, v, n)
import :: DP
implicit none
integer, intent(in) :: n
real(DP), intent(in) :: rij(n, 3)
real(DP), intent(out) :: v(n)
end subroutine h2o_pot_schwenke

subroutine h2o_pot_cvrqd(V, rOH1, rOH2, aHOH, mH, mO)
import :: DP
implicit none
real(DP), intent(out) :: V
real(DP), intent(in) :: rOH1, rOH2, aHOH, mH, mO
end subroutine h2o_pot_cvrqd
Expand Down
Loading

0 comments on commit 0750f7a

Please sign in to comment.