Debug SWAT in Eclipse – Utilize Makefile.

Don’t Want to Go through all these Processes?

No problem. The Eclipse project created in this post is uploaded to Google Code: Just check out and open in Eclipse. It’s done!

This version also add Make Target, which is a quick way to build and clean the project. Just double-click to build or clean specific version.

It’s recommended to use SVN Plugin for Eclipse to do this work. I would have another post on this topic in the near future. Please stay tuned.


  • Find Fortran Project… Menu
  • Create an Empty Makefile Project
  • Setup the Project
    • Binary Parser
    • Error Parsers
    • Fortran Build Configuration
  • Copy SWAT Source Codes and Generate Makefile
  • Build Project
  • Debug/Run SWAT.exe

Please note

  1. To compile SWAT, MinGW needs to be installed first. Please refer to another post MinGW Installation Guide for SWAT Debugging
  2. Eclipse KEPLER and PTP 7.0.3 was used in this post. These steps should also be able to be used in other version of Eclipse and PTP. For more information, please refer to my previous post Compile and Run SWAT with Photran + MinGW – the easiest way to remove mathematical errors from SWAT.

A Makefile is created in previous post. To use it in Eclipse (Photran/PTP), instead of Executable (Gnu Fortran on Windows) project, we should use the Makefile project, which would allow use of user-defined Makefile.

This post will show you how to create and configure a SWAT Makefile project to utilize the makefile.

Find Fortran Project… Menu

The Fortran Project is not list in menu File -> New when PTP is used the first time. In this case, select Projects… to open New Project window. In this window, you would find Fortran project under Fotran folder. Select it and click Next to create the project. When it’s done, you will be asked if you want to open Fortran perspective. Select Yes. The Fotran Project option would be list in menu File -> New.

Create an Empty Makefile Project

File -> New -> Fortran Project

The project name is SWAT. Select Empty Project under Makefile project and select — Other Toolchain —. Click finish to create the project..

Setup the Project

Open the Property window through right click on the project and select “Properties” to setup the project.

Binary Parser

In Fotran -> Build -> Setting, select PE Windows Parser for Binary Parsers (I’m working a Windows machine)..

Error Parsers

Select Photran Error Parser for GNU Fortran (gfortran) for Error Parsers and move it to the top. This option is not selected when the project is created.

Fortran Build Configuration

Select Fortran Build in the left panel, un-check Use default build command and change Build Command to mingw32-make.

Add debug/ to build directory as there will be two versions of Makefile, one is located in debug folder and another is located in release folder. This one is for debug version.

Change configuration name from Default to Debug.

The default configuration name is Default. It would be nice to rename it to debug. Click Manage Configurations… to open Manage Configurations window. Select default and click Rename… to change name to Debug.

Create Release Configuration

As mentioned before, there is also a release version of Makefile. It’s necessary to make a configuration for it. Here, we could copy all the settings from debug configuration to save time.

Click New… on Manage Configurations window to open Create New Configuration window. Input name as Release and select to copy settings from Debug configuration.

Change the Build directory to ${workspace_loc:/SWAT}/release/.

Copy SWAT Source Codes and Generate Makefile

Copy all the SWAT source codes to the project folder and refresh the project in Eclipse. It would show all the files. Remember to comment the first line in main.f.

Download the GenerateMakefile program and save it into the project folder. Run it to generate the Makefile for debug and release version.

Build Project

Now, it’s ready to build the project, i.e. compile SWAT source codes. Right-click the project and select Build Project to start compile SWAT source codes. You would see some output information from Console window in the bottom. From there, you would know whether or not the process is finished. All the warnings and errors would also be found in this window.

Debug/Run SWAT.exe

After SWAT is compiled successfully, it’s ready to run SWAT. Before that, there is one thing to do: setup Run/Debug Settings, which could be completed in Properties window.

Select Run/Debug Settings in the left panel and click New… to create a Run/Debug Settings. We will first create the settings for debug version. Same as the build configuration, the setting for release version could be also copied from debug version.

In the Main tab, input Fortran Application as debug\SWAT.exe.

In Arguments table, change Working directory to the model txtinout folder.

In Debugger tab, select MinGW gdb for Debugger and uncheck Stop on startup at: option.

In Common tab, select Debug in Display in favorites menu to show the setting in debug menu.

Click debug menu in the toolbar to start running SWAT.

The output information would be display in the Console window.

If some breakpoints are set, SWAT would stop running on breakpoints and ask if want to change to Debug perspective. Click yes to change to Debug perspective, which would re-arrange the windows to facilitate debugging.

You would has change to check all the variable values in Variables window under debugging mode.

Click Fortran button on the up right corner, Eclipse would go back to Fortran perspective, which is designed for coding.

Click the Debug button in the up right corner to return to Debug perspective.

© 2000 – 2021 SWAT Output Viewer All rights reserved