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 .


Tutorial #3: Load Observed Data

Observed data could be loaded to SWAT Output Viewer to be compared with the simulation results evaluate the model performance. This video talked about how to load the observed data to before you could use them in the model performance evaluation. You only need to load the observed data once. The observed data is shared by all scenarios.

Observed Data File Format: 14:35
Observed Data Database: 17:10

Observed Data File Format

As shown below, the simple two-column CSV file is use for the observed data files. The first line is assumed to be header and will not be read. The first column is the date and various format is supported for different time steps. The second column is the observed value for selected time step.

Observed Data File Format

Steps to Load Observed Data

The basic steps to load the observed data is shown below.

  1. Open your SWAT Project
  2. Select Project (the very top level) in Project Explorer
  3. Select the time interval in the right panel
  4. Select reach or reservoir on the map
  5. Select the observed data type in the right panel
  6. Use the Load button to select the observed data file

Load Observed Data

Observed Data Viewing Tools

Tools are provided to view the loaded observed data. The data could be shown for all years or a specific year.

Observed Data Table and Graph


The data table is located on the right side and will show the data time series whenever a data-set is selected. To improve the performance, it won’t show the data if the number of data exceed 1000.


The graph is located at the bottom showing the select the dataset.


Basic statistic numbers of the selected dataset is shown in the status bar.


Observed Data Database

The observed data is saved in a database once loaded. The database is located at the Scenarios folder in your SWAT project folder. It will be shared by all scenarios in this project.

Separate database is created for different time steps. There will be maximum three database files for daily, monthly and yearly receptively.

Once the observed data is saved in the database, it will be loaded automatically when loading simulation results.

Observed Data Database


Tutorial #2: Run Simulation

The SWAT model is ready to run after opened in SWAT Viewer. There are two options for the simulation run: simulation engine and output time step. The simulation engine could be any of the standard SWAT version or a customized version. The output time step could be daily, monthly or yearly. In SWAT Viewer, these options are available in Scenario View by selecting the scenario in the Project Explorer.

This video covers the process to run a simulation in SWAT Viewer. Also talked about the model output format. The format used in SWAT Viewer make it much easier to post processing the outputs and run and compare different engines on same scenario.

Run a simulation: 00:38

The output format : 7:15

Simulation Options

Simulation Options 2

You have the options to select the engine and the output time step when you run the model.

  • Model Engine: The model engine could be the standard SWAT engines or any customize engines. It’s available from the engine list.
  • Output Time Step: The output time step could be daily, monthly and yearly. There are three button for each time step. It will basically change IPRINT in file.cio.
  • Open Model Files: You may want to make the final touch before you run the simulation. There are few buttons you could use to open specific model files (file.cio, basin.ban and fig.fig) directly. Or you could open the model folder using the Open Model Folder button.

Model Outputs

Result Database

The traditional SWAT model outputs are in multiple files with same names. They will be overwritten after each simulation run. In SWAT Viewer, we want to enable to compare the outputs from different engines on same model. So the model outputs has been changed to single database with unique name so it will not be overwritten by simulation runs using different engines and time steps.

This single database approach also eliminate the need to convert the output files to a database for post-possessing which will save you significant amount of time.

Other Related Videos

Tutorial #1: Open SWAT Project show you how to open a ArcSWAT, QSWAT and MWSWAT project in SWAT Viewer.

Add Modified SWAT version to SWAT Viewer shows the way to view the results of your modified SWAT version in SWAT Viewer.

Compare SWAT versions in SWAT Viewers shows you how to compare the outputs from different SWAT version in SWAT Viewer.


QSWAT and MWSWAT is very similar in terms of interface design although they are programmed with different programming languages and in different GIS platform. In this video, these two SWAT tools are compared side-by-side to demonstrate the similarity. The guess is they are from the same development team. MWSWAT is developed first and QSWAT follows the design.

MWSWAT is a plugin for MapWindow and programmed with .NET. The development has stopped years ago. It seems it’s not very popular right now. More details are available in Waterbase website.

QSWAT is a plugin for QGIS and programmed with Python. The development starts from 2 years ago and gradually get popular. The latest release is QSWAT 1.5.

Today is Chinese New Year. Hope everyone very good luck in the year of dog!

Tutorial #1: Open SWAT Project

Most of the SWAT users use ArcSWAT, QSWAT or MWSWAT to create their models. The SWAT projects created with these tools could be opened directly in SWAT viewer. If you uses other tools, you could also manually create a SWAT project and open in SWAT viewer.

In this video, I will talk about how to open a SWAT project in SWAT Viewer. For your convenience, the time points for different tools was given below.

ArcSWAT         00:42

QSWAT             03:10

MWSWAT        06:30

Other Tools    09:20

SWAT Output Spatial Visualization

There are many ways to see SWAT outputs. Spatial visualization shows the model results on a map. It will clearly show how the selected results are distributed across subbasins or reaches. It’s very useful to pinpoint the hotspots in the watershed.

In this video, we will talk about how to do the spatial visualization with ArcSWAT, QSWAT and SWAT Viewer. You will see how SWAT viewer save your time and space.

ArcSWAT: 1:30
QSWAT: 7:20
SWAT Viewer: 11:37