Writing Fortran modules for TONTO

The overriding principle which is used in writing modules in TONTO is this:

A module is used to describe a single data type. That is, all the routines within the module concern manipulations on the data type.

This is a very general principal. In practice, there are a number of critical requirements which need to be specified so that different users can make use of each others work in an effective way. There are also aesthetic requirements which make the code more uniform and easily read.

The foo preprocessor automatically generated code which conforms to both the critical and aesthetic requirements, but you are not required to use it; this Chapter will be useful for those programmers who want to use only Fortran.

The foo preprocessor, and how to write foo modules for TONTO are described in separate Chapters.

Critical requirements

Here is the list of critical requirements which are used in TONTO :

The reason for making every routine in the module private is to prevent namespace pollution. For example, the routine get_item may be a common possibility for a routine name; using the private attribute prevents any possible name clash, since the routine may not be used. Instead, only the generic name may be used. Indeed, the provision of a generic interface means that other modules may deliberately re-use the name of the routine without a name conflict. This is called overloading. Overloading a generic name in different modules should be employed whenever the overloaded routine name performs a similar function in the different modules.

For example, suppose REALMAT and CPXMAT are two modules which describe matrices of real and complex numbers, respectively. The same generic interface name trace_ might be used in both modules to describe a routine which returns the trace of the matrix, whether real or complex. If every procedure in REALMAT had a corresponding procedure in CPXMAT with the same generic name, any code written initially using real matrices using the trace_ routine will also work for complex matrices, if the variables involved are redeclared. This is a simple example of the concept of code inheritance.