WMS:WMLib: Difference between revisions

From XMS Wiki
Jump to navigationJump to search
(Created page with " == About WMLib == WMLib is a library of ".NET-based" DLL API functions that allows you to call some of the WMS functionality from other .NET-based applications from outside of ...")
 
No edit summary
Line 1: Line 1:
== About WMLib ==
== About WMLib ==


Line 17: Line 16:


<pre>
<pre>
            try
try
            {
{
                // Set the job control start time and build the tree from a file
    // Set the job control start time and build the tree from a file
                string fileName = "C:\\treeFilePath\\wmsTreeFile.tre";
    string fileName = "C:\\treeFilePath\\wmsTreeFile.tre";
                DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0);
    DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0);
                HydroTree hydroTree = new HydroTree(currTime, 15, 300);
    HydroTree hydroTree = new HydroTree(currTime, 15, 300);
                if (FileIo.ReadTreeFile(fileName, hydroTree))
    if (FileIo.ReadTreeFile(fileName, hydroTree))
                {
    {
                    fileName = "C:\\hec1OutputPath\\WMLib.hc1";
        fileName = "C:\\hec1OutputPath\\WMLib.hc1";
                    const string hec1FileName = "C:\\hec1ExePath\\hec1.exe";
        const string hec1FileName = "C:\\hec1ExePath\\hec1.exe";
                    // Run HEC-1 and read the HEC-1 output hydrographs
        // Run HEC-1 and read the HEC-1 output hydrographs
                    if (hydroTree.RunHec1(fileName, hec1FileName))
        if (hydroTree.RunHec1(fileName, hec1FileName))
                    {
        {
                        // Get the peak flow and time before lagging
            // Get the peak flow and time before lagging
                        double peakFlow = hydroTree.GetPeakFlow();
            double peakFlow = hydroTree.GetPeakFlow();
                        DateTime peakTime = hydroTree.GetPeakTime();
            DateTime peakTime = hydroTree.GetPeakTime();
                        // Write the hydrographs to a file that can be used by the time series editor
            // Write the hydrographs to a file that can be used by the time series editor
                        myTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts");
            myTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts");
                        // Lag all hydrographs in the hydrologic tree
            // Lag all hydrographs in the hydrologic tree
                        hydroTree.ApplyLagTimes();
            hydroTree.ApplyLagTimes();
                        // Get the peak flow and time after lagging
            // Get the peak flow and time after lagging
                        peakFlow = hydroTree.GetPeakFlow();
            peakFlow = hydroTree.GetPeakFlow();
                        peakTime = hydroTree.GetPeakTime();
            peakTime = hydroTree.GetPeakTime();
                    }
        }
                    else
        else
                    {
        {
                        MessageBox.Show("Unable to run HEC-1");
            MessageBox.Show("Unable to run HEC-1");
                    }
        }
                }
    }
            }
}
            catch (Exception ex)
catch (Exception ex)
            {
{
                MessageBox.Show("An Exception Occurred: " + ex.Message);
    MessageBox.Show("An Exception Occurred: " + ex.Message);
            }
}
</pre>
</pre>

Revision as of 01:10, 10 November 2011

About WMLib

WMLib is a library of ".NET-based" DLL API functions that allows you to call some of the WMS functionality from other .NET-based applications from outside of WMS. You can send the API watershed parameters from either a WMS tree file or code-based hydrologic tree information. After the watershed parameters have been set up, the API can be used to write an HEC-1 input file and to run HEC-1. The API can then read the HEC-1 output hydrographs for each sub-basin and lag the hydrographs based on specified lag times at each outlet point. The HEC-1-computed hydrographs and/or peak flows can be obtained for each outlet and sub-basin in the hydrologic tree.

How WMLib Works

Writing code to run an HEC-1 analysis using WMLib is a simple process. Using any .NET-based programming language, you do the following to run an HEC-1 analysis and read the HEC-1 solution file:

  1. . Either manually build a hydrologic tree, specifying sub-basin and outlet hydrologic and geometric parameters, or read a hydrologic tree from a WMS Tree (.tre) file.
  2. . Run HEC-1 and read the HEC-1 output hydrographs.
  3. . Write the hydrographs to a file that can be read into the Time Series Editor (.ts). The Time Series Editor is shipped with WMS and a license to the editor is included with a license of WMS. (optional)
  4. . Lag all the hydrographs in the hydrologic tree. (optional)
  5. . Get peak flows and/or times of peak flows. (optional)

For example, if you want to do all of the above and you have a WMS tree file, you could write the following C# code:

try
{
    // Set the job control start time and build the tree from a file
    string fileName = "C:\\treeFilePath\\wmsTreeFile.tre";
    DateTime currTime = new DateTime(2010, 5, 1, 0, 0, 0);
    HydroTree hydroTree = new HydroTree(currTime, 15, 300);
    if (FileIo.ReadTreeFile(fileName, hydroTree))
    {
        fileName = "C:\\hec1OutputPath\\WMLib.hc1";
        const string hec1FileName = "C:\\hec1ExePath\\hec1.exe";
        // Run HEC-1 and read the HEC-1 output hydrographs
        if (hydroTree.RunHec1(fileName, hec1FileName))
        {
            // Get the peak flow and time before lagging
            double peakFlow = hydroTree.GetPeakFlow();
            DateTime peakTime = hydroTree.GetPeakTime();
            // Write the hydrographs to a file that can be used by the time series editor
            myTree.WriteTreeToTsFile("C:\\timeSeriesFilePath\\hydrographs.ts");
            // Lag all hydrographs in the hydrologic tree
            hydroTree.ApplyLagTimes();
            // Get the peak flow and time after lagging
            peakFlow = hydroTree.GetPeakFlow();
            peakTime = hydroTree.GetPeakTime();
        }
        else
        {
            MessageBox.Show("Unable to run HEC-1");
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show("An Exception Occurred: " + ex.Message);
}