org.ascape.view.nonvis
Class DataOutputView

java.lang.Object
  extended by org.ascape.model.event.DefaultScapeListener
      extended by org.ascape.view.nonvis.NonGraphicView
          extended by org.ascape.view.nonvis.DataView
              extended by org.ascape.view.nonvis.DataOutputView
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, ScapeListener, HasName
Direct Known Subclasses:
AllOutputView, DataOutputViewElement, ScapeOutputView

public class DataOutputView
extends DataView

A non-graphic view providing output of model data to a file. To use, (assuming you are collecting the statistics you are interested in, see Scape) just add this view to any scape, and set a file or data strem for it. Every period, statistic measurements will be written to the file or data strem. By default, all statistics are selected; get data selection to make different selections. If you would like to add more information to the period or run data, simply override the write.. methods. The rule here is that all fields must be preceeded by the '\t' character. (Of course, the first field should not be preceeded with a tab character, but ordinarily you will be calling the super method first anyway.) If you do override either writeRunData or writePeriodData, be sure to override writeRunHeader or writePeriodHeader as well.

Since:
1.0
Version:
1.9 8/1/2000
Author:
Miles Parker
See Also:
DataView, SweepGroup, SweepControlView, Scape, Serialized Form

Field Summary
static java.lang.String EOLString
          The character(s) to use for end-of-line.
protected  boolean periodHeadersWritten
          The period headers written.
protected  int runCount
          The number used for naming each consecutive run.
protected  java.io.DataOutputStream runDataStream
          The data stream statistics are written to.
protected  java.io.File runFile
          The run file.
protected  boolean runHeadersWritten
          The run headers written.
protected  long startTime
          The time the current run was started.
protected  boolean writeHeaders
          The write headers.
 
Fields inherited from class org.ascape.view.nonvis.DataView
dataSelection
 
Fields inherited from class org.ascape.model.event.DefaultScapeListener
listeningToScape, name, scape
 
Constructor Summary
DataOutputView()
          Constructs a data output view.
DataOutputView(java.io.DataOutputStream runDataStream)
          Constructs a data output view.
DataOutputView(java.io.File file)
          Constructs a data output view.
 
Method Summary
 java.lang.String getEOLSeparator()
          Returns the character(s) to be used to indicate an end-of-line; i.e.
static int getNumCharsInFileName()
          Returns the number of characters used for the sequential file name.
 java.io.DataOutputStream getPeriodDataStream()
          Returns the data stream that period (iteration by iteration) output will be written to.
 java.io.File getPeriodFile()
          Gets the period file.
 java.io.DataOutputStream getRunDataStream()
          Returns the data stream that statistics output should go to.
 java.io.File getRunFile()
          Returns the file that the run output will be written to.
 void scapeAdded(ScapeEvent scapeEvent)
          Notifies the listener that the scape has added it.
protected  void scapeChanged()
          Called for any model change that effects model state; i.e.
 void scapeClosing(ScapeEvent scapeEvent)
          On close, closes any open files.
 void scapeDeserialized(ScapeEvent scapeEvent)
          Method called once a model is deserialized.
 void scapeIterated(ScapeEvent scapeEvent)
          On scape iterate, write period data.
 void scapeStarted(ScapeEvent scapeEvent)
          On scape start, record the start time and wirte the file headers.
 void scapeStopped(ScapeEvent scapeEvent)
          On scape stop, writes the run parameters to the file.
static void setEOLSeparator(java.lang.String string)
          Sets the character(s) to be used to indicate an end-of-line; i.e.
static void setNumCharsInFileName(int _numCharsInFileName)
          Sets the number of characters to use for the sequential file name.
 void setPeriodDataStream(java.io.DataOutputStream periodDataStream)
          Defines the data stream that period (iteration by iteration) output will be written to.
 void setPeriodFile(java.io.File file)
          Defines the file that period (iteration by iteeration) output will be written to.
 void setRunDataStream(java.io.DataOutputStream runDataStream)
          Defines the data stream that run output will be written to.
 void setRunFile(java.io.File file)
          Defines the file that run output will be written to.
 boolean stopCondition()
          (Conveneince method.) If this method returns true, the current run will be stopped.
 java.lang.String toString()
          Returns a short description of this view.
 void writePeriodData()
          Writes the current period statistics to the data stream or file.
 void writePeriodHeader()
          Writes the headers for the period statistics to the run data stream or file.
 void writeRunData()
          Writes the current run parameters to the data stream or file.
 void writeRunHeader()
          Writes the headers for the run parameters to the run data stream or file.
 
