Fortran

Guide To Learn

Writing the generic interface

At this point, we have our specific procedures implemented. Now we need to define the interface such that we can simply invoke average(temperature), average(wind_speed), and so on, rather than having to match the data types, like average_real(temperature), average_int(wind_speed), and so on. To do so, we’ll open an interface block at the top of the module, before the contains statement, that will […]

Writing the specific functions

In this subsection, we’ll implement all three specific functions, one for each data type that we intend to parse: integer, real, and logical. We’ll need the following specific functions: Let’s write the first specific function, which will operate on real arrays. Note that we already wrote this function in section 5.3, when analyzing stock price time series. The real implementation […]

The problem with strong typing

In the previous section, we learned that Fortran’s strong typing discipline prohibits passing arguments of incompatible data types to procedures. This means that when you write a function that expects a real number as input, you can’t simply pass an integer as an input argument. This would trigger a compile-time error. You can see this […]

Static versus strong typing

Static and strong typing are often confused and used interchangeably. However, they describe two different properties of a programming language. A statically typed language assumes that all variables must have either a manifestly declared data type (like in Fortran or C) or a data type inferred from their use (like in Julia, Nim, or Rust) at compile time. […]

Strategy for this exercise

To find the city with the optimal climate, we’ll go through the following steps: Sounds easy, right? We covered most of the logistics around reading and processing time series data in chapters 5 and 7. Here, we’ll focus on implementing the generic average function that can operate on integer, real, or logical data.

Scroll to top