> For the complete documentation index, see [llms.txt](https://swatplus.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swatplus.gitbook.io/docs/2.3/source-code.md).

# Source Code

## Repository Links

* [SWAT+ source code repository](https://bitbucket.org/blacklandgrasslandmodels/modular_swatplus)
* [SWAT+ Editor source code repository](https://bitbucket.org/swatplus/swatplus.editor)
* [QSWAT+ source code repository](https://github.com/swat-model/QSWATPlus)

## SWAT+ Model Compile Help

The model is written in Fortran and the distributions on this website were compiled using the [Intel Fortran compiler](https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/fortran-compiler.html). This is now freely available for Windows, Linux, and MacOS. First, download and install the [Intel oneAPI Base Toolkit](https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html). Then download and install the [Intel oneAPI HPC Toolkit](https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html).

For Windows, we also use Visual Studio. Download the file below for settings configuration.

{% file src="/files/-MVXt-q-pGxasIhlNZbn" %}
Intel Fortran Visual Studio Settings
{% endfile %}

For Linux and MacOS, we currently just use the command line. First, you need to set your Intel environment. Find your installation directory and source `setvars.sh`.&#x20;

Linux example:

```
. ~/intel/oneapi/setvars.sh
```

Or for all users:

```
. /opt/intel/oneapi/setvars.sh
```

MacOS example:

```
. /opt/intel/oneapi/setvars.sh
```

Next, we use the following script to compile the model. Please note: occasionally some extra files get included in the source code repository. If you notice this, it is safe to remove them.

```
ifort -c hru_module.f90 -traceback -O3 -parallel
ifort -c time_module.f90 -traceback -O3 -parallel
ifort -c constituent_mass_module.f90 -traceback -O3 -parallel
ifort -c *_module.f90 -traceback -O3 -parallel
ifort -c allocate_parms.f90 -traceback -O3 -parallel
ifort -c *.f90 -traceback -O3 -parallel
ifort -o swatplus_exe_file_name *.o -static -traceback -O3 -parallel
```

The `-static` flag in the last line is NOT available on MacOS. Instead, you should link the LAPACK and BLAS libraries and as of macOS Monterey change your library path. The last line should be:

```
ifort -o swatplus_exe_file_name *.o -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -llapack -lblas -traceback -O3 -parallel
```

We are new to compiling in Linux and MacOS, so suggestions are more than welcome.

## SWAT+ Editor Compile Help

First set up your development environment as described in the README in the [source code repository](https://bitbucket.org/swatplus/swatplus.editor).

1. From `/src/api` run the following depending on your OS:
   * Windows: `python-build-windows`
   * Linux: `sh python-build-linux.sh`
   * MacOS: `sh python-build-mac.sh`
2. From the root of the source code directory run the following depending on your OS:
   * Windows: `npm run build:win`
   * Linux: `npm run build:linux`
   * MacOS: `npm run build:mac`
3. Program will be in `/release/dist`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://swatplus.gitbook.io/docs/2.3/source-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
