Fortran 2018 modernization: use the extended “implicit none” syntax

The statement “implicit none” forbids implicit typing of variables, but not
implicit procedure declaration. The new “implicit none (type, external)” syntax
forbids both, and is thus safer.
mr#2134
Sébastien Villemot 2023-04-14 14:21:01 +02:00
parent 0923187938
commit 62c2881bc2
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
25 changed files with 70 additions and 68 deletions

View File

@ -1,4 +1,4 @@
! Copyright © 2019-2021 Dynare Team
! Copyright © 2019-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -17,7 +17,7 @@
module blas
use iso_fortran_env
implicit none
implicit none (type, external)
#if defined(MATLAB_MEX_FILE) && __SIZEOF_POINTER__ == 8
integer, parameter :: blint = int64
@ -103,7 +103,7 @@ end module blas
module lapack
use blas
implicit none
implicit none (type, external)
interface
subroutine dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)

View File

@ -1,7 +1,7 @@
! Wrapper around MATLABs dmperm to compute the Dulmage-Mendelsohn
! decomposition
! Copyright © 2020 Dynare Team
! Copyright © 2020-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -21,7 +21,7 @@
module dulmage_mendelsohn
use iso_fortran_env
use matlab_mex
implicit none
implicit none (type, external)
! Represents a block in the fine DM decomposition
type :: dm_block

View File

@ -34,7 +34,7 @@ module matlab_fcn_closure
use iso_c_binding
use ieee_arithmetic
use matlab_mex
implicit none
implicit none (type, external)
private
public :: func, extra_args, f_indices, x_indices, x_all, matlab_fcn

View File

@ -1,4 +1,4 @@
! Copyright © 2019-2022 Dynare Team
! Copyright © 2019-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +22,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use matlab_mex
use matlab_fcn_closure
use trust_region
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,7 +1,7 @@
program dmperm_test
use iso_fortran_env
use dulmage_mendelsohn
implicit none
implicit none (type, external)
real(real64), dimension(12, 11) :: M
integer, dimension(size(M, 1)) :: row_order

View File

@ -1,7 +1,7 @@
program trust_region_test
use trust_region
use iso_fortran_env
implicit none
implicit none (type, external)
real(real64), dimension(2), parameter :: rosenbrock_guess = [ -10**4, 1 ]
real(real64), dimension(2), parameter :: rosenbrock_solution = [ 1, 1 ]

View File

@ -2,7 +2,7 @@
!
! Implementation heavily inspired from the hybrj function from MINPACK
! Copyright © 2019-2021 Dynare Team
! Copyright © 2019-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +22,7 @@
module trust_region
use iso_fortran_env
use lapack
implicit none
implicit none (type, external)
private
public :: trust_region_solve

View File

@ -1,4 +1,4 @@
! Copyright © 2022 Dynare Team
! Copyright © 2022-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +22,7 @@ module c_reduction
use lapack
use blas
use matlab_mex
implicit none
implicit none (type, external)
contains
@ -111,7 +111,7 @@ end module c_reduction
subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use c_reduction
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs
@ -191,4 +191,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
end if
end if
end subroutine mexFunction
end subroutine mexFunction

View File

@ -20,7 +20,7 @@
! This is a Fortran translation of a code originally written by Joe Pearlman
! and Alejandro Justiniano.
! Copyright © 2020-2022 Dynare Team
! Copyright © 2020-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -42,7 +42,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use ieee_arithmetic
use matlab_mex
use lapack
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,4 +1,4 @@
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +22,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use simulation
use matlab_mex
use partitions
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs
@ -98,4 +98,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
end do
end if
end subroutine mexFunction
end subroutine mexFunction

View File

@ -1,4 +1,4 @@
! Copyright © 2021-2022 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -39,7 +39,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use matlab_mex
use partitions
use simulation
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,4 +1,4 @@
! Copyright © 2021-2022 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -36,7 +36,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use matlab_mex
use partitions
use simulation
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,7 +1,7 @@
! This MEX file computes A·(B⊗C) or A·(B⊗B) without explicitly building B⊗C or
! B⊗B, so that one can consider large matrices B and/or C.
! Copyright © 2007-2022 Dynare Team
! Copyright © 2007-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -23,7 +23,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use iso_c_binding
use matlab_mex
use blas
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,8 +1,8 @@
! Provides subroutines to manipulate indexes representing elements of
! a partition for a given integer
! i.e. elements p = (α₁,…,αₘ) where each αᵢ ∈ { 0, ..., n-1 }
!
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -23,7 +23,7 @@ module partitions
use pascal
use sort
use iso_fortran_env
implicit none
implicit none (type, external)
! index represents the aforementioned (α₁,…,αₘ) objects
type index
@ -354,7 +354,7 @@ end module partitions
! program test
! use partitions
! use pascal
! implicit none
! implicit none (type, external)
! type(index) :: uidx, fidx, i1, i2
! integer, dimension(:), allocatable :: folded
! integer :: i, uj, n, d, j, nb_folded_idcs
@ -425,4 +425,4 @@ end module partitions
! print '(i3)', (nbeq(i), i=1,nb_folded_idcs)
! print '(i4)', (off(i), i=1,nb_folded_idcs)
! end program test
! end program test

View File

@ -1,6 +1,6 @@
! Provides a subroutine to build Pascal's triangle
!
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -18,7 +18,7 @@
! along with Dynare. If not, see <https://www.gnu.org/licenses/>.
module pascal
implicit none
implicit none (type, external)
type line
integer, dimension(:), allocatable :: coeffs
@ -107,4 +107,4 @@ end module pascal
! print '(i2)', multinomial([1,2,3], d, p) ! should print 60
! print '(i2)', multinomial([0,0,0,3], d, p) ! should print 20
! end program test
! end program test