Methods inherited from class org.ascape.view.nonvis.DataView
getDataSelection
 
Methods inherited from class org.ascape.view.nonvis.NonGraphicView
isGraphic
 
Methods inherited from class org.ascape.model.event.DefaultScapeListener
clone, environmentQuiting, getName, getScape, isLifeOfScape, isNotifyScapeAutomatically, notifyScapeUpdated, scapeInitialized, scapeNotification, scapeRemoved, scapeSetup, setName, setNotifyScapeAutomatically
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

runCount

protected int runCount
The number used for naming each consecutive run. Not 0-based, the first run is run 1.


EOLString

public static java.lang.String EOLString
The character(s) to use for end-of-line.


writeHeaders

protected boolean writeHeaders
The write headers.


runHeadersWritten

protected boolean runHeadersWritten
The run headers written.


periodHeadersWritten

protected boolean periodHeadersWritten
The period headers written.


startTime

protected long startTime
The time the current run was started. Used to track elapsed time for each run.


runFile

protected java.io.File runFile
The run file.


runDataStream

protected transient java.io.DataOutputStream runDataStream
The data stream statistics are written to.

Constructor Detail

DataOutputView

public DataOutputView()
Constructs a data output view. A stream must be set, and the view must be added to a scape.


DataOutputView

public DataOutputView(java.io.DataOutputStream runDataStream)
Constructs a data output view. The view must be added to a scape.

Parameters:
runDataStream - the stream to write the data to

DataOutputView

public DataOutputView(java.io.File file)
               throws java.io.IOException
Constructs a data output view. The view must be added to a scape.

Parameters:
file - the file to write the data to
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.io.IOException - if a file stream cannot be created from the file
Method Detail

getRunDataStream

public java.io.DataOutputStream getRunDataStream()
Returns the data stream that statistics output should go to.

Returns:
runDataStream the stream to write the data to

setRunDataStream

public void setRunDataStream(java.io.DataOutputStream runDataStream)
Defines the data stream that run output will be written to.

Parameters:
runDataStream - the stream to write the data to

getRunFile

public java.io.File getRunFile()
Returns the file that the run output will be written to.

Returns:
runDataStream the stream to write the data to

setRunFile

public void setRunFile(java.io.File file)
                throws java.io.IOException
Defines the file that run output will be written to. Set to null (default) if you don't want run data collected.

Parameters:
file - the file to write the data to
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.io.IOException - if a file stream cannot be created from the file

getPeriodDataStream

public java.io.DataOutputStream getPeriodDataStream()
Returns the data stream that period (iteration by iteration) output will be written to.

Returns:
the period data stream

setPeriodDataStream

public void setPeriodDataStream(java.io.DataOutputStream periodDataStream)
Defines the data stream that period (iteration by iteration) output will be written to.

Parameters:
periodDataStream - the stream to write the data to

getPeriodFile

public java.io.File getPeriodFile()
Gets the period file.

Returns:
the period file

setPeriodFile

public void setPeriodFile(java.io.File file)
                   throws java.io.IOException
Defines the file that period (iteration by iteeration) output will be written to. Set to null (default) if you don't want period data collected.

Parameters:
file - the file to write the data to
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.io.IOException - if a file stream cannot be created from the file

writePeriodHeader

public void writePeriodHeader()
                       throws java.io.IOException
Writes the headers for the period statistics to the run data stream or file. Data is output as tab delimited ASCII text, with the selected "EOLSeparator" separating each period.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writePeriodData

public void writePeriodData()
                     throws java.io.IOException
