Multi-dimensional arrays need to be padded in the fastest-moving dimension, to ensure array sections to be aligned at the desired byte boundaries : npadded= ((n +veclen– 1) /veclen) *veclen Example:
read moreRecently I had to implement a scientific paper The influence of vegetation, fire spread and fire behaviour on biomass burning and trace gas emissions: results from a process-based model into Fortran code. However, several challenges came up. Specially, edge cases not dealt within several equations. As an example: As seen, the equation shown above is…
read moreFortran namelist is a I/O method introduced in Fortran 77. It later became a standard in Fortran 90. It allows to read/write data as a dictionary like in plain text files. See below for a simple example: Derived types are user defined types. They extend the basic types REAL, INTEGER and LOGICAL. They can be…
read morePerf is a tool used to profile any code in Linux. By following the steps below, you will manage to profile your Fortran binary. It will only provide a simple overview of each function and how much time is spent there. However, this can be your first steps towards improving the execution time of your…
read moreDerived types are User-defined data types that allows to create complex data structures. It is defined with the TYPE statement. In addition, two different derived types exists: The use of PDT’s derived types can be useful in several ways: Its use allows to parametrize the following properties of an array: User types can be parametrized…
read moreWhen launching a “controlled” error it can be useful to show the whole stack trace. In such way, it is easier for the developer to find out where the problem might come. Check below how to do it: The output: Found at Stackoverflow
read moreAmong several things, pointers can be used to represent an array from a specific shape into another one. It can be useful for certain situations. However, the use of pointers is generally not recommended. This is due to potential memory management risks. For instance, It is important to keep the same size when remapping arrays…
read moreEnumeration defines a set of variables related together. It also exists in other languages. Nonetheless, It does not behave in the same way as, for example, in C. That would only allow the enum types when declared. Note It is allowed since the Standard Fortran 2003. Check below how to declare them: How to use…
read moreAn allocatable array is the same as a dynamic array. Its size is not fixed therefore it is not known at compilation time. It is defined at execution time. It has several advantages compared to an explicit shape. The most important of all is its flexibility. It is also more memory efficient because it is…
read moreAbstract objects can have multiple implementations. Fortran does not offer a direct solution to declare them as an array. However, it is still possible to handle it. Check below how to do it: Abstract type: Several implementations: and Declare a dynamic array of concrete objects: Declare a dynamic array of the abstract type shapes: First,…
read more