
LineReader |
ptolemy.actor.lib.io.LineReader |
This actor reads a file or URL, one line at a time, and outputs each line
as a string. The file or URL is specified using any form acceptable
to FileParameter. Before an end of file is reached, the endOfFile
output produces false. In the iteration where the last line
of the file is read and produced on the output port, this actor
produces true on the endOfFile port. In that iteration,
postfire() returns false. If the actor is iterated again, after the end
of file, then prefire() and postfire() will both return false, output
will produce the string "EOF", and endOfFile will produce true.
In some domains (such as SDF), returning false in postfire()
causes the model to cease executing.
In other domains (such as DE), this causes the director to avoid
further firings of this actor. So usually, the actor will not be
invoked again after the end of file is reached.
This actor reads ahead in the file so that it can produce an output
true on endOfFile in the same iteration where it outputs
the last line. It reads the first line in preinitialize(), and
subsequently reads a new line in each invocation of postfire(). The
line read is produced on the output in the next iteration
after it is read.
This actor can skip some lines at the beginning of the file or URL, with
the number specified by the numberOfLinesToSkip parameter. The
default value of this parameter is 0.
If you need to reset this line reader to start again at the beginning
of the file, the way to do this is to call initialize() during the run
of the model. This can be done, for example, using a modal model
with a transition where reset is enabled.
Author(s): Edward A. Lee, Yuhong Xiong
Version:$Id: LineReader.java,v 1.29 2005/07/08 19:56:24 cxh Exp $
Pt.Proposed Rating:Green (eal)
Pt.Accepted Rating:Yellow (cxh)
endOfFile
An output port that produces false until the end of file
is reached, at which point it produces true. The type
is boolean.
fileOrURL
The file name or URL from which to read. This is a string with
any form accepted by FileParameter.
numberOfLinesToSkip
The number of lines to skip at the beginning of the file or URL.
This parameter contains an IntToken, initially with value 0.
The value of this parameter must be non-negative.