concept field class in category fortran

appears as: Field class
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

You may have noticed that in listing 8.12, we assigned the result of diffx(h) (a two-dimensional real array) to dh, a Field instance. Normally this shouldn’t work, because the compiler on its own doesn’t know how to assign a real array to a Field instance. For this to work, we’ll need to define the custom assignment operator for the Field class with a special function. We’ll explore this and other advanced derived type topics in detail in the next chapter.

In this chapter, we’ll start by writing a simple command-line app that counts the time between now and some arbitrary date in the future, for example, your birthday. The implementation of the app is centered around a single concept-- how to apply an arithmetic operator such as addition or subtraction to a derived type. On this journey, you’ll also learn how to parse command-line arguments, validate user input, and work with dates and times. Once done, we’ll apply this knowledge to implement an almost complete arithmetic operator set for the Field class in the tsunami simulator. Besides being able to express our physics equation in an elegant way like before, we’ll also abstract away the synchronization logic in parallel execution mode by defining a custom assignment operator for the Field class. You’ll leave this chapter with powerful new knowledge that will allow you to extend the built-in arithmetic to arbitrary data types and beyond.