Fortran

Guide To Learn

Core elements of Fortran

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 […]

Putting it all together in the tsunami simulator

You now know how to import variables and procedures from modules, and also how to write your own modules. Finally, we get to put this all together to refactor, improve, and expand our wave simulator. If you’ve followed the lessons in this section, and if you’ve worked through both exercises in this chapter, you now […]

Controlling access to variables and procedures

Modules allow you to specify the visibility of variables and procedures defined in them. All entities in a module can be either public or private: For example, let’s take a look at a module that defines a function to calculate the area of a circle, given an input radius. The following listing shows how that’s […]

 Compiling Fortran modules

The tsunami simulator source code is now made of two source files: the main program (tsunami.f 90), which defines the top-level simulation loop, and the finite difference module (mod_diff.f 90). In all our work so far, we’ve always compiled our Fortran programs from single-source files. How do you compile a program that’s defined across multiple […]

The structure of a custom module

Before we begin, let’s see what a custom module may look like on the inside, and how its building blocks work (figure 4.3). Figure 4.3 Structure of a custom Fortran module Every Fortran module is defined with a pair of module/end module statements. Modules can’t have any executable code on their own. Instead, they’re used to declare data […]

Creating your first module

You’re now ready to tackle the next big item–writing your own custom module. Let’s do so by implementing it directly in the tsunami simulator. Recall that in the previous chapter we created two procedures: We defined both of these procedures in the main program. This worked well because our simulator was still rather simple. However, […]

Using portable data types

In chapter 2, I mentioned that variables of built-in types can be explicitly and portably declared using specific type kinds. Type kind parameters determine the space that numeric variables occupy in memory, which in turn limits the range for integers, and the range and precision for real and complex numbers. Most Fortran compilers by default […]

Scroll to top