Skip to content
crazyzlj edited this page Apr 22, 2020 · 4 revisions

How to build SWAT from this repository

0. Branches

  • master: Branch of revised official code. Once a new version of SWAT source code available, I will create a new branch and merge it to the master branch! Revisions are only made in typos and cross-platform compilations.
  • <MAJOR>rev<MINOR>[.<PATCH>]: SWAT versions, i.e., 2012rev670, 2012rev622.omp, etc.

1. Prerequisite

  • CMake2.8+
  • Windows:
    • Microsoft Visual Studio 2010+ and Intel Fortran compiler (ifort) 12.0+
    • or CLion and mingw64 (with gfortran 4.8+)
  • Linux/macOS:
    • GCC (with gfortran installed) 4.8+
    • ifort 12.0+

2. Compile procedure

  • common commands

    cd <path to SWAT>
    mkdir build
    cd build
    cmake ..
    make && make install

2.1. Using Visual Studio and Intel Parallel Studio XE under Windows

Take VS2013 and Intel_Parallel_Studio_XE_2017 (Intel 17.0.4) as an example.

  • Open "Intel compiler 17.0 Update 4 Intel(R) 64 Visual Studio 2013" from start menu.
  • cd to the compile destination folder. e.g., cd D:/compile/SWAT_ifort
  • Run cmake <path to SWAT src path>. e.g., cmake C:\z_code\Hydro\SWAT
    • Compile 64-bit version: cmake -G "Visual Studio 12 2013 Win64" C:\z_code\Hydro\SWAT
  • Open the project SWAT<yyyy>rev<Num>.sln, e.g. SWAT2012rev664.sln, right-click the solution name and select Build Solution.
  • After the compilation, right-click the INSTALL project and select Build, the executable of SWAT named swat<yyyy>Rev<Num><BuildType> will be located in <path to SWAT src path>/bin, e.g., C:\z_code\Hydro\SWAT\swat2012Rev664Rel.exe. In which Dbg for Debug, Rel for Release, etc.

2.2. Using GCC(gfortran) under Windows, Linux, and macOS

If you prefer the command line, the common commands above should be OK. Note that if you want specify a Fortran compiler, please add the following command before cmake command.

export FC=/path/to/your/own/Fortran/compiler
# e.g., ifort
export FC=/share/soft/intel/composer_xe_2011_sp1.6.233/bin/intel64/ifort
# e.g., gfortran
export FC=/home/zhulj/gcc4.8.4/bin/gfortran

However, if you want a user-friendly IDE for to learn and improve the SWAT model, I recommend the cross-platform IDE CLion with Fortran plugin.

CLion use CMake to manage projects. Under Windows, you may also install mingw64 (or mingw) for the gfortran compiler.

Using CLion is quite easy and intuitive. Just open the SWAT path from File -> Open.... Then CLion will automatically load the project by CMakeLists.txt existed in SWAT directory. Now, you can build SWAT model by typing Ctrl+F9 or clicking the build button.

With the latest Fortran plugin with GDB support, we can debugging SWAT in the familiar JetBrains' way.

Debugging by Fortran plugin with GDB support

Fig 1. Build SWAT executable in CLion

Debugging by Fortran plugin with GDB support 2

Fig 2. Debug Fortran code in CLion