00. Fortran Package Manager
The Fortran Package Manager (FPM) is a modern build system and package manager specifically designed for Fortran. FPM aims to simplify the process of building and testing Fortran software by providing tools and conventions that streamline these tasks. We have used FPM to help build our project.
Key Features of FPM:
-
Easy Project Creation: FPM makes it straightforward to create new Fortran projects with standardized directory structures and documentation.
-
Dependency Management: FPM handles dependencies between Fortran packages, making it easier to include external libraries and manage their versions.
-
Building and Compiling: It automates the compilation process, ensuring that Fortran code is compiled with the appropriate flags and settings.
-
Testing: FPM supports automated testing, which helps in maintaining code quality and reliability.
How to install FPM
See here for a guide on how to install FPM.
How to use FPM
In order to illustrate the uses of FPM we have created a small program in the repository called fortran_fibonacci
. In your terminal open this directory. Inside this directory we have a very simple Fortran code built with FPM. The FPM repository was initiated with the command fpm new fortran_fibonacci
and following the guide here.
To run this program type fpm run -- N
where N
is an integer. The program should return the N
th Fibonacci number.
The structure of the repository is given by
├── README.md
├── app
│ └── main.f90
├── fpm.toml
├── src
│ └── fibonacci.f90
├── LICENSE
└── test
└── check.f90
README.md
file describes how to set up the program.
The important commands when using FPM are:
-
fpm run
which compiles and runs the code -
fpm test
which complies and runs the test -
fpm help
which prints to screen all the possible FPM commands
The other important file is fpm.toml
. This file is used to configure various aspects of a Fortran project. See here for the structure of this file.
For now, the important sections are [fortran]
, which sets the default compiler settings and [dev-dependencies]
which imports the testing framework.
Testing
Here is the testing module for the program. It has a module filed with tests, test_demo
, and a program that calls and runs the tests, tester
.
Starting with test_demo
, there are three tests: test_negative
, test_0_or_1
and test_greater_than_1
. All these subroutines have an error
as an output. The error is calculated with the intrinsic check
; for example on line 26
, call check(error, fib(-6), -1)
checks if fib(-6)==-1
and returns an error if it is not.
These three tests are collected in the subroutine collect_tests
and included in the testsuite
unit test. Each new_unittest(string, test)
has a string input that gets printed to the screen when the test is run, and a subroutine test that only returns an error.
The program tester
then calls the testsuite
and reports any error it finds.