Integrate Modeled SWAT Version in Action

The basic processes to make the modified SWAT version work with SWAT Output Viewer has been covered in previous video. Many users wants to have a more detailed, step-by-step tutorial video so they could follow along to compile the viewer-compatible version themselves. So here it is.

Software Required

  1. Source Tree to clone GitHub repository and merge changes.
  2. Intel Fortran to compile the program.
  3. Tortoise Git to resolve conflicts.

GitHub Repository


1. Clone swat_sqlite repository in SourceTree.

Modified SWAT - Clone Repository

2. Create branch based on tag SWAT_Rev664 or SWAT_Rev627. Select them based on your modified version.

Modified SWAT - Create Branch

3. Copy your modified code to the local directory selected in step 1. Overwrite all existing files.

4. Commit all changes.

Modified SWAT - Commit Change

5. Merge corresponding SQLite branch. For SWAT v627, select SWAT_SQLITE_Rev627.  For SWAT v664, select SWAT_SQLITE_Rev664.

Modified SWAT - Merge SQLite branch

6. Solve conflicts. Conflicts happens when same content is modified differently in two branch. You need to tell Git which version to use. There are various tools to help visually do that. The example here is using TortoiseGit.

Modified SWAT - Solve Conflicts 1

Modified SWAT - Solve Conflicts 2

7. Give an unique name to the result database in headout_sqlite.f.

Modified SWAT - Change Output File Name

8. Create Fortran project with Intel Fortran and add all Fortran source files.

Modified SWAT - Create Fortran Project

9. Create Static Library for SQLite and add sqlite3.c, sqlite3.h and csqlite.c.

Modified SWAT - Static Library for SQLite

Modified SWAT - Static Library for SQLite 210. Set dependency for Fortran project in Solution Property window.

Modified SWAT - Set Dependency

11. Setup Runtime library.

Modified SWAT - Setup Runtime Library Fortran

Modified SWAT - Setup Runtime Library C

12. Compile and put the exe file to the swat_exe folder.

13. As the viewer doesn’t automatically support the modified versions, please contact me to enable running it in viewer .


SWAT Output Viewer – Export Annual Result to CSV File

Some research focus on the nutrient load at the outlet. An annual load table would be helpful. With SWAT Output Viewer, the table could be exported to a CSV file.

The Export button is located in the toolbar besides the help button.

Export Annual Button

To export the annual TP load, select the most downstream reach in the reach view and select TOT_Pkg in the variable list.


Click the Export Annual button and select the destination folder, the annual data will be exported to a csv file. An example file is shown below.

Export Annual Result

An Interface to Quickly View SWAT Ouputs

User ManualSWATOutputViewerManual_v0.1

Installation Package: Download from Google Drive

SWAT Output Viewer is a Windows application designed to quickly extract data from SWAT outputs and display them on thematic map or/and in time series graph. The main features includes:

  • Thematic map for subbasins and reaches to show spatial distribution;
  • Time series graph with ability to compare to observed data;
  • Quick performance statistics against observed data;
  • Quick comparison to observed data and/or outputs from other model engine and scenario;
  • Selecting SWAT components on map;
  • Ability to work with ArcSWAT projects;
  • Help functions to run simulation and check model files.

The main interface is shown below.

SWAT Output Viewer.png

Quickly Check SWAT Model Performance with SWAT Output Viewer

During SWAT model calibration, the simulated flow, sediment, nitrogen and phosphorus results are frequently compared with observed values to evaluate the model performance. SWAT Output Viewer has the ability to quickly calculate several model performance indicators on-the-fly (as shown below) once the model simulation is done. Performance View - SWAT Output Viewer

To be able to compare with observed data, the observed data needs to be imported first, which could be done in project view. Take flow data as the example. Observed flow data is available for reach 5. Then the observed flow data needs to be associated with the simulated flow from reach 5. To do this, select reach 5 on the map and chose flow (m3/s) from the Observation drop down list (as shown below). Then click the the Load button to load the observed data from selected file. The loaded data is then associated with the flow from reach 5. This process only needs to be done once.

Import Observed Data - SWAT Output Viewer

Once the observed data is loaded, it could be used to calculate the performance indicators. These indicators are automatically calculated and displayed in a table when entering the performance view as shown below. The default performance indicator is NSE. It can be change to R2, RMSE, Bias, etc. If observed data is available at more than one location or for more than one variable (flow, sediment, N and P), the performance indicator would be calculated for all the locations and variables and list in a table. The table could be sorted by any columns.

Performance Indictors - SWAT Output Viewer

Furthermore, the performance indicator of each year is also calculated when one row is selected in the table above, with which the “best” and “worst” year could be identified.

Yearly Performance Indictors - SWAT Output Viewer.png

For each year, the simulated and observed data is also plotted as shown below, where the simulated data is in read and the observed data is in green.

Simulated Observed Plot - SWAT Output Viewer.png

In SWAT Output Viewer, the performance indicators are available simply by clicking once without generating any additional files. It’s quite useful when the model is calibrated manually.