The general adapter is similar to the setup of any general adapter. Two HSPF specific settings are:
See examples of the States ExportActivity and the ExecuteActivity below.
<exportStateActivity> <moduleInstanceId>HSPF_Basin_update</moduleInstanceId> <stateExportDir>%WORK_DIR%/model</stateExportDir> <stateConfigFile>%WORK_DIR%/states/state_in.xml</stateConfigFile> <stateLocations type="file"> <stateLocation> <readLocation>Basin.uci</readLocation> <writeLocation>../work0/Basin.uci</writeLocation> </stateLocation> </stateLocations> ... </exportStateActivity>  | 
<executeActivities> <!-- Execute HSPF model--> <executeActivity> <description>OpenDa in Fews adapter</description> <command> <executable>%REGION_HOME%/Modules/OpenDaInFews/bin/run_openda_in_fews.bat</executable> </command> <arguments> <argument>-m</argument> <argument>org.openda.blackbox.wrapper.BBModelFactory</argument> <argument>hspfModel.xml</argument> <argument>-f</argument> <argument>%WORK_DIR%/run_info.xml</argument> </arguments> <timeOut>4000000</timeOut> </executeActivity> </executeActivities>  | 
There are two OpenDA files that need to be configured. The hspfWrapper.xml and the hspfModel.xml. Only if the intention is to use the HSPF model in a Data Assimilation or Calibration run a more extensive OpenDA setup, that requires additional xml-files, is needed. See http://openda.org/ for more information on OpenDA or for downloading the OpenDA binaries.
This is the wrapper file that describes the run actions (model initialize actions, compute actions, and finalize actions), and the InputOutput objects.
The HSPF adapter:
An example configuration file is shown below:
<blackBoxWrapperConfig xmlns="http://www.openda.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openda.org http://www.openda.org/schemas/openda_2.2/blackBoxWrapperConfig.xsd">
	<aliasDefinitions defaultKeyPrefix="%" defaultKeySuffix="%">
		<alias key="HSPFDIR" value="../bin"/>
		<alias key="templateDir" value="model"/>
		<alias key="instanceDir" value="work"/>
		<alias key="uciFile" value="Basin.uci"/>
		<alias key="inputParametersFile" value="BasinInput.wdm"/>
		<alias key="stateVariablesFile" value="BasinState.wdm"/>
		<alias key="outputFile" value="BasinResults.wdm"/>
		<alias key="wdmDllFile" value="../../../OpenDaInFews/bin_dll/win32_gfortran/wdm.dll"/>
		<alias key="wdmMessageFile" value="../../../OpenDaInFews/bin_dll/MESSAGE.WDM"/>
		<alias key="startTime" value="dummy"/>
		<alias key="endTime" value="dummy"/>
		<alias key="TimeZone" value="1.0"/>
	</aliasDefinitions>
	<run>
		<initializeActionsUsingDirClone instanceDir="%instanceDir%%instanceNumber%" templateDir="%templateDir%"/>
		<computeActions>
			<!-- delete all existing data in output file -->
			<action className="org.openda.model_hspf.ClearWdmFile" workingDirectory="%instanceDir%%instanceNumber%">
				<arg>%wdmDllFile%</arg>
				<arg>%wdmMessageFile%</arg>
				<arg>%outputFile%</arg>
			</action>
			<action className="org.openda.model_hspf.ClearWdmFile" workingDirectory="%instanceDir%%instanceNumber%">
				<arg>%wdmDllFile%</arg>
				<arg>%wdmMessageFile%</arg>
				<arg>%stateVariablesFile%</arg>
			</action>
			<!-- run model -->
			<action exe="%HSPFDIR%/WinHspfLt.exe" workingDirectory="%instanceDir%%instanceNumber%">
				<arg>%uciFile%</arg>
			</action>
		</computeActions>	
		<finalizeActions>
			<!-- STATES -->
			<action className="org.openda.exchange.iotools.DataCopier">
				<!-- classname of input data object -->
				<arg>-c</arg>
				<arg>org.openda.model_hspf.WdmTimeSeriesDataObject</arg>
				<!-- arguments for input data object -->
				<arg>-a</arg>
				<!-- The first argument should be the pathname of the wdm.dll file (relative to the folder with the input wdm file).
		The second argument should be the pathname of the message file (relative to the folder with the input wdm file).
		The third argument should be the role of this DataObject. Role must be 'output'.
		The fourth argument should be the timeZone that is used by the model (in hours with respect to GMT, between -12 and 12).
		The fifth and sixth arguments should be respectively the startTime and endTime of the model run.
		The (optional) seventh and further arguments should be the location and parameter ids of the time series for which exchange items should be made, if no seventh and further arguments present then exchange items will be created for all time series in the files. -->
				<arg>%wdmDllFile% %wdmMessageFile% output %TimeZone% %startTime% %endTime%</arg>
				<!-- File pathname:
		The pathname of the file containing the data for this DataObject (relative to the instance directory). -->
				<arg>%instanceDir%%instanceNumber%/%stateVariablesFile%</arg>
				<!-- classname of output data object -->
				<arg>-c</arg>
				<arg>org.openda.model_hspf.UciStateDataObject</arg>
				<!-- arguments for output data object -->
				<arg>-a</arg>
				<!-- The first argument should be the absolute state time.
				     The (optional) second argument should be the state time shift in seconds (can be negative). 
				     The timestamp for the state in the .uci file will be equal to (absolute state time) + (state time shift). -->
                <arg>%endTime% -3600</arg>
				<!-- File pathname:
		The pathname of the .uci state file containing the data for this DataObject (relative to the instance directory). -->
				<arg>%instanceDir%%instanceNumber%/%uciFile%</arg>
			</action>		
		</finalizeActions>
	</run>
	<inputOutput>
	<ioObject className="org.openda.model_hspf.UciDataObject">
			<file>%uciFile%</file>
			<id>uciDataObject</id>
			<arg>%TimeZone%</arg>
			<arg>TSTART1</arg>
			<arg>TSTOP1</arg>
			<!-- the following argument is the optional startTimeExtension. This is the startTime of the runPeriod for the HSPF model in hours relative to the startTime of the OpenDA runPeriod. This can be used to extend the runPeriod for the HSPF model (the runPeriod as it will be put in the uci file) with respect to the OpenDA runPeriod. This is useful when there is no restart file (warm state) available for the forecast. In other words the extended period will allow the model to get to a warm state before the forecast starts. -->
			<!---43800 equals 5 years-->
			<!--<arg>0</arg>-->
		</ioObject>
		<ioObject className="org.openda.model_hspf.WdmTimeSeriesIoObject">
			<file>%inputParametersFile%</file>
			<id>inputParametersIoObject</id>
			<arg>%wdmDllFile%</arg>
			<arg>%wdmMessageFile%</arg>
			<arg>input</arg>
			<arg>%TimeZone%</arg>
			<arg>TSTART2</arg>
			<arg>TSTOP2</arg>
		</ioObject>
		<ioObject className="org.openda.model_hspf.WdmTimeSeriesIoObject">
			<file>%outputFile%</file>
			<id>outputIoObject</id>
			<arg>%wdmDllFile%</arg>
			<arg>%wdmMessageFile%</arg>
			<arg>output</arg>
			<arg>%TimeZone%</arg>
			<arg>%startTime%</arg>
			<arg>%endTime%</arg>
		</ioObject>
	</inputOutput>
</blackBoxWrapperConfig> | 
This file describes the models exchangeItems and can be kept very simple by defining "allElementsFromIoObject" for the model exchangeItems. A standard configuration is shown below:
<blackBoxModelConfig xmlns="http://www.openda.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openda.org http://www.openda.org/schemas/openda_2.2/blackBoxModelConfig.xsd"> <wrapperConfig> <file>./hspfWrapper.xml</file> </wrapperConfig> <aliasValues/> <timeInfoExchangeItems start="TSTART1" end="TSTOP1"/> <timeInfoExchangeItems start="TSTART2" end="TSTOP2"/> <exchangeItems> <vector id="allElementsFromIoObject" ioObjectId="uciDataObject"/> <vector id="allElementsFromIoObject" ioObjectId="inputParametersIoObject" role="Input"/> <vector id="allElementsFromIoObject" idSuffix="_output" ioObjectId="outputIoObject" role="Output"/> </exchangeItems> <doCleanUp>false</doCleanUp> </blackBoxModelConfig>  | 
See an example ModuleDataset including the hspfWrapper.xml and the hspfModel.xml files.
To be able to run HSPF the following binaries or actions are required:
The UCI file should contain at least references to three WDM files, e.g.:
FILES
<FILE> <UN#>***<----FILE NAME------------------------------------------------->
...
WDM1 26 BasinResults.WDM 
WDM2 27 BasinInput.WDM 
WDM4 28 BasinState.WDM 
 ...
END FILES
In the EXT SOURCES (BasinInput.WDM) and EXT TARGETS (BasinState.WDM and BasinResults.WDM) blocks the items in the different WDM files should be listed.
The INIT tables will be updated by the HSPF model adapter, make sure that the table format is correct, see also XXX
Note: Be aware of the units that HSPF will use, indicated by ENGL or METR in the EXT TARGETS and EXT SOURCES Blocks
A WDM state file can be created by following the instructions below:


C TCODE - time units of data
C 1 - second 4 - day
C 2 - minute 5 - month
C 3 - hour 6 - year
