MinGW Installation Guide for SWAT Debugging

Please note that the administrative privilege is not needed in the whole processes. MinGW would not add entries into register system or change the environment variables.

  1. Download the automated GUI installer: mingw-get-setup.exe and run. Accept all the default settings and

  1. Choose MinGW packages to install. Open MinGW Installation Manager installed in previous step, select Basic Setup in the left panel and choose package mingw32-base and mingw32-gcc-fortran. Then select menu Installation -> Apply Changes to start installation. The installer would download selected package and extract them into the given folder.

  1. Go to the installation folder (C:\MinGW\bin) to check mingw32-make.exe and gfortran.exe.

  1. Want to compile SWAT outside of Eclipse? Add folder C:\MinGW\bin to the PATH variable.

Debug SWAT in Eclipse – Utilize Makefile

Don’t Want to Go through all these Processes?

No problem. The Eclipse project created in this post is uploaded to Google Code: https://swat-eclipse.googlecode.com/svn/trunk/SWAT_Makefile. Just check out and open in Eclipse. It’s done!

This version also add Make Target, which is a quick way to build and clean the project. Just double-click to build or clean specific version.

It’s recommended to use SVN Plugin for Eclipse to do this work. I would have another post on this topic in the near future. Please stay tuned.

Contents

  • Find Fortran Project… Menu
  • Create an Empty Makefile Project
  • Setup the Project
    • Binary Parser
    • Error Parsers
    • Fortran Build Configuration
  • Copy SWAT Source Codes and Generate Makefile
  • Build Project
  • Debug/Run SWAT.exe

Please note

  1. To compile SWAT, MinGW needs to be installed first. Please refer to another post MinGW Installation Guide for SWAT Debugging
  2. Eclipse KEPLER and PTP 7.0.3 was used in this post. These steps should also be able to be used in other version of Eclipse and PTP. For more information, please refer to my previous post Compile and Run SWAT with Photran + MinGW – the easiest way to remove mathematical errors from SWAT.

A Makefile is created in previous post. To use it in Eclipse (Photran/PTP), instead of Executable (Gnu Fortran on Windows) project, we should use the Makefile project, which would allow use of user-defined Makefile.

This post will show you how to create and configure a SWAT Makefile project to utilize the makefile.

Find Fortran Project… Menu

The Fortran Project is not list in menu File -> New when PTP is used the first time. In this case, select Projects… to open New Project window. In this window, you would find Fortran project under Fotran folder. Select it and click Next to create the project. When it’s done, you will be asked if you want to open Fortran perspective. Select Yes. The Fotran Project option would be list in menu File -> New.

Create an Empty Makefile Project

File -> New -> Fortran Project

The project name is SWAT. Select Empty Project under Makefile project and select — Other Toolchain —. Click finish to create the project..

Setup the Project

Open the Property window through right click on the project and select “Properties” to setup the project.

Binary Parser

In Fotran -> Build -> Setting, select PE Windows Parser for Binary Parsers (I’m working a Windows machine)..

Error Parsers

Select Photran Error Parser for GNU Fortran (gfortran) for Error Parsers and move it to the top. This option is not selected when the project is created.

Fortran Build Configuration

Select Fortran Build in the left panel, un-check Use default build command and change Build Command to mingw32-make.

Add debug/ to build directory as there will be two versions of Makefile, one is located in debug folder and another is located in release folder. This one is for debug version.

Change configuration name from Default to Debug.

The default configuration name is Default. It would be nice to rename it to debug. Click Manage Configurations… to open Manage Configurations window. Select default and click Rename… to change name to Debug.

Create Release Configuration

As mentioned before, there is also a release version of Makefile. It’s necessary to make a configuration for it. Here, we could copy all the settings from debug configuration to save time.

Click New… on Manage Configurations window to open Create New Configuration window. Input name as Release and select to copy settings from Debug configuration.

Change the Build directory to ${workspace_loc:/SWAT}/release/.

Copy SWAT Source Codes and Generate Makefile

Copy all the SWAT source codes to the project folder and refresh the project in Eclipse. It would show all the files. Remember to comment the first line in main.f.

Download the GenerateMakefile program and save it into the project folder. Run it to generate the Makefile for debug and release version.

Build Project

Now, it’s ready to build the project, i.e. compile SWAT source codes. Right-click the project and select Build Project to start compile SWAT source codes. You would see some output information from Console window in the bottom. From there, you would know whether or not the process is finished. All the warnings and errors would also be found in this window.

Debug/Run SWAT.exe

After SWAT is compiled successfully, it’s ready to run SWAT. Before that, there is one thing to do: setup Run/Debug Settings, which could be completed in Properties window.

Select Run/Debug Settings in the left panel and click New… to create a Run/Debug Settings. We will first create the settings for debug version. Same as the build configuration, the setting for release version could be also copied from debug version.

In the Main tab, input Fortran Application as debug\SWAT.exe.

In Arguments table, change Working directory to the model txtinout folder.

In Debugger tab, select MinGW gdb for Debugger and uncheck Stop on startup at: option.

In Common tab, select Debug in Display in favorites menu to show the setting in debug menu.

Click debug menu in the toolbar to start running SWAT.

The output information would be display in the Console window.

If some breakpoints are set, SWAT would stop running on breakpoints and ask if want to change to Debug perspective. Click yes to change to Debug perspective, which would re-arrange the windows to facilitate debugging.

You would has change to check all the variable values in Variables window under debugging mode.

Click Fortran button on the up right corner, Eclipse would go back to Fortran perspective, which is designed for coding.

Click the Debug button in the up right corner to return to Debug perspective.

SWAT Makefile Updated – Stop running when overflow happens

Note: This version is updated in next post SWAT Makefile Updated – Ignore Underflow, where underflow flag is removed.

The Makefile published in previous blog Makefile – Compile SWAT using gfortran without modification is updated. It’s highly recommended to update.

Download Link

Makefile Generator, Debug Makefile, Release Makefile

Updates

  1. More gfortran flags are added to make sure the SWAT will stop running when errors happen.

In previous version, SWAT would ignore all the errors (e.g. overflow) and run to the end. It’s impossible to know if there are some errors. For some cases, the results are not safe to use.

The official SWAT would stop whenever an error happens and give where the error comes from. It’s the right way to compile SWAT.

In gfortran, the flag -ffpe-trap could used to do this work. The following command flag is added to the Makefile, which would stop the program whenever invalid, zero, overflow or underflow happens.

-ffpe-trap=invalid,zero,overflow,underflow

  1. rm command is used to replace del command in the clean target.

The del command could only be called from cmd.exe. Eclipse don’t know where is this command and would fail to clean the project.

rm.exe comes along with MSYS in MinGW (package mingw-developer-toolkit and msys-base) and is usually located at C:\MinGW\msys\1.0\bin. Adding this location to the PATH variable in Windows setting or Eclipse project setting would allow Eclipse to call this function when “Clear Project” is used.

Makefile – Compile SWAT using gfortran without modification

Note: The makefile here is an older version. For the latest version, please visit another post SWAT Makefile Updated – Stop running when overflow happens.

Quick Download Link

Makefile Generator, Debug Makefile, Release Makefile

Next post will be: Use Makefile in Photran to Debug SWAT

Please note that the modparm.f doesn’t need to be compiled as parm.mod any more. That process is already included in the Makefile.

Contents

  • Why some files fail to be compiled in Photran?
  • Use additional gfortran command options to compile problematic files
  • Makefile
  • Generate Makefile
  • The only modification
  • Use Makefile

In my previous post Compile and Run SWAT with Photran + MinGW – the easiest way to remove mathematical errors from SWAT, several swat source code files need to be modified to be able to compilable within Photran. It’s nice, but it’s even better if the source codes could be compiled without any modification.

Why some files fail to be compiled in Photran?

Compare the original source codes and the modified source codes through Google codes, and find that only following files need to be modified.

  • biozone.f
  • bmpinit.f
  • carbon_zhang2.f90
  • main.f
  • modparm.f
  • ovr_sed.f
  • percmain.f
  • rthsed.f

Except for main.f, these files have a common problem: one or more lines exceed the default line length set for Fotran fix format file (*.f) and free format file (*.f90). The default limitation of the line length for *.f is 72 and for *.f90 is 132. The default Fortran compile command (shown below) in Photran doesn’t consider this situable. If the length of one line exceed the limitation, the compiler (gfortran) would give errors.

  • Debug version: gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0
  • Release version: gfortran -funderscoring -O3 -Wall -c -fmessage-length=0

Use additional gfortran command options to compile problematic files

To solve this problem, these files are modified to make sure they meet the requirement on line length in previous post. Besides this, there is also another solution: change the line length limitation using gfortran command options.

  • Fixed format (*.f): add -ffixed-line-length-132 option to set the line length limitation of fixed format Fortran file to 132
  • Freeformat (*.f): add -ffree-line-length-200
    option to set the line length limitation of free format Fortran file to 200

For example, the gfortran command for debug version of biozone.f would be

gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -ffixed-line-length-132

And the gfortran command for release version of carbon_zhang2.f90 would be

gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -ffree-line-length-200

These files could be compiled successfully with the new command.

Makefile

In default Photran settings, it’s impossible to use different command options for different source files. Applying -ffixed-line-length-132 to other *.f files would also generate compile errors. How to solve this? Using Makefile.

Makefile defines how to compile and link a program. With it, it’s possible to define different commands for different source files and compile SWAT source codes without modification. For more information, please refer to GNU make document.

Generate Makefile

There are more than 300 Fortran source files in SWAT. It’s time-consuming work to write the Makefile manually. We already know the gfortran commands and the files which need to re-set the line length limitation. A program, which would get all *.f and *.f90 in the SWAT source codes folder and generate the compile commands in the makefile, is a quite straightforward and simple way to do the work.

Based on this, a .NET console application is created (source codes, executable). It’s fairly easy to use. Copy the program file to the source codes folder and double-click.

A prompt window would pop-up to ask which version should be the Makefile generated for, debug or release. Input d or debug for debug version, r or release for release version. Then the program would start to work and generate the corresponding Makefile in debug or release folder. The debug/release folder would be created if it doesn’t exist.

The two version of Makefile for rev 615 are also available to be download directly (debug version, release version). These two files could be also used for also version as long as the number and name of source codes files is same. Create the debug/release folder in the source codes folder and put the file into the corresponding folder.

The only modification

The only modification is to comment the first line of main.f (include modparm.f). There should be some command option to ignore this line but haven’t found it:)

Use Makefile

Makefile is fairly easy to use. Just use the GNU make command which comes along with MinGW. There are two version of make in MinGW: mingw32-make and make. Either one is ok.

Open cmd.exe and navigate to the Makefile folder. Execute mingw32-make or make. It’s done!

Interesting Test – Install ArcSWAT for ArcGIS 10.0/10.1 on ArcGIS 9.3

Interesting Test – Install ArcSWAT for ArcGIS 10.0/10.1 on ArcGIS 9.3

Method in post “Manually Install ArcSWAT” was used to install ArcSWAT for ArcGIS 10.0/10.1 on ArcGIS 9.3. The installation is successful but there are some problem in stream network generation (no problem in flow direction and accumulation calculation). The reason is the new version manager system in ArcGIS 10 (new file ArcGISVersion.dll located in C:\Program Files (x86)\Common Files\ArcGIS\bin). However, it would be enough for an existing model.

Manually Install ArcSWAT

Quick Download Link

Extract Installation File

ArcGIS 9.3: Register, Unregister

ArcGIS 10.0 and higher: Register, Unregister

Note:

  1. The bat file needs to be saved in the same folder as installation file or .NET assemblies.
  2. The register and unregister bat file needs to be run as administrator.
  3. Since there will be some errors, the method in this post could also be used to install ArcSWAT for ArcGIS 10.0/10.1 on ArcGIS 9.3. 

Contents

  • Why bother to install ArcSWAT manually?
  • Important Facts
  • Extract ArcSWAT program files from installation file
  • Copy new files to existing ArcSWAT installation folder
  • Re-register ArcSWAT .NET assemblies
  • Unregister previous ArcSWAT if necessary

Why bother to install ArcSWAT manually?

  1. ArcSWAT is updated frequently and must be re-installed to use the new functions. Uninstalling the previous version and installing the new version would need around ten minutes.
  2. You may experience problems when trying to uninstall and install ArcSWAT. These problems are usually difficult to solve. Having seen some these problems in ArcSWAT user group. In some cases, it couldn’t be solved until restore the entire Windows system.

Important Facts

  1. There are usually two steps involved in program installation: 1) copy files to specific folder and 2) register some file in the system if necessary.
  2. The core of ArcSWAT is six .NET assemblies and SWAT executable file. When a new version comes out, it means one or more of these assemblies are updated. Other files are usually kept same between different versions. Of course, they would be updated once a while.

So, most of the time, upgrading ArcSWAT only means updating these six .NET assemblies and SWAT executable file. Knowing this, it’s possible to upgrade ArcSWAT without normal installation. It could be done use following steps:

  1. Get the core files
  2. Replace old files
  3. Re-register the six .NET assemblies

Extract ArcSWAT program files from installation file

There is a MSI file, namely SWAT_Install.msi, in the installation package downloaded from SWAT website. It contains all the files which will be copied to the installation folder. We will extract all the files from it.

Execute following command in cmd window.

msiexec /a [SWAT_Install.msi_path] /qb TARGETDIR=[extraction_folder_path]

Where

SWAT_Install.msi_path is the path to SWAT_install.msi

extraction_folder_path is the path to the extraction folder where the extracted files will be saved.

Following window will show up to display the progress.

Wait it to finish and all the files will be extracted to the given folder. The extracted files are around 567 MB.

A bat file could be used to do this work. Create a text file in the folder, copy following commands to the file and save it as a bat file in the same folder as the installation file. Then double-click to run the commands. This bat file also could be downloaded here.

msiexec /a SWAT_Install.msi /qb TARGETDIR=%CD%\extract

Copy new files to existing ArcSWAT installation folder

If a previous version is installed in the system, copy following files into the installation folder to replace the existing files.

  • SWAT_PM2.dll
  • SWAT_WD.dll
  • SWAT_HRU.dll
  • SWAT_InputFileGen.dll
  • SWAT_InputFileEdit.dll
  • SWAT_RunSWAT.dll
  • SWAT_32debug.exe
  • SWAT_32rel.exe
  • SWAT_64debug.exe
  • SWAT_64rel.exe
  • swat2012.exe

Please note that the name of SWAT model executable files may be different for different version. There usually four versions: 32-bit debug, 32-bit release, 64-bit debug, 64-bit release.

Re-register ArcSWAT .NET assemblies

As mentioned in my previous post ArcSWAT Structure – Developer view, the ArcSWAT extension, toolbar, menus and windows are defined in six .NET assemblies. To use the new function in the new version, they must be registered in the system.

The register process is based on the version of ArcGIS.

  • ArcGIS 9.3

Run cmd as administrator and navigate to .NET folder (which is usually located at c:\Windows\Microsoft.NET\Framework\v2.0.50727). Execute following command for each of the six ArcSWAT .NET assemblies. It’s done when you see “Type registered successfully”.

regasm [assembly_path] /codebase

where

assembly_path is the path to the ArcSWAT .NET assembly, e.g. c:\swat\ArcSWAT\SWAT_PM2.dll

The same as extracting files, a bat file could be created using following commands to do the work. An existing bat file could be downloaded here. Please not that the bat file needs to be in the same folder and run as administrator.

SET DLL_DIR=%~dp0

CD %SystemRoot%\Microsoft.NET\Framework\v2.0.50727

regasm %DLL_DIR%SWAT_HRUs.dll /codebase

regasm %DLL_DIR%SWAT_InputFileEdit.dll /codebase

