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 savedOutput.getModelName()
returns the name of the file in which the model is savedOutput.getTopOutputDir()
returns the path to the top output directoryOutput.getSimOutputDir()
returns the path to the current simulation output directoryOutput.getSimLogfileDir()
returns the path to the current simulation log files directoryOutput.getRepOutputDir()
returns the path to the current replication output directoryOutput.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 existOutput.initSimOutputDir()
callsOutput.initTopOutputDir
, and attempts to create a simulation output directory if the directory does not already existOutput.initSimLogfileDir()
callsOutput.initSimOutputDir
, and attempts to create a simulation log files directory if the directory does not already existOutput.initRepOutputDir()
callsOutput.initTopOutputDir
, and attempts to create a replication output directory if the directory does not already existOutput.initRepLogfileDir()
callsOutput.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 savedinitSimLogfilesDir
: When there are active write-in-file monitors or data collector monitors with the Logging option selectedinitRepOutputDir
: When multiple simulation replications are runinitRepLogfileDir
: 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 *)
Option.valOf(!fileid)fun initfile () =
let
val filename = OS.Path.concat (Output.getSimOutputDir(),
“Trans_Log_File.txt”)
in
Output.initSimOutputDir();
fileid := SOME (TextIO.openOut filename)
end;
The initialization, action, and stop functions for the monitor access the file using the functions that were defined in the declarations.
fun init () =
(initfile();
TextIO.output(getfid(), “Occurring transitions\n”))fun action (observedval) =
TextIO.output(getfid(), observedval)
handle Option => (initfile();
TextIO.output(getfid(), observedval))fun stop () =
(TextIO.output(getfid(), “\n\n”^”Simulation stopped after “^
Int.toString(step())^” steps\n”);
TextIO.closeOut(getfid());
fileid := NONE)
You must be logged in to post a comment.