The facilities for output management will automatically create different kinds of output directories in different situations, such as when a simulation report is generated or when data collector monitors are used. It is also possible for the user to create the output directories if necessary, and to access the names of the different output directories.
The following functions can be used to access the names of the standard output directories for CPN Tools. When a function returns a path to a directory, the directory may or may not exist.
If an attempt is made to read or write a file in a directory that cannot be accessed then a
NotValidDirExn exception will be raised.
Output.getModelDir()returns the path to the directory in which the model is saved
Output.getModelName()returns the name of the file in which the model is saved
Output.getTopOutputDir()returns the path to the top output directory
Output.getSimOutputDir()returns the path to the current simulation output directory
Output.getSimLogfileDir()returns the path to the current simulation log files directory
Output.getRepOutputDir()returns the path to the current replication output directory
Output.getRepLogfileDir()returns the path to the current replication log files directory
The following functions can be used to create the standard output directories. If an attempt to create a directory fails, then a
NotValidDirExn s exception will be raised where
s is a string describing the error.
Output.initTopOutputDir()attempts to create the top output directory if the directory does not already exist
Output.initTopOutputDir, and attempts to create a simulation output directory if the directory does not already exist
Output.initSimOutputDir, and attempts to create a simulation log files directory if the directory does not already exist
Output.initTopOutputDir, and attempts to create a replication output directory if the directory does not already exist
Output.initRepOutputDir, and attempts to create a replication log files directory if the directory does not already exist
The simulator will automatically invoke the functions to initialize/create the output directories in the following situations:
initSimOutputDir: When a simulation report is to be saved
initSimLogfilesDir: When there are active write-in-file monitors or data collector monitors with the Logging option selected
initRepOutputDir: When multiple simulation replications are run
initRepLogfileDir: When multiple simulation replications are run, and there are data collector monitors
Examples of use
Here is an example of how the output management functions could be used in a user-defined monitor.
A number of declarations are used to define auxiliary functions and reference variables.
globref fileid = (NONE : TextIO.outstream option);
fun getfid () =
(* this will raise Option exception if !fileid = NONE *)
fun initfile () =
val filename = OS.Path.concat (Output.getSimOutputDir(),
fileid := SOME (TextIO.openOut filename)
The initialization, action, and stop functions for the monitor access the file using the functions that were defined in the declarations.
fun init () =
TextIO.output(getfid(), “Occurring transitions\n”))
fun action (observedval) =
handle Option => (initfile();
fun stop () =
(TextIO.output(getfid(), “\n\n”^”Simulation stopped after “^
fileid := NONE)
You must be logged in to post a comment.