8 Working with abstract data using derived types

 

This chapter covers

  • Using derived types to create new collections and data types
  • Binding procedures to derived types
  • Refactoring the tsunami simulator to two dimensions using derived types

So far in this book we’ve worked only with the core Fortran data types: integer, real, complex, logical, and character. Although even with just these data types we’ve been able to do quite a few useful things, such as analyze time series of stock prices or buoy measurements, or write a parallel tsunami simulator, we’re still somewhat limited in what we can do. This becomes more obvious as we encounter more complex problems with abstract and unstructured data that are ubiquitous in real-world applications. So far, all of the examples we’ve worked on have been structured and thus easy to tackle with the core numeric types and arrays alone. However, this is just a small subset of problems, and real-world applications and data will require more complex and abstract data structures in our code. Such applications include machine learning, web and mobile apps, and more sophisticated physics simulations.

8.1 Recasting the tsunami simulator with derived types

 
 
 

8.2 Defining, declaring, and initializing derived types

 
 

8.2.1 Defining a derived type

 
 
 

8.2.2 Instantiating a derived type

 
 
 
 

8.2.3 Accessing derived type components

 
 
 

8.2.4 Positional vs. keyword arguments in derived type constructors

 
 

8.2.5 Providing default values for derived type components

 
 

8.2.6 Writing a custom type constructor

 
 

8.2.7 Custom type constructor for the Field type

 
 

8.3 Binding procedures to a derived type

 
 

8.3.1 Your first type-bound method

 
 
 

8.3.2 Type-bound methods for the Field type

 
 
 

8.3.3 Controlling access to type components and methods

 
 

8.3.4 Bringing it all together

 
 
 
 

8.4 Extending tsunami to two dimensions

 
 

8.4.1 Going from 1-D to 2-D arrays

 
 

8.4.2 Updating the equation set

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest