How to create an AsciiReader
The input for model systems is often contained in simple ASCII files. Wrapping these files allows you to make the data available to OpenMI-compliant systems. For example, you can wrap the output file from one component so that it serves as the input for another component. When such a file is wrapped, it can be accessed in the same way as any other OpenMI component. The wrapped output file makes it easy to test the OpenMI component that uses the file as input. It will also be possible to run the component using the data without having to run the delivering component.
To be OpenMI-compliant, a component needs to implement two interfaces: the IPublisher and ILinkableComponent interfaces. Therefore the ASCII reader needs to implement these interfaces. As with model systems, this can be done by inheriting from Oatc.OpenMI.Sdk.Wrapper.LinkableEngine and implementing specific methods.
The difference between the wrapping of ASCII files and the approach used for model components lies in the implementation of the ExchangeItems (GetOutputExchangeItem) and the GetValues call. In the case of a model component, the ExchangeItems will usually be provided by a populated model kernel. When wrapping an ASCII file, the information about possible ExchangeItems must be contained in the ASCII file itself.
Figure 1 is an example of an ASCII file (get file; there are four lines of comments, followed by a line specifying the quantity and another containing the three locations.
Figure 1 An example ASCII file
This information defines the possible OutputExchangeItems.
The OutputExchangeItems could look like the following:
Implementing an OpenMI-compatible linkable component that uses this ASCII file as input and makes the contents of the file available through OutputExchangeItems requires the following steps:
- Start developing the component by implementing org.OpenMI.Utilities.Wrapper.LinkableEngine.
- Write code for methods such as Initialize, Finalize, GetModelID and GetModelDescription.
- Write code for the SetValues, GetInputExchangeItem and GetInputExchangeItemCount methods; these methods are empty because the ASCII reader does not accept data.
- Write code for the GetOutputExchangeItem method; make sure the ASCII file is read, the ExchangeItems are extracted from the file and the OutputExchangeItems are defined.
- Write code for the GetValues method; this should extract the correct data for the requested timestamp/ExchangeItem combination from the ASCII file.
Prototype code for GetOutputExchangeItem is given in Figure 2.
Figure 2 Code for GetOutputExchangeItem
A prototype of the GetValues method is shown in Figure 3.
Figure 3 Example GetValues method