Fortran

Guide To Learn

2. Organizing your Fortran code using modules

Exercise 2: Defining the set_gaussian subroutine in a module

The task is to define the set_gaussian subroutine, which sets the values of an input array to a specific shape, in its own module. The solution is analogous to defining the diff function in the mod_diff module. This time, we’re defining the set_gaussian procedure in the mod_initial module, as shown in the following listing. Listing 4.12 Defining the set_gaussian subroutine in a custom module ❶ Imports standard type kinds […]

Exercise 1: Using portable type kinds in the tsunami simulator

The task is to import the portable type kind parameters from the iso_fortran_env module and use them in the tsunami simulator. To do this, we’ll rewrite only the declaration section, as shown in the following listing. Listing 4.11 Using portable type kinds in the tsunami simulator ❶ Assigns a name to the program ❷ Accesses only these two constants from […]

The complete code

Finally, we get to the end! The complete code for the main application is shown in the following listing. Listing 4.10 Complete code of the main program of the tsunami simulator ❶ Imports type kind parameters for numeric data ❷ Imports the diff_centered function from the mod_diff module and renames it as diff ❸ Imports the set_gaussian procedure […]

Renaming imported entities to avoid name conflict

Based on what we’ve covered so far about importing entities from Fortran modules, you can imagine a situation where variables or procedures with the same name could be imported from different modules. What happens in that case? Fortran will let you import two entities with the same name; however, it won’t let you reference them. […]

Updating the finite difference calculation

As you probably noticed in the previous subsection, in the new version of the tsunami simulator we’ll get to apply the diff function not once, but three times. It looks like our work with procedures and modules will finally pay off. There’s just one more thing we need to do, and that is make our finite difference […]

Toward realistic wave simulations

I promised in the previous chapter that we’d finally get to some more realistic wave simulations in this chapter. With the additions to the simulator in the final section of this chapter, our water will finally start to move and slosh like real water would (figure 4.4). Figure 4.4 Simulated wave propagation as a result […]

Scroll to top