How to Choose the Best Fortran 90 Compiler: A Complete Guide with Examples
Fortran is one of the oldest and most powerful programming languages used for scientific and engineering computations. With the release of Fortran 90, a major update introduced modern features like free-form syntax, dynamic memory allocation, and modules, which made the language even more versatile. However, to harness the power of Fortran 90, you need an efficient Fortran 90 compiler. In this article, we'll take a closer look at the Fortran 90 compiler, explore its features, and show you some examples to get you started.
What Is a Fortran 90 Compiler?
A Fortran 90 compiler is a software tool that translates your Fortran 90 source code into machine-readable instructions, allowing the program to run on a computer. A Fortran 90 compiler ensures that your code follows the rules of the Fortran 90 language standard and optimizes it for better performance. Without a proper compiler, your Fortran 90 program would not be executable, regardless of how efficiently it's written.
Over the years, several Fortran compilers have been developed to support Fortran 90, and they come with different features, optimization techniques, and compatibility options. Some of the most well-known Fortran compilers include the GNU Fortran (gfortran), Intel Fortran, and NAG Fortran Compiler. Each of these compilers has its advantages, so it's essential to choose the right one based on your needs.
Features of a Good Fortran 90 Compiler
When selecting a Fortran 90 compiler, there are several factors you should consider to ensure that the compiler meets your requirements. Some key features to look for in a Fortran 90 compiler include:
- Compatibility: The compiler should support the full Fortran 90 language standard, as well as newer standards such as Fortran 95, 2003, and 2008.
- Optimization: A good compiler should optimize your code for performance, allowing you to run simulations or computations faster and more efficiently.
- Debugging Support: Debugging is a crucial part of any programming project. A reliable Fortran 90 compiler should provide good debugging tools to help you find and fix errors in your code.
- Portability: The compiler should be compatible with different operating systems (e.g., Windows, Linux, macOS) and hardware architectures.
- Community and Support: A well-supported compiler, such as gfortran, often comes with extensive documentation, community forums, and other resources to help you troubleshoot problems and improve your coding skills.
Popular Fortran 90 Compilers
There are many Fortran 90 compilers available, each with its unique features and capabilities. Below are some of the most popular compilers that support Fortran 90:
1. Gfortran (GNU Fortran)
Gfortran is the free and open-source Fortran compiler from the GNU Compiler Collection (GCC). It supports Fortran 90, 95, and later versions, making it a powerful tool for compiling Fortran programs. Gfortran is widely used in academia, research, and industry because of its versatility and wide support across different platforms.
One of the advantages of Gfortran is its cross-platform compatibility. It works on Linux, macOS, and Windows, and it integrates well with other GCC tools, which can be useful for projects that require mixed-language programming (such as C and Fortran together).
To compile a Fortran 90 program with gfortran, use the following command in the terminal:
$ gfortran -o my_program my_program.f90
This will create an executable file called my_program from the Fortran source code in my_program.f90.
2. Intel Fortran Compiler
The Intel Fortran Compiler is a commercial product developed by Intel that offers high performance and advanced optimization techniques. It is known for producing highly optimized code for Intel processors, making it an excellent choice for large-scale numerical computations and scientific simulations.
Intel Fortran also supports the Fortran 90 standard and offers a number of additional features, such as automatic parallelization and vectorization, which can significantly improve the performance of your programs.
To compile a Fortran 90 program with Intel Fortran, use the following command:
$ ifort my_program.f90 -o my_program
Intel Fortran is particularly popular in fields such as computational fluid dynamics (CFD), weather forecasting, and financial modeling, where performance is a top priority.
3. NAG Fortran Compiler
The NAG Fortran Compiler is a commercial compiler that emphasizes reliability and accuracy in scientific computing. It supports the full Fortran 90 standard and is designed for high-performance computing (HPC) applications.
The NAG Fortran Compiler also provides extensive error checking and diagnostics, which can be helpful when working on complex scientific simulations. It is especially popular in academic and research settings due to its focus on correctness and numerical stability.
To compile a Fortran 90 program with NAG Fortran, use the following command:
$ nagfor my_program.f90 -o my_program
Fortran 90 Compiler Examples
Let’s dive into some practical examples of using a Fortran 90 compiler to compile and run Fortran 90 programs. Below are a few examples you can try on your own to understand the process better.
Example 1: Basic Fortran 90 Program
Let’s start with a simple "Hello, World!" program written in Fortran 90. Save the following code in a file named hello.f90:
program hello
print *, "Hello, World!"
end program hello
To compile and run this program using gfortran, use the following commands:
$ gfortran hello.f90 -o hello $ ./hello
This should output: Hello, World!
Example 2: Fortran 90 with Arrays
Fortran is known for its powerful array manipulation capabilities. Let’s create a program that calculates the sum of two arrays. Save the following code in a file named array_sum.f90:
program array_sum
integer, dimension(5) :: A, B, C
integer :: i
! Initialize arrays A and B
A = [1, 2, 3, 4, 5]
B = [6, 7, 8, 9, 10]
! Sum arrays
C = A + B
! Print result
print *, "Array A: ", A
print *, "Array B: ", B
print *, "Sum of arrays: ", C
end program array_sum
Compile and run the program as follows:
$ gfortran array_sum.f90 -o array_sum $ ./array_sum
The output should display the arrays and their sum:
Array A: 1 2 3 4 5 Array B: 6 7 8 9 10 Sum of arrays: 7 9 11 13 15
Conclusion: Choosing the Right Fortran 90 Compiler
In conclusion, a Fortran 90 compiler is an essential tool for anyone working with Fortran 90 programs. Whether you choose a free compiler like gfortran or a commercial option like Intel Fortran or NAG Fortran, selecting the right compiler can make a significant difference in terms of performance, debugging, and compatibility with your development environment.
By experimenting with different compilers and exploring the examples provided, you'll be well on your way to mastering Fortran 90 and unlocking its full potential for scientific and engineering applications.

Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!