This chapter covers:
- Overloading operators in a minimal countdown app
- Validating user input
- Synchronization on assignment in the tsunami simulator
Almost any app working with real-world data, or any program more complex than a toy model, will use derived types (classes) to handle abstract data. Fortran’s intrinsic operators for arithmetic (+, -, *, /, **) and comparison (==, /=, >=, ⇐, >, <) are available out of the box for intrinsic numeric (integer, real, complex) but not for derived types. For example, to keep track of calendar date and time in an app, you’d need to compare, add, and subtract datetime instances (data structures that represent date and time). This is where derived types (Chapter 6) and generic procedures and custom operators (Chapter 7) come together to form a powerful feature of the language: Overloading intrinsic operators for derived types. This will allow you to define what the intrinsic (and custom) operators mean for any derived type, and in a way extend the syntax of the language.