Writes the current period statistics to the data stream or file. Data is output as tab delimited ASCII text, with the selected "EOLSeparator" separating each period.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeRunHeader

public void writeRunHeader()
                    throws java.io.IOException
Writes the headers for the run parameters to the run data stream or file. Data is output as tab delimited ASCII text, with the selected "EOLSeparator" separating each period.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

writeRunData

public void writeRunData()
                  throws java.io.IOException
Writes the current run parameters to the data stream or file. Data is output as tab delimited ASCII text, with the selected "EOLSeparator" separating each period.

Throws:
java.io.IOException - Signals that an I/O exception has occurred.

stopCondition

public boolean stopCondition()
(Conveneince method.) If this method returns true, the current run will be stopped.

Returns:
true, if stop condition

getNumCharsInFileName

public static int getNumCharsInFileName()
Returns the number of characters used for the sequential file name.

Returns:
the num chars in file name

setNumCharsInFileName

public static void setNumCharsInFileName(int _numCharsInFileName)
Sets the number of characters to use for the sequential file name. File names are left padded with '0' to this number.

Parameters:
_numCharsInFileName - the _num chars in file name

scapeChanged

protected void scapeChanged()
Called for any model change that effects model state; i.e. scapeStarted and scapeIterated.


scapeIterated

public void scapeIterated(ScapeEvent scapeEvent)
On scape iterate, write period data.

Specified by:
scapeIterated in interface ScapeListener
Overrides:
scapeIterated in class DefaultScapeListener
Parameters:
scapeEvent - the scape event

scapeClosing

public void scapeClosing(ScapeEvent scapeEvent)
On close, closes any open files.

Specified by:
scapeClosing in interface ScapeListener
Overrides:
scapeClosing in class DefaultScapeListener
Parameters:
scapeEvent - the scape event

scapeStarted

public void scapeStarted(ScapeEvent scapeEvent)
On scape start, record the start time and wirte the file headers. If any headers need to be written, they are written now. Write first period data.

Specified by:
scapeStarted in interface ScapeListener
Overrides:
scapeStarted in class DefaultScapeListener
Parameters:
scapeEvent - the scape event

scapeStopped

public void scapeStopped(ScapeEvent scapeEvent)
On scape stop, writes the run parameters to the file.

Specified by:
scapeStopped in interface ScapeListener
Overrides:
scapeStopped in class DefaultScapeListener
Parameters:
scapeEvent - the scape event
See Also:
scapeStarted(org.ascape.model.event.ScapeEvent), scapeStopped(org.ascape.model.event.ScapeEvent)

scapeDeserialized

public void scapeDeserialized(ScapeEvent scapeEvent)
Method called once a model is deserialized.

Specified by:
scapeDeserialized in interface ScapeListener
Overrides:
scapeDeserialized in class DefaultScapeListener
Parameters:
scapeEvent - the scape event

scapeAdded

public void scapeAdded(ScapeEvent scapeEvent)
                throws java.util.TooManyListenersException
Notifies the listener that the scape has added it. Creates a new data selection for data output, backed by the Scape's data group.

Specified by:
scapeAdded in interface ScapeListener
Overrides:
scapeAdded in class DataView
Parameters:
scapeEvent - the scape added notification event
Throws:
java.util.TooManyListenersException - the too many listeners exception
java.util.TooManyListenersException - on attempt to add this listener to another scape when one has already been assigned

toString

public java.lang.String toString()
Description copied from class: DefaultScapeListener
Returns a short description of this view. Sames as name unless overridden.

Overrides:
toString in class DefaultScapeListener
Returns:
the string

getEOLSeparator

public java.lang.String getEOLSeparator()
Returns the character(s) to be used to indicate an end-of-line; i.e. the record delimiter. By default the platform dependent property returned by the system property "line.separator".

Returns:
the EOL separator

setEOLSeparator

public static void setEOLSeparator(java.lang.String string)
Sets the character(s) to be used to indicate an end-of-line; i.e. the record delimiter.

Parameters:
string - the string


Copyright © 1998-2008 The Brookings Institution, NuTech Solutions, Metascape, LLC All Rights Reserved.