View File

@ -1,7 +1,8 @@
! Necessary routines and functions to carry out simulations
!
! A first step is to get the associated
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +23,7 @@ module simulation
use iso_fortran_env
use partitions
use lapack
implicit none
implicit none (type, external)
! Used to store the folded decision rule tensors
type :: pol

View File

@ -1,7 +1,7 @@
! Provides a subroutine to sort integer arrays in ascending order
! As the addressed arrays are small, I use the insertion sort algorithm
!
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -19,7 +19,7 @@
! along with Dynare. If not, see <https://www.gnu.org/licenses/>.
module sort
implicit none
implicit none (type, external)
contains
subroutine sort_int(l)
@ -36,4 +36,4 @@ contains
end do
end subroutine sort_int
end module sort
end module sort

View File

@ -1,4 +1,4 @@
! Copyright © 2021 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -14,11 +14,12 @@
!
! You should have received a copy of the GNU General Public License
! along with Dynare. If not, see <https://www.gnu.org/licenses/>.
module struct
use iso_fortran_env
use iso_c_binding
use matlab_mex
implicit none
implicit none (type, external)
contains
@ -33,4 +34,4 @@ module struct
get_int_field = int(mxGetScalar(tmp))
end function get_int_field
end module struct
end module struct

View File

@ -1,4 +1,4 @@
! Copyright © 2022 Dynare Team
! Copyright © 2022-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -20,7 +20,7 @@ module pparticle_3
use matlab_mex
use partitions
implicit none
implicit none (type, external)
type tdata_3
integer :: n, m, s, q, numthreads, xx_size, uu_size, xxx_size, uuu_size
@ -340,7 +340,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use partitions
use pthread
use pparticle_3
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs
@ -577,4 +577,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
end do
end if
end subroutine mexFunction
end subroutine mexFunction

View File

@ -1,4 +1,4 @@
! Copyright © 2021-2022 Dynare Team
! Copyright © 2021-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -21,7 +21,7 @@ module pparticle
use simulation
use matlab_mex
implicit none
implicit none (type, external)
type tdata
integer :: nm, nys, endo_nbr, nvar, order, nrestricted, nparticles
@ -94,7 +94,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use matlab_mex
use pthread
use pparticle
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,4 +1,4 @@
! Copyright © 2022 Dynare Team
! Copyright © 2022-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -22,7 +22,7 @@ module l_reduction
use lapack
use blas
use matlab_mex
implicit none
implicit none (type, external)
contains
@ -126,7 +126,7 @@ end module l_reduction
subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use l_reduction
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs
@ -210,4 +210,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
end if
end if
end subroutine mexFunction
end subroutine mexFunction

View File

@ -1,4 +1,4 @@
! Fortran 2008 interface for a subset of MEX functions
! Fortran 2018 interface for a subset of MEX functions
!
! For some functions, exposing the C interface directly is not convenient (e.g.
! when they use C strings, since those need to be null-terminated, or when they
@ -28,7 +28,7 @@
! Fortran compiler better optimize the code (in some cases, this will avoid
! array copies)
! Copyright © 2019-2022 Dynare Team
! Copyright © 2019-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -66,7 +66,7 @@
module matlab_mat
use iso_fortran_env
use iso_c_binding
implicit none
implicit none (type, external)
!! C Data Types
integer, parameter :: mwSize = c_size_t
@ -411,7 +411,7 @@ end module matlab_mat
!!! Listed in same order as https://fr.mathworks.com/help/matlab/call-mex-files-1.html
module matlab_mex
use matlab_mat
implicit none
implicit none (type, external)
interface
integer(c_int) function mexCallMATLAB_internal(nlhs, plhs, nrhs, prhs, functionName) bind(c, name="mexCallMATLAB"//API_VER)

View File

@ -18,7 +18,7 @@
! eigval [complex] (n×1) vector of generalized eigenvalues
! info [integer] scalar, error code of dgges (or 30 if eigenvalue close to 0÷0)
! Copyright © 2006-2022 Dynare Team
! Copyright © 2006-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -39,7 +39,7 @@
module select_fct_mod
use iso_fortran_env
implicit none
implicit none (type, external)
real(real64) :: criterium
contains
@ -58,7 +58,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use select_fct_mod
use matlab_mex
use lapack
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs

View File

@ -1,4 +1,4 @@
! Copyright © 2022 Dynare Team
! Copyright © 2022-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -18,7 +18,7 @@
! Wrapper around pthread_create and pthread_join C routines for POSIX multithreading
module pthread
use iso_c_binding
implicit none
implicit none (type, external)
private
public :: c_pthread_create

View File

@ -1,4 +1,4 @@
! Copyright © 2022 Dynare Team
! Copyright © 2022-2023 Dynare Team
!
! This file is part of Dynare.
!
@ -28,7 +28,7 @@
subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
use matlab_mex
use blas
implicit none
implicit none (type, external)
type(c_ptr), dimension(*), intent(in), target :: prhs
type(c_ptr), dimension(*), intent(out) :: plhs
@ -95,4 +95,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction')
! Pnew <- tmp1*T' + Pnew
call matmul_add("N", "T", 1._real64, tmp1, T, 1._real64, Pnew)
end subroutine mexFunction
end subroutine mexFunction