Skip to content

Commit 23581e8

Browse files
balos1gardner48
authored andcommitted
Maintenance: Fortran formatting (#509)
Add Fortran formatting to CI and apply it
1 parent 0168f42 commit 23581e8

File tree

79 files changed

+8707
-9010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8707
-9010
lines changed

.github/workflows/check-clang-format.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ jobs:
1313
- name: Install git
1414
run: |
1515
apt update
16-
apt install -y git
16+
apt install -y git python3-pip
17+
18+
- name: Install fprettify
19+
run: pip install fprettify
1720

1821
- name: Check out repository code
1922
uses: actions/checkout@v4

doc/superbuild/source/developers/style_guide/SourceCode.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ not adhere to all of these rules.
185185
library which requires a newer standard.
186186

187187
#. All new code added to SUNDIALS should be
188-
formatted with `clang-format <https://clang.llvm.org/docs/ClangFormat.html>`_.
188+
formatted with `clang-format <https://clang.llvm.org/docs/ClangFormat.html>`_,
189+
and `fprettify <https://github.com/fortran-lang/fprettify>`_.
189190
See :ref:`Style.Formatting` for details.
190191

191192
#. Spaces not tabs.
@@ -377,9 +378,11 @@ Formatting
377378
----------
378379

379380
All new code added to SUNDIALS should be formatted with `clang-format
380-
<https://clang.llvm.org/docs/ClangFormat.html>`_. The
381-
``.clang-format`` files in the root of the project define our configurations
382-
for the tools respectively. To apply clang-format you can run:
381+
<https://clang.llvm.org/docs/ClangFormat.html>`_ and
382+
`fprettify <https://github.com/fortran-lang/fprettify>`_. The
383+
``.clang-format`` file in the root of the project defines our configuration
384+
for clang-format. We use the default fprettify settings, except we use
385+
2-space indentation. To apply ``clang-format`` and ``fprettify`` you can run:
383386

384387
.. code-block:: shell
385388

examples/arkode/F2003_custom/ark_analytic_complex_f2003.f90

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ module ode_mod
3939

4040
!======= Declarations =========
4141
implicit none
42-
integer(c_int64_t), parameter :: neq = 1
43-
integer(c_int), parameter :: Nt = 10
44-
complex(c_double_complex), parameter :: lambda = (-1d-2, 10.d0)
45-
real(c_double), parameter :: T0 = 0.d0
46-
real(c_double), parameter :: Tf = 10.d0
47-
real(c_double), parameter :: dtmax = 0.01d0
48-
real(c_double), parameter :: reltol = 1.d-6
49-
real(c_double), parameter :: abstol = 1.d-10
42+
integer(c_int64_t), parameter :: neq = 1
43+
integer(c_int), parameter :: Nt = 10
44+
complex(c_double_complex), parameter :: lambda = (-1d-2, 10.d0)
45+
real(c_double), parameter :: T0 = 0.d0
46+
real(c_double), parameter :: Tf = 10.d0
47+
real(c_double), parameter :: dtmax = 0.01d0
48+
real(c_double), parameter :: reltol = 1.d-6
49+
real(c_double), parameter :: abstol = 1.d-10
5050

5151
contains
5252

@@ -60,7 +60,7 @@ module ode_mod
6060
! -1 = non-recoverable error
6161
! ----------------------------------------------------------------
6262
integer(c_int) function Rhs(tn, sunvec_y, sunvec_f, user_data) &
63-
result(ierr) bind(C,name='Rhs')
63+
result(ierr) bind(C, name='Rhs')
6464

6565
!======= Inclusions ===========
6666
use, intrinsic :: iso_c_binding
@@ -147,13 +147,13 @@ program main
147147
print *, " "
148148
print *, "Analytical ODE test problem:"
149149
print '(2(a,f5.2),a)', " lambda = (", real(lambda), " , ", imag(lambda), " ) "
150-
print '(2(a,es8.1))', " reltol = ",reltol,", abstol = ",abstol
150+
print '(2(a,es8.1))', " reltol = ", reltol, ", abstol = ", abstol
151151

152152
! initialize SUNDIALS solution vector
153153
sunvec_y => FN_VNew_Complex(neq, sunctx)
154154
if (.not. associated(sunvec_y)) then
155-
print *, 'ERROR: sunvec = NULL'
156-
stop 1
155+
print *, 'ERROR: sunvec = NULL'
156+
stop 1
157157
end if
158158
y => FN_VGetFVec(sunvec_y)
159159

@@ -163,43 +163,43 @@ program main
163163
! create ARKStep memory
164164
arkode_mem = FARKStepCreate(c_funloc(Rhs), c_null_funptr, T0, sunvec_y, sunctx)
165165
if (.not. c_associated(arkode_mem)) then
166-
print *,'ERROR: arkode_mem = NULL'
167-
stop 1
166+
print *, 'ERROR: arkode_mem = NULL'
167+
stop 1
168168
end if
169169

170170
! main time-stepping loop: calls FARKodeEvolve to perform the integration, then
171171
! prints results. Stops when the final time has been reached
172172
tcur(1) = T0
173-
dTout = (Tf-T0)/Nt
174-
tout = T0+dTout
173+
dTout = (Tf - T0)/Nt
174+
tout = T0 + dTout
175175
yerrI = 0.d0
176176
yerr2 = 0.d0
177177
print *, " "
178178
print *, " t real(u) imag(u) error"
179179
print *, " -------------------------------------------"
180180
print '(5x,f4.1,2(2x,es9.2),2x,es8.1)', tcur(1), real(y%data(1)), imag(y%data(1)), 0.d0
181-
do iout = 1,Nt
181+
do iout = 1, Nt
182182

183-
! call integrator
184-
ierr = FARKodeEvolve(arkode_mem, tout, sunvec_y, tcur, ARK_NORMAL)
185-
if (ierr /= 0) then
186-
write(*,*) 'Error in FARKodeEvolve, ierr = ', ierr, '; halting'
187-
stop 1
188-
endif
183+
! call integrator
184+
ierr = FARKodeEvolve(arkode_mem, tout, sunvec_y, tcur, ARK_NORMAL)
185+
if (ierr /= 0) then
186+
write (*, *) 'Error in FARKodeEvolve, ierr = ', ierr, '; halting'
187+
stop 1
188+
end if
189189

190-
! compute/accumulate solution error
191-
yerr = abs( y%data(1) - Sol(tcur(1)) )
192-
yerrI = max(yerrI, yerr)
193-
yerr2 = yerr2 + yerr**2
190+
! compute/accumulate solution error
191+
yerr = abs(y%data(1) - Sol(tcur(1)))
192+
yerrI = max(yerrI, yerr)
193+
yerr2 = yerr2 + yerr**2
194194

195-
! print solution statistics
196-
print '(5x,f4.1,2(2x,es9.2),2x,es8.1)', tcur(1), real(y%data(1)), imag(y%data(1)), yerr
195+
! print solution statistics
196+
print '(5x,f4.1,2(2x,es9.2),2x,es8.1)', tcur(1), real(y%data(1)), imag(y%data(1)), yerr
197197

198-
! update output time
199-
tout = min(tout + dTout, Tf)
198+
! update output time
199+
tout = min(tout + dTout, Tf)
200200

201201
end do
202-
yerr2 = dsqrt( yerr2 / Nt )
202+
yerr2 = dsqrt(yerr2/Nt)
203203
print *, " -------------------------------------------"
204204

205205
! diagnostics output
@@ -214,7 +214,6 @@ program main
214214

215215
end program main
216216

217-
218217
! ----------------------------------------------------------------
219218
! ARKStepStats
220219
!
@@ -248,9 +247,9 @@ subroutine ARKStepStats(arkode_mem)
248247

249248
print *, ' '
250249
print *, 'Final Solver Statistics:'
251-
print '(4x,2(A,i4),A)' ,'Internal solver steps = ',nsteps(1),', (attempted = ',nst_a(1),')'
252-
print '(4x,A,i5)' ,'Total RHS evals = ',nfe(1)
253-
print '(4x,A,i5)' ,'Total number of error test failures =',netfails(1)
250+
print '(4x,2(A,i4),A)', 'Internal solver steps = ', nsteps(1), ', (attempted = ', nst_a(1), ')'
251+
print '(4x,A,i5)', 'Total RHS evals = ', nfe(1)
252+
print '(4x,A,i5)', 'Total number of error test failures =', netfails(1)
254253

255254
return
256255

0 commit comments

Comments
 (0)