regasm %DLL_DIR%SWAT_InputFileGen.dll /codebase

regasm %DLL_DIR%SWAT_PM2.dll /codebase

regasm %DLL_DIR%SWAT_RunSwat.dll /codebase

regasm %DLL_DIR%SWAT_WD.dll /codebase

  • ArcGIS 10.0 and higher

Run cmd as administrator and navigate to ArcGIS bin folder (which is usually located at C:\Program Files (x86)\Common Files\ArcGIS\bin). Execute following command for each of the six ArcSWAT .NET assemblies. It’s done when you see a window saying “Registration succeeded”.

esriregasm /p:desktop
[assembly_path]

where

assembly_path is the path to the ArcSWAT .NET assembly, e.g. c:\swat\ArcSWAT\SWAT_PM2.dll

Similar as ArcGIS 9.3, a bat file could be utilized to do the work on just a click. Please note the location of esriregasm.exe may be different on your computer. For 32-bit system, it should be C:\Program Files\Common Files\ArcGIS\bin. Check the file location and modify this file before use if necessary.

SET DLL_DIR=%~dp0

CD C:\Program Files (x86)\Common Files\ArcGIS\bin

esriregasm /p:desktop %DLL_DIR%SWAT_HRUs.dll

esriregasm /p:desktop %DLL_DIR%SWAT_InputFileEdit.dll

esriregasm /p:desktop %DLL_DIR%SWAT_InputFileGen.dll

esriregasm /p:desktop %DLL_DIR%SWAT_PM2.dll

esriregasm /p:desktop %DLL_DIR%SWAT_RunSwat.dll

esriregasm /p:desktop %DLL_DIR%SWAT_WD.dll

Unregister previous ArcSWAT if necessary

If there is a previous version installed, it needs to be unregistered first. This process also depends on ArcGIS version.

  • ArcGIS 9.3

Run cmd as administrator and navigate to .NET folder (which is usually located at c:\Windows\Microsoft.NET\Framework\v2.0.50727). Execute following command for each of the six ArcSWAT .NET assemblies. It’s done when you see “Type un-registered successfully”.

regasm [assembly_path] /unregister

where

assembly_path is the path to the ArcSWAT .NET assembly, e.g. c:\swat\ArcSWAT\SWAT_PM2.dll

A bat file is also available here with following commands, which should also be executed as administrator.

SET DLL_DIR=%~dp0

CD %SystemRoot%\Microsoft.NET\Framework\v2.0.50727

regasm %DLL_DIR%\SWAT_HRUs.dll /unregister

regasm %DLL_DIR%\SWAT_InputFileEdit.dll /unregister

regasm %DLL_DIR%\SWAT_InputFileGen.dll /unregister

regasm %DLL_DIR%\SWAT_PM2.dll /unregister

regasm %DLL_DIR%\SWAT_RunSwat.dll /unregister

regasm %DLL_DIR%\SWAT_WD.dll /unregister

  • ArcGIS 10.0 and higher

Run cmd as administrator and navigate to ArcGIS bin folder (which is usually located at C:\Program Files (x86)\Common Files\ArcGIS\bin). Execute following command for each of the six ArcSWAT .NET assemblies. It’s done when you see a window saying “Unregistration succeeded”.

esriregasm /p:desktop /u
[assembly_path]

where

assembly_path is the path to the ArcSWAT .NET assembly, e.g. c:\swat\ArcSWAT\SWAT_PM2.dll

Similarly, a bat file could be used.

SET DLL_DIR=%~dp0

CD C:\Program Files (x86)\Common Files\ArcGIS\bin

esriregasm /p:desktop /u %DLL_DIR%SWAT_HRUs.dll

esriregasm /p:desktop /u %DLL_DIR%SWAT_InputFileEdit.dll

esriregasm /p:desktop /u %DLL_DIR%SWAT_InputFileGen.dll

esriregasm /p:desktop /u %DLL_DIR%SWAT_PM2.dll

esriregasm /p:desktop /u %DLL_DIR%SWAT_RunSwat.dll

