edu.brook.ascape.view
Class DataOutputView

java.lang.Object
  |
  +--edu.brook.ascape.view.NonGraphicView
        |
        +--edu.brook.ascape.view.DataView
              |
              +--edu.brook.ascape.view.DataOutputView

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
See Also:
DataView, SweepGroup, SweepControlView, Scape

Field Summary
protected static int numCharsInFileName
          The number of characters to use for a file name.
protected  java.io.DataOutputStream periodDataStream
          The data stream statistics are written to.
protected  java.io.File periodFile
           
protected  java.io.FileOutputStream periodFileStream
          The file stream statistics are written to.
protected  java.io.DataOutputStream runDataStream
          The data stream statistics are written to.
protected  java.io.File runFile
           
protected  java.io.FileOutputStream runFileStream
          The file stream statistics are written to.
protected  long startTime
          The time the current run was started.
 
Fields inherited from class edu.brook.ascape.view.DataView
dataSelection
 
Fields inherited from class edu.brook.ascape.view.NonGraphicView
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
 void addScape(Scape scape)
          Add a scape to the view.
 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()
           
 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 onClose()
          On close, closes any open files.
 void onStart()
          On scape start, record the start time and wirte the file headers.
 void onStop()
          On scape stop, writes the run results to the file.
 void onUpdate()
          On scape update, call writePeriodData.
 void setNumCharsInFileName(int runLimit)
          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()
           
 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 results to the data stream or file.
 void writeRunHeader()
          Writes the headers for the run results to the run data stream or file.
 
Methods inherited from class edu.brook.ascape.view.DataView
getDataSelection
 
Methods inherited from class edu.brook.ascape.view.NonGraphicView
getName, getScape, NonGraphicView, NonGraphicView, onIterate, onSetup, removeScape, scapeUpdated, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numCharsInFileName

protected static int numCharsInFileName
The number of characters to use for a file name. File names are the sequential number, left padded with '0' to this size. Default is 5. For example, 35 would appear as '0035'. Obviously, a given size allows 10^size possible runs per parameter space. Setting runs per will change this value.

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

runFileStream

protected java.io.FileOutputStream runFileStream
The file stream statistics are written to.

runDataStream

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

periodFile

protected java.io.File periodFile

periodFileStream

protected java.io.FileOutputStream periodFileStream
The file stream statistics are written to.

periodDataStream

protected java.io.DataOutputStream periodDataStream
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 - 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.
Parameters:
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.
Parameters:
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 - 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.
Parameters:
runDataStream - the stream to write the data to

setPeriodDataStream

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

getPeriodFile

public java.io.File getPeriodFile()

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 - 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 a (platform independent) linefeed '\n' seperating each period.

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 a (platform independent) linefeed '\n' seperating each period.

writeRunHeader

public void writeRunHeader()
                    throws java.io.IOException
Writes the headers for the run results to the run data stream or file. Data is output as tab delimited ASCII text, with a (platform independent) linefeed '\n' seperating each period.

writeRunData

public void writeRunData()
                  throws java.io.IOException
Writes the current run results to the data stream or file. Data is output as tab delimited ASCII text, with a (platform independent) linefeed '\n' seperating each period.

stopCondition

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

getNumCharsInFileName

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

setNumCharsInFileName

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

onUpdate

public void onUpdate()
On scape update, call writePeriodData.
Overrides:
onUpdate in class NonGraphicView

onClose

public void onClose()
On close, closes any open files.
Overrides:
onClose in class NonGraphicView

onStart

public void onStart()
On scape start, record the start time and wirte the file headers. If any headers need to be written, they are written now.
Overrides:
onStart in class NonGraphicView

onStop

public void onStop()
On scape stop, writes the run results to the file.
Overrides:
onStop in class NonGraphicView
See Also:
onStart(), onStop()

addScape

public void addScape(Scape scape)
              throws java.util.TooManyListenersException
Add a scape to the view. A view can be assigned only one scape. Creates a new data selection for data output, backed by the Scape's data group.
Parameters:
scape - the scape to make this canvas the observer of
Throws:
java.util.TooManyListenersException - on attempt to add a scape when one is allready added
Overrides:
addScape in class DataView

toString

public java.lang.String toString()
Overrides:
toString in class NonGraphicView

(c) 1998-2000 The Brookings Insitution
Webpage