File IO / FileReader
Block Name: FileReader

Code File Location: VisualSim/actor/lib/io/ExpressionReader

Block Overview

o     Read from a file where the column value can have a different data type.

o   Abstract part of the model by using the response or generation from another model.

Description

This block accepts a file name as a parameter. There are a number of file path options available for this block.  To see the list, view the section on File Paths in the Reference Guide document here. The file name is a concatenation of any number of individual strings and parameters, separated by "+".  To view the file path in a demo model, click here.

This block reads a file or URL, one line at a time, evaluates each line as an expression, and outputs the token resulting from the evaluation. The first line in the file determines the data type of the output. All other lines must contain expressions that evaluate to the same type or a subtype, or a run-time type error will occur. This block will terminate at the end of the file.

This block loads one line at a time into memory before sending the output.  If you are using table that have columns with headers, use the TrafficReader block.

If the file contains a data structure, the each line would look like this:

"{X   = 1.0E-10,   Y   = 1}"

Notice the "" on the ends of each line.  Also, any strings in the file must contain /" before and after the string.

If this Reader reads a file containing data structures that have been saved from another model, make sure the data has been formatted using "recordTokenToLineWriter(input)" RegEx function before written.

View the FileReader Example in the BDE.


Connection

The input port of the FileReader can be connected to a Single Event or Traffic Generator. Lines are read from the input file when we get a trigger on the input port. So if we want to read the lines continuously, then we need to loop back the output to the input.

The output port of the FileReader can be connected to an ExpressionList, Script or TextDisplay. We make use of ExpressionList and Script blocks to convert the string data into data structure (if the input file contain Data structure template or details). For example, at the ExpressionList, we need to write  MyDS     = newToken(input). newToken(input) will convert the string Data structure template into standard data structure that can be used by other library blocks. the input to the ExpressionList will look like - "{X    = 1.0E-10,       Y    = 1, Z=\"str\"}"


Parameter

Explanation

fileOrURL
The format is either http://www.mirabilisdesign.com/filename.txt (URL, file located anywhere on the Internet) or C:/VisualSim/filename.txt (Windows) or file://VisualSim/filename.txt (Unix/Linux).  If the filename alone is listed, then the directory containing the model is assumed.  The file name is a concatenation of any number of individual strings and parameters, separated by "+".

The filename can be a parameter and can be used to name the output files differently for each simulation run during batch mode operation.