esriregasm /p:desktop /u %DLL_DIR%SWAT_WD.dll

Eclipse Compatible SWAT Updated to Rev 614 – Fix ET > PET bug

SWAT model was update to rev 614 on Jan 7, 2014. Based on the difference between rev 613 and rev 614, the Eclipse compatible version is also updated. The source codes are here: https://code.google.com/p/swat-eclipse/.

List of Changes (click the file name to see detailed changes)

  • main.f The version number is updated.
  • etact.f Line 131 and Line 172-182, to make sure the actual ET doesn’t exceed PET. This would have impact on ET and surface runoff for some cases.

It’s highly recommended to update to this version.

ArcSWAT Structure – Developer View

ArcSWAT is the standard SWAT interface which is used by most of the modelers. Knowing its structure would help understand what’s going on under each command and locate the possible exceptions more easily, which in turn would help improve model itself.

Key facts about ArcSWAT

  • ArcSWAT is ArcGIS Extension
  • ArcSWAT defines toolbar and menus
  • ArcSWAT is developed with .NET framework
  • ArcSWAT needs to be registered in system before use

ArcSWAT is ArcGIS Extension

An extension is a class which implements interface IExtension and IExtensionConfig.

ArcSWAT defines toolbar and menus

A toolbar is a class which implements interface IToolBarDef.

A menu is a class which implements interface IMenuDef.

A menu item is a class which implements interface ICommand. The method OnClick will be executed when the menu item is clicked.

ArcSWAT is developed with .NET framework

There are six .NET assemblies in ArcSWAT. They are corresponding to six menus in ArcSWAT toolbar and located at ArcSWAT installation folder.

  • SWAT_PM2.dll, project management, corresponding to “SWAT Project Setup” menu in ArcSWAT toolbar.
  • SWAT_WD.dll, watershed delineation, corresponding to “Watershed Delineator” menu in ArcSWAT toolbar
  • SWAT_HRU.dll, HRU definition, corresponding to “HRU Analysis” menu in ArcSWAT toolbar
  • SWAT_InputFileGen.dll, input generation, corresponding to “Write Input Tables” menu in ArcSWAT toolbar
  • SWAT_InputFileEdit.dll, input edit, corresponding to “Edit SWAT Input” menu in ArcSWAT toolbar
  • SWAT_RunSWAT.dll, swat simulation, corresponding to “SWAT Simulation” menu in ArcSWAT toolbar

ArcSWAT needs to be registered in system
before use

To use ArcSWAT, all six assemblies must be register in system, which is automatically done during installation.

The registration process could also be used to manually install ArcSWAT or fix problem of ArcSWAT installation.

Find Possible Solution for ArcSWAT Errors with ildasm.exe

For more details about ArcSWAT structure, please check out my another post: ArcSWAT Structure – Developer View.

Please Note:

  • SWATEditor and SWAT Check are also .NET programs. The method post here could be also used on them.
  • All the analysis and screenshots are based on ArcGIS 2009.10.1. It’s similar to other versions.
  • MSIL code given by ildasm.exe is not easy to read. For more readable solution, please consider to use free .NET decompilers out there. They could decompile .NET in C# which is more easier to read. I’m using dotPeek from JetBrains. The only problem is some methods couldn’t be decompiled in these tools and could only be analyzed in ildasm.exe.
  • Welcome to any discussions on this subject. Please send me email on hawklorry@gmail.com.

Contents

  • ildasm.exe
  • Where are the ArcSWAT assemblies?
  • Which assembly should be looked into?
  • Find codes corresponding to one ArcSWAT menu item
  • Find out what happened when one ArcSWAT menu item is clicked
  • What if error happens in a window pop-up by ArcSWAT?
  • Two kinds of errors

ArcSWAT is the most popular SWAT interface. It’s free-to-use but not open source. When something unexpected happened (like the one shown below), it’s not possible to look into source codes like SWAT model itself (please refer to my another post: Compile and Run SWAT with Photran + MinGW – the easiest way to remove mathematical errors from SWAT). So, how to find possible solutions?

