Saturday, September 11, 2010

Install gfortran: Windows Binary Installation

I have just installed gfortran on Windows XP using a binary installation. Some binary installation options for Windows can be found at http://gcc.gnu.org/wiki/GFortranBinaries. Below is an outline of the binary options that are available.

Equation.com - Binary builds that are, "are said to work well - but is not affiliated with any MinGW or GCC developer. Use at your own risk." They offer release builds in addition to the latest snapshot. Latest release version 5.4.1. Latest snapshot 4.6.2. http://www.equation.com/servlet/equation.cmd?call=fortran

Cygwin - A Unix like environment for Windows. Binary builds are provided, but Cygwin must be installed, which is something that takes time. For more information, see the Cygwin homepage http://www.cygwin.com/ and then check the gfortran wiki for links to the binaries and instructions if you decide to go that route. Latest version 4.6.x.

Of the above list, I have installed the binaries from MinGW, Equation.com, and Cygwin with success in the past. The Equation.com builds were the easiest to install, as I remember. In addition to the above installation options, I found another binary installation which I will be using for the purposes of this tutorial.

TDM-GCC - Provides an easy to use installer that has the added benefit of integrating nicely with an open source IDE. Only release versions of gcc/gfortran are available. Latest version 4.5.1.http://tdm-gcc.tdragon.net

I chose this option because of the advertised ability to easily integrate with the open source IDE (Integrated Development Environment) Code::Blocks. Here is a little more information about the TDM-GCC binary installation, from the TDM-GCC README file:

This edition of TDM-GCC is an unofficial replacement for the official GCC
binaries distributed by the MinGW project; please note the following caveats: TDM-GCC is not formally affiliated with or endorsed by the MinGW project.
No level of support for TDM-GCC is in any way guaranteed, although a best effort is made to fix bugs as they are found or forward them to GCC Bugzilla.

Using the TDM/MinGW installer is highly recommended; it can automatically
install TDM-GCC (or the official MinGW GCC) as well as all supplementary base
system packages. The installer uses a standard wizard interface with reasonable
defaults.

TDM-GCC Installation

The installation process for this binary installation could not have been easier. From the download page http://tdm-gcc.tdragon.net/download, I selected the "Bundle Installer" option. Downloading the 20MB file "tdm-gcc-4.5.1.exe" goes quickly and then installation is ready to begin. Luckily, TDM-GCC provides a very nice installer that does pretty much everything. Run "tdm-gcc-4.5.1.exe" to launch the wizard installer. We are interested in installing gfortran, however, we will also be installing gcc with their installer. When the wizard launches, following these steps:

Select the mirror to download any updates from. Again, just keep the default (SourceForge).

A list of components is shown. Expand the first item under "Components" which is named "gcc (TDM-GCC Current: 4.5.1-tdm-1)." From the options that drop down, check the box next to "fortran" to ensure that gfortran is installed by the installer. See the screen shot below:

Once you've completed the previous step, click "Install" and wait for the installer to download any updates and complete the installation of gcc/gfortran.

The default wizard options add the necessary directories to the path. To test if the installation was successful, open a command window (Start Menu->Run), enter cmd (see below), and press OK to launch the command line window (equivalent of Terminal on Mac/Linux).

The Windows command line operates much in the same way the Terminal does on Mac/Linux. For example, to test if our gfortran installation was successful, enter the following on the command line:

> gfortran
gfortran: no input files

The gfortran commands for compiling and building are the same as discussed in "Hello!", the previous post below. The only difference is that when a built executable is to be run from the Windows command line, it is invoked with just the file name and nothing else. For example, to build and run our HelloProgram.f95 on Windows, use the following:

> gfortran HelloProgram.f95 -o hello
> hello
Hello!

IDE and Debugger

As mentioned previously, Code::Blocks is an IDE for Windows that was created for use with C/C++. However, there appears to be a Fortran plugin that supports Fortran syntax highlighting, building Fortran projects, and debugging features. It works well with the TDM-GCC binary distribution that was just installed. The Fortran plug-in can be found at http://darmar.vgtu.lt. From the download page, I chose the installation file CodeBlocks_Fortran_v0.4.1_Win32.zip.

Installation instructions are provided at the above website. I have copied the instructions that will allow Code::Blocks to be interfaced properly with the TDM-GCC installation we just installed.

Windows users may need to help Code::Blocks to find MinGW and Fortran compiler on their system. Short instruction:

For example, see the "Toolchain executables" tab filled out correctly below. Would also be valid if the "mingw32-" was removed from each of the fields where it currently resides (check the folder C:\MinGW\bin to see which executables are present).

There seems to be a minor bug (the debug toolbar does not appear) when running the codeblocks.exe file provided in the .zip file from http://darmar.vgtu.lt. This is remedied by launching Code::Blocks with the codeblocks_portable.bat file which is located in the same directory.

Besides that minor glitch, everything seems to work great. Debugging works quite well. There is an option which allows variables to be viewed during debugging, found in “Debug->Debugging Windows->Watches.” There are also other debugging options, such as the ability to view the memory stack.

4 comments:

Hi many thanks it was very useful I am actually a beginner and I stopped in the installation of Gun plot because I am not finding something compatible with the Windows 64 bits which should be in the http://darmar.vgtu. download fileskindly can u assist me to continue

Fortran Resources

A Little Information

I am a relatively inexperienced programmer who has been frustrated by how hard it is for a beginner to find information about programming that is at a beginner level. For example, just installing an open source compiler can be a chore for one inexperienced with the open source community and Unix like systems.

Why Fortran?

There seem to be pros and cons to using each programming language and it seems that no matter how many people you ask, answers will always boil down to personal preference. One thing Fortran is good at is crunching numbers. While you would probably not want to write a user interface with Fortran, it has a place in the scientific and engineering community.

I would encourage any students planning on going into an engineering field to try programming before getting to college to gain familiarity with loops, matrices, and programming logic. Whether or not you want to, all engineers will be exposed to computer programming in some form or another, whether it be C++, Python, Matlab, or something else entirely. Fortran might not be taught at universities, but that doesn't mean the concepts can't be applied to other programming classes. Plus, with open source compilers, it costs nothing to tinker with!

This blog is not meant to be a definitive source for Fortran information. Rather, its aim is to localize any tips and tricks that I have come across that might be helpful to other beginner Fortran programmers. My hope is to present any ideas at a beginner level, which I would have appreciated when I was just beginning to use Fortran.