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.


ECReader – Environment Canada Climate Data Reader

ECReader (Environment Canada Climate Data Reader) is a .NET tool to download Canadian climate data from Environment Canada website. It comes from the SWAT modelling project I’m working on. I’m tired of downloading the data from EC website one station after another station, year by year and then processing them into the file format ArcSWAT wants. It’s no fun at all. As a programmer, I rather spend the same time to make a tool to do all these work in just one click. It would also help others too. So, please leave a comment or send me email ( if you needs more functions. I would be happy to add it for you. Also please follow me on wordpress or facebook to get notified for any further development.

Program Package

Source Code


The main features are list below.

  • Download climate data for a bunch of stations with just one click
  • A build-in station definition window to help locate stations of interest by name or location.
  • Support different output formats including the SWAT-ready dbf/txt format which could be used in ArcSWAT without any post-process (only for precipitation and temperature).

  • Support daily and hourly data
  • Give a map of all climate stations, which could be used outside the tool. The attribute table gives the station ID, name and the data availability of hourly, daily and monthly data. It’s a good dataset for any research required climate data. It’s available right in the tool and in csv, shapefile and kmz format for different environment.

Several posts have been published on this topic (list below). New functions would be added shortly to help fill the data gaps using nearby stations using IDW (Inverse Distance Weight) method. Lapse rate would also be considered for precipitation and temperature in this process.

December 12, 2013 Environment Canada Climate Data Reader

December 18, 2013 How to Get Environment Canada Climate Station ID From Name

December 28, 2013 Uncompleted Data Bug Fixed, Please Update

December 28, 2013 Environment Canada Climate Stations (Shapefile and KMZ)

December 31, 2013 6 More Columns Added to Environment Canada Climate Stations (Shapefile) to Help Check Data Availability

January 2, 2014 ECRearder 1.1 – New Climate Station Definition Window – No longer need to look up station IDs yourself

January 6, 2014 File Name Convention in ECReader1.1

January 9, 2014 Save and Load Defined Stations in ECReader1.1



Save and Load Defined Stations in ECReader1.1

Please follow my blog to get the latest updates on ECReader as soon as they are available.

Quick Download Link: ECReader ver 1.1

If working on a bunch of stations, you may want to save the list and load them later. There is no need to do define exactly the same stations twice. New functions has been added to ECReader1.1 to help save and load defined stations.


  • Save Defined Stations
  • Load Saved Stations
  • Automatically Save Stations

Save Defined Stations

A new button “Save as…” is added to “Define Stations” window to save defined stations. Once the stations are ready, click this button and give a file name. It’s done.

  • The stations is save as CSV file with the same format as ecstations.csv.
  • Please don’t edit the file to avoid any errors.
  • A default file name will be given in following format.

ECReader_Stations_[time stamp]

where time stamp is the time when the button is clicked.



Load Saved Stations

A new button “Load Saved Stations” is added to the main interface just after the “Define Stations…” button. Click this button and select the file just saved, the saved stations will be loaded and the number of stations loaded will be prompted. And it’s ready to download data for all these stations.

Automatically Save Stations

The defined stations would be saved automatically when the interface is closed. A file named ecstations_selected.csv would be saved to the user temp folder. This file would be loaded automatically when the interface is opened next time.

File Name Convention in ECReader1.1

Please follow my blog to get the latest updates on ECReader as soon as they are available.

Quick Download Link: ECReader ver 1.1

To make the data file easy to identify and meet the requirement of ArcSWAT, the file name convention is modified in ver 1.1.

  1. ArcSWAT 2009 dBase format and ArcSWAT 2012 ASCII format

Except for the file extension, these two format share same file name convention.

ArcSWAT 2009/2012 requires the file name no more than 8 chars. The data file is named as following.

Precipitation        P[station ID].dbf/.txt

Temperature        T[station ID].dbf/.txt


station ID is the ID of the station. If the length of station ID is less than 7 letters, 0 will be added to the left to make the file name has 8 letters including P or T.

Discussion: Another option is to use the first 7 letters of station name, which is easier to identify the station from the file name but prone to get same name from two different stations. Which option is better?


For station 4922, the data file will be P0004922.dbf/.txt and T0004922.dbf/.txt

For station 10936, the data file will be P0010936.dbf/.txt and T0010936.dbf/.txt

The gage location file is also generated with a fixed name.

Precipitation Gage     pcp.dbf/.txt

Temperature Gage     tmp.dbf/.txt

  1. Free Format Text and CSV

These two format share same file name convention.

[station name]_[province]_[start year]_[end year]


  • station name is the name of the station. If there are more than one words in the name, the space will be replaced as underscore.
  • province is the province of the station
  • start year is the bigger one of the starting year of the query time period and the starting year of available data. The purpose of these two format is usually for data analysis and No need to download data for years without data. This is also applied to end year.
  • end year is the smaller one of the end year of the query time period and the last year of available data. If the start year equals to end year, only start year will be used.


For station station GEORGETOWN WWTP located in Ontario,

  • if the query time period is from 1965 to 1965, the data file will be GEORGETOWN_WWTP_ONT_1965.txt/.csv
  • if the query time period is from 1965 to 1970, the data file will be GEORGETOWN_WWTP_ONT_1965_1970.txt/.csv