Due to Fortran being a strong type language It is required to have an implementation of the same algorithm for each type. Once done, it provides a generic subroutine. In order to achieve it in Fortran it is must be implemented in the following way: Finally: Output: ./a.out 5 11.0000000 15 No need to say…

read more

Fypp preprocessor generates Fortran code based on Python language. However, in some cases it is not straightforward. Read below to discover how to create higher level functions. Let’s say our program requires to allocate an array for N supported ranks. dim is an array with the size of each rank. To make it possible We…

read more

Overloading a subroutine means to redefine its internal functionality for a customized behavior. Overall it adapts the class new characteristics to already wide-spread Fortran functionalities (==, =, + ,-, …). Specifically, this post only focus on the operators (+,-,*,/). In the following example, mynumber is generic class to hold any type of an integer number.…

read more

Overloading a subroutine means to redefine its internal functionality for a customized behavior. Overall it adapts the class new characteristics to already wide-spread Fortran functionalities (==, =, + ,-, …). Specifically, this post only focus on assignment (=). In the following example, Mynumber is generic class to hold any type of real number. For that…

read more

Deferred procedures are those functions/subroutines that will be later implemented in a specific derived type. For instance, It can only be declared on abstract derived types. To illustrate it, our problem requires a generic class that enforces the equal (==) property. Fortran classes must implement/overload the generic ‘==’ so it is possible to compare them.…

read more

Fypp is a python based preprocessor to generate source code. It is usefull to overcome some Fortran weaknesses regarding array dimensions, types (and kind). Follow the instructions below to integrate into your CMake project. The following exmaple assumes the current project structure as: yourproject/ cmake/ utils.cmake src/ CMakelists.txt main.f90 subr.fpp common.fpp bin/ CMakelists.txt Create utils.cmake…

read more

Allocatable array is a dynamic array. It’s size is not know at compilation time. Therefore it is defined at execution time by using the keyword allocate(…). It’s life scope is kept where it is defined. Once the procedure/… reaches the end it is automatically deallocated (or released). Nevertheless, you should be careful when using allocatable…

read more

A pointer in computer programming is an object that refers to a memory address. In Fortran it is declared with the keyword pointer in its declaration. Additionally its assignment is done with the => keyword. However, in order to have an array of pointers, the following form must be used: Do not fall into the…

read more