The answer is decompiling/disassembling.

ArcSWAT consists of six .NET assemblies (shown below), which are corresponding to six menus in ArcSWAT toolbar (shown below). Decompile/Disassemble would show background codes in C# or Microsoft intermediate language (MSIL) code format, from which the background processes under all ArcSWAT menu could be analyzed and possible solutions could be reached.

ildasm.exe

ildasm.exe is a tool in Visual Studio and Windows SDK. It could parse any .NET Framework .exe or .dll assembly, and shows the information in human-readable format. A simple tutorial could be found here: http://msdn.microsoft.com/en-us/library/aa309387(v=vs.71).aspx. If it’s impossible to install Visual Studio, please get Windows SDK at http://www.microsoft.com/en-ca/download/details.aspx?id=8279 for Windows 7 and .NET 4.0. It’s free-to-use.

Where are the ArcSWAT assemblies?

They are located in ArcSWAT installation folder, which is usually c:\swat\ArcSWAT.

Which assembly should be looked into?

From ArcSWAT toolbar, the analysis assembly could be determined.

  • SWAT_PM2.dll, project management, corresponding to “SWAT Project Setup” menu in ArcSWAT toolbar.
  • SWAT_WD.dll, watershed delineation, corresponding to “Watershed Delineator” menu in ArcSWAT toolbar
  • SWAT_HRU.dll, HRU definition, corresponding to “HRU Analysis” menu in ArcSWAT toolbar
  • SWAT_InputFileGen.dll, input generation, corresponding to “Write Input Tables” menu in ArcSWAT toolbar
  • SWAT_InputFileEdit.dll, input edit, corresponding to “Edit SWAT Input” menu in ArcSWAT toolbar
  • SWAT_RunSWAT.dll, swat simulation, corresponding to “SWAT Simulation” menu in ArcSWAT toolbar

Find codes corresponding to one ArcSWAT menu item

One ArcSWAT menu item is corresponding to one class in one of the six assemblies. The name of these class would usually has a name starting with “cmb” or “com”. For example below, in SWAT_PM2.dll, there is class named cmbHelp. It’s corresponding to menu “ArcSWAT Help…”. To confirm this, expand class cmbHelp in ildasm.exe and double click on method get_Name to open it.

Considering name convention, it’s easy to find these classes just from the menu name.

Find out what happened when one ArcSWAT menu item is clicked

Method onClick is implemented in all classes corresponding to ArcSWAT menu items. The codes in this method will be executed when corresponding menu item is clicked. Double-click this method node in ildasm could open the codes. This is where should be looked into.

What if error happens in a window pop-up by ArcSWAT?

Most of the ArcSWAT menu item would pop-up a window and then further operation could be done in this window. A very good example is the “Watershed Delineation” window shown below.

In this case, the class corresponding to the window should be found first and then find the method corresponding to a specific button.

For “Watershed Delineation” window, follow steps below.

  1. Open SWAT_WD.dll with ildasm.exe.
  2. Find the class for menu “Automatic Watershed Delineation” which is “ComAutoDelin”.
  3. Expand class ComAutoDeline and double-click method “ICommand_OnClick” to open the codes window.
  4. Find the class name for the window In the codes window, which is frmMainForm. The name of classes corresponding to windows usually starts with “frm”.
  5. Find class frmMainForm in ildasm.exe and expand to check the methods. The name of methods corresponding to button clicks usually like “[button name]_click”, where button name is the name of the button. These methods are the codes corresponding to the buttons.

Two kinds of errors

Once the method body is found, possible solutions could be figured out through analysis of the codes. There would be two kinds of error.

  1. Data Problem ArcSWAT has special requirements on input data. Giving data in a different format or value would cause ArcSWAT give errors. Analysis on the codes given by ildasm.exe could help locate the problematic data.
  2. Software Problem ArcSWAT continues to be improved. There may be still some bugs there and would stuck you someday. Analysis on the codes could help locate the bug and report to the develop team.

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.

Contents

  • 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.

Example

ECReader_Stations_20140108115611

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.