Exercise: Modules and Derived Types
Continuing our vector theme, we will create a derived type for vectors in a module, along with functions for dot and cross product. (Note that although this is useful for pedagogical purposes, in practice one should use simple Fortran arrays where possible, as performance will generally be better that way). Although Intel's ifort
allows a dot (.
) notation for accessing members of the derived type, as is common to many other languages, different compilers may not, and so we stay with the %
notation.
Create a vectorsModule.f90
file:
Compile the file:
Now create calcVectors.f90
:
Compile and run: