A Fortran library for miscellaneous utilities such as data structures (List, Vector), root-finding for polynomials and nonlinear equations, etc.
- Author
- Bharat Mahajan (https://www.researchgate.net/profile/Bharat_Mahajan2)
- Version
- 0.1
- Date
- Created: 02/12/2020
- Copyright
- Copyright 2020 Bharat Mahajan
Repository
https://github.com/princemahajan/FMUTIL
Introduction
FMUTil is a modern object-oriented Fortran library that provides (as of now):
- Data structures
- Vector (similar to C++ STL Vectors) with fast vector slicing
- List (similar to Python List)
- Root-finding algorithms
- Polynomial roots by computing eigenvalues of the companion matirx (require Intel MKL)
- Roots of a nonlinear equation using Brent's algorithm
- A simple binary search method for sorted arrays
How to Use
- For Vector data structure of any type, define the type of the Vector element and the assignment operation as follows.
type,
extends(vecelem) ::
relem
real :: rdata
contains
contains
implicit none
class(relem), intent(out) :: lhs
class(VecElem), intent(in) :: rhs
select type (rhs)
lhs%rdata = rhs%rdata
end select
end module TestModule
program test
integer :: ctr
type(Vector) :: vec
type(relem) :: rd1, rd2
rd1%rdata = 3.1416
ctr = vec%PushBack(rd1)
rd1%rdata = 2.718
call vec%Insert(2,[rd1, rd1])
do ctr = 1, vec%Size()
rd2 = vec%ElemAt(ctr)
print *, 'int(', ctr, ')=', rd2%rdata
end do
end program Test
program test
integer :: ctr
type(List) :: list
class(*), allocatable :: item
type(relem) :: rd1
rd1%rdata = 3.1416
ctr = list%PushBack(100)
ctr = list%PushBack(rd1)
ctr = list%PushBack(rd1%rdata)
ctr = list%Insert(3,'pi')
do ctr = 1, list%Size()
item = list%Item(ctr)
select type (item)
type is (real)
print *, item
type is (relem)
print *, item
type is (integer)
print *, item
type is (chanracter(len=*))
print *, item
end select
end do
end program Test
- See the test program files, test.f90 and testmod.f90, in tests folder for more features and functionality.
Installation
FMUTIL is tested with Intel Fortran Compiler and MinGW-W64 gfortran. Doxyfile is provided for generating extensive API documentation using Doxygen. FMUTIL has only dependency on Intel MKL for polynomial root-finding. The CMakeLists file is provided along with additional CMake modules for compiler options and a Find module for finding and linking Intel MKL is also provided. These files can be used to auto generate Visual Studio projects or makefiles on Windows and Linux using CMake. A find module for FMUTIL is provided that generates CMake config files for easily linking FMUTIL using the find_package() command. The steps to link FMUTIL in cmake-based projects are:
- Set the environment variable "MKLROOT" with the path to the Intel MKL installation directory. On typical Windows system, it looks something like "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.0.117\windows\mkl"
- Set the environment variable "IFORT_COMPILER20" with the path to the Fortran Compiler installation directory. On typical Windows system, it looks something like "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020\windows\"
- In cmake GUI or command-line, set FMUTIL_INSTALL_LIB_DIR to the desired directory, where the compiled library, modules, and cmake config files will be installed.
- In cmake GUI or command-line, set FMUTIL_INSTALL_BIN_DIR to the desired directory, where the compiled test executables will be installed.
- In your project CMakeLists.txt, insert
find_package(
fmutil required 0.1 config
paths "<SAME_PATH_AS_IN_FMUTIL_INSTALL_LIB_DIR>" no_cmake_package_registry)