FileToVector, FileToMatrix, and FileToHashMap

The FileToVector, FileToMatrix, and FileToHashMap objects read data contained in a file.

The DataFile keyword specifies the file to be read.  The data must be delimited by either spaces or tabs (but NOT commas), and can consist of any mixture of numbers (with or without units), strings, objects, arrays, maps, and lambda functions.  An entry that contains spaces must be enclosed by single quotes.

An entry can be given in expression format or it can take advantage of rules that allow a somewhat simpler format.  The following table gives some examples of valid data entries:

Data File Entries

Entry

Rule

Examples

Comment

Records that begin with a # symbol are ignored.

# This is a comment

Number

Numbers are entered in expression format.

1.0

 

1.0[m]

 

'1.0 [m]'

Time Stamp

Time stamps can be entered as either:

'YYYY-MM-DD HH:MM:SS.SSS' or

YYYY-MM-DDTHH:MM:SS.SSS

See Table 4‑14 for more details.

 

'0000-01-02 06:24:00.0'

 

 0000-01-02T06:24:00.0

Object

Object names can be entered with or without square brackets

 

[Server1]

 

Server1

Array

Arrays are entered in expression format.  They must be enclosed by single quotes.

 

 

'{1,2,3}'

 

'{1, 2, 3}'

String

Any entry that cannot be interpreted as a valid number, object, or array is treated as a string.

 

 

'"Quick red fox"'

 

'Quick red fox'

 

Quick_red_fox

When JaamSim is executed from the API, the DataFile input can be replaced by a call to the setValue method for this object, which populates the data directly.

The data read from the file is made available to the model through an output named Value.  The two objects differ in the type of data returned by this output:

·         FileToVector: the Value output returns a single array combining all the records in the file. 

·         FileToMatrix: the Value output returns an array of arrays, with one internal array for each record that was read.

·         FileToHashMap: the Value output returns a map with the first entry in each line of the file treated as the key and with the corresponding value consisting of the remaining entries collected as an array.

The data file is first read when the simulation is started.  It is re-read and the Value output updated whenever the object receives an entity.