Friday, December 16, 2011

Working out kinks in VB.net/BASINS

I mentioned last week that I was working on revising a portion of the BASINS source code to reproduce the statistics and advice previously calculated by the antiquated HSPEXP program. I'm happy to report that I've gotten the portion of the code I was working with up and running, producing area summaries, statistics, and graphs using Virginia Tech's standard formatting, in a new(ish) program that just runs the statistics and does not require BASINS to be launched. Getting the portion of the code up and running took a little time but was not complicated, after addressing the issues in my last post. However, creating a setup file that would run on Windows 7 proved to be a little more challenging, and I thought I'd write about it to help both future BASINS coders and general VB.net coders alike.

My first problem was that the code I'm working with requires an old DLL created (I think) using FORTRAN - hass_ent.dll. I had tried to enter the version of the DLL published with EPA's version of BASINS 4 into the registry on a Windows 7 machine - no luck. Additionally, the version of BASINS available from EPA would not install on a Windows 7 machine. I believe I mentioned in my last post that Aqua Terra has released an updated version of BASINS on their website, which is nearly impossible to find if you don't know what you're looking for. So I tried downloading and installing the "Installer for GenSCN and WDMUtil" available at that website (following the 'keep it simple stupid' mentality, I decided to try installing just what I needed - WDMUtil and HSPF - rather than the full-blown package). Ta-da! It installed. The version of HSPF in that package does not run, but WDMUtil does. The full blown BASINS upgrade includes a newer version of HSPF (3.0), my hunch is that it will run on Windows 7...but again, keeping it simple, I haven't messed with that yet. All I needed for my purposes was to get something to install hass_ent.dll, and the GenSCN and WDMUtil installer was successful for that purpose.

My next problem arose from the fact that I had updated the references for the BASINS source code in a rather patchwork fashion...first I tried downloading DLLs from MapWindow, then I realized several of the needed files were actually available with the BASINS installation available from EPA and just copied the ones I needed, and then when I was still having trouble I upgraded my BASINS installation as above and referenced those DLLs...so depending on when I brought which projects into my VB.net solution, projects using the 'same' DLL might actually reference two different files. Additionally, there was a BASINS project available that compiled into MapWinUtility.dll that was slightly different from the MapWinUtility.dll that seems to be the default for MapWindow, and of course my patchwork solution was referencing both of them. Once I finally got the code to compile after all the various downloads and updates I didn't think to check that all 15 of the member projects were referencing the same DLLs.

I was receiving multiple errors as a result of this. Additionally, once I attempted to publish the file, I got an actual error in Visual Basic 2010 Express that would no longer let me compile the project. These errors were "two or more files have the same target path" within the development environment and "reference in the manifest does not match the identity of the downloaded assembly" while attempting to install the code on a new computer. I had an earlier error "must be strong signed in order to be marked as a prerequisite" that had caused me to change the status of stdole.dll from 'prerequisite' to 'include' in the Publish->Application files screen for my main project (note that the file it said needed to be strong signed was NOT stdole.dll...but fixing that one fixed the error). I think that change might have launched the other errors... At any rate, after googling and googling I finally started checking the references and discovered I had several with the same name pointing to different actual files. I changed the same-named references in all the projects to point to the same DLLs and poof! my errors vanished.

I suppose this is no great surprise - kind of a 'well, duh' kind of moment. I agree. However, I think it is an easy mistake to make with code acquired WITHOUT all the required references, code that forces you to go identify and download all those references yourself. I had googled and tried things for hours before thinking to check my individual project references, so I'm suggesting it here in hopes it may save someone else a lot of wasted time!

5 comments:

  1. Hi Rebecca, Im an MS student at VT working with HSPF. I have had major issues with running basins and WDMUtil on Windows7. I actually have yet to use it without a crash and cannot create my own import script for WDMUtil. Glad I found your blog! The link you provide to the 2012 basins updates is great, but all of the files download with an .EXX extension? Can you recommend a program to open these executable files? Cant seem to find any myself. Thanks!

    ReplyDelete
    Replies
    1. Hi! Thanks for commenting.

      I suppose I should have posted a link to the download page rather than the download itself; if you go to the parent page (http://www.aquaterra.com/basins4/), you can see that the .exx is actually an .exe file - they've changed the extension, presumably to bypass things that would block downloads of .exe files. So just change the .exx extension to .exe and then double click and you should be in good shape.

      If you are at VT working with HSPF and haven't already, I HIGHLY recommend getting in touch with Dr. Brian Benham in the Biological Systems Engineering department. His group has been using HSPF for years and may be able to help you through any hiccups you encounter.

      Good luck!

      Delete
  2. how to convert data from .txt files to .ws file using WDMutil?

    ReplyDelete
  3. Hi Rebecca, I hope this is still a viable forum to use.

    I am having issues getting my WDMutil to operate successfuly without crashing. I have downloaded the Basins ver 4.1 from AquaTerra and have also installed the seperate WDMUtil and GenScn software, since Basins no longer includes these together.

    My problem is that WDM util will launch from Basins, but when I try to open a WDM file, it will immediately encounter a problem and crash. This is severely limiting because it really impacts how much you can manipulate the WDM files and meteorological data that is driving the HSPF model.

    Does anyone have this problem? Workarounds? Someone to contact regarding an issue like this? I'm working in Windows 7 with a 64bit machine. Any suggestions are greatly appreciated. Thanks in advance for the help!

    ReplyDelete
    Replies
    1. Hi Gordon,

      Sadly problems with WDMUtil are all too common...I can't tell you the number of times I've somehow corrupted a WDM file and had to start over from scratch. A corrupted WDM file would cause the behavior you're seeing, though I can't promise it's that and not a software issue.

      If you're using HSPF (?), a workaround is to use MUTSIN files for timeseries input and PLTGEN files for timeseries output. These are described in the HSPF manual. These are just flat text files, easily manipulated with Notepad or your favorite text editor, and they don't corrupt easily! When I used HSPF on a regular basis I put almost everything in MUTSIN and PLTGEN format to avoid WDMUtil, though I did still use WDM files for meteorological data.

      If you do need to use WDM files...first, I would make lots of backups in case you corrupt one. Second, I noticed at BASINS 4.1 that they feel most of what you'd need to do with a WDM file can be done within BASINS (I haven't used BASINS 4.1 so I can't tell you what specifically to look for), so you might try poking around the BASINS interface to see if there is an alternative to WDMUtil. Finally, if all else fails, I've found the BASINS listserv (see bottom of this page: http://water.epa.gov/scitech/datait/models/basins/index.cfm) to be a very useful place, both to search archives and to ask questions of current and expert users.

      Hope this helps! I feel your pain!

      -Rebecca

      Delete